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

LibGfx: Remove the optional Error member from QOI's decoder context

This commit is contained in:
Timothy Flynn 2023-02-09 13:25:09 -05:00 committed by Linus Groh
parent bd4bddf31b
commit 142f327e63
2 changed files with 8 additions and 13 deletions

View file

@ -217,6 +217,9 @@ ErrorOr<ImageFrameDescriptor> QOIImageDecoderPlugin::frame(size_t index)
if (index > 0) if (index > 0)
return Error::from_string_literal("Invalid frame index"); return Error::from_string_literal("Invalid frame index");
// No one should try to decode the frame again after an error was already returned.
VERIFY(m_context->state != QOILoadingContext::State::Error);
if (m_context->state == QOILoadingContext::State::NotDecoded) { if (m_context->state == QOILoadingContext::State::NotDecoded) {
TRY(decode_header_and_update_context(*m_context->stream)); TRY(decode_header_and_update_context(*m_context->stream));
TRY(decode_image_and_update_context(*m_context->stream)); TRY(decode_image_and_update_context(*m_context->stream));
@ -224,14 +227,9 @@ ErrorOr<ImageFrameDescriptor> QOIImageDecoderPlugin::frame(size_t index)
TRY(decode_image_and_update_context(*m_context->stream)); TRY(decode_image_and_update_context(*m_context->stream));
} }
if (m_context->state == QOILoadingContext::State::ImageDecoded) { VERIFY(m_context->state == QOILoadingContext::State::ImageDecoded);
VERIFY(m_context->bitmap); VERIFY(m_context->bitmap);
return ImageFrameDescriptor { m_context->bitmap, 0 }; return ImageFrameDescriptor { m_context->bitmap, 0 };
}
VERIFY(m_context->state == QOILoadingContext::State::Error);
VERIFY(m_context->error.has_value());
return *m_context->error;
} }
ErrorOr<void> QOIImageDecoderPlugin::decode_header_and_update_context(AK::Stream& stream) ErrorOr<void> QOIImageDecoderPlugin::decode_header_and_update_context(AK::Stream& stream)
@ -240,8 +238,7 @@ ErrorOr<void> QOIImageDecoderPlugin::decode_header_and_update_context(AK::Stream
auto error_or_header = decode_qoi_header(stream); auto error_or_header = decode_qoi_header(stream);
if (error_or_header.is_error()) { if (error_or_header.is_error()) {
m_context->state = QOILoadingContext::State::Error; m_context->state = QOILoadingContext::State::Error;
m_context->error = error_or_header.release_error(); return error_or_header.release_error();
return *m_context->error;
} }
m_context->state = QOILoadingContext::State::HeaderDecoded; m_context->state = QOILoadingContext::State::HeaderDecoded;
m_context->header = error_or_header.release_value(); m_context->header = error_or_header.release_value();
@ -254,8 +251,7 @@ ErrorOr<void> QOIImageDecoderPlugin::decode_image_and_update_context(AK::Stream&
auto error_or_bitmap = decode_qoi_image(stream, m_context->header.width, m_context->header.height); auto error_or_bitmap = decode_qoi_image(stream, m_context->header.width, m_context->header.height);
if (error_or_bitmap.is_error()) { if (error_or_bitmap.is_error()) {
m_context->state = QOILoadingContext::State::Error; m_context->state = QOILoadingContext::State::Error;
m_context->error = error_or_bitmap.release_error(); return error_or_bitmap.release_error();
return *m_context->error;
} }
m_context->state = QOILoadingContext::State::ImageDecoded; m_context->state = QOILoadingContext::State::ImageDecoded;
m_context->bitmap = error_or_bitmap.release_value(); m_context->bitmap = error_or_bitmap.release_value();

View file

@ -35,7 +35,6 @@ struct QOILoadingContext {
OwnPtr<AK::Stream> stream {}; OwnPtr<AK::Stream> stream {};
QOIHeader header {}; QOIHeader header {};
RefPtr<Bitmap> bitmap; RefPtr<Bitmap> bitmap;
Optional<Error> error;
}; };
class QOIImageDecoderPlugin final : public ImageDecoderPlugin { class QOIImageDecoderPlugin final : public ImageDecoderPlugin {