mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:47:35 +00:00
LibGfx: Remove SSE version of Color::blend()
I could not discover proof that this is actually faster than the non-SSE version. In addition, for these relatively simple structures, the compiler is often sufficiently smart to generate SSE code itself. For a synthetic font benchmark I wrote, this results in a nice 11% decrease in runtime.
This commit is contained in:
parent
3f9cfa144c
commit
5bac9df865
1 changed files with 5 additions and 24 deletions
|
@ -204,37 +204,18 @@ public:
|
||||||
|
|
||||||
constexpr Color blend(Color source) const
|
constexpr Color blend(Color source) const
|
||||||
{
|
{
|
||||||
if (!alpha() || source.alpha() == 255)
|
if (alpha() == 0 || source.alpha() == 255)
|
||||||
return source;
|
return source;
|
||||||
|
|
||||||
if (!source.alpha())
|
if (source.alpha() == 0)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
#ifdef __SSE__
|
|
||||||
using AK::SIMD::i32x4;
|
|
||||||
|
|
||||||
const i32x4 color = {
|
|
||||||
red(),
|
|
||||||
green(),
|
|
||||||
blue()
|
|
||||||
};
|
|
||||||
const i32x4 source_color = {
|
|
||||||
source.red(),
|
|
||||||
source.green(),
|
|
||||||
source.blue()
|
|
||||||
};
|
|
||||||
|
|
||||||
int const d = 255 * (alpha() + source.alpha()) - alpha() * source.alpha();
|
int const d = 255 * (alpha() + source.alpha()) - alpha() * source.alpha();
|
||||||
const i32x4 out = (color * alpha() * (255 - source.alpha()) + 255 * source.alpha() * source_color) / d;
|
u8 r = (red() * alpha() * (255 - source.alpha()) + source.red() * 255 * source.alpha()) / d;
|
||||||
return Color(out[0], out[1], out[2], d / 255);
|
u8 g = (green() * alpha() * (255 - source.alpha()) + source.green() * 255 * source.alpha()) / d;
|
||||||
#else
|
u8 b = (blue() * alpha() * (255 - source.alpha()) + source.blue() * 255 * source.alpha()) / d;
|
||||||
int d = 255 * (alpha() + source.alpha()) - alpha() * source.alpha();
|
|
||||||
u8 r = (red() * alpha() * (255 - source.alpha()) + 255 * source.alpha() * source.red()) / d;
|
|
||||||
u8 g = (green() * alpha() * (255 - source.alpha()) + 255 * source.alpha() * source.green()) / d;
|
|
||||||
u8 b = (blue() * alpha() * (255 - source.alpha()) + 255 * source.alpha() * source.blue()) / d;
|
|
||||||
u8 a = d / 255;
|
u8 a = d / 255;
|
||||||
return Color(r, g, b, a);
|
return Color(r, g, b, a);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE Color mixed_with(Color other, float weight) const
|
ALWAYS_INLINE Color mixed_with(Color other, float weight) const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue