Bug 198628 - SVG fill gradients don't support P3 color space
Summary: SVG fill gradients don't support P3 color space
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: Safari 12
Hardware: Mac macOS 10.14
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-06-06 16:04 PDT by wk1
Modified: 2020-05-24 18:05 PDT (History)
7 users (show)

See Also:


Attachments
Test case (788 bytes, image/svg+xml)
2019-06-06 16:04 PDT, wk1
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description wk1 2019-06-06 16:04:32 PDT
Created attachment 371534 [details]
Test case

WebKit doesn't render gradients containing display-p3 colors correctly.

The attached SVG file shows a square filled with a blue linear gradient and a circle filled with a flat purple color. All colors are in display-p3 color space and are specified using CSS color() syntax. The circle renders as expected, but the fill of the square is white.

Environment:
Safari 12.1.1 (14607.2.6.1.1)
macOS 10.14.5 (18F132)
Comment 1 Radar WebKit Bug Importer 2019-06-06 22:18:18 PDT
<rdar://problem/51511996>
Comment 2 wk1 2019-06-10 14:15:53 PDT
The bug is related to how WebCore incorporates the opacity of the stop into the color of the stop. For combining the stop's color and opacity, the color is converted to RGBA32, which doesn't work for extended (i.e. P3) colors.

There is a FIXME comment present that the current approach should be changed, but it notes that the corresponding member function of Color rounds the alpha component differently and is therefore not used.

https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/svg/SVGStopElement.cpp#L98

What is the suggested way to proceed?
Comment 3 Simon Fraser (smfr) 2020-05-24 13:38:08 PDT
As of https://trac.webkit.org/changeset/262035/webkit, the gradient now shows up. I'm not sure if it's using extended color correctly. yet.
Comment 4 Sam Weinig 2020-05-24 18:03:17 PDT
Cool. We should probably add a test case for this then. Not sure what our best bet is. Ref-test vs. the same css gradient? Some pixel poking getImageData()?
Comment 5 Sam Weinig 2020-05-24 18:05:09 PDT
As for accuracy, I am also not sure. The general gradient code uses a color space called kCGColorSpaceExtendedSRGB when any stop contains an extended color. I haven't been able to find any good documentation on that colorspace and whether P3 is a subset of it. (Not mention, "correct" here is not really defined yet - https://github.com/w3c/csswg-drafts/issues/4647)