ungoogled-software / ungoogled-chromium-archlinux

Arch Linux packaging for ungoogled-chromium
BSD 3-Clause "New" or "Revised" License
344 stars 38 forks source link

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

Open Yasand123 opened 1 year ago

Yasand123 commented 1 year ago

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 commented 1 year ago

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

Yasand123 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.