1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 15:57:35 +00:00

LibGfx: Use ErrorOr<T> for Bitmap::rotated()

This commit is contained in:
Andreas Kling 2021-11-06 11:56:44 +01:00
parent 2da4cfcc80
commit 69c4614a94
5 changed files with 11 additions and 10 deletions

View file

@ -55,7 +55,7 @@ void ViewWidget::flip(Gfx::Orientation orientation)
void ViewWidget::rotate(Gfx::RotationDirection rotation_direction) void ViewWidget::rotate(Gfx::RotationDirection rotation_direction)
{ {
m_bitmap = m_bitmap->rotated(rotation_direction); m_bitmap = m_bitmap->rotated(rotation_direction).release_value_but_fixme_should_propagate_errors();
set_scale(m_scale); set_scale(m_scale);
resize_window(); resize_window();

View file

@ -152,10 +152,10 @@ RefPtr<Gfx::Bitmap> PDFViewer::render_page(const PDF::Page& page)
if (page.rotate != 0) { if (page.rotate != 0) {
int rotation_count = (page.rotate / 90) % 4; int rotation_count = (page.rotate / 90) % 4;
if (rotation_count == 3) { if (rotation_count == 3) {
bitmap = bitmap->rotated(Gfx::RotationDirection::CounterClockwise); bitmap = bitmap->rotated(Gfx::RotationDirection::CounterClockwise).release_value_but_fixme_should_propagate_errors();
} else { } else {
for (int i = 0; i < rotation_count; i++) for (int i = 0; i < rotation_count; i++)
bitmap = bitmap->rotated(Gfx::RotationDirection::Clockwise); bitmap = bitmap->rotated(Gfx::RotationDirection::Clockwise).release_value_but_fixme_should_propagate_errors();
} }
} }

View file

@ -518,8 +518,7 @@ void Image::flip(Gfx::Orientation orientation)
void Image::rotate(Gfx::RotationDirection direction) void Image::rotate(Gfx::RotationDirection direction)
{ {
for (auto& layer : m_layers) { for (auto& layer : m_layers) {
auto rotated = layer.bitmap().rotated(direction); auto rotated = layer.bitmap().rotated(direction).release_value_but_fixme_should_propagate_errors();
VERIFY(rotated);
layer.set_bitmap(*rotated); layer.set_bitmap(*rotated);
layer.did_modify_bitmap(rect()); layer.did_modify_bitmap(rect());
} }

View file

@ -347,11 +347,13 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::clone() const
return new_bitmap.release_nonnull(); return new_bitmap.release_nonnull();
} }
RefPtr<Gfx::Bitmap> Bitmap::rotated(Gfx::RotationDirection rotation_direction) const ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::rotated(Gfx::RotationDirection rotation_direction) const
{ {
auto new_bitmap = Gfx::Bitmap::try_create(this->format(), { height(), width() }, scale()); auto new_bitmap = Gfx::Bitmap::try_create(this->format(), { height(), width() }, scale());
if (!new_bitmap) if (!new_bitmap) {
return nullptr; // FIXME: Propagate the *real* error, once we have it.
return Error::from_errno(ENOMEM);
}
auto w = this->physical_width(); auto w = this->physical_width();
auto h = this->physical_height(); auto h = this->physical_height();
@ -367,7 +369,7 @@ RefPtr<Gfx::Bitmap> Bitmap::rotated(Gfx::RotationDirection rotation_direction) c
} }
} }
return new_bitmap; return new_bitmap.release_nonnull();
} }
RefPtr<Gfx::Bitmap> Bitmap::flipped(Gfx::Orientation orientation) const RefPtr<Gfx::Bitmap> Bitmap::flipped(Gfx::Orientation orientation) const

View file

@ -111,7 +111,7 @@ public:
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> clone() const; ErrorOr<NonnullRefPtr<Gfx::Bitmap>> clone() const;
[[nodiscard]] RefPtr<Gfx::Bitmap> rotated(Gfx::RotationDirection) const; ErrorOr<NonnullRefPtr<Gfx::Bitmap>> rotated(Gfx::RotationDirection) const;
[[nodiscard]] RefPtr<Gfx::Bitmap> flipped(Gfx::Orientation) const; [[nodiscard]] RefPtr<Gfx::Bitmap> flipped(Gfx::Orientation) const;
[[nodiscard]] RefPtr<Gfx::Bitmap> scaled(int sx, int sy) const; [[nodiscard]] RefPtr<Gfx::Bitmap> scaled(int sx, int sy) const;
[[nodiscard]] RefPtr<Gfx::Bitmap> scaled(float sx, float sy) const; [[nodiscard]] RefPtr<Gfx::Bitmap> scaled(float sx, float sy) const;