Re: [csswg-drafts] [css-color-4] CSS gamut mapping algorithm pseudocode can result in infinite looping for some inputs (#6999)

> Once the low and high chroma is close enough to consider they've converged

The algorithm doesn't test for this directly, instead testing for the deltaE between the current and clipped colors. However, that does assume that the only difference between the two is chroma. In the case @weinig mentioned, the chroma difference is almost zero and the deltaE value is entirely due to the lightness difference. So it will never converge.

> (maybe the intention had assumed that lightness would always be within an acceptable range?).

Yes. There are algorithms that "toe in" the source black point to the destination blackpoint (black point compensation) but that matters more for HDR (and for print, where the deepest black cannot be assumed to have L=0), and similarly to map the source and destination media whitepoints (again, for HDR). But for RGB SDR, which is what this algorithm is for, then yes the assumption was that 

1. the source and destination whitepoints are idential (relative colorimetry)
2. the source and destination blackpoints are identical (no black point compensation)
3. the Lightness values are in range and thus chroma reduction will always converge.

>  I think this can also be fixed by clamping the origin_OKLCH lightness values between 0 and 1, since regardless of hue, the chroma should be reducible to an in gamut value in that lightness range. In practice, this probably means just returning { 1 1 1 origin.alpha } if lightness >= 1 and { 0 0 0 origin.alpha } if lightness is 0.

I agree that there is no point reducing the chroma for black, colors darker than black, white, and colors lighter than (media) white. We already know the answer. So yes, I think the initial steps should be

1. let origin_OKLCH be origin converted to the OKLCH color space
2. if the Lightness of origin_OKLCH is greater than or equal to 100%, return { 1 1 1 origin.alpha } in _destination_
3. if the Lightness of origin_OKLCH is less than or equal to 0%, return { 0 0 0 origin.alpha } in _destination_
4. let inGamut(color) be a function _etc etc as before_

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


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

Received on Wednesday, 2 February 2022 15:53:36 UTC