Re: [csswg-drafts] [css-color-4] Move gamut mapping to a future spec (#8444)

>  HWB require in-gamut sRGB values as input, and give nonsense values if they get negative number or numbers grester than 100%. 

Do they, though? An experiment:

The `srgb` equivalent of display-p3 red (`color(display-p3 1 0 0)`) is `color(srgb 1.09306 -0.226721 -0.150111)`. This is clearly out-of-gamut, but not nonsensical. Both UAs I've tested (safari TPM and chrome canary) [treat it as valid input](https://jsfiddle.net/o8dnrgqf/) and [wpt validates similar test cases as valid](https://github.com/web-platform-tests/wpt/blob/2c23021044/css/css-color/parsing/color-valid-color-function.html#L36).

Using the algorithm defined [in 7.2](https://csswg.sesse.net/css-color-4/#rgb-to-hsl) and the srgb equivalent of display-p3 red as input [1.09306 -0.226721 -0.150111] we get the hsl equivalent of [356.51714943615644, 152.34001932269007, 43.31695]. [See a demo here](https://jsfiddle.net/0Lao6ed8/). This value round trips fine using the algorithm in 7.1, with some float-precision issues.

Is a hue of 356 degrees, a saturation of 152% and a lightness of 43% nonsensical if negative values and values greater than one for srgb are not?

[Here's a demo for arbitrary values for display-p3 input, including HWB](https://jsfiddle.net/zn6uhgj7/1/).  All resulting values for hsl make sense if we allow saturation > 100%. The highest value I was able to see was about 300%. All values roundtrip to srgb with only rounding errors on the order of 10^-16. I see similar results with HWB, with some negative values for whiteness and blackness when out-of-gamut

> Since color-mix() from CSS Color 5 is the only feature for color 4 or 5 that can result in intermediate out-of-gamut results

What I should have said here is "out-of-gamut results that are observable through script and are expected to be gamut mapped as opposed to left-as-is." Per the discussion here it would appear that we can further narrow this case to be color-mix values in the `hsl` and `hwb` colorspaces. If we allow representation of out-of-gamut `hsl` and `hwb` colors, like we already do for other colorspaces, then we can remove the need to gamut map colors in a script-visible way, which was the original intention of this issue. 

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


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

Received on Friday, 24 February 2023 22:25:57 UTC