Skip to content

Commit 9572c36

Browse files
committed
Add "srgb-linear" and "display-p3-linear" to PredefinedColorSpace
https://bugs.webkit.org/show_bug.cgi?id=306644 Reviewed by Devin Rousso. Adds support for "srgb-linear" and "display-p3-linear" to PredefinedColorSpace. Mostly plumbing, as underlying support was already there. Also imports relevant test cases from WPT. Tests: imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.display-p3-linear.html imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.srgb-linear.html imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.display-p3-linear.html imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.display-p3-linear.worker.html imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.srgb-linear.html imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.srgb-linear.worker.html * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.display-p3-linear-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.display-p3-linear.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.fillText.html: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.fillText.shadow.html: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.strokeText.html: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.to.p3.html: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.to.srgb-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.to.srgb.html: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.toBlob.p3.canvas.html: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.toBlob.with.putImageData.html: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.toDataURL.jpeg.p3.canvas.html: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.toDataURL.p3.canvas.html: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.toDataURL.with.putImageData.html: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.srgb-linear-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.srgb-linear.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/WEB_FEATURES.yml: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/w3c-import.log: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.display-p3-linear-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.display-p3-linear.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.display-p3-linear.worker-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.display-p3-linear.worker.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.display-p3-linear.worker.js: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.p3.to.p3.html: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.p3.to.p3.worker.js: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.p3.to.srgb-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.p3.to.srgb.html: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.p3.to.srgb.worker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.p3.to.srgb.worker.js: * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.srgb-linear-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.srgb-linear.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.srgb-linear.worker-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.srgb-linear.worker.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/2d.color.space.srgb-linear.worker.js: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/WEB_FEATURES.yml: Added. * LayoutTests/imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/w3c-import.log: * Source/JavaScriptCore/inspector/protocol/Canvas.json: * Source/WebCore/bindings/js/SerializedScriptValue.cpp: * Source/WebCore/html/canvas/PredefinedColorSpace.cpp: * Source/WebCore/html/canvas/PredefinedColorSpace.h: * Source/WebCore/html/canvas/PredefinedColorSpace.idl: * Source/WebCore/inspector/InspectorCanvas.cpp: * Source/WebCore/platform/graphics/ColorConversion.cpp: * Source/WebCore/platform/graphics/PlatformColorSpace.h: * Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js: * Source/WebInspectorUI/UserInterface/Models/Canvas.js: * Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in: Canonical link: https://commits.webkit.org/306563@main
1 parent d5b064d commit 9572c36

File tree

46 files changed

+457
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+457
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2d.color.space.display-p3-linear
2+
test getImageData color conversion with a display-p3-linear uint8 canvas
3+
Actual output:
4+
5+
PASS test getImageData color conversion with a display-p3-linear uint8 canvas
6+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
4+
<title>Canvas test: 2d.color.space.display-p3-linear</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/html/canvas/resources/canvas-tests.js"></script>
8+
<link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css">
9+
<body class="show_output">
10+
11+
<h1>2d.color.space.display-p3-linear</h1>
12+
<p class="desc">test getImageData color conversion with a display-p3-linear uint8 canvas</p>
13+
14+
15+
<p class="output">Actual output:</p>
16+
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
17+
18+
<ul id="d"></ul>
19+
<script>
20+
var t = async_test("test getImageData color conversion with a display-p3-linear uint8 canvas");
21+
_addTest(function(canvas, ctx) {
22+
23+
const color_style = 'color(display-p3-linear 0.0392 0.3922 0.7843)';
24+
// [0.0392, 0.3922, 0.7843, 1.0] * 255 = [10, 100, 200, 255]
25+
const epsilon = 2;
26+
ctx.fillStyle = color_style;
27+
ctx.fillRect(0, 0, 10, 10);
28+
29+
// Read without specifying a color space. The result should be the specified
30+
// color.
31+
let pixel_expected = [10, 100, 200, 255];
32+
let image_data = ctx.getImageData(5, 5, 1, 1);
33+
_assertSame(image_data.colorSpace, "display-p3-linear", "image_data.colorSpace", "\"display-p3-linear\"");
34+
assert_approx_equals(image_data.data[0], pixel_expected[0], 2);
35+
assert_approx_equals(image_data.data[1], pixel_expected[1], 2);
36+
assert_approx_equals(image_data.data[2], pixel_expected[2], 2);
37+
assert_approx_equals(image_data.data[3], pixel_expected[3], 2);
38+
39+
// Read back to display-p3. This will convert from linear to sRGB transfer
40+
// function.
41+
pixel_expected = [58, 168, 229, 255];
42+
image_data = ctx.getImageData(5, 5, 1, 1, {colorSpace:"display-p3"});
43+
_assertSame(image_data.colorSpace, "display-p3", "image_data.colorSpace", "\"display-p3\"");
44+
assert_approx_equals(image_data.data[0], pixel_expected[0], 2);
45+
assert_approx_equals(image_data.data[1], pixel_expected[1], 2);
46+
assert_approx_equals(image_data.data[2], pixel_expected[2], 2);
47+
assert_approx_equals(image_data.data[3], pixel_expected[3], 2);
48+
49+
}, {colorSpace: "display-p3-linear"});
50+
</script>
51+

LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.fillText.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
34
<title>Canvas test: 2d.color.space.p3.fillText</title>
45
<script src="/resources/testharness.js"></script>
56
<script src="/resources/testharnessreport.js"></script>

LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.fillText.shadow.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
34
<title>Canvas test: 2d.color.space.p3.fillText.shadow</title>
45
<script src="/resources/testharness.js"></script>
56
<script src="/resources/testharnessreport.js"></script>

LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.strokeText.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
34
<title>Canvas test: 2d.color.space.p3.strokeText</title>
45
<script src="/resources/testharness.js"></script>
56
<script src="/resources/testharnessreport.js"></script>

LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.to.p3.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
34
<title>Canvas test: 2d.color.space.p3.to.p3</title>
45
<script src="/resources/testharness.js"></script>
56
<script src="/resources/testharnessreport.js"></script>
@@ -26,7 +27,7 @@ <h1>2d.color.space.p3.to.p3</h1>
2627
ctx.fillStyle = color_style;
2728
ctx.fillRect(0, 0, 10, 10);
2829

29-
var pixel = ctx.getImageData(5, 5, 1, 1, {colorSpace: "display-p3", storageFormat: "uint8"}).data;
30+
var pixel = ctx.getImageData(5, 5, 1, 1, {colorSpace: "display-p3"}).data;
3031
_assertSame(pixel.length, pixel_expected.length, "pixel.length", "pixel_expected.length");
3132
assert_approx_equals(pixel[0], pixel_expected[0], 2);
3233
assert_approx_equals(pixel[1], pixel_expected[1], 2);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
2d.color.space.p3.to.srgb
2-
test getImageData with srsb and uint8 from display p3 uint8 canvas
2+
test getImageData with srgb and uint8 from display p3 uint8 canvas
33
Actual output:
44

5-
PASS test getImageData with srsb and uint8 from display p3 uint8 canvas
5+
PASS test getImageData with srgb and uint8 from display p3 uint8 canvas
66

LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.to.srgb.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
34
<title>Canvas test: 2d.color.space.p3.to.srgb</title>
45
<script src="/resources/testharness.js"></script>
56
<script src="/resources/testharnessreport.js"></script>
@@ -8,15 +9,15 @@
89
<body class="show_output">
910

1011
<h1>2d.color.space.p3.to.srgb</h1>
11-
<p class="desc">test getImageData with srsb and uint8 from display p3 uint8 canvas</p>
12+
<p class="desc">test getImageData with srgb and uint8 from display p3 uint8 canvas</p>
1213

1314

1415
<p class="output">Actual output:</p>
1516
<canvas id="c" class="output" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
1617

1718
<ul id="d"></ul>
1819
<script>
19-
var t = async_test("test getImageData with srsb and uint8 from display p3 uint8 canvas");
20+
var t = async_test("test getImageData with srgb and uint8 from display p3 uint8 canvas");
2021
_addTest(function(canvas, ctx) {
2122

2223
var color_style = 'rgb(50, 100, 150)';
@@ -25,7 +26,7 @@ <h1>2d.color.space.p3.to.srgb</h1>
2526
ctx.fillStyle = color_style;
2627
ctx.fillRect(0, 0, 10, 10);
2728

28-
var pixel = ctx.getImageData(5, 5, 1, 1, {colorSpace: "srgb", storageFormat: "uint8"}).data;
29+
var pixel = ctx.getImageData(5, 5, 1, 1, {colorSpace: "srgb"}).data;
2930
_assertSame(pixel.length, pixel_expected.length, "pixel.length", "pixel_expected.length");
3031
assert_approx_equals(pixel[0], pixel_expected[0], 2);
3132
assert_approx_equals(pixel[1], pixel_expected[1], 2);

LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.toBlob.p3.canvas.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
34
<title>Canvas test: 2d.color.space.p3.toBlob.p3.canvas</title>
45
<script src="/resources/testharness.js"></script>
56
<script src="/resources/testharnessreport.js"></script>

LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/2d.color.space.p3.toBlob.with.putImageData.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. -->
3+
<meta charset="UTF-8">
34
<title>Canvas test: 2d.color.space.p3.toBlob.with.putImageData</title>
45
<script src="/resources/testharness.js"></script>
56
<script src="/resources/testharnessreport.js"></script>

0 commit comments

Comments
 (0)