Open Bug 1847503 Opened 11 months ago Updated 2 months ago

[css-color] Implement gamut mapping for out of range colors

Categories

(Core :: CSS Parsing and Computation, enhancement, P3)

enhancement

Tracking

()

People

(Reporter: tlouw, Assigned: tlouw)

References

(Blocks 3 open bugs)

Details

Attachments

(1 file)

When converting colors to different color spaces, the resulting color might sometimes be out of gamut for the target color space. This is usually ok, but once the color is used to render elements to the screen (or printer, etc), it needs to be mapped into the target color space's gamut range.

For instance, lch(79.4% 62.5 55.71) converted to srgb (which is used to render to the screen at the moment) is color(srgb 1.075 0.665 0.396) where the red component is out of gamut. Gamut mapping this color according to the specification would yield color(srgb 1.0 0.683 0.455) which is in gamut and ready to render to the screen.

See: https://drafts.csswg.org/css-color-4/#gamut-mapping

Assignee: nobody → tlouw
Blocks: css-color-4
Severity: -- → S3
Priority: -- → P3

The specification has had some updates in the past few months and a new reference to gamut mapping is converting certain colors to black or white when gamut mapping for display

https://drafts.csswg.org/css-color/#specifying-lab-lch

If the lightness of a Lab color (after clamping) is 0%, or 100% the color will be displayed as black, or white, respectively due to gamut mapping to the display.

Blocks: 1847421

When colors are converted to sRGB to render onto the display, make sure
that they are within sRGB gamut limits.

Gamut mapping is implemented according to:
https://drafts.csswg.org/css-color-4/#gamut-mapping

The color-mix-non-srgb-001 test is checking the expected result in
sRGB, which happens to be out of gamut limits, but because the test
is for color-mix and not gamut mapping, I changed the expected
results to the color space of the mix.

Attachment #9358618 - Attachment description: WIP: Bug 1847503 - Map colors into gamut limits before rendering. r=#layout → Bug 1847503 - Map colors into gamut limits before rendering. r=#layout
Attachment #9358618 - Attachment description: Bug 1847503 - Map colors into gamut limits before rendering. r=#layout → WIP: Bug 1847503 - Map colors into gamut limits before rendering. r=#layout
Attachment #9358618 - Attachment description: WIP: Bug 1847503 - Map colors into gamut limits before rendering. r=#layout → Bug 1847503 - Map colors into gamut limits before rendering. r=#layout
Pushed by tlouw@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/667d97f09248
Map colors into gamut limits before rendering. r=layout-reviewers,emilio
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/42606 for changes under testing/web-platform/tests

Backed out for causing reftest failures on anim-css-fill-overflow-1-by.svg.

Flags: needinfo?(tlouw)
Upstream PR was closed without merging

After implementing the gamut mapping, I started getting a failure in the SVG animations using SMIL.

According to the SMIL spec, out of gamut colors should just be clipped, but now that we're implementing gamut mapping, it makes more sense to gamut map the results.

The spec:
https://www.w3.org/TR/SVG11/animate.html

19.2.15 The ‘animateColor’ element
...
Out of range color values can be provided, but user agent processing will be implementation
dependent. User agents should clamp color values to allow color range values as late as
possible, but note that system differences might preclude consistent behavior across
different systems.

The specific test and reference is here:
https://searchfox.org/mozilla-central/rev/eadfec923e2b9c927ade8d0dd4f08a82da50a8a9/layout/reftests/svg/smil/style/anim-css-fill-overflow-1-by.svg
https://searchfox.org/mozilla-central/rev/eadfec923e2b9c927ade8d0dd4f08a82da50a8a9/layout/reftests/svg/smil/style/anim-css-fill-overflow-1-ref.svg

Flags: needinfo?(tlouw)
Attachment #9358618 - Attachment description: Bug 1847503 - Map colors into gamut limits before rendering. r=#layout → Bug 1847503 - Map colors into gamut limits before rendering. r=emilio,#layout
Pushed by tlouw@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/e5e1bc9736a5
Map colors into gamut limits before rendering. r=layout-reviewers,emilio
Flags: needinfo?(tlouw)
Upstream PR was closed without merging
Pushed by tlouw@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/09a6e2a57a02
Map colors into gamut limits before rendering. r=layout-reviewers,emilio

Backed out for causing canvas failures on canvas-display-p3-drawImage.https.html

Backout link

Push with failures

Failure log

This is also failing: https://treeherder.mozilla.org/logviewer?job_id=434599606&repo=autoland&lineNumber=6515

Upstream PR was closed without merging
Attachment #9358618 - Attachment description: Bug 1847503 - Map colors into gamut limits before rendering. r=emilio,#layout → WIP: Bug 1847503 - Map colors into gamut limits before rendering. r=emilio,#layout

How does this interact with feDisplacementMap filters? https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDisplacementMap I would expect in2 not to be affected as it's supposed to work on the raw pixel values of the image. If those are corrected then you'll get different displacements on different devices. See also bug 500321

I'm not 100% on the workings of feDisplacementMap, but this gamut mapping is only done for colors, not images.

Every incoming color for SVG is converted to sRGB, e.g. <rect width="2" height="2" style="fill: color(display-p3 1 0 0);"/>, the fill color will be converted to: rgb(98.23% 21.8% 0%). So any any "raw pixel value" should be in sRGB if gamut mapping is not applied, you will work with "invalid" colors.

Duplicate of this bug: 1830268

This is an exact match for what I was asking for, so I think it's better to mark the duplicate to here, rather than bug 1626624. The existence of this bug seems to suggest that the resolution of bug 1830268 was in error.

Blocks: 1823363
Flags: needinfo?(tlouw)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: