Bug 166339 - Skia renderer is not applying gamma correction on text
Summary: Skia renderer is not applying gamma correction on text
Status: REOPENED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: graphics stack (show other bugs)
Version:
(earliest affected)
25.2.2.2 release
Hardware: All All
: medium minor
Assignee: Jonathan Clark
URL:
Whiteboard: target:26.2.0 target:25.8.0.0.beta2 t...
Keywords:
: 153456 (view as bug list)
Depends on:
Blocks:
 
Reported: 2025-04-25 15:51 UTC by tobias
Modified: 2025-07-03 19:15 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Text in Writer with Skia-backend enabled (13.05 KB, image/png)
2025-04-25 15:51 UTC, tobias
Details
Text in Writer with Skia-backend disabled (gdi based rendering?) (7.97 KB, image/png)
2025-04-25 15:52 UTC, tobias
Details
Text in MS Edge with default settings (also using Skia) (8.78 KB, image/png)
2025-04-25 16:04 UTC, tobias
Details
Text with and without windows-text-gamma.patch.0 (16.65 KB, image/png)
2025-07-02 20:29 UTC, Jonathan Clark
Details
ScreenshotA (33.41 KB, image/jpeg)
2025-07-03 14:07 UTC, Telesto
Details
Screenshot (72.27 KB, image/jpeg)
2025-07-03 14:07 UTC, Telesto
Details
Screenshot (33.34 KB, image/jpeg)
2025-07-03 14:09 UTC, Telesto
Details
Comparison screenshot (41.65 KB, image/png)
2025-07-03 15:07 UTC, Jonathan Clark
Details
Comparison screenshot detail (13.05 KB, image/png)
2025-07-03 15:12 UTC, Jonathan Clark
Details

Note You need to log in before you can comment on or make changes to this bug.
Description tobias 2025-04-25 15:51:35 UTC
Created attachment 200518 [details]
Text in Writer with Skia-backend enabled

Using the Skia-backend on Windows and X11, text is rendered too bold on white backgrounds and too light on dark backgrounds. There is also colour bleeding if you choose colours with a low brightness contrast, like pure green and pure red. Similar to this bug report: https://github.com/AvaloniaUI/Avalonia/issues/5282
There are also pronounced colour fringes from the Cleartype-like rendering.

I suspect, the Skia renderer is not applying correct gamma blending, i.e. is doing the linear blending in the sRGB colour-space. The sRGB colour-space has a gamma function on its values, e.g. RGB 128,128,128 is *not* neutral grey, but darker.

Some background reading about gamma correct font rendering:
> https://www.puredevsoftware.com/blog/2019/01/22/sub-pixel-gamma-correct-font-rendering/
> https://freetype.org/freetype2/docs/hinting/text-rendering-general.html
> https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/

Windows is using a gamma of 1.9 internally for font rendering with Cleartype, one could change these settings with Cleartype-Tuner, but it has become merely disfunctional.
> https://learn.microsoft.com/de-de/dotnet/desktop/wpf/advanced/cleartype-registry-settings?view=netframeworkdesktop-4.8

Qt, starting at some point in the version 5 life-cycle, is also using 1.9:
> https://mail.kde.org/pipermail/kde/2017-December/028694.html

Chromium used hard-coded values for its different platforms, but a large patch from Microsoft changed that on Windows, modern Edge is using that for some time now:
> https://developer.chrome.com/blog/better-text-rendering-in-chromium-based-browsers-on-windows

I couldn't find the lines in the codebase that handle the text rendering, I would appreciate any help to find them, so I can understand what's going on.
Comment 1 tobias 2025-04-25 15:52:19 UTC
Created attachment 200519 [details]
Text in Writer with Skia-backend disabled (gdi based rendering?)
Comment 2 tobias 2025-04-25 15:54:31 UTC
Note that even with the old rendering on Windows, which is slightly better than Skia, you still have contrast issues in the red on green example.
Comment 3 tobias 2025-04-25 16:04:50 UTC
Created attachment 200520 [details]
Text in MS Edge with default settings (also using Skia)

The rendering in Edge is mostly correct, slight contrast issue in the green on red text due to gamma 1.9 instead of 2.2
Comment 4 Buovjaga 2025-07-01 06:19:19 UTC
Interestingly we are patching Skia with: 1ad3f6b8d9e0ef1e921c3ed5526ea352d67265cf

"(do not) use SK_GAMMA_APPLY_TO_A8 also for Skia text on Windows

This is the Windows variant of the SK_GAMMA_APPLY_TO_A8 disabling,
again I don't quite understand why we need to disable this,
but with this patch Skia text rendering on Windows seems to be
pixel-perfect when compared with the VCL gen backend."
Comment 5 Jonathan Clark 2025-07-02 20:29:53 UTC
Created attachment 201612 [details]
Text with and without windows-text-gamma.patch.0

On the left side is with the Skia patch, on the right is without. Note the dark fringing around the red/green text on the left.
Comment 6 Jonathan Clark 2025-07-02 20:31:54 UTC
(In reply to Buovjaga from comment #4)
> Interestingly we are patching Skia with:
> 1ad3f6b8d9e0ef1e921c3ed5526ea352d67265cf
> 
> "(do not) use SK_GAMMA_APPLY_TO_A8 also for Skia text on Windows
> 
> This is the Windows variant of the SK_GAMMA_APPLY_TO_A8 disabling,
> again I don't quite understand why we need to disable this,
> but with this patch Skia text rendering on Windows seems to be
> pixel-perfect when compared with the VCL gen backend."

Confirmed: the bug is being caused by this patch.
Comment 7 Commit Notification 2025-07-02 23:23:03 UTC
Jonathan Clark committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/bfa28a257ae621747dddbb61f228705cf46079b8

tdf#166339 vcl: Removed Windows skia text gamma patch

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 8 Buovjaga 2025-07-03 05:54:20 UTC
(In reply to Commit Notification from comment #7)
> Jonathan Clark committed a patch related to this issue.
> It has been pushed to "master":
> 
> https://git.libreoffice.org/core/commit/
> bfa28a257ae621747dddbb61f228705cf46079b8
> 
> tdf#166339 vcl: Removed Windows skia text gamma patch

I tested on Windows and the green fringing in bold Chinese text reported in bug 153456 is gone. I notice the UI text becomes a lighter, comparing back and forth with two LibreOffice versions, looking at the main menu or a dialog like Help - About. You might even call it faint, so I wonder if it would lead to complaints.

Version: 26.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: bfa28a257ae621747dddbb61f228705cf46079b8
CPU threads: 2; OS: Windows 11 X86_64 (build 26100); UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded
Comment 9 Buovjaga 2025-07-03 07:04:24 UTC
Tobias: you are, of course, invited to test with a daily build: https://dev-builds.libreoffice.org/daily/master/current.html
Comment 10 Commit Notification 2025-07-03 08:59:05 UTC
Jonathan Clark committed a patch related to this issue.
It has been pushed to "libreoffice-25-8":

https://git.libreoffice.org/core/commit/8efaebbc54c3be7d76d9d0a9480f8d47473c65cf

tdf#166339 vcl: Removed Windows skia text gamma patch

It will be available in 25.8.0.0.beta2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 11 Commit Notification 2025-07-03 11:48:36 UTC
Jonathan Clark committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/9f509a54f61740785a1f135ddec99573ba3e8a41

tdf#166339 vcl: Removed Windows skia text gamma patch

It will be available in 25.2.6.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 12 Jonathan Clark 2025-07-03 13:41:21 UTC
I'm still investigating the X11 and MacOS versions of this bug. What I'm seeing looks like the artifacts I'd expect from Skia's own gamma hack, but I need to properly validate that.

https://skia.org/docs/dev/design/raster_tragedy/

(In reply to Buovjaga from comment #8)
> I tested on Windows and the green fringing in bold Chinese text reported in
> bug 153456 is gone.

If there are no objections, I think it's safe to mark bug 153456 a duplicate of this bug.

> I notice the UI text becomes a lighter, comparing back
> and forth with two LibreOffice versions, looking at the main menu or a
> dialog like Help - About. You might even call it faint, so I wonder if it
> would lead to complaints.

windows-text-gamma.patch.0 had a negative effect on subpixel antialiasing (demonstrated quite well by bug 153456). I can't rule out user complaints, but I think it would be better to address them by adjusting our UI font sizes on Windows, rather than relying on math tweaks that break ClearType.
Comment 13 Telesto 2025-07-03 14:07:10 UTC
Created attachment 201638 [details]
ScreenshotA
Comment 14 Telesto 2025-07-03 14:07:23 UTC
Created attachment 201639 [details]
Screenshot
Comment 15 Telesto 2025-07-03 14:09:57 UTC
Created attachment 201640 [details]
Screenshot
Comment 16 Telesto 2025-07-03 14:25:23 UTC
(In reply to Jonathan Clark from comment #12)
> > I notice the UI text becomes a lighter, comparing back
> > and forth with two LibreOffice versions, looking at the main menu or a
> > dialog like Help - About. You might even call it faint, so I wonder if it
> > would lead to complaints.

It's little faint, indeed. It's bit worse for for me with Dark UI. It's especially the UI font. The text in the main editor is fine

 
> windows-text-gamma.patch.0 had a negative effect on subpixel antialiasing
> (demonstrated quite well by bug 153456). I can't rule out user complaints,
> but I think it would be better to address them by adjusting our UI font
> sizes on Windows, rather than relying on math tweaks that break ClearType.

I'm unsure if you should backport it 25.2 already. Font rendering is pretty essential. The current approach has been proven since 2020, without many bug reports. Testing the waters first seems a better approach, IMHO.
Comment 17 Buovjaga 2025-07-03 14:40:19 UTC
*** Bug 153456 has been marked as a duplicate of this bug. ***
Comment 18 Buovjaga 2025-07-03 14:42:33 UTC
(In reply to Telesto from comment #16)
> I'm unsure if you should backport it 25.2 already. Font rendering is pretty
> essential. The current approach has been proven since 2020, without many bug
> reports. Testing the waters first seems a better approach, IMHO.

Patch went into 25.2.6, which will be released in September, so at least there is time to test: https://wiki.documentfoundation.org/ReleasePlan/25.2#25.2.6_release
Comment 19 Jonathan Clark 2025-07-03 15:07:50 UTC
Created attachment 201642 [details]
Comparison screenshot

Screenshot comparing UI text in light and dark mode, with and without the patch. This screenshot uses subpixel antialiasing, so may look different depending on your monitor's subpixel layout.

In light mode, UI text appears to have a lighter weight with the patch than without. In dark mode, the situation is reversed.
Comment 20 Jonathan Clark 2025-07-03 15:12:32 UTC
Created attachment 201643 [details]
Comparison screenshot detail

Another comparison screenshot, zoomed to show pixel-level differences.

Without the patch, there is intense green color fringing on most characters. In light mode, the fringing is on the outside of the glyphs. In dark mode, it is inside of the glyphs.

With the patch, the color fringing more accurately represents the subpixel coverage of the glyphs.
Comment 21 Jonathan Clark 2025-07-03 15:15:49 UTC
(In reply to Telesto from comment #16)
> (In reply to Jonathan Clark from comment #12)
> > > I notice the UI text becomes a lighter, comparing back
> > > and forth with two LibreOffice versions, looking at the main menu or a
> > > dialog like Help - About. You might even call it faint, so I wonder if it
> > > would lead to complaints.
> 
> It's little faint, indeed. It's bit worse for for me with Dark UI. It's
> especially the UI font. The text in the main editor is fine

Posted some additional UI text comparison screenshots to make sure we're on the same page. What I've observed is that the text has less weight in light mode, but more weight in dark mode.
Comment 22 Commit Notification 2025-07-03 19:12:41 UTC
Jonathan Clark committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/6e7860f021b27193b44f803b1e39f3508559bb47

tdf#166339 vcl: Use gamma-corrected font rendering in Skia

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 23 Telesto 2025-07-03 19:15:39 UTC
(In reply to Jonathan Clark from comment #21)
> Posted some additional UI text comparison screenshots to make sure we're on
> the same page. What I've observed is that the text has less weight in light
> mode, but more weight in dark mode.

Yes, same here