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

LibGfx: Use premultiplied alpha when scaling images

This commit replaces usages of `Color::interpolate()` with
`Color::mixed_with()` in image scaling functions. The latter
uses premultiplied alpha, which results in more visually
pleasing edges when images are scaled against a transparent
background.

These changes affect the SmoothPixels and BilinearBlend scaling modes
of `Painter::draw_scaled_bitmap()` as well as the `Bitmap::scaled()`
function.

Fixes #17153.
This commit is contained in:
Tim Ledbetter 2023-02-16 22:22:21 +00:00 committed by Jelle Raaijmakers
parent 2480b94ae7
commit 5a6b995444
2 changed files with 11 additions and 11 deletions

View file

@ -403,9 +403,9 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const
auto c = get_pixel(i, j + 1);
auto d = get_pixel(i + 1, j + 1);
auto e = a.interpolate(b, u);
auto f = c.interpolate(d, u);
auto color = e.interpolate(f, v);
auto e = a.mixed_with(b, u);
auto f = c.mixed_with(d, u);
auto color = e.mixed_with(f, v);
new_bitmap->set_pixel(x, y, color);
}
}
@ -421,7 +421,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const
auto a = get_pixel(i, old_bottom_y);
auto b = get_pixel(i + 1, old_bottom_y);
auto color = a.interpolate(b, u);
auto color = a.mixed_with(b, u);
new_bitmap->set_pixel(x, new_bottom_y, color);
}
@ -437,7 +437,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const
auto c = get_pixel(old_right_x, j);
auto d = get_pixel(old_right_x, j + 1);
auto color = c.interpolate(d, v);
auto color = c.mixed_with(d, v);
new_bitmap->set_pixel(new_right_x, y, color);
}