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

Tweak SK_GAMMA_EXPONENT and SK_GAMMA_CONTRAST to get proper gamma correction for text #212

Open
Yasand123 opened this issue Jan 11, 2023 · 6 comments

Comments

@Yasand123
Copy link

Background.

You are probably familiar with this unfortunate limitation we have on Linux. Thankfully there's an option to apply proper gamma levels for text on Chromium independently, but it is not tweaked by default for the GNU/Linux operating system. It would be nice to have this done by you guys.

@jstkdng
Copy link
Member

jstkdng commented Jan 11, 2023

So, you'd like us to add a patch that changes the gamma values? to which values exactly?

@Yasand123
Copy link
Author

Yasand123 commented Jan 11, 2023

So, you'd like us to add a patch that changes the gamma values? to which values exactly?

General consensus is that it should be somewhere between 1.8 and 2.2. This test by Alankila should give us a good idea on what the value should be. From my testing on different displays, I find 2.2 to be the closest to what I would consider a good default. In reality there's no "correct" exponent value, but 2.2 seems to be a very good approximation and any error caused by it is minute and it's certainly better than having no gamma correction at all.

That's for SK_GAMMA_EXPONENT. As for SK_GAMMA_CONTRAST maybe it should be ignored for now because it's more of a preference.

@jstkdng
Copy link
Member

jstkdng commented Jan 14, 2023

ok, the patch seems simple enough to maintain

diff --git a/skia/BUILD.gn b/skia/BUILD.gn
index b2c8b79..7e2ee53 100644
--- a/skia/BUILD.gn
+++ b/skia/BUILD.gn
@@ -139,7 +139,7 @@ config("skia_library_config") {
   # Settings for text blitting, chosen to approximate the system browser.
   if (is_linux || is_chromeos) {
     defines += [
-      "SK_GAMMA_EXPONENT=1.2",
+      "SK_GAMMA_EXPONENT=2.2",
       "SK_GAMMA_CONTRAST=0.2",
     ]
   } else if (is_android) {

@jstkdng
Copy link
Member

jstkdng commented Jan 14, 2023

Ok, I've built a new version with that patch enabled.
https://download.opensuse.org/repositories/home:/justkidding:/arch/Arch/x86_64/ungoogled-chromium-109.0.5414.74-2-x86_64.pkg.tar.zst

can you give it a test?

@Yasand123
Copy link
Author

Alright. After some testing it seems 2.2 for SK_GAMMA_EXPONENT is good. Contrast might need to be increased a little, maybe to ~0.5, but that needs more testing. Correcting the gamma level fixed the semi-broken rendering for dark themes in websites, as previously the dark background would bleed into the text affecting its thickness and color.

As for light themes, that's a different story. Increasing the gamma exponent meant, by definition, that the dark text would look a little too thin on lighter backgrounds. You either get proper dark mode or proper light mode but not both simultaneously (by default).

This issue was expected, and I am currently playing with some stem darkening parameters for FreeType. Stem darkening was created as a counter measure for exactly this purpose, and both Windows and macOS use it as both do gamma corrected rendering system-wide.

The settings in question are autofitter:darkening-parameters and cff:darkening-parameters.

Unfortunately I can't seem to be able get the proper values yet, I had the impression that it would be a lot more straightforward but seeing how time consuming this process is, I doubt the average user would bother. The good news is that if you're primarily a dark mode user you'll be happy without having to tweak anything.

I'll be testing stuff from time to time and I'll make sure to give an update if I ever find a good solution. But yeah, we definitely cannot make this the default unfortunately.

Maybe keep the link and patch here for those who are interested. I personally will probably keep patching ungoogled-chromium as I'm primarily a dark mode user.

Thank you for your time, and for the pre-compiled package, I really appreciate it! If you have no further comments feel free to close the issue.

@Yasand123
Copy link
Author

Update: I did one last test and I think this looks very acceptable now, only enabling stem darkening without editing any of the extra parameters (so cff:no-stem-darkening=0 and autofitter:no-stem-darkening=0 exported as env variables) gives us a good result for light themes. So I guess it's still a viable option for those who want it? The issue is, I am not sure if everyone will be happy about the changes, and I don't think you can maintain 2 builds simultaneously. It's ultimately up to you.

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

No branches or pull requests

2 participants