Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should gamut mapping be done in the gamutSpace of a color space? #432

Open
lloydk opened this issue Feb 13, 2024 · 0 comments
Open

Should gamut mapping be done in the gamutSpace of a color space? #432

lloydk opened this issue Feb 13, 2024 · 0 comments

Comments

@lloydk
Copy link
Collaborator

lloydk commented Feb 13, 2024

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?

image

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);
	}

image

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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant