summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2023-02-17 19:02:03 +0000
committerJelle Raaijmakers <jelle@gmta.nl>2023-02-18 17:10:04 +0100
commite5a39d134b6a18ea3b98be955f2edcc90eae2b3e (patch)
tree775dc3ba05ee50c890626778ad24559b88c378ea
parent8a94c7a7f75adfb367d71567cf118d8ef89d867b (diff)
downloadserenity-e5a39d134b6a18ea3b98be955f2edcc90eae2b3e.zip
LibGfx: Move Color::mixed_with() inline
This seems to give a small speedup to gradient painting and removes Color::mixed_with() (which was 10% of the time) from the profile.
-rw-r--r--Userland/Libraries/LibGfx/Color.cpp24
-rw-r--r--Userland/Libraries/LibGfx/Color.h24
2 files changed, 23 insertions, 25 deletions
diff --git a/Userland/Libraries/LibGfx/Color.cpp b/Userland/Libraries/LibGfx/Color.cpp
index b2c7256f59..b21b3bb4e0 100644
--- a/Userland/Libraries/LibGfx/Color.cpp
+++ b/Userland/Libraries/LibGfx/Color.cpp
@@ -315,30 +315,6 @@ Optional<Color> Color::from_string(StringView string)
return Color(r.value(), g.value(), b.value(), a.value());
}
-Color Color::mixed_with(Color other, float weight) const
-{
- if (alpha() == other.alpha() || with_alpha(0) == other.with_alpha(0)) {
- return Gfx::Color {
- round_to<u8>(mix<float>(red(), other.red(), weight)),
- round_to<u8>(mix<float>(green(), other.green(), weight)),
- round_to<u8>(mix<float>(blue(), other.blue(), weight)),
- round_to<u8>(mix<float>(alpha(), other.alpha(), weight)),
- };
- }
- // Fallback to slower, but more visually pleasing premultiplied alpha mix.
- // This is needed for linear-gradient()s in LibWeb.
- auto mixed_alpha = mix<float>(alpha(), other.alpha(), weight);
- auto premultiplied_mix_channel = [&](float channel, float other_channel, float weight) {
- return round_to<u8>(mix<float>(channel * alpha(), other_channel * other.alpha(), weight) / mixed_alpha);
- };
- return Gfx::Color {
- premultiplied_mix_channel(red(), other.red(), weight),
- premultiplied_mix_channel(green(), other.green(), weight),
- premultiplied_mix_channel(blue(), other.blue(), weight),
- round_to<u8>(mixed_alpha),
- };
-}
-
Vector<Color> Color::shades(u32 steps, float max) const
{
float shade = 1.f;
diff --git a/Userland/Libraries/LibGfx/Color.h b/Userland/Libraries/LibGfx/Color.h
index a135bb76aa..42626ab49a 100644
--- a/Userland/Libraries/LibGfx/Color.h
+++ b/Userland/Libraries/LibGfx/Color.h
@@ -237,7 +237,29 @@ public:
#endif
}
- Color mixed_with(Color other, float weight) const;
+ Color mixed_with(Color other, float weight) const
+ {
+ if (alpha() == other.alpha() || with_alpha(0) == other.with_alpha(0)) {
+ return Gfx::Color {
+ round_to<u8>(mix<float>(red(), other.red(), weight)),
+ round_to<u8>(mix<float>(green(), other.green(), weight)),
+ round_to<u8>(mix<float>(blue(), other.blue(), weight)),
+ round_to<u8>(mix<float>(alpha(), other.alpha(), weight)),
+ };
+ }
+ // Fallback to slower, but more visually pleasing premultiplied alpha mix.
+ // This is needed for linear-gradient()s in LibWeb.
+ auto mixed_alpha = mix<float>(alpha(), other.alpha(), weight);
+ auto premultiplied_mix_channel = [&](float channel, float other_channel, float weight) {
+ return round_to<u8>(mix<float>(channel * alpha(), other_channel * other.alpha(), weight) / mixed_alpha);
+ };
+ return Gfx::Color {
+ premultiplied_mix_channel(red(), other.red(), weight),
+ premultiplied_mix_channel(green(), other.green(), weight),
+ premultiplied_mix_channel(blue(), other.blue(), weight),
+ round_to<u8>(mixed_alpha),
+ };
+ }
Color interpolate(Color other, float weight) const noexcept
{