From 3c3da1ce8c919266d82a2421386d32fd38ab5549 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Mon, 4 Aug 2025 14:33:30 +0300 Subject: [PATCH] LibGfx: Allow specifying outside color in Bitmap::cropped() This is required for LibWeb bitmap cropping. --- Libraries/LibGfx/Bitmap.cpp | 4 ++-- Libraries/LibGfx/Bitmap.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Libraries/LibGfx/Bitmap.cpp b/Libraries/LibGfx/Bitmap.cpp index ed408899272..d22cde2a2ba 100644 --- a/Libraries/LibGfx/Bitmap.cpp +++ b/Libraries/LibGfx/Bitmap.cpp @@ -158,7 +158,7 @@ void Bitmap::apply_mask(Gfx::Bitmap const& mask, MaskKind mask_kind) } } -ErrorOr> Bitmap::cropped(Gfx::IntRect crop) const +ErrorOr> Bitmap::cropped(Gfx::IntRect crop, Gfx::Color outside_color) const { auto new_bitmap = TRY(Gfx::Bitmap::create(format(), alpha_type(), { crop.width(), crop.height() })); @@ -167,7 +167,7 @@ ErrorOr> Bitmap::cropped(Gfx::IntRect crop) const int global_x = x + crop.left(); int global_y = y + crop.top(); if (global_x >= width() || global_y >= height() || global_x < 0 || global_y < 0) { - new_bitmap->set_pixel(x, y, Gfx::Color::Black); + new_bitmap->set_pixel(x, y, outside_color); } else { new_bitmap->set_pixel(x, y, get_pixel(global_x, global_y)); } diff --git a/Libraries/LibGfx/Bitmap.h b/Libraries/LibGfx/Bitmap.h index ad730f2a430..682becefd70 100644 --- a/Libraries/LibGfx/Bitmap.h +++ b/Libraries/LibGfx/Bitmap.h @@ -73,7 +73,7 @@ public: ErrorOr> clone() const; - ErrorOr> cropped(Gfx::IntRect) const; + ErrorOr> cropped(Gfx::IntRect, Gfx::Color outside_color = Gfx::Color::Black) const; ErrorOr> to_bitmap_backed_by_anonymous_buffer() const; [[nodiscard]] ShareableBitmap to_shareable_bitmap() const;