mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:17:44 +00:00
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.
This commit is contained in:
parent
10e54a29b2
commit
1c807410cd
2 changed files with 72 additions and 31 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue