facelessuser / coloraide

A library to aid in using colors
https://facelessuser.github.io/coloraide
MIT License
195 stars 12 forks source link

Improve gamut mapping #246

Closed facelessuser closed 2 years ago

facelessuser commented 2 years ago

This has changed a little bit. Initially, we wanted to correct an issue where when using oklch-chroma, we return oklch(1 0 none) or oklch(0 0 none) if lightness is extreme on either the light or dark side. This is per the CSS spec (returning white or black that is, not necessarily the way we do it). The problem is that conversion back from oklch(1 0 none) is sometimes slightly out of gamut for sRGB, and HSL can't handle that at all and will give a non-achromatic result. Returning sRGB white or black is far more reliable.

While doing this we noticed that we force HDR spaces to shortcut returning white or black when lightness was extreme for an SDR range. This is incorrect, so we now declare a space's dynamic range and can make judgments based this. As far as GMA is concerned, this means not applying SDR shortcuts on an HDR space.

Additionally, we've decided that GMA/clipping should not return an undefined channel as zero. Instead, an undefined channel is neither in gamut nor out of gamut, it isn't defined. This will prevent us from wiping out undefined channels when interpolating and a fit is required.

facelessuser commented 2 years ago

@gir-bot lgtm