w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.42k stars 652 forks source link

[css-images] Don't force non-legacy colors to interpolate in a gamma-encoded space #5883

Closed LeaVerou closed 2 years ago

LeaVerou commented 3 years ago

Surprisingly, Color 4 does not actually have an interpolation section. Color 5 does, and Color 4 is even referencing Color 5 in a section. Images 3 on the other hand defines its own interpolation rules, and specifies that gradients interpolated in premultiplied (gamma-corrected) RGBA, which is clearly from back when all we were dealing with were sRGB colors (though interpolating in gamma-corrected space is suboptimal for those too).

Where to define interpolation? Since Color 4 defines the actual color values, Color 4 needs to define how they interpolate. We cannot define values in one level and interpolation in the next level and we can't have level N citing level N+1.

How to interpolate? In previous discussions, the rule we had discussed was that if two colors are in the same color space, they interpolate in that color space, otherwise in Lab. After further thinking, I don't think that's a good idea. It does maintain backwards compat for old sRGB forms, but it forces new RGB forms like color(display-p3) or even color(srgb) (which we resolved in #5825 that is stored separately from legacy sRGB formats) to also interpolate in gamma-corrected space. Instead, I think the rule should be that colors interpolate in Lab (or XYZ), unless both colors being interpolated are legacy sRGB forms (for backwards compat) OR the host syntax defines a different interpolation space (e.g. color-mix()).

svgeesus commented 3 years ago

Not that surprising. CSS Color 4 is about specifying colors. (It's also pretty stable and seeing multiple implementations, so will go to CR soon).

CSS Color 5 is about combining and manipulating color - mixing, contrast calculation, and the like. It is therefore natural that it has a section on Color interpolation, which includes alpha premultiplication, and hue interpolation (that subsection mainly written by @LeaVerou , with corrections by @dbaron).

Color 5 is less mature, though we do have a resolution to publi

So the color interpolation is in the right specification. It is true though that it should probably hace been called something like CSS Color Manipulation 1.

svgeesus commented 3 years ago

By the way, as CSSWG already discussed, how to interpolate colors also depends on why you are interpolating for. As an example, compositing should be done in a linear-light space like CIE Lab.

Edit: I meant to type CIE XYZ there.

So Compositing-1 needs updating there; it currently only allows compositing in gamma-encoded sRGB. Filters-1 likewise needs updating (it currently only allows linear-light sRGB). And the definitions of gradients in CSS Images-4 need updating (again they are restricted to gamma-encoded sRGB, so you can't interpolate sRGB to P3 for example).

I'm not prepared to hold up CSS Color 4 while all those other specs get their wider-than-sRGB upgrades.

svgeesus commented 3 years ago

Instead, I think the rule should be that colors interpolate in Lab (or XYZ), unless both colors being interpolated are legacy sRGB forms (for backwards compat)

That I certainly agree with.

dbaron commented 3 years ago

What are you suggesting for handling of alpha in interpolation?

svgeesus commented 3 years ago

OR the host syntax defines a different interpolation space (e.g. color-mix()).

Color-5 already says that.

Host syntax can override the interpolation color space and specify which color space is used for interpolation. For example, color-mix and color-adjust override the default to LCH.

svgeesus commented 3 years ago

What are you suggesting for handling of alpha in interpolation?

Interpolating with alpha defines this (for all colorspaces, not just for sRGB).

LeaVerou commented 3 years ago

By the way, as CSSWG already discussed, how to interpolate colors also depends on why you are interpolating for. As an example, compositing should be done in a linear-light space like XYZ. So Compositing-1 needs updating there; it currently only allows compositing in gamma-encoded sRGB. Filters-1 likewise needs updating (it currently only allows linear-light sRGB). And the definitions of gradients in CSS Images-4 need updating (again they are restricted to gamma-encoded sRGB, so you can't interpolate sRGB to P3 for example). I'm not prepared to hold up CSS Color 4 while all those other specs get their wider-than-sRGB upgrades.

We should definitely not hold up Color 4 until other specs update, but that's not what I was proposing. Color 4 needs to have an interpolation section, which defines interpolation for the common case (gradients, transitions etc), and clarifies that other specs may wish to override, leaving it up to them. We typically define how values interpolate in the same spec where the values are defined. Otherwise, if a UA wishes to implement Color 4 but not Color 5, how are they supposed to implement e.g. gradients between Lab colors? Surely they can't (and shouldn't) follow the Images spec and interpolate them in (s)RGBA.

dbaron commented 3 years ago

Interpolating with alpha defines this (for all colorspaces, not just for sRGB).

Sounds good to me (although perhaps some of the text in the examples should also have normative text saying the same thing).

svgeesus commented 3 years ago

although perhaps some of the text in the examples should also have normative text saying the same thing

Oof, yes, will check for anything only said in examples! Although, checking, I don't see anything in the text that is not mentioned normatively - do you have any specific text in mind?

svgeesus commented 3 years ago

After further offline discussion with @fantasai and @LeaVerou I plan to move the entire Color interpolation section from CSS Color 5 to CSS Color 4.

@tabatkins (for Color 4) @una @argyleink (for Color 5) any objections to that?

The color interpolation section was not in the CSS Color 5 First Public Working Draft so there is no patent policy implication. However since Color 4 will be going to CR soon, I want to get it into Color 4 before that, so that we get the patent policy protection on that section as soon as the CR exclusion period ends.

svgeesus commented 3 years ago

After that move, and building on the recent decision about color(srgb ...) being a higher-bit-depth non-legacy opt-in, I can then fix that section so that the legacy colors do the broken thing they already do for Web compat, while the non-legacy colors do the right thing by default and with more flexibility.

argyleink commented 3 years ago

no objections 👍🏻

svgeesus commented 3 years ago

@LeaVerou wrote:

Where to define interpolation? Since Color 4 defines the actual color values, Color 4 needs to define how they interpolate. We cannot define values in one level and interpolation in the next level and we can't have level N citing level N+1.

done

How to interpolate? In previous discussions, the rule we had discussed was that if two colors are in the same color space, they interpolate in that color space, otherwise in Lab. After further thinking, I don't think that's a good idea. It does maintain backwards compat for old sRGB forms, but it forces new RGB forms like color(display-p3) or even color(srgb) (which we resolved in #5825 that is stored separately from legacy sRGB formats) to also interpolate in gamma-corrected space. Instead, I think the rule should be that colors interpolate in Lab (or XYZ), unless both colors being interpolated are legacy sRGB forms (for backwards compat) OR the host syntax defines a different interpolation space (e.g. color-mix()).

also done

Still needs some examples, but please review.

Myndex commented 3 years ago

....compositing should be done in a linear-light space like CIE Lab....

I do agree that most compositing is usually best in a linearized space.

BUT..... LAB is not a linear light space, and I know you know LAB and LUV are perceptual, so not sure which space was actually meant?

In Film/TV LUV or a variant is commonly used, at least "in the guts" of color grading gear. LAB is better suited to reflected colors. I don't remember any time where I used either for compositing though, only for adjusting/grading.

In film/TV typically we linearize RGB. In particular, when possible we linearize the destination or delivery workspace, then the only transform needed on output is applying the transfer curve.

Here's a GIST comparing LAB and LUV:

Where's the LUV?

svgeesus commented 3 years ago

@Myndex wrote:

In Film/TV LUV or a variant is commonly used, at least "in the guts" of color grading gear. LAB is better suited to reflected colors.

I have seen this "LUV for emissive color, LAB for reflective color" meme repeatedly, but never with any actual evidence. I believe it can be traced back to the 1976 CIE committee that standardized both LUV and LAB, and was given as a rather handwavy justification for standardizing both.

Since then, ever paper or book or system that I have seen uses LAB and not LUV, unless:

Checking just now the indexes for six books on various color science topics, LAB is mentioned all over and LUV gets a single mention near the beginning, mostly to note that it is not used, has poor distance metrics, and gives wildly inaccurate predictions for corresponding colors.

If you have examples of CIE LUV being used, please cite them.

If you have examples of a system derived from LUV being used, please name that system.

svgeesus commented 3 years ago

BUT..... LAB is not a linear light space, and I know you know LAB and LUV are perceptual, so not sure which space was actually meant?

I meant to type CIE XYZ. Comment above edited to correct it. Thanks for noticing!

Myndex commented 3 years ago

Hey Chris, @svgeesus

I have seen this "LUV for emissive color, LAB for reflective color" meme repeatedly, but never with any actual evidence.

Yea, I've seen that, and had not given it too much weight until I began some comparative evaluations — I hope you know I question everything and believe no one! (I come from the "question authority" generation after all, LOL). 😎

and was given as a rather handwavy justification for standardizing both.

And, both LAB and LUV are a little handwavy. But also computationally simple compared to complete models.

ever paper or book or system that I have seen uses LAB and not LUV,

I do rely a bit on R.W.G. Hunt's The Reproduction of Colour where he says:

"This quantity is called the CIE 1976 (Luv*) colour difference ....This type of space is useful in studies of colour television because, in the associated chromaticity diagrams, additive mixtures of stimuli lie on straight lines joining the points representing those stimuli..."

Otherwise YES I do agree, especially for general color appearance modeling. LUV is near the bottom of the bunch for general purpose appearance modeling and reflective colors, and therefore not given much weight in many books on the subject. In particular I know Mark Fairchild dismisses LUV pretty harshly, and indeed LUV is NOT useful for color differences of reflected/surface colors.

Nevertheless, it seems somewhat prominent in " HIGH DYNAMIC RANGE IMAGING (2010)" though that is probably due to SGI's development of LogLuv.

And stepping away from pure color theory, data visualization has an affinity for LUV over LAB. From "INFORMATION VISUALIZATION Perception for Design 2nd ed":

"...These are called the CIElab and the CIEluv uniform color spaces.....the two standards have somewhat different properties that make them useful for different tasks. Only the CIEluv formula is described here. It is generally held to be better for specifying large color differences...."

If you have examples of CIE LUV being used, please cite them. If you have examples of a system derived from LUV being used, please name that system.

I have cited/mentioned/examples.... I realize I write a lot, not sure if you have ever received any of the direct emails I've sent you? I also discuss this more in depth in issue #6061 and below are links to

I have a Gist with examples, links, etc: which was linked in the above message, again: Where's The Luv?

Some Use Cases

I've also noticed as I started digging deeper into neurological research the use of CIELUV for research work, such as in this paper: https://www.nature.com/articles/srep42364.pdf

What Caused my Interest: As it happens, in developing SAPC I was working more with LAB — but being often frustrated with a lack of fit to collected data, I started working more with LUV, and also examining other models. TO BE CLEAR: I am not trying to dismiss LAB in any way, but I did add LUV to the models I'm working with, and I've found several aspects that make it favorable over LAB on self illuminated displays.

TL;DR

All that said, I am not the publicist for LUV! LOL ... just pointing out that it has useful applications, and my own experiments and comparisons have shown clear advantages over LAB for use on self illuminated displays for color picking.

Thank you!!

Andy

svgeesus commented 3 years ago

I do rely a bit on R.W.G. Hunt's The Reproduction of Colour where he says:

Hunts' work is well regarded and was seminal in it's day, but the first edition dates to 1957. The fifth edition, which I have, is from 1995 and is a somewhat light re-warming of the 1987 fourth edition. So in terms of evaluating the impact of the 1976 color models, it necessarily misses a lot of later work.

"This quantity is called the CIE 1976 (Luv*) colour difference

Yes, it has a color difference formula. Comparative studies tend to rate it last, and more modern studies don't even evaluate it at all.

This type of space is useful in studies of colour television because, in the associated chromaticity diagrams

I mentioned the (limited) value of chromaticity diagrams as one use case. For stage lighting design, in particular, they were fairly useful This was in the days before personal computers or even programmable calculators, it was a benefit to plot light sources on a large chromaticity diagram drawn on graph paper, connect them with a straight line, and be able to directly read off the resulting mixture chromaticities to two or perhaps three decimal places.

Nowadays they are typically used in reviews or monitors or TVs, as a first approximation to show the gamut of one device compared to another. But due to the lack of perceptual uniformity it is easy to be led astray here. The MacAdam ellipses are still very elliptical and vary greatly in size.

LUV is near the bottom of the bunch for general purpose appearance modeling and reflective colors,

Also for emissive colors. The flaws of the model are not suddenly cured because the light from a colored patch is directly generated rather than being the modified, reflected light. And there is only a small difference in geometry separating an opaque patch illuminated from above, and a translucent filter illuminated from behind by a backlight, as in LCD displays.

" HIGH DYNAMIC RANGE IMAGING (2010)"

(I don't have that one yet, it is eye-wateringly expensive and I fund all my book purchases; W3C doesn't cover them.)

CalMAN™ uses CIELuv

No, CalMan used to use Lab, with deltaE2000 for all color differences, and now has moved to using ICtCp, with deltaITP.

I am not trying to dismiss LAB in any way, but I did add LUV to the models I'm working with, and I've found several aspects that make it favorable over LAB on self illuminated displays.

Thanks for the clarification. Some of your comments, and in particular the personal mails you sent to me earlier, gave a very different impression where you seemed to suggest that any use of Lab was entirely erroneous and purely due to commercial pressure from one or two companies. I'm glad to hear you state more clearly your position - thanks!

I AGREE that Jzazbz is better.

It is better in some ways. I find that the dreaded blue-to-purple shift in Lab is a little over-compensated, giving a turquoise case to blue chroma reduction. It also depends more on the state of adaptation and is sensitive to the scaling (where media white is placed, on the absolute luminance scale used in PQ).

Lastly, while this is interesting and useful discussion, it is entirely unrelated to the topic of this particular issue "Don't force non-legacy colors to interpolate in a gamma-encoded space".

I do hope, though, that your more wide-ranging views will be brought to bear during the Color Workshop. I would also encourage you to submit your research to a Color Science journal.

Myndex commented 3 years ago

Hi @svgeesus I moved my reply to the approriate thread:

https://github.com/w3c/csswg-drafts/issues/6061#issuecomment-790304661

svgeesus commented 3 years ago

To recap, the color interpolation section has been moved from Color 5 to Color 4 and the requested edits have been made to that section.

The remaining part is

Images 3 on the other hand defines its own interpolation rules, and specifies that gradients interpolated in premultiplied (gamma-corrected) RGBA, which is clearly from back when all we were dealing with were sRGB colors (though interpolating in gamma-corrected space is suboptimal for those too).

Re-tagging therefore to Images 4, which is the current work.

Smilebags commented 3 years ago

I would like to read up on any recent progress on Images 4, in particular whether there is anything regarding the space in which compositing occurs (essentially the equivalent of the new CSS colour interpolation options). I am curious to see the direction in which the web is going in terms of how WCG and/or HDR content will be composited in a webpage. Is there any draft specifications in this area?

svgeesus commented 2 years ago

@Smilebags interpolation for gradients would be defined in images 4 (with perceptually uniform spaced like Lab and CH being the most desirable options), but interpolation for compositing would be defined in CSS Compositing; it currently has a gamma-encoded sRGB default and an update would add CIE XYZ because there needs to be a linear-light option.

Smilebags commented 2 years ago

Thanks for that information @svgeesus. I have been keeping an eye on OKLab and was excited to see your recent presentation on it. I'm optimistic that it will provide a very nice modern default for gradient and colour scheme generation, in particular in domains such as data visualisation and design systems. I agree the most problematic part of compositing on the web is the lack of an option for linear-light blending. That seems like it should also simplify (or at least be a part of) the solution to compositing of HDR and WCG content into a webpage.

svgeesus commented 2 years ago

There were some good presentations about HDR and HDR/SDR compositing at the workshop:

HDR: Compositing and tone mapping

LeaVerou commented 2 years ago

To recap, the color interpolation section has been moved from Color 5 to Color 4 and the requested edits have been made to that section.

The remaining part is

Images 3 on the other hand defines its own interpolation rules, and specifies that gradients interpolated in premultiplied (gamma-corrected) RGBA, which is clearly from back when all we were dealing with were sRGB colors (though interpolating in gamma-corrected space is suboptimal for those too).

Re-tagging therefore to Images 4, which is the current work.

Since color interpolation syntax was just added to gradient functions in https://github.com/w3c/csswg-drafts/commit/1f940c6aa92606b447b9b10f880d089833511f77 , I’m gonna go ahead and close this.