LibGfx/PortableFormat: Read the header during initialization

This is done as a part of #19893.
This commit is contained in:
Lucas CHOLLET 2023-07-10 16:42:59 -04:00 committed by Sam Atkins
parent f3ff9c26bc
commit 9ff706339b
Notes: sideshowbarker 2024-07-17 00:57:24 +09:00
2 changed files with 4 additions and 14 deletions

View file

@ -195,9 +195,8 @@ static ErrorOr<void> read_header(Context& context)
template<typename TContext>
static ErrorOr<void> decode(TContext& context)
{
VERIFY(context.state == TContext::State::NotDecoded);
VERIFY(context.state == TContext::State::HeaderDecoded);
TRY(read_header(context));
TRY(read_image_data(context));
context.state = TContext::State::BitmapDecoded;

View file

@ -82,17 +82,6 @@ PortableImageDecoderPlugin<TContext>::PortableImageDecoderPlugin(NonnullOwnPtr<S
template<typename TContext>
IntSize PortableImageDecoderPlugin<TContext>::size()
{
if (m_context->state == TContext::State::Error)
return {};
if (m_context->state < TContext::State::BitmapDecoded) {
if (decode(*m_context).is_error()) {
m_context->state = TContext::State::Error;
// FIXME: We should propagate errors
return {};
}
}
return { m_context->width, m_context->height };
}
@ -100,7 +89,9 @@ template<typename TContext>
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> PortableImageDecoderPlugin<TContext>::create(ReadonlyBytes data)
{
auto stream = TRY(try_make<FixedMemoryStream>(data));
return adopt_nonnull_own_or_enomem(new (nothrow) PortableImageDecoderPlugin<TContext>(move(stream)));
auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) PortableImageDecoderPlugin<TContext>(move(stream))));
TRY(read_header(*plugin->m_context));
return plugin;
}
template<typename TContext>