mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibGfx/TinyVG: Decode the header in create()
and remove initialize()
This is done as a part of #19893.
This commit is contained in:
parent
dcb7c299bf
commit
35dcd16ea6
Notes:
sideshowbarker
2024-07-17 05:06:13 +09:00
Author: https://github.com/LucasChollet
Commit: 35dcd16ea6
Pull-request: https://github.com/SerenityOS/serenity/pull/20013
Reviewed-by: https://github.com/MacDue ✅
2 changed files with 4 additions and 21 deletions
|
@ -507,13 +507,8 @@ struct TinyVGLoadingContext {
|
|||
static ErrorOr<void> decode_header_and_update_context(TinyVGLoadingContext& context)
|
||||
{
|
||||
VERIFY(context.state == TinyVGLoadingContext::State::NotDecoded);
|
||||
auto header_or_error = decode_tinyvg_header(context.stream);
|
||||
if (header_or_error.is_error()) {
|
||||
context.state = TinyVGLoadingContext::State::Error;
|
||||
return header_or_error.release_error();
|
||||
}
|
||||
context.header = TRY(decode_tinyvg_header(context.stream));
|
||||
context.state = TinyVGLoadingContext::State::HeaderDecoded;
|
||||
context.header = header_or_error.release_value();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -534,8 +529,6 @@ static ErrorOr<void> ensure_fully_decoded(TinyVGLoadingContext& context)
|
|||
{
|
||||
if (context.state == TinyVGLoadingContext::State::Error)
|
||||
return Error::from_string_literal("TinyVGImageDecoderPlugin: Decoding failed!");
|
||||
if (context.state == TinyVGLoadingContext::State::NotDecoded)
|
||||
TRY(decode_header_and_update_context(context));
|
||||
if (context.state == TinyVGLoadingContext::State::HeaderDecoded)
|
||||
TRY(decode_image_data_and_update_context(context));
|
||||
VERIFY(context.state == TinyVGLoadingContext::State::ImageDecoded);
|
||||
|
@ -549,7 +542,9 @@ TinyVGImageDecoderPlugin::TinyVGImageDecoderPlugin(ReadonlyBytes bytes)
|
|||
|
||||
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> TinyVGImageDecoderPlugin::create(ReadonlyBytes bytes)
|
||||
{
|
||||
return adopt_nonnull_own_or_enomem(new (nothrow) TinyVGImageDecoderPlugin(bytes));
|
||||
auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TinyVGImageDecoderPlugin(bytes)));
|
||||
TRY(decode_header_and_update_context(*plugin->m_context));
|
||||
return plugin;
|
||||
}
|
||||
|
||||
bool TinyVGImageDecoderPlugin::sniff(ReadonlyBytes bytes)
|
||||
|
@ -560,20 +555,9 @@ bool TinyVGImageDecoderPlugin::sniff(ReadonlyBytes bytes)
|
|||
|
||||
IntSize TinyVGImageDecoderPlugin::size()
|
||||
{
|
||||
if (m_context->state == TinyVGLoadingContext::State::NotDecoded)
|
||||
(void)decode_header_and_update_context(*m_context);
|
||||
|
||||
if (m_context->state == TinyVGLoadingContext::State::Error)
|
||||
return {};
|
||||
|
||||
return { m_context->header.width, m_context->header.height };
|
||||
}
|
||||
|
||||
ErrorOr<void> TinyVGImageDecoderPlugin::initialize()
|
||||
{
|
||||
return decode_header_and_update_context(*m_context);
|
||||
}
|
||||
|
||||
ErrorOr<ImageFrameDescriptor> TinyVGImageDecoderPlugin::frame(size_t, Optional<IntSize> ideal_size)
|
||||
{
|
||||
TRY(ensure_fully_decoded(*m_context));
|
||||
|
|
|
@ -81,7 +81,6 @@ public:
|
|||
static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes);
|
||||
|
||||
virtual IntSize size() override;
|
||||
virtual ErrorOr<void> initialize() override;
|
||||
virtual bool is_animated() override { return false; }
|
||||
virtual size_t loop_count() override { return 0; }
|
||||
virtual size_t frame_count() override { return 1; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue