1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:17:44 +00:00

LibGfx: Fix off-by-some in Painter::draw_scaled_bitmap_with_transform()

Before this, drawing a 1x1 bitmap scaled up to MxN would only fill
M/2 x N/2 pixel, due to source_point going outside (0, 0).
This commit is contained in:
Nico Weber 2024-01-09 21:29:16 -05:00 committed by Andreas Kling
parent 822b7720e1
commit 7fb32b6682
3 changed files with 53 additions and 1 deletions

View file

@ -2489,7 +2489,10 @@ void Painter::draw_scaled_bitmap_with_transform(IntRect const& dst_rect, Bitmap
for (int x = 0; x < clipped_bounding_rect.width(); ++x) {
auto point = Gfx::IntPoint { x, y };
auto sample_point = point + start_offset;
auto source_point = sample_transform.map(sample_point).to_rounded<int>();
// AffineTransform::map(IntPoint) rounds internally, which is wrong here. So explicitly call the FloatPoint version, and then truncate the result.
auto source_point = Gfx::IntPoint { sample_transform.map(Gfx::FloatPoint { sample_point }) };
if (!source_rect.contains(source_point))
continue;
auto source_color = bitmap.get_pixel(source_point);