mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
LibWeb/CSS: Avoid double promotion in CSSColorValue code
Co-authored-by: Nico Weber <thakis@chromium.org>
This commit is contained in:
parent
06154b87dd
commit
b09b23a162
Notes:
github-actions[bot]
2024-11-06 11:49:46 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/b09b23a162d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2193 Reviewed-by: https://github.com/gmta ✅
3 changed files with 7 additions and 7 deletions
|
@ -71,7 +71,7 @@ Optional<float> CSSColorValue::resolve_with_reference_value(CSSStyleValue const&
|
|||
{
|
||||
// <percentage> | <number> | none
|
||||
auto normalize_percentage = [one_hundred_percent_value](Percentage const& percentage) {
|
||||
return percentage.as_fraction() * one_hundred_percent_value;
|
||||
return static_cast<float>(percentage.as_fraction()) * one_hundred_percent_value;
|
||||
};
|
||||
|
||||
if (style_value.is_percentage())
|
||||
|
|
|
@ -13,13 +13,13 @@ namespace Web::CSS {
|
|||
Color CSSHWB::to_color(Optional<Layout::NodeWithStyle const&>) const
|
||||
{
|
||||
auto const h_val = resolve_hue(m_properties.h).value_or(0);
|
||||
auto const w_val = clamp(resolve_with_reference_value(m_properties.w, 100.0).value_or(0), 0, 100) / 100.0;
|
||||
auto const b_val = clamp(resolve_with_reference_value(m_properties.b, 100.0).value_or(0), 0, 100) / 100.0;
|
||||
auto const w_val = clamp(resolve_with_reference_value(m_properties.w, 100.0).value_or(0), 0, 100) / 100.0f;
|
||||
auto const b_val = clamp(resolve_with_reference_value(m_properties.b, 100.0).value_or(0), 0, 100) / 100.0f;
|
||||
auto const alpha_val = resolve_alpha(m_properties.alpha).value_or(1);
|
||||
|
||||
if (w_val + b_val >= 1.0) {
|
||||
auto to_byte = [](double value) {
|
||||
return round_to<u8>(clamp(value * 255.0, 0.0, 255.0));
|
||||
if (w_val + b_val >= 1.0f) {
|
||||
auto to_byte = [](float value) {
|
||||
return round_to<u8>(clamp(value * 255.0f, 0.0f, 255.0f));
|
||||
};
|
||||
u8 gray = to_byte(w_val / (w_val + b_val));
|
||||
return Color(gray, gray, gray, to_byte(alpha_val));
|
||||
|
|
|
@ -44,7 +44,7 @@ Color CSSRGB::to_color(Optional<Layout::NodeWithStyle const&>) const
|
|||
auto resolve_alpha_to_u8 = [](CSSStyleValue const& style_value) -> Optional<u8> {
|
||||
auto alpha_0_1 = resolve_alpha(style_value);
|
||||
if (alpha_0_1.has_value())
|
||||
return llround(clamp(alpha_0_1.value() * 255.0, 0.0, 255.0));
|
||||
return llround(clamp(alpha_0_1.value() * 255.0f, 0.0f, 255.0f));
|
||||
return {};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue