1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:37:35 +00:00

PixelPaint+LibGfx: Allow resizing images and layers

This PR adds resize ability to PixelPaint as per issue 11862.
The previous behaviour was to always rescale the canvas when
resizing an image. This adds a checkbox to toggle between
rescaling, and resizing which blits the existing canvas to
the top left of the new, resized canvas.

As part of this, a new ScalingMode is added to
LibGfx - None.
This commit is contained in:
jack gleeson 2022-10-10 12:54:06 -07:00 committed by Sam Atkins
parent d6334dcab1
commit 4bf587811f
6 changed files with 35 additions and 3 deletions

View file

@ -230,7 +230,11 @@ void Layer::resize(Gfx::IntSize const& new_size, Gfx::IntPoint const& new_locati
auto dst = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, new_size).release_value_but_fixme_should_propagate_errors();
Gfx::Painter painter(dst);
painter.draw_scaled_bitmap(dst_rect, *m_content_bitmap, src_rect, 1.0f, scaling_mode);
if (scaling_mode == Gfx::Painter::ScalingMode::None) {
painter.blit(src_rect.top_left(), *m_content_bitmap, src_rect, 1.0f);
} else {
painter.draw_scaled_bitmap(dst_rect, *m_content_bitmap, src_rect, 1.0f, scaling_mode);
}
m_content_bitmap = move(dst);
}
@ -239,7 +243,12 @@ void Layer::resize(Gfx::IntSize const& new_size, Gfx::IntPoint const& new_locati
auto dst = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, new_size).release_value_but_fixme_should_propagate_errors();
Gfx::Painter painter(dst);
painter.draw_scaled_bitmap(dst_rect, *m_mask_bitmap, src_rect, 1.0f, scaling_mode);
if (scaling_mode == Gfx::Painter::ScalingMode::None) {
painter.blit(src_rect.top_left(), *m_content_bitmap, src_rect, 1.0f);
} else {
painter.draw_scaled_bitmap(dst_rect, *m_mask_bitmap, src_rect, 1.0f, scaling_mode);
}
m_mask_bitmap = move(dst);
}