mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:48:11 +00:00
LibGfx: SIMD optimized alpha blending
This commit is contained in:
parent
893adbb79c
commit
fe3963f3d4
1 changed files with 20 additions and 0 deletions
|
@ -29,6 +29,7 @@
|
|||
#include <AK/Assertions.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/SIMD.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
|
||||
|
@ -131,12 +132,31 @@ public:
|
|||
if (!source.alpha())
|
||||
return *this;
|
||||
|
||||
#ifdef __SSE__
|
||||
using AK::SIMD::i32x4;
|
||||
|
||||
const i32x4 color = {
|
||||
red(),
|
||||
green(),
|
||||
blue()
|
||||
};
|
||||
const i32x4 source_color = {
|
||||
source.red(),
|
||||
source.green(),
|
||||
source.blue()
|
||||
};
|
||||
|
||||
const int d = 255 * (alpha() + source.alpha()) - alpha() * source.alpha();
|
||||
const i32x4 out = (color * alpha() * (255 - source.alpha()) + 255 * source.alpha() * source_color) / d;
|
||||
return Color(out[0], out[1], out[2], d / 255);
|
||||
#else
|
||||
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;
|
||||
return Color(r, g, b, a);
|
||||
#endif
|
||||
}
|
||||
|
||||
Color to_grayscale() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue