Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix high contrast render in midnight mode #197

Closed
wants to merge 4 commits into from

Conversation

Atreyagaurav
Copy link
Contributor

Uses the Lightness values from the pdf-view-midnight-colors fg and bg to scale the inverted color's lightness. Band-aid till a better method is found.

Related to: #69

Uses the Lightness values from the `pdf-view-midnight-colors` `fg` and `bg` to scale the inverted color's lightness.
Band-aid till better method is found.

Related to: vedang#69
@Atreyagaurav
Copy link
Contributor Author

Atreyagaurav commented Mar 3, 2023

I'll add this here as well, so you don't have to head over to the related PR. It tries to make the #69 implementation better by trying to respect the user configured fg and bg color lightness in the midnight mode.

Here, the bottom part of the image is when I have inverted the PDF.

This is on: (setq pdf-view-midnight-colors '("gray70" . "gray25")), it works normally (same as after #69) if you have (setq pdf-view-midnight-colors '("white" . "black")), and it works well for default pdf-view-midnight-colors as well.

image

I haven't tested it for a variety of colors, but in theory this should work. This should at least act as a band-aid for the sudden change to high contrast rendering that doesn't respect user configurations. And it might be a good idea to add that only lightness value is used in the documentation.

@Atreyagaurav
Copy link
Contributor Author

@fw623 @smithzvk Did you guys test this out? Does this work, or do you have some suggestions?

@smithzvk
Copy link
Contributor

smithzvk commented Mar 28, 2023 via email

@Atreyagaurav
Copy link
Contributor Author

Hi @vedang, you're probably busy, but can you look into it?

The new default with oklab color inversion is great, so people like me are reluctant to go back to the old behavior where the customization colors are respected, but images are grayscale.

I've made this modification as soon as I updated pdf-tools and came across it. And I've been using it for almost a month, and it works well for my use cases. Others might benefit from it too.

@smithzvk
Copy link
Contributor

smithzvk commented Apr 4, 2023

Ok, I took a look at this and it looks like it solves the issue. I made some changes which I think are improvements. I can't tack them onto this PR as I'm not a maintainer of this software. Please look here for a commit which you can try out and add if you like it (I certainly do): smithzvk@61ce548 smithzvk@777530e

High contrast
image
Low contrast
image
Blue theme
image
Weird colors
image

I was bugged that it didn't pick up the hue from the background, however, so I made the all color a/b parameters start from the a/b parameters of the BG color. This makes the PDF background (white) map to your BG color and PDF foreground (black) map to your FG color, which can be set to your theme background making it seem pretty seamless. Note that if you set your BG and FG to a color theme without zero saturation (a gray tone of some sort), then you recover the original behavior.

I also reinstated the cached transforms for background and the last color computed.

I also refactored the loop to move the switch statement outside of the loop. It is more repetitive, but it was needed to get rid of some warnings about potentially uninitialized variables. It should also be faster as the branch was removed from the loop.

I also ditched the gamma correction as it seemed to be doing the wrong thing and I never had a theoretical reasoning for it. I can get similar results if I just set my BG color to something like gray5 instead of black. Barely a difference in background but the hinting on the fonts is showing again. The root of my issue may have always been some kind of display calibration issue.

@Atreyagaurav
Copy link
Contributor Author

Atreyagaurav commented Apr 4, 2023

@smithzvk Thank you for checking it out and the addition of the color as well instead of just the lightness from fg and bg.

Out of topic but thank you for introducing the oklab inversion and your initial code, I took that code to write a shader for picom and now I can use this inversion on any window if they don't have dark mode. It's great.

@smithzvk
Copy link
Contributor

smithzvk commented Apr 5, 2023

@vedang Just FYI, you didn't request a review, but I think this looks pretty good. Let me know if there is anything I can do to help move this forward.

@Atreyagaurav thanks. Out of modesty, I'll point out that all I did was scratch my own itch using a bunch of work done by someone else (Björn Ottosson, Emacs, and Pdf-Tools). The capability you describe with picom makes me want to try it, thanks for pointing it out. A lot of software out there is broken in terms of dark themes (Ghidra, GNU Radio, GMAT, most Java stuff that isn't JavaFX based).

@Atreyagaurav
Copy link
Contributor Author

@vedang Hi. It has been a really long time, could you find a little bit of your time to review it and possibly merge it? I'm sure the unexpected change in default has other people also wondering why their config is broken.

@smithzvk Open source is all about trying out things based on the other people's prior work so you definitely deserve the credit for making this possible. And let me know (my contact info is in my readme) if you tried the picom thing, it's working great for me on qpdfview. I'm sure it'll do well in other ones as well.

@vedang
Copy link
Owner

vedang commented May 24, 2023

Thank you for the work @Atreyagaurav ! I will review the change this week and merge it in :(

I'm sad about the fact that I am not able to give much time to pdf-tools at the moment. But the fact that this has been reviewed by @smithzvk helps a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants