mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 08:37:35 +00:00
LibGfx: Use ErrorOr<T> for Bitmap::clone()
This commit is contained in:
parent
c417820bff
commit
2da4cfcc80
6 changed files with 23 additions and 11 deletions
|
@ -332,17 +332,19 @@ Bitmap::Bitmap(BitmapFormat format, Core::AnonymousBuffer buffer, const IntSize&
|
|||
allocate_palette_from_format(m_format, palette);
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Bitmap> Bitmap::clone() const
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::clone() const
|
||||
{
|
||||
auto new_bitmap = Bitmap::try_create(format(), size(), scale());
|
||||
|
||||
if (!new_bitmap)
|
||||
return nullptr;
|
||||
if (!new_bitmap) {
|
||||
// FIXME: Propagate the *real* error, once we have it.
|
||||
return Error::from_errno(ENOMEM);
|
||||
}
|
||||
|
||||
VERIFY(size_in_bytes() == new_bitmap->size_in_bytes());
|
||||
memcpy(new_bitmap->scanline(0), scanline(0), size_in_bytes());
|
||||
|
||||
return new_bitmap;
|
||||
return new_bitmap.release_nonnull();
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Bitmap> Bitmap::rotated(Gfx::RotationDirection rotation_direction) const
|
||||
|
|
|
@ -109,7 +109,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] RefPtr<Gfx::Bitmap> clone() const;
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> clone() const;
|
||||
|
||||
[[nodiscard]] RefPtr<Gfx::Bitmap> rotated(Gfx::RotationDirection) const;
|
||||
[[nodiscard]] RefPtr<Gfx::Bitmap> flipped(Gfx::Orientation) const;
|
||||
|
|
|
@ -733,8 +733,14 @@ ImageFrameDescriptor GIFImageDecoderPlugin::frame(size_t i)
|
|||
m_context->error_state = GIFLoadingContext::ErrorState::FailedToDecodeAllFrames;
|
||||
}
|
||||
|
||||
auto image_or_error = m_context->frame_buffer->clone();
|
||||
if (image_or_error.is_error()) {
|
||||
m_context->error_state = GIFLoadingContext::ErrorState::FailedToDecodeAllFrames;
|
||||
return {};
|
||||
}
|
||||
|
||||
ImageFrameDescriptor frame {};
|
||||
frame.image = m_context->frame_buffer->clone();
|
||||
frame.image = image_or_error.release_value_but_fixme_should_propagate_errors();
|
||||
frame.duration = m_context->images.at(i).duration * 10;
|
||||
|
||||
if (frame.duration <= 10) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue