Re: [csswg-drafts] [css-color] Computing lch/lab to srgb with lightness = 0% or 100% (#8794)

> I am a bit confused. As `color(xyz-d50 1 1 1)` is mapped to `lab(100 6.0964191 -13.2359)`, does it mean is mapped to outside of the `lab` color space color gamut and appear white on screen?

`[color(xyz-d50 1 1 1)`](https://colorjs.io/apps/convert/?color=color(xyz-d50%201%201%201)&precision=6) is `lab(100 6.09642 -13.236)`. Lab doesn't have a gamut boundary. But we also don't have Lab displays so, for display on an RGB monitor, as that color is out of gamut for the monitor it will be gamut mapped. For example on a P3 monitor, `color(display-p3 1.00713 0.98792 1.09289)` is out of gamut. The gamut mapping is in Oklch, so we have `oklch(1.00362 0.03919 295.358)` and looking at step 3 of [the gamut mapping algorithm](https://drafts.csswg.org/css-color-4/#binsearch):

> if the Lightness of origin_Oklch is greater than or equal to 100%, return { 1 1 1 origin.alpha } in destination

so we return `color(display-p3 1 1 1)` which is white.

> For `color-mix` with values outside of gamut, how does it work? ex: `color-mix(in hsl, lab(0 104.3 -50.9) 100%, rgb(0, 0, 0) 0%)` should return `color(srgb 0.351376 -0.213938 0.299501)` or `color(srgb 0 0 0)`?

[`lab(0 104.3 -50.9)`](https://colorjs.io/apps/convert/?color=lab(0%20104.3%20-50.9)&precision=6) is a very high chroma but is as light as black. In HSL (which has a D65 white point as it is derived from sRGB) it will be [`hsl(305.51 411.277% 6.87231%)`](https://colorjs.io/apps/convert/?color=hsl(305.51%20411.277%25%206.87231%25)&precision=6) and the computed value is in sRGB which is `color(srgb 0.351365 -0.2139 0.299453)`. 

But if we try to display that color it is out of gamut on an sRGB screen (indeed, on any screen) so we convert to Oklch for gamut mapping: `oklch(0.18314 0.3973 336.648)` and the lightness is not over 1 or under 0 so we gamut map it. Notice the lightness has gone up to 18% as a result of chromatic adaptation, in Lab it is, after all these conversions, `lab(0.00004 104.3 -50.9)` which is super close to the originally specified color.






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


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

Received on Thursday, 16 November 2023 16:50:10 UTC