mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibGfx: SIMD optimized alpha blending
This commit is contained in:
parent
893adbb79c
commit
fe3963f3d4
Notes:
sideshowbarker
2024-07-19 00:59:36 +09:00
Author: https://github.com/ccapitalK Commit: https://github.com/SerenityOS/serenity/commit/fe3963f3d4f Pull-request: https://github.com/SerenityOS/serenity/pull/4354 Issue: https://github.com/SerenityOS/serenity/issues/69
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
Reference in a new issue