Should gamut mapping be done in the gamutSpace of a color space?
Opened this issue · 0 comments
lloydk commented
For example, srgb
and hsl
have the same gamutSpace
(srgb
).
Should gamut mapping color(display-p3 1 0 0)
to srgb
and hsl
result in the same srgb
color when converting the gamut mapped hsl
color to srgb
?
hsluv
is off by quite a bit. Possibly because the hsluv
conversion routines don't deal with colors outside the srgb
gamut very well?
Gamut checking for all three colors is done in the srgb
space but the clipping portion of the algorithms (and maybe other parts) is done in the origin space.
Here's a quick hack of the CSS portion of the toGamut
function to do the mapping in gamutSpace
and the gamut mapping results:
if (method === "css") {
let gamutSpace = color.space.gamutSpace;
let colorInGamutSpace = to(color, gamutSpace);
let mappedColor = toGamutCSS(colorInGamutSpace, {space: gamutSpace});
spaceColor = to(mappedColor, color.space);
}
Color notebook code
let color = new Color("color(display-p3 1 0 0)");
let rgb = color.to("srgb", {inGamut: true})
let hsl = color.to("hsl", {inGamut: true}).to("srgb")
let hsluv = color.to("hsluv", {inGamut: true}).to("srgb")