浏览代码

LibGfx/PortableFormat: Read the header during initialization

This is done as a part of #19893.
Lucas CHOLLET 2 年之前
父节点
当前提交
9ff706339b

+ 1 - 2
Userland/Libraries/LibGfx/ImageFormats/PortableImageLoaderCommon.h

@@ -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;

+ 3 - 12
Userland/Libraries/LibGfx/ImageFormats/PortableImageMapLoader.h

@@ -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>