From 4adef05e6ddf89e7193a33bc2d04e9baea8aa3b2 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Fri, 14 Jul 2023 18:33:14 -0400 Subject: [PATCH] LibGfx/WebP: Decode the first chunk in `create()` And remove `initialize()`. This is done as a part of #19893. --- .../LibGfx/ImageFormats/WebPLoader.cpp | 34 +++---------------- .../LibGfx/ImageFormats/WebPLoader.h | 1 - 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp index 45f7a182fc..65db20f1c6 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp @@ -529,9 +529,6 @@ static ErrorOr read_webp_first_chunk(WebPLoadingContext& context) if (context.state >= WebPLoadingContext::State::FirstChunkRead) return {}; - if (context.state < WebPLoadingContext::HeaderDecoded) - TRY(decode_webp_header(context)); - context.chunks_cursor = context.data.slice(sizeof(WebPFileHeader)); auto first_chunk = TRY(decode_webp_advance_chunk(context.chunks_cursor)); @@ -579,8 +576,7 @@ static ErrorOr decode_webp_chunks(WebPLoadingContext& context) if (context.state >= WebPLoadingContext::State::ChunksDecoded) return {}; - if (context.state < WebPLoadingContext::FirstChunkDecoded) - TRY(decode_webp_first_chunk(context)); + VERIFY(context.state >= WebPLoadingContext::FirstChunkDecoded); if (context.first_chunk->type == FourCC("VP8X")) return decode_webp_extended(context, context.chunks_cursor); @@ -711,24 +707,9 @@ bool WebPImageDecoderPlugin::set_error(ErrorOr const& error_or) IntSize WebPImageDecoderPlugin::size() { - if (m_context->state == WebPLoadingContext::State::Error) - return {}; - - if (m_context->state < WebPLoadingContext::State::FirstChunkDecoded) { - if (set_error(decode_webp_first_chunk(*m_context))) - return {}; - } - return m_context->size.value(); } -ErrorOr WebPImageDecoderPlugin::initialize() -{ - auto header_okay_or_error = decode_webp_header(*m_context); - set_error(header_okay_or_error); - return header_okay_or_error; -} - bool WebPImageDecoderPlugin::sniff(ReadonlyBytes data) { WebPLoadingContext context; @@ -741,19 +722,14 @@ bool WebPImageDecoderPlugin::sniff(ReadonlyBytes data) ErrorOr> WebPImageDecoderPlugin::create(ReadonlyBytes data) { auto context = TRY(try_make()); - return adopt_nonnull_own_or_enomem(new (nothrow) WebPImageDecoderPlugin(data, move(context))); + auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) WebPImageDecoderPlugin(data, move(context)))); + TRY(decode_webp_header(*plugin->m_context)); + TRY(decode_webp_first_chunk(*plugin->m_context)); + return plugin; } bool WebPImageDecoderPlugin::is_animated() { - if (m_context->state == WebPLoadingContext::State::Error) - return false; - - if (m_context->state < WebPLoadingContext::State::FirstChunkDecoded) { - if (set_error(decode_webp_first_chunk(*m_context))) - return false; - } - return m_context->first_chunk->type == FourCC("VP8X") && m_context->vp8x_header.has_animation; } diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.h b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.h index 9d7df0acc9..215e677fdd 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.h +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.h @@ -21,7 +21,6 @@ public: virtual IntSize size() override; - virtual ErrorOr initialize() override; virtual bool is_animated() override; virtual size_t loop_count() override; virtual size_t frame_count() override;