Description
Section 13.2 of CSS Color 4 contains a non-normative section describing a binary search gamut-mapping algorithm. Though user agents are beginning to ship CSS Color 4, there is still a lot of ongoing debate over the appropriateness of this algorithm (#7610). Proposed alternatives can be found here: #7653.
Some UA developers met recently to discuss the issue. A consensus was reached that it would be better to allow out-of-gamut color conversions to remain out-of-gamut (as opposed to clipping) while the working group continues to develop a gamut mapping algorithm. To that end, we could move the entire section 13 to a CSS Color 5 or 6 while this work is being done.
For CSS Color 4, step 8 in converting colors could be removed. And since colors are now possibly out-of-gamut Converting sRGB Colors to HSL would need to deal with rgb channels outside of the [0,1] range:
/**
* @param {number} red - Red component
* @param {number} green - Green component
* @param {number} blue - Blue component
* @return {number[]} Array of HSL values: [snip]
*/
function rgbToHsl (red, green, blue) {
red = Math.min(Math.max(red, 0), 1);
green = Math.min(Math.max(green, 0), 1);
blue = Math.min(Math.max(blue, 0), 1);
let max = Math.max(red, green, blue);
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, our exposure to out-of-gamut colors would remain relatively minimal and we can preserve interoperability. Leaving out-of-gamut results and not clipping avoids the worst results, like saturation at the boundaries and different results for canvases. It has the added bonus of color conversions round tripping.