mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibGfx: Add Bitmap::scaled_to_size()
This commit is contained in:
parent
3907374621
commit
a4dec92ed0
Notes:
sideshowbarker
2024-07-17 10:31:19 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/a4dec92ed0 Pull-request: https://github.com/SerenityOS/serenity/pull/21488 Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 7 additions and 2 deletions
|
@ -362,7 +362,6 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(int sx, int sy) const
|
|||
return new_bitmap;
|
||||
}
|
||||
|
||||
// http://fourier.eng.hmc.edu/e161/lectures/resize/node3.html
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const
|
||||
{
|
||||
VERIFY(sx >= 0.0f && sy >= 0.0f);
|
||||
|
@ -371,8 +370,13 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const
|
|||
|
||||
int scaled_width = (int)ceilf(sx * (float)width());
|
||||
int scaled_height = (int)ceilf(sy * (float)height());
|
||||
return scaled_to_size({ scaled_width, scaled_height });
|
||||
}
|
||||
|
||||
auto new_bitmap = TRY(Gfx::Bitmap::create(format(), { scaled_width, scaled_height }, scale()));
|
||||
// http://fourier.eng.hmc.edu/e161/lectures/resize/node3.html
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled_to_size(Gfx::IntSize size) const
|
||||
{
|
||||
auto new_bitmap = TRY(Gfx::Bitmap::create(format(), size, scale()));
|
||||
|
||||
auto old_width = physical_width();
|
||||
auto old_height = physical_height();
|
||||
|
|
|
@ -114,6 +114,7 @@ public:
|
|||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> flipped(Gfx::Orientation) const;
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled(int sx, int sy) const;
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled(float sx, float sy) const;
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled_to_size(Gfx::IntSize) const;
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> cropped(Gfx::IntRect, Optional<BitmapFormat> new_bitmap_format = {}) const;
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> to_bitmap_backed_by_anonymous_buffer() const;
|
||||
[[nodiscard]] ErrorOr<ByteBuffer> serialize_to_byte_buffer() const;
|
||||
|
|
Loading…
Reference in a new issue