Diff
Modified: trunk/LayoutTests/ChangeLog (272124 => 272125)
--- trunk/LayoutTests/ChangeLog 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/LayoutTests/ChangeLog 2021-01-31 20:24:46 UTC (rev 272125)
@@ -1,3 +1,18 @@
+2021-01-31 Sam Weinig <[email protected]>
+
+ Add support for color(prophoto-rgb ...) as part of CSS Color 4
+ https://bugs.webkit.org/show_bug.cgi?id=221116
+
+ Reviewed by Antti Koivisto.
+
+ * TestExpectations:
+ Remove now passing prophoto-rgb tests.
+
+ * fast/css/parsing-color-function-expected.txt:
+ * fast/css/parsing-color-function.html:
+ Add prophoto-rgb as an rgb type so it gets tested with the
+ others.
+
2021-01-30 Sam Weinig <[email protected]>
Add support for color(rec2020 ...) as part of CSS Color 4
Modified: trunk/LayoutTests/TestExpectations (272124 => 272125)
--- trunk/LayoutTests/TestExpectations 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/LayoutTests/TestExpectations 2021-01-31 20:24:46 UTC (rev 272125)
@@ -4604,8 +4604,6 @@
# Unsupported css color() variants
webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-003.html [ ImageOnlyFailure ] # Invalid test, no colorspace specified
webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-004.html [ ImageOnlyFailure ] # Invalid test, no colorspace specified
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-009.html [ ImageOnlyFailure ] # Requires prophoto-rgb support
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-010.html [ ImageOnlyFailure ] # Requires prophoto-rgb support
webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-014.html [ ImageOnlyFailure ] # Requires fallback (at parse time) support
webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-015.html [ ImageOnlyFailure ] # Requires fallback (at parse time) support (unclear if this makes sense)
webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-016.html [ ImageOnlyFailure ] # Requires xyz support
Modified: trunk/LayoutTests/fast/css/parsing-color-function-expected.txt (272124 => 272125)
--- trunk/LayoutTests/fast/css/parsing-color-function-expected.txt 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/LayoutTests/fast/css/parsing-color-function-expected.txt 2021-01-31 20:24:46 UTC (rev 272125)
@@ -93,6 +93,36 @@
PASS computedStyle("background-color", "color(rec2020 0% 0 0deg)") is "rgba(0, 0, 0, 0)"
PASS computedStyle("background-color", "color(rec2020 0% 0% 0deg)") is "rgba(0, 0, 0, 0)"
PASS computedStyle("background-color", "color(rec2020 40% 0 0deg)") is "rgba(0, 0, 0, 0)"
+
+Testing color(prophoto-rgb ...)
+PASS computedStyle("background-color", "color(prophoto-rgb 0% 0% 0%)") is "color(prophoto-rgb 0 0 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 10% 10% 10%)") is "color(prophoto-rgb 0.1 0.1 0.1)"
+PASS computedStyle("background-color", "color(prophoto-rgb .2 .2 25%)") is "color(prophoto-rgb 0.2 0.2 0.25)"
+PASS computedStyle("background-color", "color(prophoto-rgb 0 0 0 / 1)") is "color(prophoto-rgb 0 0 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 0% 0 0 / 0.5)") is "color(prophoto-rgb 0 0 0 / 0.5)"
+PASS computedStyle("background-color", "color(prophoto-rgb 20% 0 10/0.5)") is "color(prophoto-rgb 0.2 0 1 / 0.5)"
+PASS computedStyle("background-color", "color(prophoto-rgb 20% 0 10/50%)") is "color(prophoto-rgb 0.2 0 1 / 0.5)"
+PASS computedStyle("background-color", "color(prophoto-rgb 400% 0 10/50%)") is "color(prophoto-rgb 1 0 1 / 0.5)"
+PASS computedStyle("background-color", "color(prophoto-rgb 50% -160 160)") is "color(prophoto-rgb 0.5 0 1)"
+PASS computedStyle("background-color", "color(prophoto-rgb 50% -200 200)") is "color(prophoto-rgb 0.5 0 1)"
+PASS computedStyle("background-color", "color(prophoto-rgb 0 0 0 / -10%)") is "color(prophoto-rgb 0 0 0 / 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 0 0 0 / 110%)") is "color(prophoto-rgb 0 0 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 0 0 0 / 300%)") is "color(prophoto-rgb 0 0 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 50% -200)") is "color(prophoto-rgb 0.5 0 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 50%)") is "color(prophoto-rgb 0.5 0 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb)") is "color(prophoto-rgb 0 0 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 50% -200 / 0.5)") is "color(prophoto-rgb 0.5 0 0 / 0.5)"
+PASS computedStyle("background-color", "color(prophoto-rgb 50% / 0.5)") is "color(prophoto-rgb 0.5 0 0 / 0.5)"
+PASS computedStyle("background-color", "color(prophoto-rgb / 0.5)") is "color(prophoto-rgb 0 0 0 / 0.5)"
+
+Test invalid values
+PASS computedStyle("background-color", "color(prophoto-rgb 0 0 0 0)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 0deg 0% 0)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 0% 0 0 1)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 0% 0 0 10%)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 0% 0 0deg)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 0% 0% 0deg)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color(prophoto-rgb 40% 0 0deg)") is "rgba(0, 0, 0, 0)"
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/fast/css/parsing-color-function.html (272124 => 272125)
--- trunk/LayoutTests/fast/css/parsing-color-function.html 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/LayoutTests/fast/css/parsing-color-function.html 2021-01-31 20:24:46 UTC (rev 272125)
@@ -34,7 +34,7 @@
shouldBeEqualToString('innerStyle("' + property + '", "' + value + '")', expected);
}
- for (const color of [ "srgb", "a98-rgb", "rec2020" ]) {
+ for (const color of [ "srgb", "a98-rgb", "rec2020", "prophoto-rgb" ]) {
debug('');
debug(`Testing color(${color} ...)`);
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (272124 => 272125)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2021-01-31 20:24:46 UTC (rev 272125)
@@ -1,3 +1,22 @@
+2021-01-31 Sam Weinig <[email protected]>
+
+ Add support for color(prophoto-rgb ...) as part of CSS Color 4
+ https://bugs.webkit.org/show_bug.cgi?id=221116
+
+ Reviewed by Antti Koivisto.
+
+ Add some new WPT tests for color(prophoto-rgb ) that will be upstreamed shortly.
+ (see https://github.com/web-platform-tests/wpt/pull/27416).
+
+ * web-platform-tests/css/css-color/prophoto-rgb-001-expected.html: Added.
+ * web-platform-tests/css/css-color/prophoto-rgb-001.html: Added.
+ * web-platform-tests/css/css-color/prophoto-rgb-002-expected.html: Added.
+ * web-platform-tests/css/css-color/prophoto-rgb-002.html: Added.
+ * web-platform-tests/css/css-color/prophoto-rgb-003-expected.html: Added.
+ * web-platform-tests/css/css-color/prophoto-rgb-003.html: Added.
+ * web-platform-tests/css/css-color/prophoto-rgb-004-expected.html: Added.
+ * web-platform-tests/css/css-color/prophoto-rgb-004.html: Added.
+
2021-01-30 Sam Weinig <[email protected]>
Add support for color(rec2020 ...) as part of CSS Color 4
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-001-expected.html (0 => 272125)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-001-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-001-expected.html 2021-01-31 20:24:46 UTC (rev 272125)
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Green square reference</title>
+<style>
+ .test { background-color: #008000; width: 12em; height: 12em;}
+</style>
+<body>
+ <p>Test passes if you see a green square, and no red.</p>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-001.html (0 => 272125)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-001.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-001.html 2021-01-31 20:24:46 UTC (rev 272125)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: prophoto-rgb</title>
+<link rel="author" title="Sam Weinig" href=""
+<link rel="help" href=""
+<link rel="match" href=""
+<meta name="assert" content="prophoto-rgb with no alpha">
+<style>
+ .test { background-color: red; width: 12em; height: 12em; }
+ .test { background-color: color(prophoto-rgb 0.230479 0.395789 0.129968); } /* green (sRGB #008000) converted to prophoto-rgb */
+</style>
+<body>
+ <p>Test passes if you see a green square, and no red.</p>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-002-expected.html (0 => 272125)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-002-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-002-expected.html 2021-01-31 20:24:46 UTC (rev 272125)
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Black square reference</title>
+<style>
+ .test { background-color: #000000; width: 12em; height: 12em; }
+</style>
+<body>
+ <p>Test passes if you see a black square, and no red.</p>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-002.html (0 => 272125)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-002.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-002.html 2021-01-31 20:24:46 UTC (rev 272125)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: prophoto-rgb</title>
+<link rel="author" title="Sam Weinig" href=""
+<link rel="help" href=""
+<link rel="match" href=""
+<meta name="assert" content="prophoto-rgb with no alpha">
+<style>
+ .test { background-color: red; width: 12em; height: 12em; }
+ .test { background-color: color(prophoto-rgb 0 0 0); } /* black (sRGB #000000) converted to prophoto-rgb */
+</style>
+<body>
+ <p>Test passes if you see a black square, and no red.</p>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-003-expected.html (0 => 272125)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-003-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-003-expected.html 2021-01-31 20:24:46 UTC (rev 272125)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: CSS Color 4: prophoto-rgb</title>
+<style>
+ body { background-color: grey; }
+ .test { background-color: lab(100% 0.0131 0.0085); width: 12em; height: 12em; } /* color(prophoto-rgb 1 1 1) converted to Lab */
+</style>
+<body>
+ <p>Test passes if you see a single square, and not two rectangles of different colors.</p>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-003.html (0 => 272125)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-003.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-003.html 2021-01-31 20:24:46 UTC (rev 272125)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: prophoto-rgb</title>
+<link rel="author" title="Sam Weinig" href=""
+<link rel="help" href=""
+<link rel="match" href=""
+<meta name="assert" content="prophoto-rgb with no alpha">
+<style>
+ body { background-color: grey; }
+ .test { background-color: red; width: 12em; height: 6em; margin-top: 0; }
+ .ref { background-color: lab(100% 0.0131 0.0085); width: 12em; height: 6em; margin-bottom: 0; } /* color(prophoto-rgb 1 1 1) converted to Lab */
+ .test { background-color: color(prophoto-rgb 1 1 1); }
+</style>
+<body>
+ <p>Test passes if you see a single square, and not two rectangles of different colors.</p>
+ <div class="ref"></div>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-004-expected.html (0 => 272125)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-004-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-004-expected.html 2021-01-31 20:24:46 UTC (rev 272125)
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: CSS Color 4: prophoto-rgb</title>
+<style>
+ .test { background-color: lab(87.5745% -186.6921 150.9905); width: 12em; height: 12em; } /* color(prophoto-rgb 0 1 0) converted to Lab */
+</style>
+<body>
+ <p>Test passes if you see a single square, and not two rectangles of different colors.</p>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-004.html (0 => 272125)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-004.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-004.html 2021-01-31 20:24:46 UTC (rev 272125)
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: prophoto-rgb</title>
+<link rel="author" title="Sam Weinig" href=""
+<link rel="help" href=""
+<link rel="match" href=""
+<meta name="assert" content="prophoto-rgb with no alpha">
+<style>
+ .test { background-color: red; width: 12em; height: 6em; margin-top: 0; }
+ .ref { background-color: lab(87.5745% -186.6921 150.9905); width: 12em; height: 6em; margin-bottom: 0; } /* color(prophoto-rgb 0 1 0) converted to Lab */
+ .test { background-color: color(prophoto-rgb 0 1 0); }
+</style>
+<body>
+ <p>Test passes if you see a single square, and not two rectangles of different colors.</p>
+ <div class="ref"></div>
+ <div class="test"></div>
+</body>
Modified: trunk/Source/WebCore/ChangeLog (272124 => 272125)
--- trunk/Source/WebCore/ChangeLog 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/ChangeLog 2021-01-31 20:24:46 UTC (rev 272125)
@@ -1,3 +1,76 @@
+2021-01-31 Sam Weinig <[email protected]>
+
+ Add support for color(prophoto-rgb ...) as part of CSS Color 4
+ https://bugs.webkit.org/show_bug.cgi?id=221116
+
+ Reviewed by Antti Koivisto.
+
+ Tests: imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-001.html
+ imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-002.html
+ imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-003.html
+ imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-004.html
+
+ * css/CSSValueKeywords.in:
+ Add prophoto-rgb keyword.
+
+ * css/parser/CSSPropertyParserHelpers.cpp:
+ (WebCore::CSSPropertyParserHelpers::parseColorFunctionForRGBTypes):
+ (WebCore::CSSPropertyParserHelpers::parseColorFunctionParameters):
+ Parse color(prophoto-rgb ) using the existing generic rgb type color function
+ parsing function.
+
+ * platform/graphics/ColorConversion.cpp:
+ (WebCore::convertFromD50WhitePointToD65WhitePoint):
+ (WebCore::convertFromD65WhitePointToD50WhitePoint):
+ Move these chromatic adaptation conversions up in the file so they can be reused by
+ toLinearProPhotoRGB(copnst XYZA&) and toXYZA(const LinearProPhotoRGB).
+
+ (WebCore::toLinearProPhotoRGB):
+ (WebCore::toProPhotoRGB):
+ (WebCore::toXYZA):
+ * platform/graphics/ColorConversion.h:
+ (WebCore::toLinearRec2020):
+ (WebCore::toProPhotoRGB):
+ (WebCore::toLinearProPhotoRGB):
+ (WebCore::callWithColorType):
+ Add conversion support for ProPhotoRGB, utilizing the ProPhotoRGBTransferFunction
+ for gamma correction.
+
+ * platform/graphics/ColorSerialization.cpp:
+ (WebCore::serialization):
+ (WebCore::serializationForCSS):
+ (WebCore::serializationForHTML):
+ (WebCore::serializationForRenderTreeAsText):
+ * platform/graphics/ColorSerialization.h:
+ Add serialization support, matching other rgb color() function
+ types.
+
+ * platform/graphics/ColorSpace.cpp:
+ (WebCore::operator<<):
+ * platform/graphics/ColorSpace.h:
+ Add ProPhotoRGB as a new ColorSpace.
+
+ * platform/graphics/ColorTransferFunctions.h:
+ (WebCore::mode>::toGammaEncoded):
+ (WebCore::mode>::toLinear):
+ Add transfer function for ProPhotoRGB. Both clamped and unclamped
+ are implemented, though for now, only the clamped variant is
+ being used. Also fix small bug in unclamped Rec2020TransferFunction
+ that I meant to land before where the sign wasn't getting applied
+ to the whole computation.
+
+ * platform/graphics/ColorTypes.h:
+ Add ProPhotoRGB and LinearProPhotoRGB types. Fix typo in forward
+ declaration of the XYZA type.
+
+ * platform/graphics/cg/ColorSpaceCG.cpp:
+ (WebCore::proPhotoRGBColorSpaceRef):
+ * platform/graphics/cg/ColorSpaceCG.h:
+ (WebCore::cachedCGColorSpace):
+ Add support for the ProPhotoRGB as a CoreGraphics color space, where
+ it is known as kCGColorSpaceROMMRGB (ROMM stands for Reference Output
+ Medium Metric, another name for ProPhoto).
+
2021-01-31 Zalan Bujtas <[email protected]>
[LFC][IFC] TrailingTextContent should be able to tell if even the first run in the set does not fit
Modified: trunk/Source/WebCore/css/CSSValueKeywords.in (272124 => 272125)
--- trunk/Source/WebCore/css/CSSValueKeywords.in 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/css/CSSValueKeywords.in 2021-01-31 20:24:46 UTC (rev 272125)
@@ -1406,6 +1406,7 @@
a98-rgb
display-p3
// lab
+prophoto-rgb
// rec2020
// sRGB
Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (272124 => 272125)
--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp 2021-01-31 20:24:46 UTC (rev 272125)
@@ -894,7 +894,7 @@
template<typename ColorType>
static Color parseColorFunctionForRGBTypes(CSSParserTokenRange& args)
{
- ASSERT(args.peek().id() == CSSValueA98Rgb || args.peek().id() == CSSValueDisplayP3 || args.peek().id() == CSSValueRec2020 || args.peek().id() == CSSValueSRGB);
+ ASSERT(args.peek().id() == CSSValueA98Rgb || args.peek().id() == CSSValueDisplayP3 || args.peek().id() == CSSValueProphotoRgb || args.peek().id() == CSSValueRec2020 || args.peek().id() == CSSValueSRGB);
consumeIdentRaw(args);
double channels[3] = { 0, 0, 0 };
@@ -958,6 +958,9 @@
case CSSValueLab:
color = parseColorFunctionForLabParameters(args);
break;
+ case CSSValueProphotoRgb:
+ color = parseColorFunctionForRGBTypes<ProPhotoRGB<float>>(args);
+ break;
case CSSValueRec2020:
color = parseColorFunctionForRGBTypes<Rec2020<float>>(args);
break;
Modified: trunk/Source/WebCore/platform/graphics/ColorConversion.cpp (272124 => 272125)
--- trunk/Source/WebCore/platform/graphics/ColorConversion.cpp 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/platform/graphics/ColorConversion.cpp 2021-01-31 20:24:46 UTC (rev 272125)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017, 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -65,6 +65,22 @@
0.0f, 0.0451133818589026f, 1.043944368900976f
};
+// ProPhotoRGB Matrices.
+
+// https://drafts.csswg.org/css-color/#color-conversion-code
+static constexpr ColorMatrix<3, 3> xyzToLinearProPhotoRGBMatrix {
+ 1.3457989731028281f, -0.25558010007997534f, -0.05110628506753401f,
+ -0.5446224939028347f, 1.5082327413132781f, 0.02053603239147973f,
+ 0.0f, 0.0f, 1.2119675456389454f
+};
+
+// https://drafts.csswg.org/css-color/#color-conversion-code
+static constexpr ColorMatrix<3, 3> linearProPhotoRGBToXYZMatrix {
+ 0.7977604896723027f, 0.13518583717574031f, 0.0313493495815248f,
+ 0.2880711282292934f, 0.7118432178101014f, 0.00008565396060525902f,
+ 0.0f, 0.0f, 0.8251046025104601f
+};
+
// Rec2020 Matrices.
// https://drafts.csswg.org/css-color/#color-conversion-code
@@ -115,6 +131,18 @@
-0.0092345f, 0.0150436f, 0.7521316f
};
+// MARK: Chromatic Adaptation conversions.
+
+static XYZA<float> convertFromD50WhitePointToD65WhitePoint(const XYZA<float>& color)
+{
+ return makeFromComponentsClampingExceptAlpha<XYZA<float>>(D50ToD65Matrix.transformedColorComponents(asColorComponents(color)));
+}
+
+static XYZA<float> convertFromD65WhitePointToD50WhitePoint(const XYZA<float>& color)
+{
+ return makeFromComponentsClampingExceptAlpha<XYZA<float>>(D65ToD50Matrix.transformedColorComponents(asColorComponents(color)));
+}
+
// MARK: Gamma conversions.
template<typename TransferFunction, typename ColorType> static auto toLinear(const ColorType& color) -> typename ColorType::LinearCounterpart
@@ -165,6 +193,18 @@
return toGammaEncoded<SRGBTransferFunction<float, TransferFunctionMode::Unclamped>>(color);
}
+// ProPhotoRGB <-> LinearProPhotoRGB conversions.
+
+LinearProPhotoRGB<float> toLinearProPhotoRGB(const ProPhotoRGB<float>& color)
+{
+ return toLinear<ProPhotoRGBTransferFunction<float, TransferFunctionMode::Clamped>>(color);
+}
+
+ProPhotoRGB<float> toProPhotoRGB(const LinearProPhotoRGB<float>& color)
+{
+ return toGammaEncoded<ProPhotoRGBTransferFunction<float, TransferFunctionMode::Clamped>>(color);
+}
+
// Rec2020 <-> LinearRec2020 conversions.
LinearRec2020<float> toLinearRec2020(const Rec2020<float>& color)
@@ -227,6 +267,27 @@
return makeFromComponentsClampingExceptAlpha<XYZA<float>>(linearSRGBToXYZMatrix.transformedColorComponents(asColorComponents(color)));
}
+// - LinearProPhotoRGB matrix conversions.
+
+LinearProPhotoRGB<float> toLinearProPhotoRGB(const XYZA<float>& color)
+{
+ // We expect XYZA colors to be using the D65 white point, unlike ProPhotoRGB, which
+ // uses a D50 white point, so as a first step, use the Bradford transform to convert
+ // the incoming XYZA color to D50 white point.
+ auto xyzWithD50WhitePoint = convertFromD65WhitePointToD50WhitePoint(color);
+ return makeFromComponentsClampingExceptAlpha<LinearProPhotoRGB<float>>(xyzToLinearProPhotoRGBMatrix.transformedColorComponents(asColorComponents(xyzWithD50WhitePoint)));
+}
+
+XYZA<float> toXYZA(const LinearProPhotoRGB<float>& color)
+{
+ auto xyzWithD50WhitePoint = makeFromComponentsClampingExceptAlpha<XYZA<float>>(linearProPhotoRGBToXYZMatrix.transformedColorComponents(asColorComponents(color)));
+
+ // We expect XYZA colors to be using the D65 white point, unlike ProPhotoRGB, which
+ // uses a D50 white point, so as a final step, use the Bradford transform to convert
+ // the resulting XYZA color to a D65 white point.
+ return convertFromD50WhitePointToD65WhitePoint(xyzWithD50WhitePoint);
+}
+
// - LinearRec2020 matrix conversions.
LinearRec2020<float> toLinearRec2020(const XYZA<float>& color)
@@ -251,18 +312,6 @@
return makeFromComponentsClampingExceptAlpha<XYZA<float>>(linearSRGBToXYZMatrix.transformedColorComponents(asColorComponents(color)));
}
-// MARK: Chromatic Adaptation conversions.
-
-static XYZA<float> convertFromD50WhitePointToD65WhitePoint(const XYZA<float>& color)
-{
- return makeFromComponentsClampingExceptAlpha<XYZA<float>>(D50ToD65Matrix.transformedColorComponents(asColorComponents(color)));
-}
-
-static XYZA<float> convertFromD65WhitePointToD50WhitePoint(const XYZA<float>& color)
-{
- return makeFromComponentsClampingExceptAlpha<XYZA<float>>(D65ToD50Matrix.transformedColorComponents(asColorComponents(color)));
-}
-
// MARK: HSL conversions.
HSLA<float> toHSLA(const SRGBA<float>& color)
@@ -508,6 +557,18 @@
return toLCHA(toLab(color));
}
+// - ProPhotoRGB combination functions.
+
+XYZA<float> toXYZA(const ProPhotoRGB<float>& color)
+{
+ return toXYZA(toLinearProPhotoRGB(color));
+}
+
+ProPhotoRGB<float> toProPhotoRGB(const XYZA<float>& color)
+{
+ return toProPhotoRGB(toLinearProPhotoRGB(color));
+}
+
// - Rec2020 combination functions.
XYZA<float> toXYZA(const Rec2020<float>& color)
Modified: trunk/Source/WebCore/platform/graphics/ColorConversion.h (272124 => 272125)
--- trunk/Source/WebCore/platform/graphics/ColorConversion.h 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/platform/graphics/ColorConversion.h 2021-01-31 20:24:46 UTC (rev 272125)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017, 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,10 +29,19 @@
namespace WebCore {
-// All color types must at least implement the following conversions to and from the XYZA color space:
-// XYZA<float> toXYZA(const ColorType<float>&);
-// ColorType<float> toColorType(const XYZA<float>&);
+// All color types must at least implement the following conversions to and from the XYZA color space
//
+// XYZA<float> toXYZA(const `ColorType`<float>&);
+// `ColorType`<float> to`ColorType`(const XYZA<float>&);
+//
+// as well as an identity conversion
+//
+// constexpr `ColorType`<float> to`ColorType`(const `ColorType`<float>& color) { return color; }
+//
+// and a generic conversion utilizing a conversion the XYZ color space
+//
+// template<typename T> `ColorType`<float> to`ColorType`(const T& color)
+//
// Any additional conversions can be thought of as optimizations, shortcutting unnecessary steps, though
// some may be integral to the base conversion.
@@ -91,6 +100,12 @@
// Additions
WEBCORE_EXPORT ExtendedSRGBA<float> toExtendedSRGBA(const LinearExtendedSRGBA<float>&);
+// LinearProPhotoRGB
+WEBCORE_EXPORT XYZA<float> toXYZA(const LinearProPhotoRGB<float>&);
+WEBCORE_EXPORT LinearProPhotoRGB<float> toLinearProPhotoRGB(const XYZA<float>&);
+// Additions
+WEBCORE_EXPORT ProPhotoRGB<float> toProPhotoRGB(const LinearProPhotoRGB<float>&);
+
// LinearRec2020
WEBCORE_EXPORT XYZA<float> toXYZA(const LinearRec2020<float>&);
WEBCORE_EXPORT LinearRec2020<float> toLinearRec2020(const XYZA<float>&);
@@ -103,6 +118,12 @@
// Additions
WEBCORE_EXPORT SRGBA<float> toSRGBA(const LinearSRGBA<float>&);
+// ProPhotoRGB
+WEBCORE_EXPORT XYZA<float> toXYZA(const ProPhotoRGB<float>&);
+WEBCORE_EXPORT ProPhotoRGB<float> toProPhotoRGB(const XYZA<float>&);
+// Additions
+WEBCORE_EXPORT LinearProPhotoRGB<float> toLinearProPhotoRGB(const ProPhotoRGB<float>&);
+
// Rec2020
WEBCORE_EXPORT XYZA<float> toXYZA(const Rec2020<float>&);
WEBCORE_EXPORT Rec2020<float> toRec2020(const XYZA<float>&);
@@ -128,8 +149,10 @@
constexpr LinearA98RGB<float> toLinearA98RGB(const LinearA98RGB<float>& color) { return color; }
constexpr LinearDisplayP3<float> toLinearDisplayP3(const LinearDisplayP3<float>& color) { return color; }
constexpr LinearExtendedSRGBA<float> toLinearExtendedSRGBA(const LinearExtendedSRGBA<float>& color) { return color; }
+constexpr LinearProPhotoRGB<float> toLinearRec2020(const LinearProPhotoRGB<float>& color) { return color; }
constexpr LinearRec2020<float> toLinearRec2020(const LinearRec2020<float>& color) { return color; }
constexpr LinearSRGBA<float> toLinearSRGBA(const LinearSRGBA<float>& color) { return color; }
+constexpr ProPhotoRGB<float> toProPhotoRGB(const ProPhotoRGB<float>& color) { return color; }
constexpr Rec2020<float> toRec2020(const Rec2020<float>& color) { return color; }
constexpr SRGBA<float> toSRGBA(const SRGBA<float>& color) { return color; }
constexpr XYZA<float> toXYZA(const XYZA<float>& color) { return color; }
@@ -185,6 +208,11 @@
return toLinearExtendedSRGBA(toXYZA(color));
}
+template<typename T> LinearProPhotoRGB<float> toLinearProPhotoRGB(const T& color)
+{
+ return toLinearProPhotoRGB(toXYZA(color));
+}
+
template<typename T> LinearRec2020<float> toLinearRec2020(const T& color)
{
return toLinearRec2020(toXYZA(color));
@@ -195,6 +223,11 @@
return toLinearSRGBA(toXYZA(color));
}
+template<typename T> ProPhotoRGB<float> toProPhotoRGB(const T& color)
+{
+ return toProPhotoRGB(toXYZA(color));
+}
+
template<typename T> Rec2020<float> toRec2020(const T& color)
{
return toRec2020(toXYZA(color));
@@ -217,6 +250,8 @@
return std::invoke(std::forward<Functor>(functor), makeFromComponents<Lab<T>>(components));
case ColorSpace::LinearRGB:
return std::invoke(std::forward<Functor>(functor), makeFromComponents<LinearSRGBA<T>>(components));
+ case ColorSpace::ProPhotoRGB:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<ProPhotoRGB<T>>(components));
case ColorSpace::Rec2020:
return std::invoke(std::forward<Functor>(functor), makeFromComponents<Rec2020<T>>(components));
case ColorSpace::SRGB:
Modified: trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp (272124 => 272125)
--- trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp 2021-01-31 20:24:46 UTC (rev 272125)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -68,6 +68,8 @@
return "lab"_s;
case ColorSpace::LinearRGB:
return "linear-srgb"_s;
+ case ColorSpace::ProPhotoRGB:
+ return "prophoto-rgb"_s;
case ColorSpace::Rec2020:
return "rec2020"_s;
case ColorSpace::SRGB:
@@ -159,6 +161,23 @@
return serialization(color);
}
+// MARK: ProPhotoRGB<float> overloads
+
+String serializationForCSS(const ProPhotoRGB<float>& color)
+{
+ return serialization(color);
+}
+
+String serializationForHTML(const ProPhotoRGB<float>& color)
+{
+ return serialization(color);
+}
+
+String serializationForRenderTreeAsText(const ProPhotoRGB<float>& color)
+{
+ return serialization(color);
+}
+
// MARK: Rec2020<float> overloads
String serializationForCSS(const Rec2020<float>& color)
Modified: trunk/Source/WebCore/platform/graphics/ColorSerialization.h (272124 => 272125)
--- trunk/Source/WebCore/platform/graphics/ColorSerialization.h 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/platform/graphics/ColorSerialization.h 2021-01-31 20:24:46 UTC (rev 272125)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -35,6 +35,7 @@
template<typename> struct DisplayP3;
template<typename> struct Lab;
template<typename> struct LinearSRGBA;
+template<typename> struct ProPhotoRGB;
template<typename> struct Rec2020;
template<typename> struct SRGBA;
@@ -64,6 +65,10 @@
WEBCORE_EXPORT String serializationForHTML(const LinearSRGBA<float>&);
WEBCORE_EXPORT String serializationForRenderTreeAsText(const LinearSRGBA<float>&);
+WEBCORE_EXPORT String serializationForCSS(const ProPhotoRGB<float>&);
+WEBCORE_EXPORT String serializationForHTML(const ProPhotoRGB<float>&);
+WEBCORE_EXPORT String serializationForRenderTreeAsText(const ProPhotoRGB<float>&);
+
WEBCORE_EXPORT String serializationForCSS(const Rec2020<float>&);
WEBCORE_EXPORT String serializationForHTML(const Rec2020<float>&);
WEBCORE_EXPORT String serializationForRenderTreeAsText(const Rec2020<float>&);
Modified: trunk/Source/WebCore/platform/graphics/ColorSpace.cpp (272124 => 272125)
--- trunk/Source/WebCore/platform/graphics/ColorSpace.cpp 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/platform/graphics/ColorSpace.cpp 2021-01-31 20:24:46 UTC (rev 272125)
@@ -45,6 +45,9 @@
case ColorSpace::LinearRGB:
ts << "LinearRGB";
break;
+ case ColorSpace::ProPhotoRGB:
+ ts << "ProPhotoRGB";
+ break;
case ColorSpace::Rec2020:
ts << "Rec2020";
break;
Modified: trunk/Source/WebCore/platform/graphics/ColorSpace.h (272124 => 272125)
--- trunk/Source/WebCore/platform/graphics/ColorSpace.h 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/platform/graphics/ColorSpace.h 2021-01-31 20:24:46 UTC (rev 272125)
@@ -36,6 +36,7 @@
DisplayP3,
Lab,
LinearRGB,
+ ProPhotoRGB,
Rec2020,
SRGB,
};
Modified: trunk/Source/WebCore/platform/graphics/ColorTransferFunctions.h (272124 => 272125)
--- trunk/Source/WebCore/platform/graphics/ColorTransferFunctions.h 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/platform/graphics/ColorTransferFunctions.h 2021-01-31 20:24:46 UTC (rev 272125)
@@ -43,6 +43,14 @@
};
template<typename T, TransferFunctionMode mode>
+struct ProPhotoRGBTransferFunction {
+ static constexpr T gamma = 1.8;
+
+ static T toGammaEncoded(T);
+ static T toLinear(T);
+};
+
+template<typename T, TransferFunctionMode mode>
struct Rec2020TransferFunction {
static constexpr T alpha = 1.09929682680944;
static constexpr T beta = 0.018053968510807;
@@ -78,6 +86,40 @@
return result;
}
+// MARK: ProPhotoRGBTransferFunction.
+
+template<typename T, TransferFunctionMode mode> T ProPhotoRGBTransferFunction<T, mode>::toGammaEncoded(T c)
+{
+ if constexpr (mode == TransferFunctionMode::Clamped) {
+ if (c < 1.0 / 512.0)
+ return 16.0 * c;
+
+ return clampTo<T>(std::pow(c, 1.0 / gamma), 0, 1);
+ } else {
+ if (std::abs(c) < 1.0 / 512.0)
+ return 16.0 * c;
+
+ float sign = std::signbit(c) ? -1.0 : 1.0;
+ return std::pow(c, 1.0 / gamma) * sign;
+ }
+}
+
+template<typename T, TransferFunctionMode mode> T ProPhotoRGBTransferFunction<T, mode>::toLinear(T c)
+{
+ if constexpr (mode == TransferFunctionMode::Clamped) {
+ if (c <= 16.0 / 512.0)
+ return c / 16.0;
+
+ return clampTo<T>(std::pow(c, gamma), 0, 1);
+ } else {
+ if (std::abs(c) <= 16.0 / 512.0)
+ return c / 16.0;
+
+ float sign = std::signbit(c) ? -1.0 : 1.0;
+ return std::pow(c, gamma) * sign;
+ }
+}
+
// MARK: Rec2020TransferFunction.
template<typename T, TransferFunctionMode mode> T Rec2020TransferFunction<T, mode>::toGammaEncoded(T c)
@@ -92,7 +134,7 @@
return 4.5f * c;
float sign = std::signbit(c) ? -1.0 : 1.0;
- return sign * alpha * std::pow(c, gamma) - (alpha - 1.0);
+ return (alpha * std::pow(c, gamma) - (alpha - 1.0)) * sign;
}
}
Modified: trunk/Source/WebCore/platform/graphics/ColorTypes.h (272124 => 272125)
--- trunk/Source/WebCore/platform/graphics/ColorTypes.h 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/platform/graphics/ColorTypes.h 2021-01-31 20:24:46 UTC (rev 272125)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -40,11 +40,13 @@
template<typename> struct LinearA98RGB;
template<typename> struct LinearDisplayP3;
template<typename> struct LinearExtendedSRGBA;
+template<typename> struct LinearProPhotoRGB;
template<typename> struct LinearRec2020;
template<typename> struct LinearSRGBA;
+template<typename> struct ProPhotoRGB;
template<typename> struct Rec2020;
template<typename> struct SRGBA;
-template<typename> struct XYZ;
+template<typename> struct XYZA;
// MARK: Make functions.
@@ -258,6 +260,12 @@
};
template<typename T> LinearExtendedSRGBA(T, T, T, T) -> LinearExtendedSRGBA<T>;
+template<typename T> struct LinearProPhotoRGB : RGBAType<LinearProPhotoRGB, T, RGBModel<T>> {
+ using RGBAType<LinearProPhotoRGB, T, RGBModel<T>>::RGBAType;
+ using GammaEncodedCounterpart = ProPhotoRGB<T>;
+};
+template<typename T> LinearProPhotoRGB(T, T, T, T) -> LinearProPhotoRGB<T>;
+
template<typename T> struct LinearRec2020 : RGBAType<LinearRec2020, T, RGBModel<T>> {
using RGBAType<LinearRec2020, T, RGBModel<T>>::RGBAType;
using GammaEncodedCounterpart = Rec2020<T>;
@@ -271,6 +279,13 @@
};
template<typename T> LinearSRGBA(T, T, T, T) -> LinearSRGBA<T>;
+template<typename T> struct ProPhotoRGB : RGBAType<ProPhotoRGB, T, RGBModel<T>> {
+ using RGBAType<ProPhotoRGB, T, RGBModel<T>>::RGBAType;
+ using LinearCounterpart = LinearProPhotoRGB<T>;
+ static constexpr auto colorSpace = ColorSpace::ProPhotoRGB;
+};
+template<typename T> ProPhotoRGB(T, T, T, T) -> ProPhotoRGB<T>;
+
template<typename T> struct Rec2020 : RGBAType<Rec2020, T, RGBModel<T>> {
using RGBAType<Rec2020, T, RGBModel<T>>::RGBAType;
using LinearCounterpart = LinearRec2020<T>;
Modified: trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp (272124 => 272125)
--- trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp 2021-01-31 20:24:46 UTC (rev 272125)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -100,6 +100,20 @@
return linearRGBColorSpace;
}
+CGColorSpaceRef proPhotoRGBColorSpaceRef()
+{
+ static CGColorSpaceRef proPhotoRGBColorSpace;
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
+#if PLATFORM(COCOA)
+ proPhotoRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceROMMRGB);
+#else
+ proPhotoRGBColorSpace = sRGBColorSpaceRef();
+#endif
+ });
+ return proPhotoRGBColorSpace;
+}
+
CGColorSpaceRef rec2020ColorSpaceRef()
{
static CGColorSpaceRef rec2020ColorSpace;
Modified: trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h (272124 => 272125)
--- trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h 2021-01-31 17:16:58 UTC (rev 272124)
+++ trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h 2021-01-31 20:24:46 UTC (rev 272125)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -36,6 +36,7 @@
WEBCORE_EXPORT CGColorSpaceRef extendedSRGBColorSpaceRef();
WEBCORE_EXPORT CGColorSpaceRef labColorSpaceRef();
WEBCORE_EXPORT CGColorSpaceRef linearRGBColorSpaceRef();
+WEBCORE_EXPORT CGColorSpaceRef proPhotoRGBColorSpaceRef();
WEBCORE_EXPORT CGColorSpaceRef rec2020ColorSpaceRef();
WEBCORE_EXPORT CGColorSpaceRef sRGBColorSpaceRef();
@@ -50,6 +51,8 @@
return labColorSpaceRef();
case ColorSpace::LinearRGB:
return linearRGBColorSpaceRef();
+ case ColorSpace::ProPhotoRGB:
+ return proPhotoRGBColorSpaceRef();
case ColorSpace::Rec2020:
return rec2020ColorSpaceRef();
case ColorSpace::SRGB: