LibWeb/CSS: Add support for the a98-rgb color space in color()

This makes us pass the following WPT tests:
 - css/css-color/a98rgb-001.html
 - css/css-color/a98rgb-002.html
 - css/css-color/a98rgb-003.html
 - css/css-color/a98rgb-004.html
 - css/css-color/predefined-007.html
 - css/css-color/predefined-008.html
This commit is contained in:
Lucas CHOLLET 2024-11-13 23:17:40 -05:00 committed by Andreas Kling
commit a59d9a3986
Notes: github-actions[bot] 2024-11-16 09:31:06 +00:00
13 changed files with 146 additions and 1 deletions

View file

@ -413,6 +413,24 @@ Color Color::from_linear_srgb(float red, float green, float blue, float alpha)
clamp(lroundf(alpha * 255.f), 0, 255));
}
// https://www.w3.org/TR/css-color-4/#predefined-a98-rgb
Color Color::from_a98rgb(float r, float g, float b, float alpha)
{
auto to_linear = [](float c) {
return pow(c, 563. / 256);
};
auto linear_r = to_linear(r);
auto linear_g = to_linear(g);
auto linear_b = to_linear(b);
float x = 0.57666904 * linear_r + 0.18555824 * linear_g + 0.18822865 * linear_b;
float y = 0.29734498 * linear_r + 0.62736357 * linear_g + 0.07529146 * linear_b;
float z = 0.02703136 * linear_r + 0.07068885 * linear_g + 0.99133754 * linear_b;
return from_xyz65(x, y, z, alpha);
}
Color Color::from_xyz50(float x, float y, float z, float alpha)
{
// See commit description for these values