diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-09-20 19:48:56 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-20 22:18:20 +0200 |
commit | 1c807410cd06ded77b964ed6e9097e6d5451f791 (patch) | |
tree | 83d3a6daa3843a5428ad5c9c2a3ee0468c93e7ab /Userland/Libraries/LibGfx/Painter.h | |
parent | 10e54a29b2aabdee6577514acf81624637349677 (diff) | |
download | serenity-1c807410cd06ded77b964ed6e9097e6d5451f791.zip |
LibGfx: Add optional bilinear filtering to draw_scaled_bitmap()
The algorithm is quite simple: You grab a 2x2 area of pixels around the
point you want from the source bitmap, and then linearly interpolate
between them based on how far they are from that point.
This works well when scaling up images, and moderately well when scaling
down - small details may get skipped over. The way GPUs solve this is
with mipmaps, which is not something I want to get into right now. (And
increases the memory usage per bitmap by 50%.)
I have not focused on performance, but this does reuse much of the
existing fixed-point calculation, and uses constexpr so that the
performance for nearest-neighbor should be the same as it was
previously.
Diffstat (limited to 'Userland/Libraries/LibGfx/Painter.h')
-rw-r--r-- | Userland/Libraries/LibGfx/Painter.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGfx/Painter.h b/Userland/Libraries/LibGfx/Painter.h index d87ef7aeec..56b0cc9a58 100644 --- a/Userland/Libraries/LibGfx/Painter.h +++ b/Userland/Libraries/LibGfx/Painter.h @@ -32,6 +32,11 @@ public: Dashed, }; + enum class ScalingMode { + NearestNeighbor, + BilinearBlend, + }; + void clear_rect(IntRect const&, Color); void fill_rect(IntRect const&, Color); void fill_rect_with_dither_pattern(IntRect const&, Color, Color); @@ -46,8 +51,8 @@ public: void draw_focus_rect(IntRect const&, Color); void draw_bitmap(IntPoint const&, CharacterBitmap const&, Color = Color()); void draw_bitmap(IntPoint const&, GlyphBitmap const&, Color = Color()); - void draw_scaled_bitmap(IntRect const& dst_rect, Gfx::Bitmap const&, IntRect const& src_rect, float opacity = 1.0f); - void draw_scaled_bitmap(IntRect const& dst_rect, Gfx::Bitmap const&, FloatRect const& src_rect, float opacity = 1.0f); + void draw_scaled_bitmap(IntRect const& dst_rect, Gfx::Bitmap const&, IntRect const& src_rect, float opacity = 1.0f, ScalingMode = ScalingMode::NearestNeighbor); + void draw_scaled_bitmap(IntRect const& dst_rect, Gfx::Bitmap const&, FloatRect const& src_rect, float opacity = 1.0f, ScalingMode = ScalingMode::NearestNeighbor); void draw_triangle(IntPoint const&, IntPoint const&, IntPoint const&, Color); void draw_ellipse_intersecting(IntRect const&, Color, int thickness = 1); void set_pixel(IntPoint const&, Color); |