mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:48:11 +00:00
LibWeb: Use floats instead of doubles for CSS numbers
Using doubles isn't necessary, and they make things slightly bigger and slower, so let's use floats instead.
This commit is contained in:
parent
1f5b5d3f99
commit
0795b9f7bb
6 changed files with 33 additions and 33 deletions
|
@ -2476,9 +2476,9 @@ Optional<Color> Parser::parse_color(StyleComponentValueRule const& component_val
|
|||
&& g_val.is(Token::Type::Percentage)
|
||||
&& b_val.is(Token::Type::Percentage)) {
|
||||
|
||||
u8 r = clamp(lroundf(r_val.percentage() * 2.55), 0, 255);
|
||||
u8 g = clamp(lroundf(g_val.percentage() * 2.55), 0, 255);
|
||||
u8 b = clamp(lroundf(b_val.percentage() * 2.55), 0, 255);
|
||||
u8 r = clamp(lroundf(r_val.percentage() * 2.55f), 0, 255);
|
||||
u8 g = clamp(lroundf(g_val.percentage() * 2.55f), 0, 255);
|
||||
u8 b = clamp(lroundf(b_val.percentage() * 2.55f), 0, 255);
|
||||
return Color(r, g, b);
|
||||
}
|
||||
} else if (function.name().equals_ignoring_case("rgba")) {
|
||||
|
@ -2498,7 +2498,7 @@ Optional<Color> Parser::parse_color(StyleComponentValueRule const& component_val
|
|||
auto r = r_val.to_integer();
|
||||
auto g = g_val.to_integer();
|
||||
auto b = b_val.to_integer();
|
||||
auto a = clamp(lroundf(a_val.number_value() * 255.0), 0, 255);
|
||||
auto a = clamp(lroundf(a_val.number_value() * 255.0f), 0, 255);
|
||||
if (AK::is_within_range<u8>(r) && AK::is_within_range<u8>(g) && AK::is_within_range<u8>(b))
|
||||
return Color(r, g, b, a);
|
||||
|
||||
|
@ -2512,10 +2512,10 @@ Optional<Color> Parser::parse_color(StyleComponentValueRule const& component_val
|
|||
auto b = b_val.percentage();
|
||||
auto a = a_val.number_value();
|
||||
|
||||
u8 r_255 = clamp(lroundf(r * 2.55), 0, 255);
|
||||
u8 g_255 = clamp(lroundf(g * 2.55), 0, 255);
|
||||
u8 b_255 = clamp(lroundf(b * 2.55), 0, 255);
|
||||
u8 a_255 = clamp(lroundf(a * 255.0), 0, 255);
|
||||
u8 r_255 = clamp(lroundf(r * 2.55f), 0, 255);
|
||||
u8 g_255 = clamp(lroundf(g * 2.55f), 0, 255);
|
||||
u8 b_255 = clamp(lroundf(b * 2.55f), 0, 255);
|
||||
u8 a_255 = clamp(lroundf(a * 255.0f), 0, 255);
|
||||
return Color(r_255, g_255, b_255, a_255);
|
||||
}
|
||||
} else if (function.name().equals_ignoring_case("hsl")) {
|
||||
|
@ -2530,9 +2530,9 @@ Optional<Color> Parser::parse_color(StyleComponentValueRule const& component_val
|
|||
&& s_val.is(Token::Type::Percentage)
|
||||
&& l_val.is(Token::Type::Percentage)) {
|
||||
|
||||
auto h = static_cast<float>(h_val.number_value());
|
||||
auto s = static_cast<float>(s_val.percentage() / 100.0f);
|
||||
auto l = static_cast<float>(l_val.percentage() / 100.0f);
|
||||
auto h = h_val.number_value();
|
||||
auto s = s_val.percentage() / 100.0f;
|
||||
auto l = l_val.percentage() / 100.0f;
|
||||
return Color::from_hsl(h, s, l);
|
||||
}
|
||||
} else if (function.name().equals_ignoring_case("hsla")) {
|
||||
|
@ -2549,10 +2549,10 @@ Optional<Color> Parser::parse_color(StyleComponentValueRule const& component_val
|
|||
&& l_val.is(Token::Type::Percentage)
|
||||
&& a_val.is(Token::Type::Number)) {
|
||||
|
||||
auto h = static_cast<float>(h_val.number_value());
|
||||
auto s = static_cast<float>(s_val.percentage() / 100.0f);
|
||||
auto l = static_cast<float>(l_val.percentage() / 100.0f);
|
||||
auto a = static_cast<float>(a_val.number_value());
|
||||
auto h = h_val.number_value();
|
||||
auto s = s_val.percentage() / 100.0f;
|
||||
auto l = l_val.percentage() / 100.0f;
|
||||
auto a = a_val.number_value();
|
||||
return Color::from_hsla(h, s, l, a);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue