mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-19 07:49:05 +00:00
LibGfx: Allow specifying outside color in Bitmap::cropped()
This is required for LibWeb bitmap cropping.
This commit is contained in:
parent
bf2dc77dfc
commit
3c3da1ce8c
Notes:
github-actions[bot]
2025-08-04 21:40:34 +00:00
Author: https://github.com/IdanHo
Commit: 3c3da1ce8c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5702
Reviewed-by: https://github.com/gmta ✅
2 changed files with 3 additions and 3 deletions
|
@ -158,7 +158,7 @@ void Bitmap::apply_mask(Gfx::Bitmap const& mask, MaskKind mask_kind)
|
|||
}
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::cropped(Gfx::IntRect crop) const
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> 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<NonnullRefPtr<Gfx::Bitmap>> 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));
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ public:
|
|||
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> clone() const;
|
||||
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> cropped(Gfx::IntRect) const;
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> cropped(Gfx::IntRect, Gfx::Color outside_color = Gfx::Color::Black) const;
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> to_bitmap_backed_by_anonymous_buffer() const;
|
||||
|
||||
[[nodiscard]] ShareableBitmap to_shareable_bitmap() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue