-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Canvas 2D context color serialization #8917
Comments
The The scope of #6562 is 2D canvas and ImageData. The WebGL API with analogous scope is drawingBufferColorSpace/unpackColorSpace. |
It is indeed covered there, but that's not what the |
To the original question:
No. The values of Is there disagreement on this? |
I meant the color space of the color. |
Then this is in the context of CSS Color Level 4's new color syntax, and not #6562. It appears that canvas prefers serializing to hex notation over |
I guess in my mind that issue made using non-sRGB color values more meaningful and therefore we should have considered this. |
CSS Color 4 has a concept of legacy color syntax. Essentially, pre-css color 4 colors (rgb, rgba, hsl, hsla) get serialized as they always have. Non-legacy colors are serialized as described in csswg.sesse.net/css-color-4. The simplest solution would just be to do exactly what CSS is doing, while preserving "opaque colors are hex" quirk from https://html.spec.whatwg.org/#serialisation-of-a-color.
Could we even link to https://csswg.sesse.net/css-color-4/#serializing-color-function-values? |
Yeah, it's fine to link CSS's algorithms and the more we can reuse the better I think. As long as sRGB continues to do the same thing I think we're good. |
Great! Should we add this to some sort of agenda or should I just make a PR with the spec changes to this repo? |
Just a PR is fine. And you can count WebKit as supportive of fixing this. |
Browsers aren't interoperable:
|
I think ideally we do whatever requires keeping around the least amount of state while retaining full precision. From that perspective it seems nice that if What Gecko does for inputs that are not compatible with @tabatkins @svgeesus what are the chances of the CSS WG taking over the definition of canvas CSS color serialization? It doesn't seem good for us to continue maintaining this. Looking at https://csswg.sesse.net/css-color-4/#serializing-color-values we'd have to special case quite a bit to get our desired results. |
I agree. And if Canvas needs a special "for Canvas, serialize legacy sRGB as hex" we can certainly add that sort of language. When serializing colors, in addition to the syntactic form, the required minimum precision (bit depth) needs to be considered and also, it is better to avoid color space conversions. Serializing
Sure, that makes total sense. Just tell us what you need. |
@Loirooriol wrote:
I read those results as "Gecko strictly follows the current Canvas https://html.spec.whatwg.org/#serialisation-of-a-color" which, as @annevk says, has not yet been updated. I assume that when it has been updated and points to CSS Color serialization, Gecko will then produce the same results as Blink and WebKit currently do, right? |
@svgeesus here is what I think we want:
(I noticed that HTML also has https://html.spec.whatwg.org/#colours for |
@annevk I agree with your 1 and 2, for the existing 8-bit Canvas 2D which has just |
I guess one thing that isn't specified right now is what precision we parse and store the colors in. It's clear at the 2D context level we only operate on one byte per channel, but it's not clear when setting And I think that's probably what we want as well, even though it becomes lossy once you start painting. Otherwise the API starts to expose too many underlying mode switches going forward. |
Servo was just rounding to a RGBA with three 8-bit ints and one 32-bit float. But Firefox changed the shared style API so now Servo stores the full color. Then the logic that I tentatively adopted is: if the color would serialize (as a computed color with |
However, the current HTML algorithm uses either
Which is why I am restarting this discussion, to agree on text which would go in CSS Color 4 as a replacement to the HTML one. |
Until the float canvas proposal is adopted but even then, we can have different serialization for integer and float 2D contexts. CSS Color 4 says:
|
I hadn't realized that maintaining the hex serialization part in HTML was a goal. I thought it was all being moved over to CSS, which makes total sense because of the necessary branching logic (if it is sRGB and if the values are in [0..255] and are 1 byte per component and the alpha is exactly 1 then output |
I suppose it would be better if Using that algorithm for 24-bit sRGB colors + alpha sounds good. This has some implications for the design of
|
I like
Yes, although note here is no route to serialize as hex. We could easily add a "serialize as hex" option if it would be helpful for canvas.
|
From HTML's perspective we have these requirements:
I think for
So here is what this would mean for the CSS Color specification for maximum clarity:
Does that make sense? Once that's in place I can update the |
Canvas is currently limited to 8 bits/component but I would like to write this bit of CSS Color such that it needs small extension rather than a total rewrite once canvas gets the float option. It isn't clear to me what is expected if the color picker returns an |
@svgeesus yes, that's how we should handle those. Note that "Limited sRGB" and associated rounding (which HTML will handle) is for @domenic also pointed out that for |
Although fillStyle, strokeStyle, and shadowColor setters accepted all kinds of CSS color values, those could not be serialized. Update that by relying on CSS Color for serialization instead, which now has a HTMLCompatible named parameter to preserve compatibility with 2D canvas and <input type=color> for certain colors. While here, also link the algorithm to be used for color space conversion and correct the reference for 'relative-colorimetric'. Fixes #8917.
Is there something preventing us from doing the suggestion in this comment: It seems like a simple solution.
I disagree with that goal. And there's a ton of complexity in answering if a color "is a color compatible with
I agree very strongly with this goal. Let's not hyper-optimize things around the rapidly vanishing 8-bit sRGB land. |
@ccameron-chromium that solution doesn't preserve backwards compatibility as CSS doesn't serialize RGB inputs in the same way that canvas does today. See #10481 and w3c/csswg-drafts#10550 for the current proposal here. There might well be some tweaks possible, but I'm pretty certain that this needs to be the model by-and-large. |
@annevk I'm looking over this discussion again and working on a spec edit to capture it. Is this solely for use with Canvas or also other places? So the requirements are:
otherwise you get the CSS serialization. Right? |
Why is it easier to express if this is for canvas only? We also want this for I also don't think it depends on the color space of the canvas. It only depends on the color space of the color. If you use a P3 color on a RGB canvas it shouldn't really get converted at this level. |
Its okay, I found suitable language in the serializing alpha section about "internal 8 bit representation" so I re-used that.
Agreed, so to make that clearer I will add an example with a P3 canvas and imageData = context.getImageData(0, 0, 1, 1, { colorSpace: "srgb" }); |
@svgeesus this will not impact |
Okay. Have a look at except I pushed that before seeing your comment just now. Will look at the WPT for better examples. Comments welcome. |
And now directly viewable here |
Thanks, I left feedback in the CSS WG issue thread here: w3c/csswg-drafts#10550 (comment). |
Although fillStyle, strokeStyle, and shadowColor setters accepted all kinds of CSS color values, those could not be serialized. Update that by relying on CSS Color for serialization instead, which now has a HTMLCompatible named parameter to preserve compatibility with 2D canvas and <input type=color> for certain colors. While here, also link the algorithm to be used for color space conversion and correct the reference for 'relative-colorimetric'. Fixes #8917.
Although fillStyle, strokeStyle, and shadowColor setters accepted all kinds of CSS color values, those could not be serialized. Update that by relying on CSS Color for serialization instead, which now has an HTML-compatible serialization method to preserve compatibility with 2D canvas and <input type=color> for certain colors. While here, also link the algorithm to be used for color space conversion and correct the reference for 'relative-colorimetric'. Tests: web-platform-tests/wpt#47148. Fixes #8917.
…n, a=testonly Automatic update from web-platform-tests 2D canvas color parsing and serialization For whatwg/html#8917, w3c/csswg-drafts#10550, and whatwg/html#10481. -- wpt-commits: 6b71c578c4e9113e56b5445d4697b6a97aedf37d wpt-pr: 47148
…n, a=testonly Automatic update from web-platform-tests 2D canvas color parsing and serialization For whatwg/html#8917, w3c/csswg-drafts#10550, and whatwg/html#10481. -- wpt-commits: 6b71c578c4e9113e56b5445d4697b6a97aedf37d wpt-pr: 47148 UltraBlame original commit: ba0041c24e1332e588896b9fb72ed44e32f1a385
…n, a=testonly Automatic update from web-platform-tests 2D canvas color parsing and serialization For whatwg/html#8917, w3c/csswg-drafts#10550, and whatwg/html#10481. -- wpt-commits: 6b71c578c4e9113e56b5445d4697b6a97aedf37d wpt-pr: 47148 UltraBlame original commit: ba0041c24e1332e588896b9fb72ed44e32f1a385
…n, a=testonly Automatic update from web-platform-tests 2D canvas color parsing and serialization For whatwg/html#8917, w3c/csswg-drafts#10550, and whatwg/html#10481. -- wpt-commits: 6b71c578c4e9113e56b5445d4697b6a97aedf37d wpt-pr: 47148 UltraBlame original commit: ba0041c24e1332e588896b9fb72ed44e32f1a385
…n, a=testonly Automatic update from web-platform-tests 2D canvas color parsing and serialization For whatwg/html#8917, w3c/csswg-drafts#10550, and whatwg/html#10481. -- wpt-commits: 6b71c578c4e9113e56b5445d4697b6a97aedf37d wpt-pr: 47148
Although fillStyle, strokeStyle, and shadowColor setters accepted all kinds of CSS color values, those could not be serialized. Update that by relying on CSS Color for serialization instead, which now has an HTML-compatible serialization method to preserve compatibility with 2D canvas and <input type=color> for certain colors. While here, also link the algorithm to be used for color space conversion and correct the reference for 'relative-colorimetric'. Tests: web-platform-tests/wpt#47148. Fixes whatwg#8917.
Presumably the goal of #6562 was to enable new kind of color values. And these can be set. But they cannot be serialized as both
fillStyle
andstrokeStyle
use https://html.spec.whatwg.org/#serialisation-of-a-color which has not been updated. That serialization probably needs to switch on the color space?cc @ccameron-chromium @whatwg/canvas
The text was updated successfully, but these errors were encountered: