diff --git a/SharedGraphics/Painter.cpp b/SharedGraphics/Painter.cpp index 1bfb8b0621..70d0d53f90 100644 --- a/SharedGraphics/Painter.cpp +++ b/SharedGraphics/Painter.cpp @@ -349,21 +349,20 @@ void Painter::blit(const Point& position, const GraphicsBitmap& source, const Re } template -ALWAYS_INLINE static void do_draw_integer_scaled_bitmap(GraphicsBitmap& target, const Rect& dst_rect, const Rect& clipped_rect, const GraphicsBitmap& source, int hscale, int vscale, int hfactor, int vfactor, GetPixel get_pixel) +ALWAYS_INLINE static void do_draw_integer_scaled_bitmap(GraphicsBitmap& target, const Rect& dst_rect, const GraphicsBitmap& source, int hfactor, int vfactor, GetPixel get_pixel) { - for (int y = clipped_rect.top(); y <= clipped_rect.bottom(); y += vfactor) { - for (int x = clipped_rect.left(); x <= clipped_rect.right(); x += hfactor) { - 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); - + for (int y = source.rect().top(); y <= source.rect().bottom(); ++y) { + int dst_y = dst_rect.y() + y * vfactor; + for (int x = source.rect().left(); x <= source.rect().right(); ++x) { + auto src_pixel = get_pixel(source, x, y); for (int yo = 0; yo < vfactor; ++yo) { - auto* scanline = (Color*)target.scanline(y + yo); + auto* scanline = (Color*)target.scanline(dst_y + yo); + int dst_x = dst_rect.x() + x * hfactor; for (int xo = 0; xo < hfactor; ++xo) { if constexpr (has_alpha_channel) - scanline[x + xo] = scanline[x].blend(src_pixel); + scanline[dst_x + xo] = scanline[dst_x + xo].blend(src_pixel); else - scanline[x + xo] = src_pixel; + scanline[dst_x + xo] = src_pixel; } } } @@ -377,12 +376,12 @@ ALWAYS_INLINE static void do_draw_scaled_bitmap(GraphicsBitmap& target, const Re int hfactor = dst_rect.width() / src_rect.width(); int vfactor = dst_rect.height() / src_rect.height(); if (hfactor == 2 && vfactor == 2) - return do_draw_integer_scaled_bitmap(target, dst_rect, clipped_rect, source, hscale, vscale, 2, 2, get_pixel); + return do_draw_integer_scaled_bitmap(target, dst_rect, source, 2, 2, get_pixel); if (hfactor == 3 && vfactor == 3) - return do_draw_integer_scaled_bitmap(target, dst_rect, clipped_rect, source, hscale, vscale, 3, 3, get_pixel); + return do_draw_integer_scaled_bitmap(target, dst_rect, source, 3, 3, get_pixel); if (hfactor == 4 && vfactor == 4) - return do_draw_integer_scaled_bitmap(target, dst_rect, clipped_rect, source, hscale, vscale, 4, 4, get_pixel); - return do_draw_integer_scaled_bitmap(target, dst_rect, clipped_rect, source, hscale, vscale, hfactor, vfactor, get_pixel); + return do_draw_integer_scaled_bitmap(target, dst_rect, source, 4, 4, get_pixel); + return do_draw_integer_scaled_bitmap(target, dst_rect, source, hfactor, vfactor, get_pixel); } for (int y = clipped_rect.top(); y <= clipped_rect.bottom(); ++y) {