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
[css-color] Add OKLab, OKLCH #6642
Comments
|
Note - the gamut mapping section does not yet exist, because gamut mapping in CIE LCH gave unacceptable results in the 270-330 degree hue range and also because deltaE 2000 is complex, but is needed for good results and deltaE 76 is fast but not good enough. Using OKLCH and deltaEOK (which is the simple root-rum-of-squares) gives better results and is computationally simple. |
|
lgtm, nice attention to detail |
|
Curious, would it use the new lightness discussed here? https://bottosson.github.io/posts/colorpicker/#intermission---a-new-lightness-estimate-for-oklab Or would it be based on the original Oklab work that doesn't adjust the lightness? |
|
The new Lr lightness estimator brings in a dependency on viewing conditions, which the original OK L did not have; and which is an advantage of the original OK L especially if it allows extension to HDR or at least EDR. Lr also adds a little computational complexity. I would like to examine it some more and also see how it impacts deltaE, but my initial impression is to stick with the original OK L. I'm very open to thoughts on which would be the better option though. |
Makes sense. I've only played with Lr to experiment with Okhsl and Okhsv, but use it in no other way. So there may be good reasons to avoid it if using it for distancing. I also hadn't thought of implications in regards to HDR. Something to experiment with though. |
|
I quickly read thru the slides, and didn't catch this detail - can you elaborate on why we'd want to add these in addition to the existing lab()/lch(), rather than just changing those functions to use the OKLab space? Is there a good reason to keep the existing Lab functions? |
Good question, and the main reason I suggest keeping them around is because there is lots of hardware (instrumentation, like spectrophotometers) and software which generates Lab (or LCH, or both) values. The secondary reason is that Lab and LCH have decades of user experience with them, while OKLab/OKLCH have less than a year. So:
|
|
My issue is just that, given a choice between "lab" and "oklab", where the two look practically identical in most cases, people will naturally reach for "lab". We should bless the shortest, most convenient names with the most preferred syntaxes, even if we allow other types in other ways. (And in particular, we've accidentally set a precedent of all the specialized color functions have three-letter names. That probably can't persist forever, but for now, at least, "oklab" would join "color" as looking a little out-of-place and possibly "advanced". Presumably we'd be able to offer the old Lab via |
|
Three letters you say?
But this idea was already dismissed for cie() = cie( /* Lab */ [<percentage> && <number>{2}]
| /* Luv */ <percentage>{3}
| /* LCH */ [<number>{2} && <angle>]
[ / <alpha-value> ]?
)
okl() = okl( /* Lab */ [<percentage> && <number>{2}]
| /* LCH */ [<number>{2} && <angle>]
[ / <alpha-value> ]?
) |
I don't think any precedent has been set. |
|
So, I am curious. It seems there is talk about using chroma reduction using Oklch for gamut mapping/reduction. I was playing around with this and was noticing some interesting things when gamut mapping using this method. Granted, maybe I'm doing something wrong here. This is based on the same algorithm used in color.js for Lch chroma and using the currently specified ∆Eok in that library. When using something like display-p3, things get mapped very similar as they do with Lch vs Oklch, granted I think their blue range is very similar. But when using something like rec2020 which has a wider blue range, the mapping gets dull blues. (oklch chroma reduction on top). This doesn't happen as much with greens and lesser with reds. Now granted there doesn't seem to be an official algorithm posted yet, and so I'm more curious if all these edge cases have been evaluated. Maybe the actual algorithm that is to be used compensates for this. I'm more curious if it improves in some places, but lesser in others, or if there is a better algorithm (different from the CIELCH one used on colorjs.io) that is planned to be used that works well with Oklch? It's possible I'm just not implementing correctly, and in that case, I will wait patiently to better understand how the reduction is actually done, or keep plugging away to see what I'm doing wrong |
|
Thanks for investigating. Any chance you could post your test code? |
|
Yep, let me throw something together publicly that you can play around with. |
rgb(), hsl(), hwb(), lab(), lch(). I specifically said it was accidental, but it's still there, and people pattern-match. color() is the exception, and it is an exceptional function compared to the others. This doesn't mean we're forced into this, but it does, I think, imply that people will reach for the 3-latter Regardless, tho, that wasn't my point. My point is just that when having two names that are variants of each other, one of which is longer than the other, people will naturally reach for the shorter one by default; this is a relatively standard principle of language-design UX. If we think that OKLab is better than Lab for authors, then we'll be doing them a disservice by having |
|
I do think that rec2020 gamut mapping needs more investigation (as noted on the next steps slide) and in particular I want to do some I notice that OKLab and CIE Lab have different lightness estimation for high-chroma blues. Here is rec2020 blue with OKLCH chroma reduced to zero without clip and with clip on deltaEOK < 0.02. In both, the colors on the upper part are the sRGB color (if in gamut) or salmon (if in display-p3) or red (if outside display-p3) while the lower part shows the linear-light display-p3 component values. I can easily put the same thing together where the upper part is display-p3 and the gamut clip is to the display-p3 gamut (but it will currently only display on Safari TP and BFO Publisher) |
oof. That would be super confusing, surely. However, renaming |
|
So, here is a link to a working example with code. You can edit it and play around with it: https://facelessuser.github.io/coloraide/playground/?source=https%3A%2F%2Fgist.githubusercontent.com%2Ffacelessuser%2F26ff61052f1e4a180d2f98a499d08595%2Fraw%2F454c4a9911e626e537f184b281f51382e83025aa%2Fokfit.py Basically, I am just interpolating between black and blue in the rec2020 space. Then I convert it to sRGB and fit it in that space and display it directly. I scale the ∆Eok to by 100 as the difference between black and white is ~0 - 1 and ∆E2000 is ~0-100. I've done it without the scaling, adjusting the limits and such, and the results are basically the same. It seems green starts getting mixed in as chroma reduces. Again. Maybe there are some assumptions here that just aren't right. This is the exact same algorithm used for the CIELCH fitting. |
|
I have been debating this with myself for a good while, hence the lack of comment. I did watch @svgeesus' talk (and I really recommend watching it to anyone who wants to have an opinion on this), and I do agree there are significant advantages in Oklab over Lab. However, Lab has been established for 45 years. It has a ton of tooling around it. It has drawbacks, yes, but those are widely studied. Same as all the color formats currently in CSS, they all have drawbacks, but are all old and established, and their drawbacks studied and known. Oklab on the other hand is very new. It has not yet been fully explored, and it has almost no tooling that supports it. Its advantages are known, but its drawbacks are still being researched. It seems a little premature to add it to CSS, especially as a named function. I’m not saying we shouldn't, but it gives me pause. As a secondary point, we need to decide when we add things as a named function and when as a I disagree that authors will always reach for the shortest syntax. Firstly, a lot of the time colors are reused via variables, not re-specified. Secondly, if that were true, One issue with Oklab is that it uses different coordinates than Lab, namely 0-1 ranges instead of 0-100. If we do add such a syntax in CSS, I wonder if there is value in trying to harmonize the two a little. |
I made my point pithily in the middle of a longer argument, but to be more specific: given two seemingly identical or very similar pieces of functionality, people will tend to reach for the one with shorter name/syntax, both because it's easier, and because (partially due to this effect) API designers usually give the preferred solution a shorter name. Hex notation, especially 3-char hex, is substantially different in both abilities and syntax to any other color function, so it doesn't necessarily fit into this. On the other hand, lab() and oklab() functions, which take essentially identical arguments and output approximately identical colors, are exactly the pattern I'm talking about. (Also who would choose "oklab" over "lab"? If it was betterlab(), sure, but just ok? Pass. ^_^) (Also, for the generic case of "I need a quick color and I know very roughly what it should be but don't care about the details right now", I personally do reach for 3-char hex first precisely because it is the shortest color syntax that satisfies that use-case.)
|
|
@svgeesus made the point that we need OkLab to be able to specify a reasonable gamut mapping algorithm in Color 4, and as an interpolation space for gradients etc, so it doesn't actually matter whether authors use it, because we can still use it as an interpolation and gamut mapping space. For me that tips the scales towards yes, let's add this. My question regarding named functions vs |
|
These edits have now done everything agreed, with the exception of Define gamut mapping which has it's own issue |
Thanks! I tested it out and got much better results on neutrals (zeroes to 8dp). Updated sample code (and also color.js) |
|
Sounds good, glad I could help! |
|
Exciting stuff! This would certainly increase the reach of Oklab significantly. Let me know if I can be of assistance in any way. One thing to discuss is that I've been considering making a second revision of Oklab for a few reasons. The things I'm considering addressing are:
Do you have any thoughts around this? This would end up being the most significant usage of Oklab I think, so it makes sense to make sure it is fit for purpose! Thanks! |
I believe the most recent M1 matrix in the CSS spec no longer uses the M1 matrix from your article, but now uses a recalculated M1 based on the XYZ to Linear sRGB transfer function which is based on the 4 digit whitepoint now. Or are you referring to some other aspect of the M1 calculation that also should be changed? |
|
@bottosson wrote
I must admit that I already did this, in the sample code which is part of CSS Color 4. I had been troubled by the neutral colors non-zero Chroma in OKLCH, which was worst at white and thus likely due to whitepoint differences. It seems you had used the ASTM XYZ values, to 6 significant figures; while for the various predefined RGB spaces I was getting the best results with the 4-digit x,y values. @facelessuser posted in this thread explaining how to derive a new M1 based on your linear-srgb to LMS C++ code and my (well, the sRGB standard) XYZ to sRGB, so that is what I used and it means roundtripping is now excellent.
Yes in general, rounding is a consistent source of problems and they compound.
That would be a breaking change but I would be interested to know more. |
|
Yeah, exactly. Definitely makes sense that that solution works, although would be good to define the matrix in a way that is independent of sRGB. I think a good way to define M1 would be along these lines (here in python and numpy, but it is just matrix operations): This way the accuracy of white mapping to zero chroma is only dependent on the accuracy of the computations, not the rounding of the matrices. Regarding the scaling of a&b: Yes, this would certainly be a breaking change, so I am a bit hesitant about it as well. On the other hand the potential improvement is pretty large. I unfortunately didn't spend that much time calculating and validating that scaling factor when I first derived Oklab since I was mostly focused on the orthogonality between L, C and h (and I didn't expect it to become so widespread so quickly), and it seems like it is off by quite a bit. I've recently done some tests with color distance datasets as implemented in Colorio |
|
(re-opening so that more people will notice this valuable discussion) |
|
For the scaling of a & b , this statement in the OKlab defining article did give me slight pause:
because the formula for deltaE2000 introduces a mean-chroma-dependent asymmetry between a and b, strongest right on the neutral axis (recalculated a is 1.5 times b) then fading off to below 1.1 at chroma 27 and below 1.01 at chroma 40. csswg-drafts/css-color-4/deltaE2000.js Lines 27 to 40 in b9ec4cb
(For the curious, the values of Cbar, G, and adash are tabulated here) This means that:
Which is a very useful property of OKLab, for gamut mapping and gradient generation |
|
The new matrix calculation really is much closer when calculating the transform for white. This is super useful to know. It is also fairly easy to get the sRGB Linear -> LMS calculation (for anyone who needs it to calculate Okhsl and Okhsv), you just need to take your higher precision XYZ D65 to LMS matrix and dot it with your RGB to XYZ transform so you are left with the RGB to LMS matrix. |
|
Closing again as the edits have been made and discussion seems to have died down. |
https://bugs.webkit.org/show_bug.cgi?id=233507 Reviewed by Cameron McCormack. LayoutTests/imported/w3c: Add new tests for oklab() and oklch() based on the existing lab() and lch() tests. * web-platform-tests/css/css-color/oklab-001-expected.html: Added. * web-platform-tests/css/css-color/oklab-001.html: Added. * web-platform-tests/css/css-color/oklab-002-expected.html: Added. * web-platform-tests/css/css-color/oklab-002.html: Added. * web-platform-tests/css/css-color/oklab-003-expected.html: Added. * web-platform-tests/css/css-color/oklab-003.html: Added. * web-platform-tests/css/css-color/oklab-004-expected.html: Added. * web-platform-tests/css/css-color/oklab-004.html: Added. * web-platform-tests/css/css-color/oklab-005-expected.html: Added. * web-platform-tests/css/css-color/oklab-005.html: Added. * web-platform-tests/css/css-color/oklab-006-expected.html: Added. * web-platform-tests/css/css-color/oklab-006.html: Added. * web-platform-tests/css/css-color/oklab-007-expected.html: Added. * web-platform-tests/css/css-color/oklab-007.html: Added. * web-platform-tests/css/css-color/oklab-008-expected.html: Added. * web-platform-tests/css/css-color/oklab-008.html: Added. * web-platform-tests/css/css-color/oklch-001-expected.html: Added. * web-platform-tests/css/css-color/oklch-001.html: Added. * web-platform-tests/css/css-color/oklch-002-expected.html: Added. * web-platform-tests/css/css-color/oklch-002.html: Added. * web-platform-tests/css/css-color/oklch-003-expected.html: Added. * web-platform-tests/css/css-color/oklch-003.html: Added. * web-platform-tests/css/css-color/oklch-004-expected.html: Added. * web-platform-tests/css/css-color/oklch-004.html: Added. * web-platform-tests/css/css-color/oklch-005-expected.html: Added. * web-platform-tests/css/css-color/oklch-005.html: Added. * web-platform-tests/css/css-color/oklch-006-expected.html: Added. * web-platform-tests/css/css-color/oklch-006.html: Added. * web-platform-tests/css/css-color/oklch-007-expected.html: Added. * web-platform-tests/css/css-color/oklch-007.html: Added. * web-platform-tests/css/css-color/oklch-008-expected.html: Added. * web-platform-tests/css/css-color/oklch-008.html: Added. Source/WebCore: Tests: imported/w3c/web-platform-tests/css/css-color/oklab-001.html imported/w3c/web-platform-tests/css/css-color/oklab-002.html imported/w3c/web-platform-tests/css/css-color/oklab-003.html imported/w3c/web-platform-tests/css/css-color/oklab-004.html imported/w3c/web-platform-tests/css/css-color/oklab-005.html imported/w3c/web-platform-tests/css/css-color/oklab-006.html imported/w3c/web-platform-tests/css/css-color/oklab-007.html imported/w3c/web-platform-tests/css/css-color/oklab-008.html imported/w3c/web-platform-tests/css/css-color/oklch-001.html imported/w3c/web-platform-tests/css/css-color/oklch-002.html imported/w3c/web-platform-tests/css/css-color/oklch-003.html imported/w3c/web-platform-tests/css/css-color/oklch-004.html imported/w3c/web-platform-tests/css/css-color/oklch-005.html imported/w3c/web-platform-tests/css/css-color/oklch-006.html imported/w3c/web-platform-tests/css/css-color/oklch-007.html imported/w3c/web-platform-tests/css/css-color/oklch-008.html Adds support for oklab() and oklch() CSS colors and as interpolation parameters for color-mix(). OKLab (and its polar form OKLCH) is a relatively new Lab-like colorspace that aims to be an improved (improved hue linearity, hue uniformity, and chroma uniformity) Lab. It was create by Björn Ottosson and is documented at https://bottosson.github.io/posts/oklab/. * css/CSSValueKeywords.in: Add 'oklab' and 'oklch' to the keyword list so they can be used as function identifiers. Remove old mention of 'lab' in the color() function section, since 'lab' is no longer a valid colorspace to use in the color() function (rather, only lab() is supported). * css/parser/CSSPropertyParserHelpers.cpp: (WebCore::CSSPropertyParserHelpers::parseLabParameters): (WebCore::CSSPropertyParserHelpers::parseRelativeLabParameters): (WebCore::CSSPropertyParserHelpers::parseNonRelativeLabParameters): (WebCore::CSSPropertyParserHelpers::parseLCHParameters): (WebCore::CSSPropertyParserHelpers::parseRelativeLCHParameters): (WebCore::CSSPropertyParserHelpers::parseNonRelativeLCHParameters): (WebCore::CSSPropertyParserHelpers::parseColorFunction): Generalize lab and lch function parsing to also support the oklab and oklch variants (they have the same parsing rules). (WebCore::CSSPropertyParserHelpers::consumeColorMixColorSpaceAndComma): (WebCore::CSSPropertyParserHelpers::mixColorComponents): Add support for using oklab and oklch as the interpolation space of a color-mix(). This was already generalized so all it meant doing was adding mappings of the new identifiers to enums and mixColorComponentsInColorSpace calls. * platform/graphics/ColorComponents.h: (WebCore::ColorComponents::subset const): Fix compile error (no one had used subset yet it seems). 'std::remove_const_t<decltype(T::Size)>' was likely copied from mapColorComponents() where it is templatized and needs to deduce the loop variable, but that is not needed here. * platform/graphics/ColorConversion.cpp: (WebCore::convertToPolarForm): (WebCore::convertToRectangularForm): Move conversion to/from polar/rectangular forms from the LCHA conversion code here, so that it can be reused for OKLCHA. (WebCore::OKLab<float>>::convert): Add support for converting OKLab to/from XYZ D65. Matrix values come from https://bottosson.github.io/posts/oklab/ with updates from w3c/csswg-drafts#6642 (comment) (WebCore::OKLCHA<float>>::convert): Add support for converting OKLCHA. This is identical to the LCHA code above. (WebCore::converColorComponents): Add cases for new colorspaces. * platform/graphics/ColorConversion.h: Add converters for new colorspaces. Update diagram with them as well. * platform/graphics/ColorMatrix.h: (WebCore::ColorMatrix::transformedColorComponents const): Generalize transformedColorComponents to work with any size ColorComponents object. This allows the OKLab conversion code to be a bit simpler as it can operate on just the non-alpha components in a more systematic way. * platform/graphics/ColorModels.h: Add new predicate template variables to help when needing to check what model a particular color type uses. * platform/graphics/ColorSerialization.cpp: (WebCore::serialization): (WebCore::serializationForCSS): (WebCore::serializationForHTML): (WebCore::serializationForRenderTreeAsText): Add serialization support for new colorspaces. Also removes unused support for serializing lab colors using the color(lab ...) syntax which has not been supported for some time. * platform/graphics/ColorSpace.cpp: * platform/graphics/ColorSpace.h: * platform/graphics/cg/ColorSpaceCG.h: Add OKLab and OKLCH to the list of enumerated colorspaces and add mappings to their newly defined types OKLab<T> and OKLCHA<T>. * platform/graphics/ColorTypes.h: (WebCore::OKLab::OKLab): (WebCore::OKLCHA::OKLCHA): Add new types OKLab<T> and OKLCHA<T> (it looks like at some point an earlier version of this must have partially landed as there were existing forward declarations). Like Lab<T> and LCHA<T>, these new types use the LabModel<T> and LCHModel<T> models, but unlike them they use a whitepoint of D65. * platform/graphics/ColorUtilities.h: Generalize isBlack and isWhite to have a variant that works with Lab, LCH, OKLab and OKLCH (as they all are identical) using SFINAE, use the new model predicates to make this more clear. LayoutTests: Update existing tests for lab() and lch() to also test oklab() and oklch(). As they have the same parsing rules, this is mostly done by templatizing the tests and running them in a loop. * fast/css/parsing-color-mix-expected.txt: * fast/css/parsing-color-mix.html: * fast/css/parsing-lab-colors-expected.txt: * fast/css/parsing-lab-colors.html: * fast/css/parsing-relative-color-syntax-expected.txt: * fast/css/parsing-relative-color-syntax.html: Canonical link: https://commits.webkit.org/244573@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@286191 268f45cc-cd09-0410-ab3c-d52691b4dbfc
https://bugs.webkit.org/show_bug.cgi?id=233507 Reviewed by Cameron McCormack. LayoutTests/imported/w3c: Add new tests for oklab() and oklch() based on the existing lab() and lch() tests. * web-platform-tests/css/css-color/oklab-001-expected.html: Added. * web-platform-tests/css/css-color/oklab-001.html: Added. * web-platform-tests/css/css-color/oklab-002-expected.html: Added. * web-platform-tests/css/css-color/oklab-002.html: Added. * web-platform-tests/css/css-color/oklab-003-expected.html: Added. * web-platform-tests/css/css-color/oklab-003.html: Added. * web-platform-tests/css/css-color/oklab-004-expected.html: Added. * web-platform-tests/css/css-color/oklab-004.html: Added. * web-platform-tests/css/css-color/oklab-005-expected.html: Added. * web-platform-tests/css/css-color/oklab-005.html: Added. * web-platform-tests/css/css-color/oklab-006-expected.html: Added. * web-platform-tests/css/css-color/oklab-006.html: Added. * web-platform-tests/css/css-color/oklab-007-expected.html: Added. * web-platform-tests/css/css-color/oklab-007.html: Added. * web-platform-tests/css/css-color/oklab-008-expected.html: Added. * web-platform-tests/css/css-color/oklab-008.html: Added. * web-platform-tests/css/css-color/oklch-001-expected.html: Added. * web-platform-tests/css/css-color/oklch-001.html: Added. * web-platform-tests/css/css-color/oklch-002-expected.html: Added. * web-platform-tests/css/css-color/oklch-002.html: Added. * web-platform-tests/css/css-color/oklch-003-expected.html: Added. * web-platform-tests/css/css-color/oklch-003.html: Added. * web-platform-tests/css/css-color/oklch-004-expected.html: Added. * web-platform-tests/css/css-color/oklch-004.html: Added. * web-platform-tests/css/css-color/oklch-005-expected.html: Added. * web-platform-tests/css/css-color/oklch-005.html: Added. * web-platform-tests/css/css-color/oklch-006-expected.html: Added. * web-platform-tests/css/css-color/oklch-006.html: Added. * web-platform-tests/css/css-color/oklch-007-expected.html: Added. * web-platform-tests/css/css-color/oklch-007.html: Added. * web-platform-tests/css/css-color/oklch-008-expected.html: Added. * web-platform-tests/css/css-color/oklch-008.html: Added. Source/WebCore: Tests: imported/w3c/web-platform-tests/css/css-color/oklab-001.html imported/w3c/web-platform-tests/css/css-color/oklab-002.html imported/w3c/web-platform-tests/css/css-color/oklab-003.html imported/w3c/web-platform-tests/css/css-color/oklab-004.html imported/w3c/web-platform-tests/css/css-color/oklab-005.html imported/w3c/web-platform-tests/css/css-color/oklab-006.html imported/w3c/web-platform-tests/css/css-color/oklab-007.html imported/w3c/web-platform-tests/css/css-color/oklab-008.html imported/w3c/web-platform-tests/css/css-color/oklch-001.html imported/w3c/web-platform-tests/css/css-color/oklch-002.html imported/w3c/web-platform-tests/css/css-color/oklch-003.html imported/w3c/web-platform-tests/css/css-color/oklch-004.html imported/w3c/web-platform-tests/css/css-color/oklch-005.html imported/w3c/web-platform-tests/css/css-color/oklch-006.html imported/w3c/web-platform-tests/css/css-color/oklch-007.html imported/w3c/web-platform-tests/css/css-color/oklch-008.html Adds support for oklab() and oklch() CSS colors and as interpolation parameters for color-mix(). OKLab (and its polar form OKLCH) is a relatively new Lab-like colorspace that aims to be an improved (improved hue linearity, hue uniformity, and chroma uniformity) Lab. It was create by Björn Ottosson and is documented at https://bottosson.github.io/posts/oklab/. * css/CSSValueKeywords.in: Add 'oklab' and 'oklch' to the keyword list so they can be used as function identifiers. Remove old mention of 'lab' in the color() function section, since 'lab' is no longer a valid colorspace to use in the color() function (rather, only lab() is supported). * css/parser/CSSPropertyParserHelpers.cpp: (WebCore::CSSPropertyParserHelpers::parseLabParameters): (WebCore::CSSPropertyParserHelpers::parseRelativeLabParameters): (WebCore::CSSPropertyParserHelpers::parseNonRelativeLabParameters): (WebCore::CSSPropertyParserHelpers::parseLCHParameters): (WebCore::CSSPropertyParserHelpers::parseRelativeLCHParameters): (WebCore::CSSPropertyParserHelpers::parseNonRelativeLCHParameters): (WebCore::CSSPropertyParserHelpers::parseColorFunction): Generalize lab and lch function parsing to also support the oklab and oklch variants (they have the same parsing rules). (WebCore::CSSPropertyParserHelpers::consumeColorMixColorSpaceAndComma): (WebCore::CSSPropertyParserHelpers::mixColorComponents): Add support for using oklab and oklch as the interpolation space of a color-mix(). This was already generalized so all it meant doing was adding mappings of the new identifiers to enums and mixColorComponentsInColorSpace calls. * platform/graphics/ColorComponents.h: (WebCore::ColorComponents::subset const): Fix compile error (no one had used subset yet it seems). 'std::remove_const_t<decltype(T::Size)>' was likely copied from mapColorComponents() where it is templatized and needs to deduce the loop variable, but that is not needed here. * platform/graphics/ColorConversion.cpp: (WebCore::convertToPolarForm): (WebCore::convertToRectangularForm): Move conversion to/from polar/rectangular forms from the LCHA conversion code here, so that it can be reused for OKLCHA. (WebCore::OKLab<float>>::convert): Add support for converting OKLab to/from XYZ D65. Matrix values come from https://bottosson.github.io/posts/oklab/ with updates from w3c/csswg-drafts#6642 (comment) (WebCore::OKLCHA<float>>::convert): Add support for converting OKLCHA. This is identical to the LCHA code above. (WebCore::converColorComponents): Add cases for new colorspaces. * platform/graphics/ColorConversion.h: Add converters for new colorspaces. Update diagram with them as well. * platform/graphics/ColorMatrix.h: (WebCore::ColorMatrix::transformedColorComponents const): Generalize transformedColorComponents to work with any size ColorComponents object. This allows the OKLab conversion code to be a bit simpler as it can operate on just the non-alpha components in a more systematic way. * platform/graphics/ColorModels.h: Add new predicate template variables to help when needing to check what model a particular color type uses. * platform/graphics/ColorSerialization.cpp: (WebCore::serialization): (WebCore::serializationForCSS): (WebCore::serializationForHTML): (WebCore::serializationForRenderTreeAsText): Add serialization support for new colorspaces. Also removes unused support for serializing lab colors using the color(lab ...) syntax which has not been supported for some time. * platform/graphics/ColorSpace.cpp: * platform/graphics/ColorSpace.h: * platform/graphics/cg/ColorSpaceCG.h: Add OKLab and OKLCH to the list of enumerated colorspaces and add mappings to their newly defined types OKLab<T> and OKLCHA<T>. * platform/graphics/ColorTypes.h: (WebCore::OKLab::OKLab): (WebCore::OKLCHA::OKLCHA): Add new types OKLab<T> and OKLCHA<T> (it looks like at some point an earlier version of this must have partially landed as there were existing forward declarations). Like Lab<T> and LCHA<T>, these new types use the LabModel<T> and LCHModel<T> models, but unlike them they use a whitepoint of D65. * platform/graphics/ColorUtilities.h: Generalize isBlack and isWhite to have a variant that works with Lab, LCH, OKLab and OKLCH (as they all are identical) using SFINAE, use the new model predicates to make this more clear. LayoutTests: Update existing tests for lab() and lch() to also test oklab() and oklch(). As they have the same parsing rules, this is mostly done by templatizing the tests and running them in a loop. * fast/css/parsing-color-mix-expected.txt: * fast/css/parsing-color-mix.html: * fast/css/parsing-lab-colors-expected.txt: * fast/css/parsing-lab-colors.html: * fast/css/parsing-relative-color-syntax-expected.txt: * fast/css/parsing-relative-color-syntax.html: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@286191 268f45cc-cd09-0410-ab3c-d52691b4dbfc



svgeesus commentedSep 20, 2021
•
edited
For the background and explanation of why to add this feature, please see this Color Workshop presentation which has a video presentation, plus associated slides and transcript. You can just skim the slides/transcript if you are pressed for time.
Having done so, and given the rationale presented, the specific proposal is to add OKLab as follows: Edit: items re-ordered so highest priority is first.
CSS Color 4
labtooklabas the default. If we don't do this, color interpolation in gradients, animations and transitions will not be as good, and will sometimes give surprising hue shifts.oklab()andoklch()(as well as the existinglab()andlch()which are still useful) and add their implementation to the sample code. Not doing this means we have a colorspace of proven usefulness, implemented inside the browser, but we deny users access to it.CSS Color 5
oklabandoklchas defined color spaces which can be used incolor-mix(). Depends on 3.oklab()andoklch()to Relative Color Syntax. Depends on 3.@argyleink @una @tabatkins @LeaVerou
The text was updated successfully, but these errors were encountered: