1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:27:45 +00:00

LibGfx: Painter::blit_filtered should take into account alpha value

If either the destination or calculated source pixel color contains
an alpha value, we should blend them together.
This commit is contained in:
Tom 2021-02-10 23:29:16 -07:00 committed by Andreas Kling
parent dd0833107f
commit 130d48fa13

View file

@ -590,9 +590,13 @@ void Painter::blit_filtered(const IntPoint& position, const Gfx::Bitmap& source,
for (int row = first_row; row <= last_row; ++row) { for (int row = first_row; row <= last_row; ++row) {
for (int x = 0; x <= (last_column - first_column); ++x) { for (int x = 0; x <= (last_column - first_column); ++x) {
u8 alpha = Color::from_rgba(src[x]).alpha(); u8 alpha = Color::from_rgba(src[x]).alpha();
if (alpha == 0xff) if (alpha == 0xff) {
dst[x] = filter(Color::from_rgba(src[x])).value(); auto color = filter(Color::from_rgba(src[x]));
else if (!alpha) if (color.alpha() == 0xff)
dst[x] = color.value();
else
dst[x] = Color::from_rgba(dst[x]).blend(color).value();
} else if (!alpha)
continue; continue;
else else
dst[x] = Color::from_rgba(dst[x]).blend(filter(Color::from_rgba(src[x]))).value(); dst[x] = Color::from_rgba(dst[x]).blend(filter(Color::from_rgba(src[x]))).value();
@ -605,9 +609,13 @@ void Painter::blit_filtered(const IntPoint& position, const Gfx::Bitmap& source,
const RGBA32* src = source.scanline(safe_src_rect.top() + row / s) + safe_src_rect.left() + first_column / s; const RGBA32* src = source.scanline(safe_src_rect.top() + row / s) + safe_src_rect.left() + first_column / s;
for (int x = 0; x <= (last_column - first_column); ++x) { for (int x = 0; x <= (last_column - first_column); ++x) {
u8 alpha = Color::from_rgba(src[x / s]).alpha(); u8 alpha = Color::from_rgba(src[x / s]).alpha();
if (alpha == 0xff) if (alpha == 0xff) {
dst[x] = filter(Color::from_rgba(src[x / s])).value(); auto color = filter(Color::from_rgba(src[x / s]));
else if (!alpha) if (color.alpha() == 0xff)
dst[x] = color.value();
else
dst[x] = Color::from_rgba(dst[x]).blend(color).value();
} else if (!alpha)
continue; continue;
else else
dst[x] = Color::from_rgba(dst[x]).blend(filter(Color::from_rgba(src[x / s]))).value(); dst[x] = Color::from_rgba(dst[x]).blend(filter(Color::from_rgba(src[x / s]))).value();