Re: [csswg-drafts] [css-color-5] relative color syntax: numbers vs. percentages in `calc()` (#9759)

So, lets work out that test case. There may be some confusion in the spec because the conversion color space (`rgb()`) and the serialization format(`color(srgb)`) have differing requirements here.

`rebeccapurple` is `#663399`  or `rgb(102 51 153)`

In `rgb(from rebeccapurple ...)` [we have](https://drafts.csswg.org/css-color-5/#relative-RGB) r=102 g=51 b=153 a=1.0

In `rgb(from rebeccapurple b alpha r / g)` we have, internally, r=b=153, g=alpha=1.0, b=r=102, a=g=51 so `rgb(153 1.0 102 / 51)`. 

This is where it gets unclear, [CSS Color 4 says](https://drafts.csswg.org/css-color-4/#rgb-functions):

> Values outside these ranges are not invalid, but are clamped to the ranges defined here at parsed-value time.

So we clamp the alpha (in this test case, the only out of range component). Which means this is the same as specifying `rgb(153 1.0 102 / 1)`.

The serialized specified value [must use `color(srgb)`](https://drafts.csswg.org/css-color-5/#serial-relative-color) so it will be serialized as (to whatever precision)

"color(srgb 0.6 0.00392156863 0.4)" with the alpha not serialized as it is 1.

So yes, that subtest is wrong in the green and alpha values.

```js
fuzzy_test_computed_color(`rgb(from rebeccapurple b alpha r / g)`, `color(srgb 0.6 1 0.4 / 0.2)`);
```

But the worrying and unclear thing, to me, is that the whole reason we added the serialization of RCS `rgb()`, `hsl()` and `hwb()` to `color(srgb)` specifically to enable round-tripping of out of gamut values. But the text from CSS Color 4 that I quoted above prevents that, which means that CSS Color 5 needs to specifically say that _RCS versions of those color functions do **not** clamp out of range values._ And then, do we really want unclamped alpha values like that?


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


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

Received on Friday, 12 January 2024 15:48:57 UTC