diff --git a/Userland/Libraries/LibGfx/ImageFormats/QOILoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/QOILoader.cpp index a638c10932d..4ae923adffb 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/QOILoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/QOILoader.cpp @@ -170,23 +170,9 @@ QOIImageDecoderPlugin::QOIImageDecoderPlugin(NonnullOwnPtr stream) IntSize QOIImageDecoderPlugin::size() { - if (m_context->state < QOILoadingContext::State::HeaderDecoded) { - // FIXME: This is a weird API (inherited from ImageDecoderPlugin), should probably propagate errors by returning ErrorOr. - // For the time being, ignore the result and rely on the context's state. - (void)decode_header_and_update_context(); - } - - if (m_context->state == QOILoadingContext::State::Error) - return {}; - return { m_context->header.width, m_context->header.height }; } -ErrorOr QOIImageDecoderPlugin::initialize() -{ - return decode_header_and_update_context(); -} - bool QOIImageDecoderPlugin::sniff(ReadonlyBytes data) { FixedMemoryStream stream { { data.data(), data.size() } }; @@ -196,7 +182,9 @@ bool QOIImageDecoderPlugin::sniff(ReadonlyBytes data) ErrorOr> QOIImageDecoderPlugin::create(ReadonlyBytes data) { auto stream = TRY(try_make(data)); - return adopt_nonnull_own_or_enomem(new (nothrow) QOIImageDecoderPlugin(move(stream))); + auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) QOIImageDecoderPlugin(move(stream)))); + TRY(plugin->decode_header_and_update_context()); + return plugin; } ErrorOr QOIImageDecoderPlugin::frame(size_t index, Optional) @@ -207,12 +195,8 @@ ErrorOr QOIImageDecoderPlugin::frame(size_t index, Optiona // 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) { - TRY(decode_header_and_update_context()); + if (m_context->state == QOILoadingContext::State::HeaderDecoded) TRY(decode_image_and_update_context()); - } else if (m_context->state == QOILoadingContext::State::HeaderDecoded) { - TRY(decode_image_and_update_context()); - } VERIFY(m_context->state == QOILoadingContext::State::ImageDecoded); VERIFY(m_context->bitmap); @@ -222,13 +206,8 @@ ErrorOr QOIImageDecoderPlugin::frame(size_t index, Optiona ErrorOr QOIImageDecoderPlugin::decode_header_and_update_context() { VERIFY(m_context->state < QOILoadingContext::State::HeaderDecoded); - auto error_or_header = decode_qoi_header(*m_context->stream); - if (error_or_header.is_error()) { - m_context->state = QOILoadingContext::State::Error; - return error_or_header.release_error(); - } + m_context->header = TRY(decode_qoi_header(*m_context->stream)); m_context->state = QOILoadingContext::State::HeaderDecoded; - m_context->header = error_or_header.release_value(); return {}; } diff --git a/Userland/Libraries/LibGfx/ImageFormats/QOILoader.h b/Userland/Libraries/LibGfx/ImageFormats/QOILoader.h index 4a26592e7cb..c9407c1a2fc 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/QOILoader.h +++ b/Userland/Libraries/LibGfx/ImageFormats/QOILoader.h @@ -45,7 +45,6 @@ public: virtual IntSize size() override; - virtual ErrorOr initialize() override; virtual bool is_animated() override { return false; } virtual size_t loop_count() override { return 0; } virtual size_t frame_count() override { return 1; }