LibWeb/CSS: Use double in CSSHWB::to_color()

See previous the commit description for more details about the floating
points operations.

The hwb test cases in `css-color-functions` are now rendered identically
to what firefox does (I haven't checked the others tests, but they
aren't affected by this commit).
This commit is contained in:
Lucas CHOLLET 2024-11-18 00:04:51 -05:00
parent 4099215e29
commit d820fde70a
5 changed files with 29 additions and 6 deletions

View file

@ -25,8 +25,8 @@ Color CSSHWB::to_color(Optional<Layout::NodeWithStyle const&>) const
return Color(gray, gray, gray, to_byte(alpha_val)); return Color(gray, gray, gray, to_byte(alpha_val));
} }
float value = 1 - b_val; auto value = 1 - b_val;
float saturation = 1 - (w_val / value); auto saturation = 1 - (w_val / value);
return Color::from_hsv(h_val, saturation, value).with_opacity(alpha_val); return Color::from_hsv(h_val, saturation, value).with_opacity(alpha_val);
} }

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Color 4: CSS Color 4: hwb</title>
<style>
.test { background-color: rgb(20% 70% 20%); width: 12em; height: 12em; } /* hwb(120 20% 30%) converted to sRGB */
</style>
<body>
<p>Test passes if you see a single square, and not two rectangles of different colors.</p>
<div class="test"></div>
</body>

View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Color 4: hwb</title>
<link rel="author" title="Sam Weinig" href="mailto:weinig@apple.com">
<link rel="help" href="https://drafts.csswg.org/css-color-4/#the-hwb-notation">
<link rel="match" href="../../../../expected/wpt-import/css/css-color/hwb-004-ref.html">
<meta name="assert" content="hwb with no alpha">
<style>
.test { background-color: red; width: 12em; height: 6em; margin-top: 0; }
.ref { background-color: rgb(20% 70% 20%); width: 12em; height: 6em; margin-bottom: 0; } /* hwb(120 20% 30%) converted to sRGB */
.test { background-color: hwb(120 20% 30%); }
</style>
<body>
<p>Test passes if you see a single square, and not two rectangles of different colors.</p>
<div class="ref"></div>
<div class="test"></div>
</body>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 113 KiB

View file

@ -162,7 +162,3 @@ Text/input/wpt-import/css/css-backgrounds/animations/discrete-no-interpolation.h
; https://github.com/LadybirdBrowser/ladybird/issues/2314 ; https://github.com/LadybirdBrowser/ladybird/issues/2314
Text/input/test-http-test-server.html Text/input/test-http-test-server.html
; Multiple bugs are affecting these tests. To avoid having to rebase them every
; single time, let's deactivate them for a bit.
Screenshot/input/css-color-functions.html