mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 16:10:20 +00:00
LibGfx/PortableFormat: Read the header during initialization
This is done as a part of #19893.
This commit is contained in:
parent
f3ff9c26bc
commit
9ff706339b
Notes:
sideshowbarker
2024-07-17 00:57:24 +09:00
Author: https://github.com/LucasChollet Commit: https://github.com/SerenityOS/serenity/commit/9ff706339b Pull-request: https://github.com/SerenityOS/serenity/pull/19932 Reviewed-by: https://github.com/AtkinsSJ ✅
2 changed files with 4 additions and 14 deletions
|
@ -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;
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue