w3c / csswg-drafts

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

[css-color-4] Evaluate static gamut mapping algorithms for oklab/oklch spaces #10579

Open ccameron-chromium opened 1 month ago

ccameron-chromium commented 1 month ago

Separating the action item "ccameron: review gamut mapping algorithms" from here into a new issue. Tagging in @foolip @LeaVerou @svgeesus for the more limited discussion here (please feel free to include anyone else).

From the linked resolution in the issue, these algorithms are not to be applied to the various RGB spaces. I'd like to scope my comments to just "gamut mapping to apply to oklab/oklch" spaces, since I feel a bit differently about XYZ and Lab spaces (I would want XYZ and Lab to follow RGB, because they are the canonical profile connection spaces used in ICC based color matching, and don't want to mix this discussion with those issues).

The properties that I'd like for the algorithm to apply to just-oklab/oklch are much looser. An iterative algorithm with quadratic convergence is quite fine.

There were lots of algorithms listed in issue 9449, so I'd like to collect a reduced list of candidates here to discuss.

To provide an extremely short list:

svgeesus commented 1 month ago

Thanks for starting this.

  • Projecting in Lab to the Rec2020 gamut boundary along constant L

Why Lab and not Oklab, given the hue curvature of Lab (especially in blues, but also in orange to a lesser extent).

I agree that mapping to a smoothed gamut boundary may well be better.

  • Projecting in Rec2020 YUV along constant Y

That is video luma, right? Where Y is computed without bothering to undo gamma-encoding first?

ccameron-chromium commented 1 month ago

Thanks for starting this.

  • Projecting in Lab to the Rec2020 gamut boundary along constant L

Why Lab and not Oklab, given the hue curvature of Lab (especially in blues, but also in orange to a lesser extent).

Sorry, that was a typo. I fixed up the original comment.

I agree that mapping to a smoothed gamut boundary may well be better.

  • Projecting in Rec2020 YUV along constant Y

That is video luma, right? Where Y is computed without bothering to undo gamma-encoding first?

In the experiments that I did (which was not very exhaustive), I was doing this in linear space, but that was just because it was easier to plug into the pipeline at that stage.

Another option was to find the nearest point in the L2 sense in YUV space (either linear or gamma encoded). I haven't investigated that thoroughly.

svgeesus commented 1 month ago

Sorry, that was a typo. I fixed up the original comment.

Ah okay, makes sense.

I was doing this in linear space

That makes the calculated lightness accurate, so good. It doesn't make the UV plane perceptually uniform, of course.

svgeesus commented 1 month ago

There is some concave nastiness around the blue corner of the gamut that it would be nice to avoid.

This is clearly seen in CSS Color 4, Figure 2.

sRGB-DisplayP3-rec2020-in-Oklab