-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix failures in relative-color-out-of-gamut-expected due to rgbToHwb algorithm #31636
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
Fix failures in relative-color-out-of-gamut-expected due to rgbToHwb algorithm #31636
Conversation
EWS run on previous version of this PR (hash 3c5acad) |
Note: This patch does not reverse (parts of) https://commits.webkit.org/277999@main, because I wrote it before I looked for a cause. Reviewer(s), let me know if you'd prefer me to actually try and reverse (assuming the whole course of action is the right way to go, of course). |
Thanks for looking into this @squelart! Is this fix purely based on what the current WPT tests are testing, or was there some conversion with the WG on this? Perhaps I am misunderstanding standing you, but it seems like you are saying WebKit is doing what the spec suggests. If that is the case, should the test be updated instead? |
Yes this PR intends to fix what the WPT tests are testing, but I think it's particular to WebKit because of how it handles No conversation with WG, maybe we should start one, especially if the specs need updating.
tl;dr: I believe WebKit follows the specs very closely, and it results in out-of-gamut errors. The first failing test is:
Now we have similar tests above that are not failing, e.g.:
Notice that the "from" colors are the same, there is a straight colorspace conversion, and the resulting relative colors are compared against the same srgb color. Now, WebKit handles In any case, as extra proof that this is the point of failure, I can add the following test line:
And this fails the same way, pointing at the rgb-to-hwb conversion. Now about the specs, we have https://drafts.csswg.org/css-color-4/#rgb-to-hwb
As you can see this uses
With the corresponding bit of code:
As it says, the hue is rotated and the saturation is made positive. This is probably the correct thing to do for HSL colors; my naive thinking is that it's like normalizing a vector with negative length by flipping its direction and negating the length, the resulting vector is the same. Would you like me to open an issue against the specs? My suggestion for a spec change would be similar to this PR: Rewrite the Sam, do you agree with my analysis? |
I think the tests are wrong, given they are supposed to test the spec. Let’s take this to CSS WG GitHub for discussion. If we want to make a short term fix, I would propose updating the test to match the spec, and pushing that to WPT. |
Alright, I've filed w3c/csswg-drafts#10695 |
3c5acad
to
f6a1b27
Compare
EWS run on current version of this PR (hash f6a1b27) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matches the spec change at: w3c/csswg-drafts@ead8668
…algorithm https://bugs.webkit.org/show_bug.cgi?id=277538 rdar://133045692 Reviewed by Tim Nguyen. The suggested rgbToHwb algorithm at https://drafts.csswg.org/css-color-4/#rgb-to-hwb used to use rgbToHsl to compute the hue, discarding the saturation and lightness. But rgbToHsl special-cases negative saturations (possible with out-of-gamut colors), and flips the hue in that case, resulting in incorrect out-of-gamut HWB values. This was fixed in w3c/csswg-drafts#10718 This patch here replicates w3c/csswg-drafts#10718 in the equivalent WebKit function, it fixes failures in relative-color-out-of-gamut-expected.html, but also in color-mix-out-of-gamut-expected.html. * LayoutTests/imported/w3c/web-platform-tests/css/css-color/parsing/color-mix-out-of-gamut-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-color/parsing/relative-color-out-of-gamut-expected.txt: * Source/WebCore/platform/graphics/ColorConversion.cpp: (WebCore::ExtendedSRGBA<float>>::convert): Canonical link: https://commits.webkit.org/282101@main
f6a1b27
to
d26cb4a
Compare
Committed 282101@main (d26cb4a): https://commits.webkit.org/282101@main Reviewed commits have been landed. Closing PR #31636 and removing active labels. |
d26cb4a
f6a1b27