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

[css-color-5] Clarify / add example of gamut mapping during color-mix() #6913

Closed
weinig opened this issue Dec 25, 2021 · 4 comments
Closed
Assignees
Labels
Closed Accepted as Obvious Bugfix Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-color-4 Current Work css-color-5 Color modification

Comments

@weinig
Copy link
Contributor

weinig commented Dec 25, 2021

The color-mix() function has the following step defined:

Both colors are converted to the specified <color-space>. If the specified color space has a smaller gamut than the one in which the color to be adjusted is specified, gamut mapping will occur.

It would be useful to understand exactly when this applies, as its not entirely clear to me.

For instance, would the following require gamut mapping?

color-mix(in srgb, color(display-p3 0 1 0) 100%, red 0%)

Should the color(display-p3 0 1 0) color be gamut mapped to the sRGB gamut, or would it be ok for this to produce a result like color(srgb -5.35 10.17 -3.43)?

Presumably this only applies to srgb, srgb-linear, hsl and hwb at the moment as well, but clarification would also be helpful.

@svgeesus svgeesus added css-color-4 Current Work css-color-5 Color modification labels Dec 29, 2021
@svgeesus
Copy link
Contributor

I agree this is under-specified and confusing. I suspect the language you quote was not updated when we went to extended colorspaces for all the predefined RGB spaces.

hsl and hwb certainly are unable to express out of gamut colors, so in those cases certainly gamut mapping would occur. And doing manipulations in hsl is likely to be common as people move color-manipulation logic from the likes of Sass where hsl was until recently the only option.

Should the color(display-p3 0 1 0) color be gamut mapped to the sRGB gamut, or would it be ok for this to produce a result like color(srgb -5.35 10.17 -3.43)?

Well ideally it would produce color(srgb -0.5116 1.01827 -0.3107) :) but yes, there is color space conversion but no gamut mapping in this case

CSS Color 4 says, in Color Spaces for Interpolation:

If the colors to be interpolated are outside the gamut of the interpolation space, then once converted to that space, they will contain out of range values.

These are not clipped, but the values are interpolated as-is.

I think the fix is to change the text you cited, from "has a smaller gamut" to "cannot express the color" plus adding an example.

@svgeesus svgeesus self-assigned this Dec 29, 2021
@weinig
Copy link
Contributor Author

weinig commented Jan 4, 2022

Is it safe to say that for the non-legacy colors, gamut mapping will only happen at used value time? For things like computed value, returning the un-mapped value is the right thing to do?

@svgeesus
Copy link
Contributor

svgeesus commented Jan 8, 2022

@weinig yes, indeed

@svgeesus
Copy link
Contributor

svgeesus commented Jan 9, 2022

Clarified that gamut mapping for color-mix() is only used when an oog color cannot be expressed (hsl and hwb).

Added an example, with display-p3 green mixed in hsl.

@svgeesus svgeesus added Closed Accepted as Obvious Bugfix Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. and removed Needs Edits labels Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed Accepted as Obvious Bugfix Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-color-4 Current Work css-color-5 Color modification
Projects
None yet
Development

No branches or pull requests

2 participants