From 6a78e7e6a8a4816a3c36e9e7d25102b2b25a8ba6 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 22 Jan 2021 10:19:10 -0500 Subject: [PATCH] LibGfx: Correctly handle source rect offset in draw_scaled_bitmap The do_draw_integer_scaled_bitmap() fastpath already handled this correctly, but the arbitrary scale path did not. --- Userland/Demos/LibGfxScaleDemo/main.cpp | 2 ++ Userland/Libraries/LibGfx/Painter.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Demos/LibGfxScaleDemo/main.cpp b/Userland/Demos/LibGfxScaleDemo/main.cpp index aa5fdd6373..e8dffe98f1 100644 --- a/Userland/Demos/LibGfxScaleDemo/main.cpp +++ b/Userland/Demos/LibGfxScaleDemo/main.cpp @@ -100,6 +100,8 @@ void Canvas::draw(Gfx::Painter& painter) auto buggie = Gfx::Bitmap::load_from_file("/res/graphics/buggie.png"); painter.blit({ 25, 39 }, *buggie, { 2, 30, 62, 20 }); + painter.draw_scaled_bitmap({ 88, 39, 62 * 2, 20 * 2 }, *buggie, { 2, 30, 62, 20 }); + painter.draw_scaled_bitmap({ 202, 39, 80, 40 }, *buggie, { 2, 30, 62, 20 }); } int main(int argc, char** argv) diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 4060a7afed..a47327c236 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -843,7 +843,7 @@ ALWAYS_INLINE static void do_draw_scaled_bitmap(Gfx::Bitmap& target, const IntRe for (int x = clipped_rect.left(); x <= clipped_rect.right(); ++x) { auto scaled_x = ((x - dst_rect.x()) * hscale) >> 16; auto scaled_y = ((y - dst_rect.y()) * vscale) >> 16; - auto src_pixel = get_pixel(source, scaled_x, scaled_y); + auto src_pixel = get_pixel(source, scaled_x + src_rect.left(), scaled_y + src_rect.top()); if (has_opacity) src_pixel.set_alpha(src_pixel.alpha() * opacity); if constexpr (has_alpha_channel) {