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

Text is not gamma corrected #230

Closed
jrmuizel opened this issue Mar 9, 2016 · 9 comments
Closed

Text is not gamma corrected #230

jrmuizel opened this issue Mar 9, 2016 · 9 comments

Comments

@jrmuizel
Copy link
Contributor

@jrmuizel jrmuizel commented Mar 9, 2016

On Windows and OS X text is blended in a way that tries to be more correct gamma.

For example, OS X blends using a gamma of 2.0. CoreGraphics implements this by reading from the destination framebuffer while shading (this is supported on all platforms that CoreGraphics runs on). Skia has a pre-blend step that tries to mimic this without needing to read from the framebuffer. See SkTMaskGamma_build_correcting_lut near https://skia.googlesource.com/skia.git/+/master/src/core/SkMaskGamma.cpp#78

@pcwalton
Copy link
Collaborator

@pcwalton pcwalton commented Apr 1, 2016

How does Core Graphics read from the destination framebuffer while shading? I thought that was unsupported on all desktop GPUs…

@jrmuizel
Copy link
Contributor Author

@jrmuizel jrmuizel commented Apr 1, 2016

GL_NV_texture_barrier lets you read from the destination framebuffer if you play nice.

@pcwalton
Copy link
Collaborator

@pcwalton pcwalton commented Apr 1, 2016

Very interesting. I do have that extension on my Intel.

This yields another alternative approach to that of WR2.

cc @glennw

@jrmuizel jrmuizel mentioned this issue Oct 21, 2016
20 of 24 tasks complete
@jrmuizel
Copy link
Contributor Author

@jrmuizel jrmuizel commented Nov 4, 2016

I think the best approach here is probably to do what Skia does and preblend. This approach will across all of the platforms we need to support and the fact that Skia does it suggests it good enough.

Basically it builds a lookup table for 1 << MAX_LUM_BITS (8) different luminance values using SkTMaskGamma_build_correcting_lut.

these lookup tables are then used to adjust the mask so that when composited using linear blending the result is somewhat similar to a gamma corrected results.

The larger impact of this is that we need to include the luminance value of the text color in the glyph cache key.

@glennw
Copy link
Member

@glennw glennw commented Nov 4, 2016

@jrmuizel That seems like a good approach.

@kvark
Copy link
Member

@kvark kvark commented Nov 7, 2016

If we don't aim to be precisely matching the native OS text rendering, we might also consider just using sRGB framebuffer for the GPU text anti-aliased rendering:

When blending is enabled along with the new sRGB update mode, red, green, and blue framebuffer color components are treated as sRGB values that are converted to linear color values, blended with the high-precision color values generated by fragment coloring, and then the blend result is encoded for sRGB just prior to being written into the framebuffer

@samlh
Copy link

@samlh samlh commented Nov 7, 2016

Fair warning, that extension has had some confusing specification history - see e.g. https://lists.freedesktop.org/archives/mesa-dev/2016-August/125215.html

@jrmuizel
Copy link
Contributor Author

@jrmuizel jrmuizel commented Dec 5, 2016

I've ported the skia preblend code to rust here: https://github.com/jrmuizel/mac-font-stuff/blob/master/src/lib.rs#L57

@changm
Copy link
Contributor

@changm changm commented Jan 30, 2017

This should be fixed for dwrite / cg fonts.

#774

#775

@changm changm closed this Jan 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.