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 @@ + + +
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 @@ + + +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 @@ + + +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