LibWeb/CSS: Add support for the srgb-linear color space in color()

That makes us pass the following WPT tests:
 - css/css-color/srgb-linear-001.html
 - css/css-color/srgb-linear-002.html
 - css/css-color/srgb-linear-003.html
This commit is contained in:
Lucas CHOLLET 2024-11-15 08:16:35 -05:00 committed by Andreas Kling
commit 7c2601f315
Notes: github-actions[bot] 2024-11-15 19:35:12 +00:00
11 changed files with 104 additions and 1 deletions

View file

@ -17,6 +17,8 @@ CSSColorValue::ColorType color_type_from_string_view(StringView color_space)
{
if (color_space == "srgb"sv)
return CSSColorValue::ColorType::sRGB;
if (color_space == "srgb-linear"sv)
return CSSColorValue::ColorType::sRGBLinear;
if (color_space == "xyz-d50"sv)
return CSSColorValue::ColorType::XYZD50;
if (color_space == "xyz"sv || color_space == "xyz-d65")
@ -68,6 +70,9 @@ Color CSSColor::to_color(Optional<Layout::NodeWithStyle const&>) const
return Color(to_u8(c1), to_u8(c2), to_u8(c3), to_u8(alpha_val));
}
if (color_type() == ColorType::sRGBLinear)
return Color::from_linear_srgb(c1, c2, c3, alpha_val);
if (color_type() == ColorType::XYZD50)
return Color::from_xyz50(c1, c2, c3, alpha_val);

View file

@ -21,7 +21,7 @@ public:
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const override;
virtual String to_string() const override;
static constexpr Array s_supported_color_space = { "srgb"sv, "xyz"sv, "xyz-d50"sv, "xyz-d65"sv };
static constexpr Array s_supported_color_space = { "srgb"sv, "srgb-linear"sv, "xyz"sv, "xyz-d50"sv, "xyz-d65"sv };
private:
CSSColor(ColorType color_type, ValueComparingNonnullRefPtr<CSSStyleValue> c1, ValueComparingNonnullRefPtr<CSSStyleValue> c2, ValueComparingNonnullRefPtr<CSSStyleValue> c3, ValueComparingNonnullRefPtr<CSSStyleValue> alpha)

View file

@ -31,6 +31,7 @@ public:
OKLab,
OKLCH,
sRGB, // This is used by CSSColor for color(srgb ...).
sRGBLinear,
XYZD50,
XYZD65,
};