Re: [csswg-drafts] [css-color-4] Premultiplication in cylindrical spaces and mixing (#11238)

If we're talking about mathematical principles, then I think we'll agree to disagree. That's pretty much academic, as I think we've pretty much converged on not providing compositing methods in cylindrical spaces (partly because of this complexity, partly because it inevitably creates discontinuities). Here's my reasoning though.

There are two interpretations of premultiplied alpha. One is as a filter passing a certain fraction (1 - alpha) of light of the underlying layer, plus adding some additional light. The other is as a convenient mathematical representation of a weighted point in some space, where the actual point can be recovered by dividing by alpha. It's valuable because many different flavors of weighted sum can be computed using only multiplication.

While the former interpretation is appealing, and is certainly meaningful in linear color spaces, I don't think it's particularly valid more generally. Even in nonlinear spaces, it has no real physical interpretation, though it can be considered a (fairly poor) approximation of the linear interpretation. More to the point, as long as what you're computing is a weighted sum of some sort (as is the case both for lerp and over), the two interpretations are the same. And indeed, the result is mathematically invariant to any *affine* transformation of the coordinates.

In the weighted sum interpretation, I consider what CSS specifies for hue premultiplication to be subtly wrong, as the hue component is *not* weighted by the alpha of the associated color, while the others are. That slightly degrades the perceptual linearity of the result. But I think it's fair to characterize this as subtle, as it only affects lerping cases where the endpoints have different alpha.

Of course, the concept of a weighted sum of hue is dodgy in any case; the average of orange and magenta can be either red or cyan depending on which way round you take. But there's no denying it's *useful.*

I'll also argue that the weighted sum interpretation is potentially useful for compositing in color spaces such as Oklab. As I mentioned above, compositing in device RGB is a better approximation than linear compositing to paint layering (Kubelka-Munk). The practical difference is that linear blending of low-key and high-key wipes out the shadow details in the former, while blending in a more perceptually uniform space does not. And Oklab would have better hue linearity. So I think we *will* implement compositing in arbitrary rectangular spaces. Whether it should be in CSS is a different question, as of course it has costs; anything not supported by system compositors, especially so.

So I think what CSS has is good enough and a bit messy, which probably as it should be for a web standard. Premultiplying hue is cleaner in some ways but also messier in others, particularly the hue fixup logic. So I'm fine with the logic staying the same as it is and the color 5 spec language changed to match color 4.

-- 
GitHub Notification of comment by raphlinus
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/11238#issuecomment-2495731573 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Sunday, 24 November 2024 01:15:40 UTC