xournalpp icon indicating copy to clipboard operation
xournalpp copied to clipboard

Color inversion

Open fxkrait opened this issue 6 years ago • 26 comments

I would like to be able to write my notes on a dark background, but then print and export them in the standard white background.

Currently, I can set the color of each page individually. However, if I choose to export the notes, I have to manually edit the background color of each page individually to white. This takes too long. It would also be nice to be able to mass change color of the writing as well.

Potential solutions include:

  1. Allow the mass selection of multiple pages to be able to change the properties in bulk from the page bar.
  • shift select multiple pages
  • control + a: Select all pages
  1. A dark theme that changes the color of the background and potentially some of the pen colors.(user defined as to what they map to between the dark theme being written on and light theme export) Yet, upon export the user can choose to export in the "light" theme option.

Notes: 2 is a better solution in the whole as it also allows pen colors to be changed between the different themes. For example, on a light theme I would use white background with black ink. However, on a dark theme, I would use a dark background, and maybe light grey ink.

  • In this solution, the theme could automatically map the light themes black ink color to the grey color. So upon export, anything written in the dark theme with grey ink, can be exported in the light theme as white background with black ink.

fxkrait avatar May 25 '19 08:05 fxkrait

I was just now looking for this. I would love this feature. Evince supports inverting PDF colors, which works great. There also seems to be a patch set for Xournal (not Xournal++) that adds this feature at https://gitlab.com/gi1242/xournal.

lalten avatar May 25 '19 11:05 lalten

I fully support this request. In addition, It would be useful to have such a colored, semitransparent background ON TOP of a pdf background. I use xournalpp to read and annotate articles in pdf who are on white background. In order to avoid straining my eyes I add a green background. For the moment I produce it with a semi-transparent filled full-page highlighter. This is of course not optimal. A solution as proposed by fxkrait would be better, but again I stress that it should be allowed ON TOP of a pdf background. Thanks a lot for your work!

enricoar avatar May 29 '19 13:05 enricoar

If this is for relieving eye-strain or taking notes in a dark setting without disrupting others there may be an option in your windowing system already:

Mac: Cmd+Alt+Ctrl+8 Windows10: 1. Hold "Win" and "+" 2. Wait 3 seconds 3. Press "ctrl" + "alt" + "i" Windows 10,8,7: Settings->EaseOfAccess->Magnifier->gear icon->color inversion Linux KDE - System Settings->Desktop effects->Invert (entire screen or individual windows) Linux Compiz - CompizConfig Settings Manager->Negative. (entire screen or individual windows) Linux X-Windows: Without the window manager you can tell X-Windows directly using xcalib:

    sudo apt-get install xcalib
    xcalib -s 0 -invert -alter
    xcalib -c    #clear.. back to normal

There is also a program called xrandr-invert-colors that is said to work better with multi-monitor setups.

JJones780 avatar Jun 02 '19 21:06 JJones780

I would also like to suggest handling it the same way as zathura does, which works extremely well IMO. In zathura it's possible to define the background and foreground colors and whether to invert them, all colors in the document are then mapped between those 2 values.

For example:

set recolor                     true
set recolor-lightcolor          "#182e3a"
set recolor-darkcolor           "#fffefd"

shiro avatar Mar 13 '20 21:03 shiro

I agree that inverting colors would be great. In my case, I'd like to use it to take student pdf (so white background/black text), invert it only during annotation (to save my eyes), and then save it as normal white background/black text so that I can give it back to students. Thanks!

tobiasBora avatar Jun 06 '20 18:06 tobiasBora

I'd like to offer my help in implementing an algorithm that inverts the brightness of any color while keeping the original hue

AnotherNeko avatar Jan 26 '21 09:01 AnotherNeko

If this is for relieving eye-strain or taking notes in a dark setting without disrupting others there may be an option in your windowing system already:

Mac: Cmd+Alt+Ctrl+8 Windows10: 1. Hold "Win" and "+" 2. Wait 3 seconds 3. Press "ctrl" + "alt" + "i" Windows 10,8,7: Settings->EaseOfAccess->Magnifier->gear icon->color inversion Linux KDE - System Settings->Desktop effects->Invert (entire screen or individual windows) Linux Compiz - CompizConfig Settings Manager->Negative. (entire screen or individual windows) Linux X-Windows: Without the window manager you can tell X-Windows directly using xcalib:

    sudo apt-get install xcalib
    xcalib -s 0 -invert -alter
    xcalib -c    #clear.. back to normal

There is also a program called xrandr-invert-colors that is said to work better with multi-monitor setups.

I think you guys just need to reverse any colors on paper or PDF page when displaying while keep the original settings not change.

That's what you guys need to do.

Just like the Night Mode in gnome PDF viewer: https://wiki.gnome.org/Apps/Evince

image

yingshaoxo avatar Feb 05 '21 01:02 yingshaoxo

This would help save my eyes after long note-taking sessions!

Svalorzen avatar Jun 02 '21 18:06 Svalorzen

Yes, Please work on this feature.

mostafatouny avatar Jan 21 '23 04:01 mostafatouny

You wrote about inverting every color. Colors may be important. If they are inverted, they could mean different things. I think it would be a good idea to only invert the background and the default black pen and the default white pen. Saved in the file would still be the "normal" colors, so converting to PDF could use the data from the file not from the display.

DerMueller avatar Mar 13 '23 08:03 DerMueller

Yes, you are right

Saved data should remain the same, but the display color get changed

On Mon, Mar 13, 2023, 4:14 PM DerMueller @.***> wrote:

You wrote about inverting every color. Colors may be important. If they are inverted, they could mean different things. I think it would be a good idea to only invert the background and the default black pen and the default white pen. Saved in the file would still be the "normal" colors, so converting to PDF could use the data from the file not from the display.

— Reply to this email directly, view it on GitHub https://github.com/xournalpp/xournalpp/issues/1172#issuecomment-1465689517, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEDE7LLDE27RXYCPW6HXCDTW33JO5ANCNFSM4HPUE5PQ . You are receiving this because you commented.Message ID: @.***>

yingshaoxo avatar Mar 13 '23 11:03 yingshaoxo

This feature would be a really useful addition.

I would also like to suggest allowing to invert colours on an imported PDF files. It would be nice if this would work independently of the background / pen colour and it would be fine if the colours got inverted as well, as I guess there's no way of preserving the colours on an imported PDF.

This would be a great feature if I had to annotate already existing PDF file and I still wanted to do it with a dark background (as most PDFs are exported with a white background)

JustCryen avatar Jun 13 '23 19:06 JustCryen

I've messed around with inversion filters in Krita, and I think I found a solution for this: apply a +180 degree hue shift after inverting each RGB channel. This results in colors and highlights looking about the same while flipping the brightness of every pixel.

AnotherNeko avatar Jun 13 '23 21:06 AnotherNeko

I've found a workaround for anyone using Gnome. This works on Gnome with Wayland, I'd imagine it works on Gnome with X11 as well, but I haven't tested that combination. I'm running Gnome 44, haven't tested this on any previous Gnome version.

Normal

Screenshot from 2023-07-07 10-07-44

With workaround

Screenshot from 2023-07-07 10-07-14

Steps

You'll want to make sure you're using a light gtk theme and light xournal theme (from settings), otherwise the window will become bright when the colors invert.

Gnome Settings -> Accessibility -> Zoom, then

  • Set magnification factor to 1
  • Disable crosshairs
  • Enable inverted option
  • Adjust the brightness, contrast and color as you prefer

image

Non-Gnome users

You may find success with this workaround that was mentioned earlier in this thread by Jones780 https://github.com/xournalpp/xournalpp/issues/1172#issuecomment-498065344

francium avatar Jul 07 '23 14:07 francium

Cool find @francium

I have Gnome 43.6 X11 here with dark theme and this "Dark Theme" option doesn't seem to do much, I just noticed it only changes the background color of the sidebar, but everything else was already dark from the system dark theme: buttons, toolbar, menus, options, dialogs, and so on all use the system dark theme.

scarlion1 avatar Jul 08 '23 22:07 scarlion1

@scarlion1 don't confuse the gtk theme from the pdf's colors. The buttons, toolbars, menus is controlled by the gtk theme. I think xournalpp still uses some old gtk version so it's toolbar, buttons, etc don't automatically switch like other apps might when you change your gnome dark/light theme setting.

The pdf's color's don't change because of gtk/gnome dark/light theme setting. For that we need the code to support inverting the pdf's colors

francium avatar Jul 08 '23 23:07 francium

Another workaround is to use KDE Plasma's feature of inverting colors of individual windows (e.g., see https://askubuntu.com/questions/63930/how-can-i-invert-my-display-colours-under-kubuntu)

fanzhuyifan avatar Oct 02 '23 21:10 fanzhuyifan

any updates?

Xyueta avatar Feb 26 '24 19:02 Xyueta

I'm not terribly familiar with the code base but I did manage to get inverted pdf colors by changing xournalpp/src/core/view/background/PdfBackgroundView.cpp to:

#include "PdfBackgroundView.h"

#include <glib.h>  // for g_warning

#include "control/PdfCache.h"                // for PdfCache
#include "util/Assert.h"                     // for xoj_assert
#include "view/background/BackgroundView.h"  // for BackgroundView, view

using namespace xoj::view;

PdfBackgroundView::PdfBackgroundView(double pageWidth, double pageHeight, size_t pageNo, PdfCache* pdfCache):
        BackgroundView(pageWidth, pageHeight), pageNo(pageNo), pdfCache(pdfCache) {}

void PdfBackgroundView::draw(cairo_t* cr) const {
    if (pdfCache) {
        // get zoom from cairo
        cairo_matrix_t matrix = {0};
        cairo_get_matrix(cr, &matrix);
        xoj_assert(matrix.xx == matrix.yy && matrix.xy == 0.0 && matrix.yx == 0.0);  // Homothety matrix
        double scaleX;
        double scaleY;
        cairo_surface_get_device_scale(cairo_get_target(cr), &scaleX, &scaleY);
        xoj_assert(scaleX == scaleY);
        double pixelsPerPageUnit = matrix.xx * scaleX;
        pdfCache->render(cr, pageNo, pixelsPerPageUnit, pageWidth, pageHeight);
        // --- Begin Color Inversion ---
        // Save the current state of the Cairo context
        cairo_save(cr);

        // Set the operator to CAIRO_OPERATOR_DIFFERENCE to invert colors
        cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE);

        // Set the source color to white (1.0, 1.0, 1.0)
        cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);

        // Paint over the entire area to invert colors
        cairo_rectangle(cr, 0, 0, pageWidth, pageHeight);
        cairo_fill(cr);

        // Restore the Cairo context to its previous state
        cairo_restore(cr);
        // --- End Color Inversion ---
    } else {
        g_warning("PdfBackgroundView::draw Missing pdf cache: cannot render the pdf page");
        PdfCache::renderMissingPdfPage(cr, pageWidth, pageHeight);
    }
}

I'll try and get it compiling and running without errors over the next few days, right now I appear to be missing all toolbars and most menus. Given that this has been open for 5 years now I figure any progress is better than none and it's 12am on a weekday.

atodoron avatar Oct 07 '24 13:10 atodoron

Implementing this will require some thinking. What happens when you export in pdf for instance? Should imported images be inverted as well? There are many questions such a feature rises.

Essentially, I think it boils down to this: Is the user writing in white on a black document, or are they writing in black on a white page but seeing as if they were writing in white on a black page? To me, the latter would make more sense, but it means thinking through how the UI should behave.

bhennion avatar Oct 08 '24 18:10 bhennion

Implementing this will require some thinking. What happens when you export in pdf for instance? Should imported images be inverted as well? There are many questions such a feature rises.

Essentially, I think it boils down to this: Is the user writing in white on a black document, or are they writing in black on a white page but seeing as if they were writing in white on a black page? To me, the latter would make more sense, but it means thinking through how the UI should behave.

Colour inversion should have no effect on the document file (just like zooming). It should be a read-only feature that does not modify the document in any way.

debnath-d avatar Oct 09 '24 06:10 debnath-d

Ok, I think we agree on that. Then the UI need to be adapted in several places:

  • We should not only invert the colors of the background PDF (or page in general), but also the colors of any annotation - otherwise the user may not see them properly
  • We should also probably do something to the Color toolbar icons: if you select red and what you see when writing is turquoise, the feeling will be awkward. Still, inverting the displayed colors of the icons is not great either: the user should still know what it'll look like in the end.
  • The cursors colors should be adapted as well
  • Other things I'm forgetting.

This app is not just a viewer, so edition-related aspects must be thought through as well.

bhennion avatar Oct 09 '24 15:10 bhennion

Considering color theory, I think it makes more sense to invert the luminosity rather than inverting each color channel individually. One way to do this is pseudocode colorInvertedLuminosity=hueRotate(Color(1-pixel.r, 1-pixel.g, 1-pixel.b), PI)

On October 9, 2024 11:13:25 AM EDT, Benjamin Hennion @.***> wrote:

Ok, I think we agree on that. Then the UI need to be adapted in several places:

  • We should not only invert the colors of the background PDF (or page in general), but also the colors of any annotation - otherwise the user may not see them properly
  • We should also probably do something to the Color toolbar icons: if you select red and what you see when writing is turquoise, the feeling will be awkward. Still, inverting the displayed colors of the icons is not great either: the user should still know what it'll look like in the end.
  • The cursors colors should be adapted as well
  • Other things I'm forgetting.

This app is not just a viewer, so edition-related aspects must be thought through as well.

-- Reply to this email directly or view it on GitHub: https://github.com/xournalpp/xournalpp/issues/1172#issuecomment-2402621328 You are receiving this because you commented.

Message ID: @.***>

AnotherNeko avatar Oct 09 '24 15:10 AnotherNeko

Considering color theory, I think it makes more sense to invert the luminosity rather than inverting each color channel individually. One way to do this is colorInvertedLuminosity=hueRotate(Color(1-pixel.r, 1-pixel.g, 1-pixel.b), PI)

Yes, this is better. When using Okular, I prefer using "Invert Lightness" which does the same thing.

@bhennion please consider this suggestion.

debnath-d avatar Oct 09 '24 16:10 debnath-d

I wouldn't even change the colors. just invert black-white. That alone would be useful for multiple people. Something like @francium did as a workaround. If you want color inversion/lightning inversion, it could be possible to switch that in the settings. Would it be possible to switch the colors on the fly (like in OneNote)? It would be handy to easely switch between white/inverted, to check if the colors look right.

DerMueller avatar Oct 10 '24 05:10 DerMueller

What I believe @DerMueller is saying that the back/white ink colour gets inverted so that you can see them on the wrong colour background, e.g. normal mode has black pen and white paper, inverted mode has white pen default and black paper.

In due course it may be a better idea to add this as part of a night mode enhancement that is application wide. Currently I have a bunch of inverted notes that I don't actually want to be black bg/white fg but am forced to use because of the way the system handles paper colour changes.

@bhennion is there any developer documentation out there on how to isolate a build from the regular system? It currently seems like there is a conflict between the version I have from the OS installed and the one I'm building myself.

atodoron avatar Oct 10 '24 21:10 atodoron

In case some of you interested in this missed it: I started implementing this in https://github.com/xournalpp/xournalpp/pull/6090 if you want to influence (like the formula used for inverting/recoloring or what elements should be included in the recoloring or what parameters should be configurable) the implementation feel free to join the discussion.

atticus-sullivan avatar Nov 26 '24 22:11 atticus-sullivan

With https://github.com/xournalpp/xournalpp/pull/6090 merged, should we close this issue?

atticus-sullivan avatar Dec 10 '24 15:12 atticus-sullivan

How exactly do I enable it?

salastro avatar Apr 19 '25 14:04 salastro

Not sure if the PR is still only available on nightly (so you might not have this option yet)

Then the setting is available in the preferences under View

atticus-sullivan avatar Apr 19 '25 17:04 atticus-sullivan