Re: [csswg-drafts] [css-color-4] When do color space conversions happen? (#867)

> Maybe I missed something, but as far as I can tell css-color-4 is silent about whether converting colors expressed in different profiles/spaces (using color(), lab(), lch(), or gray()) to the working color space is something that happens at computed value time, used value time, or some other time, and how that affects serialization.

I realize that this issue has lain dormant for a while, so some updates:

- The section on [resolving <color> values](https://drafts.csswg.org/css-color-4/#resolving-color-values) (started by @frivoal ) has been fleshed out.
- A new section on [serializing <color> values](https://drafts.csswg.org/css-color-4/#serializing-color-values) expands what CSSOM used to say from sRGB-only to all the color formats. Colors in `color()` are kept as specified. `lab() and `lch()` srialize as lab, and `gray()` was removed per WG discussion.
- CSS Color 5, which is about mixing and modifying colors has [a section on color interpolation](https://drafts.csswg.org/css-color-5/#interpolation) which states that if two colors to be interpolated are in the same space, they interpolate in that space (this gives us legacy compat for sRGB values); that colors in different spaces are converted to lab for interpolation, and that individual properties or functions may override that (for example `color-mix()` overrides the space to LCH by default and allows any other space to be explicitly specified.

Not all the places which carry out color interpolation have been ungraded to point to Color 5 or to define whether they allow overriding to another space; I'm getting to them one by one.

This per-property or per-function definition is more flexible than a single per-document or per-element working colorspace. Some operations (like compositing) are best done in a linear-light space like XYZ or a linearised RGB space; some like transitions, gradients, animations are best done in Lab so that the intermediate values are perceptually evenly spaced.

> If the computed value is not in the same color space, how can you animate? what is 25% of the way between color(foo 0 0 0) to color(bar 0 0 100)? 25% of the way between 0 and 100 is 25, but 25% of the way between foo and bar is what?

When they are interpolated, the first color is converted to L1 a1 b1 and the second to L2 a2 b2 and those components are linearly interpolated to give the 25% value. If they are not fully opaque, Color 5 also defines [interpolating with alpha](https://drafts.csswg.org/css-color-5/#interpolation-alpha)

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


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

Received on Friday, 13 November 2020 13:02:29 UTC