1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:07: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

@ -1248,6 +1248,9 @@ ALWAYS_INLINE static void do_draw_scaled_bitmap(Gfx::Bitmap& target, IntRect con
case Painter::ScalingMode::BilinearBlend:
do_draw_scaled_bitmap<has_alpha_channel, Painter::ScalingMode::BilinearBlend>(target, dst_rect, clipped_rect, source, src_rect, get_pixel, opacity);
break;
case Painter::ScalingMode::None:
do_draw_scaled_bitmap<has_alpha_channel, Painter::ScalingMode::None>(target, dst_rect, clipped_rect, source, src_rect, get_pixel, opacity);
break;
}
}
@ -1262,6 +1265,11 @@ void Painter::draw_scaled_bitmap(IntRect const& a_dst_rect, Gfx::Bitmap const& s
if (scale() == source.scale() && a_src_rect == int_src_rect && a_dst_rect.size() == int_src_rect.size())
return blit(a_dst_rect.location(), source, int_src_rect, opacity);
if (scaling_mode == ScalingMode::None) {
IntRect clipped_draw_rect { (int)a_src_rect.location().x(), (int)a_src_rect.location().y(), a_dst_rect.size().width(), a_dst_rect.size().height() };
return blit(a_dst_rect.location(), source, clipped_draw_rect, opacity);
}
auto dst_rect = to_physical(a_dst_rect);
auto src_rect = a_src_rect * source.scale();
auto clipped_rect = dst_rect.intersected(clip_rect() * scale());