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

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.
This commit is contained in:
Jelle Raaijmakers 2022-03-23 09:02:14 +01:00 committed by Andreas Kling
parent fd7a059e09
commit f790a69431

View file

@ -5,6 +5,7 @@
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
*
* 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;