From 4236177e4f3018cb51367eeb3e46856e964c3bac Mon Sep 17 00:00:00 2001 From: FrHun <28605587+frhun@users.noreply.github.com> Date: Tue, 6 Dec 2022 00:06:51 +0100 Subject: [PATCH] LibGfx: Preserve scale on Bitmap crop --- Userland/Libraries/LibGfx/Bitmap.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index 1f08a0aadc..4f15f04a42 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -459,12 +459,13 @@ ErrorOr> Bitmap::scaled(float sx, float sy) const ErrorOr> Bitmap::cropped(Gfx::IntRect crop, Optional new_bitmap_format) const { - auto new_bitmap = TRY(Gfx::Bitmap::try_create(new_bitmap_format.value_or(format()), { crop.width(), crop.height() }, 1)); + auto new_bitmap = TRY(Gfx::Bitmap::try_create(new_bitmap_format.value_or(format()), { crop.width(), crop.height() }, scale())); + auto scaled_crop = crop * scale(); - for (int y = 0; y < crop.height(); ++y) { - for (int x = 0; x < crop.width(); ++x) { - int global_x = x + crop.left(); - int global_y = y + crop.top(); + for (int y = 0; y < scaled_crop.height(); ++y) { + for (int x = 0; x < scaled_crop.width(); ++x) { + int global_x = x + scaled_crop.left(); + int global_y = y + scaled_crop.top(); if (global_x >= physical_width() || global_y >= physical_height() || global_x < 0 || global_y < 0) { new_bitmap->set_pixel(x, y, Gfx::Color::Black); } else {