summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx
diff options
context:
space:
mode:
authorjack gleeson <jack@jpgleeson.com>2022-10-10 12:54:06 -0700
committerSam Atkins <atkinssj@gmail.com>2022-11-02 10:59:18 +0000
commit4bf587811f4a90cf22b6118a55f72f3c16f1f45f (patch)
tree4225096d12509c7956c7758dedc899c0a73bc566 /Userland/Libraries/LibGfx
parentd6334dcab15556f7133fa85db7b55b1ecc40da7d (diff)
downloadserenity-4bf587811f4a90cf22b6118a55f72f3c16f1f45f.zip
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.
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r--Userland/Libraries/LibGfx/Painter.cpp8
-rw-r--r--Userland/Libraries/LibGfx/Painter.h1
2 files changed, 9 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp
index bfd566709b..9773b58fc3 100644
--- a/Userland/Libraries/LibGfx/Painter.cpp
+++ b/Userland/Libraries/LibGfx/Painter.cpp
@@ -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());
diff --git a/Userland/Libraries/LibGfx/Painter.h b/Userland/Libraries/LibGfx/Painter.h
index 3405d0befd..845978ce1b 100644
--- a/Userland/Libraries/LibGfx/Painter.h
+++ b/Userland/Libraries/LibGfx/Painter.h
@@ -38,6 +38,7 @@ public:
NearestNeighbor,
SmoothPixels,
BilinearBlend,
+ None,
};
void clear_rect(IntRect const&, Color);