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-4] Clarify how interpolation / premultiplication works for colors with "missing"/none alpha components #6967

Closed
weinig opened this issue Jan 19, 2022 · 3 comments
Assignees
Labels
css-color-4 Current Work

Comments

@weinig
Copy link
Contributor

weinig commented Jan 19, 2022

The section on interpolating with alpha does not include rules for what happens if one or both of the alpha components are none. It would be helpful for this to be explicitly defined as it is, at least to, non-obvious what the desired behavior is.

@svgeesus
Copy link
Contributor

Gosh this is almost like being n Candidate Recommendation, where the spec is improved by feedback from implementers.

So, in 4.3. "Missing"/none Color Components I see

If a color with a missing component is interpolated with another color, the missing component is treated as having the other color’s component value. If both colors are missing the given component, the interpolated color will also be missing that component.

and that clearly belongs in a new subsection of 12. Interpolation, after 12.1 Color space for interpolation and before 12.2. Interpolating with alpha.

If there is one missing component, the rule is clear - the value from the other color is used, so by the time we get to alpha premultiplication there are no none values.

If there are two though, we still have none. Now, we could force it to zero, at which point alpha premultiplication and un-premultiplication has no effect because 0 × alpha = 0. Or we could leave it none and say this component is unaffected by alpha premultiplication (in code, NaN × 0 = NaN) and the value in the interpolated result is still none.

I guess the only difference is, not when the interpolated result is used directly, but when it takes part in another interpolation.

For example, if a gradient stop is being animated between two values, both of which have (the same) missing value, and then the interpolated stop value takes part in gradient interpolation with the preceding and following color stops. We would want to preserve the none, right?

So I think that is what we should do (and this would be a great example for the spec too, now I think about it).

@svgeesus svgeesus self-assigned this Jan 21, 2022
@svgeesus
Copy link
Contributor

@weinig edits made, look good to you?

@weinig
Copy link
Contributor Author

weinig commented Jan 22, 2022

Edits look good, but I am still unsure about the case of interpolating two colors where the alpha channel for both is none, e.g. oklch(78.3% 0.108 326.5 / none) and oklch(39.2% 0.4 10.5 / none).

I think it is clear the resulting color will have an alpha channel of none, but I am not clear on how the premultiplication step happens (the reverse, a color channel being none and defined alpha is now well defined).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-color-4 Current Work
Projects
None yet
Development

No branches or pull requests

2 participants