diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-color/greensquare-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-color/greensquare-ref.html new file mode 100644 index 00000000000..35a31f8f564 --- /dev/null +++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-color/greensquare-ref.html @@ -0,0 +1,10 @@ + + +Green square reference + + +

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

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

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

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

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

+
+ diff --git a/Userland/Libraries/LibGfx/Color.cpp b/Userland/Libraries/LibGfx/Color.cpp index bebbd47cdd1..d980a4016cc 100644 --- a/Userland/Libraries/LibGfx/Color.cpp +++ b/Userland/Libraries/LibGfx/Color.cpp @@ -423,6 +423,16 @@ Color Color::from_xyz50(float x, float y, float z, float alpha) return from_linear_srgb(red, green, blue, alpha); } +Color Color::from_xyz65(float x, float y, float z, float alpha) +{ + // https://en.wikipedia.org/wiki/SRGB#From_CIE_XYZ_to_sRGB + float red = 3.2406 * x - 1.5372 * y - 0.4986 * z; + float green = -0.9689 * x + 1.8758 * y + 0.0415 * z; + float blue = 0.0557 * x - 0.2040 * y + 1.0570 * z; + + return from_linear_srgb(red, green, blue, alpha); +} + Color Color::from_lab(float L, float a, float b, float alpha) { // Third edition of "Colorimetry" by the CIE diff --git a/Userland/Libraries/LibGfx/Color.h b/Userland/Libraries/LibGfx/Color.h index df2c4c01cde..a6f2c3377de 100644 --- a/Userland/Libraries/LibGfx/Color.h +++ b/Userland/Libraries/LibGfx/Color.h @@ -184,6 +184,7 @@ public: static Color from_lab(float L, float a, 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); // https://bottosson.github.io/posts/oklab/ diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColor.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColor.cpp index 5c147a59c6e..512015be80b 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColor.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColor.cpp @@ -11,6 +11,19 @@ namespace Web::CSS { +namespace { + +CSSColorValue::ColorType color_type_from_string_view(StringView color_space) +{ + if (color_space == "xyz-d50"sv) + return CSSColorValue::ColorType::XYZD50; + if (color_space == "xyz"sv || color_space == "xyz-d65") + return CSSColorValue::ColorType::XYZD65; + VERIFY_NOT_REACHED(); +} + +} + ValueComparingNonnullRefPtr CSSColor::create(StringView color_space, ValueComparingNonnullRefPtr c1, ValueComparingNonnullRefPtr c2, ValueComparingNonnullRefPtr c3, ValueComparingRefPtr alpha) { VERIFY(any_of(s_supported_color_space, [=](auto supported) { return color_space == supported; })); @@ -18,8 +31,7 @@ ValueComparingNonnullRefPtr CSSColor::create(StringView color_space, V if (!alpha) alpha = NumberStyleValue::create(1); - if (color_space == "xyz-d50") - return adopt_ref(*new (nothrow) CSSColor(ColorType::XYZD50, move(c1), move(c2), move(c3), alpha.release_nonnull())); + return adopt_ref(*new (nothrow) CSSColor(color_type_from_string_view(color_space), move(c1), move(c2), move(c3), alpha.release_nonnull())); VERIFY_NOT_REACHED(); } @@ -52,6 +64,9 @@ Color CSSColor::to_color(Optional) const if (color_type() == ColorType::XYZD50) return Color::from_xyz50(c1, c2, c3, alpha_val); + if (color_type() == ColorType::XYZD65) + return Color::from_xyz65(c1, c2, c3, alpha_val); + VERIFY_NOT_REACHED(); } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColor.h b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColor.h index 5a0f402fa44..36b2843ecc9 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColor.h +++ b/Userland/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 = { "xyz-d50"sv }; + static constexpr Array s_supported_color_space = { "xyz"sv, "xyz-d50"sv, "xyz-d65"sv }; private: CSSColor(ColorType color_type, ValueComparingNonnullRefPtr c1, ValueComparingNonnullRefPtr c2, ValueComparingNonnullRefPtr c3, ValueComparingNonnullRefPtr alpha) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.h index 9b3f16fe30e..bde9c251078 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSColorValue.h @@ -31,6 +31,7 @@ public: OKLab, OKLCH, XYZD50, + XYZD65, }; ColorType color_type() const { return m_color_type; }