From f790a69431378c07806048cd769b201a5f69aadd Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Wed, 23 Mar 2022 09:02:14 +0100 Subject: [PATCH] LibGfx: Draw last row and column of scaled bitmaps in Painter There was an off-by-one bug in `Painter::do_draw_scaled_bitmap` where the last column and row of the source bitmap would be skipped. This was especially visible in PixelPaint when zooming in and out on smaller images. Instead of the top/left of the pixel, we now use the bottom/right side of the pixel as a threshold to stop drawing. --- Userland/Libraries/LibGfx/Painter.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index ad0c2f6d47..c5176c6f23 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -5,6 +5,7 @@ * Copyright (c) 2021, Sam Atkins * Copyright (c) 2022, Tobias Christiansen * Copyright (c) 2022, Linus Groh + * Copyright (c) 2022, Jelle Raaijmakers * * SPDX-License-Identifier: BSD-2-Clause */ @@ -1123,15 +1124,18 @@ ALWAYS_INLINE static void do_draw_scaled_bitmap(Gfx::Bitmap& target, IntRect con i64 vscale = (src_rect.height() * shift) / dst_rect.height(); i64 src_left = src_rect.left() * shift; i64 src_top = src_rect.top() * shift; + i64 clipped_src_bottom_shifted = (clipped_src_rect.y() + clipped_src_rect.height()) * shift; + i64 clipped_src_right_shifted = (clipped_src_rect.x() + clipped_src_rect.width()) * shift; for (int y = clipped_rect.top(); y <= clipped_rect.bottom(); ++y) { auto* scanline = (Color*)target.scanline(y); auto desired_y = ((y - dst_rect.y()) * vscale + src_top); - if (desired_y < clipped_src_rect.left() || desired_y > clipped_src_rect.bottom() * shift) + if (desired_y < clipped_src_rect.top() || desired_y > clipped_src_bottom_shifted) continue; + for (int x = clipped_rect.left(); x <= clipped_rect.right(); ++x) { auto desired_x = ((x - dst_rect.x()) * hscale + src_left); - if (desired_x < clipped_src_rect.left() || desired_x > clipped_src_rect.right() * shift) + if (desired_x < clipped_src_rect.left() || desired_x > clipped_src_right_shifted) continue; Color src_pixel;