LibGfx/WebP: Decode the first chunk in create()

And remove `initialize()`.

This is done as a part of #19893.
This commit is contained in:
Lucas CHOLLET 2023-07-14 18:33:14 -04:00 committed by Andreas Kling
parent ed67acb16d
commit 4adef05e6d
Notes: sideshowbarker 2024-07-17 03:03:15 +09:00
2 changed files with 5 additions and 30 deletions

View File

@ -529,9 +529,6 @@ static ErrorOr<void> 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<void> 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<void> 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<void> 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<NonnullOwnPtr<ImageDecoderPlugin>> WebPImageDecoderPlugin::create(ReadonlyBytes data)
{
auto context = TRY(try_make<WebPLoadingContext>());
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;
}

View File

@ -21,7 +21,6 @@ public:
virtual IntSize size() override;
virtual ErrorOr<void> initialize() override;
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;