Re: [css-houdini-drafts] [css-typed-om] Inputs for the CSSColorValue constructors (#1014)

@annevk wrote

> Some input syntax aspects might have to be preserved in certain cases because of legacy roundtripping behavior, but ideally that is minimized as it there is not a lot of benefit to it. I would actually have expected color(srgb 0 1 0), #0f0, and rgb(0% 100% 0%) to all end up as the same type with a bit indicating how it would need to be serialized back (if any API has to preserve that today, not sure).

I agree that, apart from serialization (which use of Typed OM should minimize) preserving the minutiae of input syntax, particularly the mess of sRGB legacy syntaxes, has not much value and should not be the primary goal of a CSS Color model, far less a Web-wide color model if that is what we are designing (still unclear on that).

Color serialization was moved from CSSOM, where it was sRGB only and 8bit only, to CSS Color 4 by CSS WG resolution. 

Currently all the legacy sRGB syntaxes - `rgb()`, `rgba()`, `hsl()` `hwb`  and named (X11 and system) colors [serialize the same way](https://drafts.csswg.org/css-color-4/#serializing-sRGB-values) - and not in a very nice way either, but one chosen for maximum legacy compat. So the bit depth is no longer fixed at 8 per component, but uses a real number which means 8bit values still serialize as integers: `rgb(146.06, 107.46, 131.2 / 0.8)`. The minimum conformant bit depth is still 8 though.

However, the `color()` function [serializes separately](https://drafts.csswg.org/css-color-4/#serializing-color-function-values), partly for consistency within the color function (values are in the range [0-1] and also as a non-legacy sRGB opt-in to better behavior (interpolate in Lab instead of gamma-encoded sRGB, minimum bit depth 10). Plus of course it can use other color spaces, like `display-p3`.

> I also agree that we should not have separate (non-CSS) color and CSS color types. We don't have that today with string-based colors either and thus far that has been great and allowed for reuse of a great deal of logic between canvas, CSS, and SVG.

Re-use of concepts has certainly been great, for example the [Canvas HDR proposal](https://github.com/w3c/ColorWeb-CG/blob/master/hdr-in-png-requirements.md) re-uses a lot from CSS Color 4. As you say, some syntax details are already not preserved and are not the most important aspect anyway.

But one reason the string-based syntax stuff worked okay was that it didn't have much to do. The only colorspace was sRGB so there was no need for colorspace conversion when mixing, interpolating, compositing or animating. As we move into a Wide Clor Gamut and High Dynamic Range world, those conversions are necessary and commonplace.

-- 
GitHub Notification of comment by svgeesus
Please view or discuss this issue at https://github.com/w3c/css-houdini-drafts/issues/1014#issuecomment-841183865 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 14 May 2021 11:23:31 UTC