diff --git a/Libraries/LibGfx/Color.cpp b/Libraries/LibGfx/Color.cpp index df473a61163..399481b5e45 100644 --- a/Libraries/LibGfx/Color.cpp +++ b/Libraries/LibGfx/Color.cpp @@ -453,6 +453,29 @@ Color Color::from_display_p3(float r, float g, float b, float alpha) return from_xyz65(x, y, z, alpha); } +// https://www.w3.org/TR/css-color-4/#predefined-prophoto-rgb +Color Color::from_pro_photo_rgb(float r, float g, float b, float alpha) +{ + auto to_linear = [](float c) -> float { + u8 sign = c < 0 ? -1 : 1; + float absolute = abs(c); + + if (absolute <= 16. / 252) + return c / 16; + return sign * pow(c, 1.8); + }; + + auto linear_r = to_linear(r); + auto linear_g = to_linear(g); + auto linear_b = to_linear(b); + + float x = 0.79776664 * linear_r + 0.13518130 * linear_g + 0.03134773 * linear_b; + float y = 0.28807483 * linear_r + 0.71183523 * linear_g + 0.00008994 * linear_b; + float z = 0.00000000 * linear_r + 0.00000000 * linear_g + 0.82510460 * linear_b; + + return from_xyz50(x, y, z, alpha); +} + Color Color::from_xyz50(float x, float y, float z, float alpha) { // See commit description for these values diff --git a/Libraries/LibGfx/Color.h b/Libraries/LibGfx/Color.h index ba7e3dc58a1..4bbfd4dd58b 100644 --- a/Libraries/LibGfx/Color.h +++ b/Libraries/LibGfx/Color.h @@ -185,6 +185,7 @@ public: static Color from_a98rgb(float r, float g, float b, float alpha = 1.0f); static Color from_display_p3(float r, float g, float b, float alpha = 1.0f); static Color from_lab(float L, float a, float b, float alpha = 1.0f); + static Color from_pro_photo_rgb(float r, float g, float b, float alpha = 1.0f); static Color from_xyz50(float x, float y, float z, float alpha = 1.0f); static Color from_xyz65(float x, float y, float z, float alpha = 1.0f); static Color from_linear_srgb(float x, float y, float z, float alpha = 1.0f); diff --git a/Libraries/LibWeb/CSS/StyleValues/CSSColor.cpp b/Libraries/LibWeb/CSS/StyleValues/CSSColor.cpp index 6c3ec478e4a..91811f21ecb 100644 --- a/Libraries/LibWeb/CSS/StyleValues/CSSColor.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/CSSColor.cpp @@ -23,6 +23,8 @@ CSSColorValue::ColorType color_type_from_string_view(StringView color_space) return CSSColorValue::ColorType::sRGB; if (color_space == "srgb-linear"sv) return CSSColorValue::ColorType::sRGBLinear; + if (color_space == "prophoto-rgb"sv) + return CSSColorValue::ColorType::ProPhotoRGB; if (color_space == "xyz-d50"sv) return CSSColorValue::ColorType::XYZD50; if (color_space == "xyz"sv || color_space == "xyz-d65") @@ -83,6 +85,9 @@ Color CSSColor::to_color(Optional) const if (color_type() == ColorType::sRGBLinear) return Color::from_linear_srgb(c1, c2, c3, alpha_val); + if (color_type() == ColorType::ProPhotoRGB) + return Color::from_pro_photo_rgb(c1, c2, c3, alpha_val); + if (color_type() == ColorType::XYZD50) return Color::from_xyz50(c1, c2, c3, alpha_val); diff --git a/Libraries/LibWeb/CSS/StyleValues/CSSColor.h b/Libraries/LibWeb/CSS/StyleValues/CSSColor.h index c606f5faa87..c54cf824ceb 100644 --- a/Libraries/LibWeb/CSS/StyleValues/CSSColor.h +++ b/Libraries/LibWeb/CSS/StyleValues/CSSColor.h @@ -21,7 +21,7 @@ public: virtual Color to_color(Optional) const override; virtual String to_string() const override; - static constexpr Array s_supported_color_space = { "a98-rgb"sv, "display-p3"sv, "srgb"sv, "srgb-linear"sv, "xyz"sv, "xyz-d50"sv, "xyz-d65"sv }; + static constexpr Array s_supported_color_space = { "a98-rgb"sv, "display-p3"sv, "srgb"sv, "srgb-linear"sv, "prophoto-rgb"sv, "xyz"sv, "xyz-d50"sv, "xyz-d65"sv }; private: CSSColor(ColorType color_type, ValueComparingNonnullRefPtr c1, ValueComparingNonnullRefPtr c2, ValueComparingNonnullRefPtr c3, ValueComparingNonnullRefPtr alpha) diff --git a/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.h b/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.h index c3aa5c83aa5..415c2ad20c4 100644 --- a/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.h +++ b/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.h @@ -34,6 +34,7 @@ public: OKLCH, sRGB, // This is used by CSSColor for color(srgb ...). sRGBLinear, + ProPhotoRGB, XYZD50, XYZD65, }; diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-color/greensquare-display-p3-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-color/greensquare-display-p3-ref.html new file mode 100644 index 00000000000..2134c9681f0 --- /dev/null +++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-color/greensquare-display-p3-ref.html @@ -0,0 +1,10 @@ + + +Green square color(display-p3 0 1 0) reference + + +

Test passes if you see a green square, and no red.

+
+ diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-color/prophoto-rgb-003-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-color/prophoto-rgb-003-ref.html new file mode 100644 index 00000000000..e938de60345 --- /dev/null +++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-color/prophoto-rgb-003-ref.html @@ -0,0 +1,11 @@ + + +CSS Color 4: CSS Color 4: prophoto-rgb + + +

Test passes if you see a single square, and not two rectangles of different colors.

+
+ diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-color/prophoto-rgb-004-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-color/prophoto-rgb-004-ref.html new file mode 100644 index 00000000000..8c5f24bcf7e --- /dev/null +++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-color/prophoto-rgb-004-ref.html @@ -0,0 +1,10 @@ + + +CSS Color 4: CSS Color 4: prophoto-rgb + + +

Test passes if you see a single square, and not two rectangles of different colors.

+
+ diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-color/predefined-009.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/predefined-009.html new file mode 100644 index 00000000000..7cad0578ad7 --- /dev/null +++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/predefined-009.html @@ -0,0 +1,17 @@ + + +CSS Color 4: predefined colorspaces, prophoto-rgb, decimal values + + + + + + +

Test passes if you see a green square, and no red.

+

+

+ diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-color/predefined-010.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/predefined-010.html new file mode 100644 index 00000000000..f0c18b204f2 --- /dev/null +++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/predefined-010.html @@ -0,0 +1,17 @@ + + +CSS Color 4: predefined colorspaces, prophoto-rgb, percent values + + + + + + +

Test passes if you see a green square, and no red.

+

+

+ diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-001.html new file mode 100644 index 00000000000..c9826952449 --- /dev/null +++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-001.html @@ -0,0 +1,15 @@ + + +CSS Color 4: prophoto-rgb + + + + + + +

Test passes if you see a green square, and no red.

+
+ diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-002.html new file mode 100644 index 00000000000..8721f851fed --- /dev/null +++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-002.html @@ -0,0 +1,15 @@ + + +CSS Color 4: prophoto-rgb + + + + + + +

Test passes if you see a black square, and no red.

+
+ diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-003.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-003.html new file mode 100644 index 00000000000..fe2d0a7f9ca --- /dev/null +++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-003.html @@ -0,0 +1,18 @@ + + +CSS Color 4: prophoto-rgb + + + + + + +

Test passes if you see a single square, and not two rectangles of different colors.

+
+
+ diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-004.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-004.html new file mode 100644 index 00000000000..346d3a95732 --- /dev/null +++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-004.html @@ -0,0 +1,17 @@ + + +CSS Color 4: prophoto-rgb + + + + + + +

Test passes if you see a single square, and not two rectangles of different colors.

+
+
+ diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-005.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-005.html new file mode 100644 index 00000000000..b7e4eebb60b --- /dev/null +++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-color/prophoto-rgb-005.html @@ -0,0 +1,15 @@ + + +CSS Color 4: prophoto-rgb + + + + + + +

Test passes if you see a green square, and no red.

+
+