mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:07:35 +00: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
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)
|
static ErrorOr<void> decode_header_and_update_context(TinyVGLoadingContext& context)
|
||||||
{
|
{
|
||||||
VERIFY(context.state == TinyVGLoadingContext::State::NotDecoded);
|
VERIFY(context.state == TinyVGLoadingContext::State::NotDecoded);
|
||||||
auto header_or_error = decode_tinyvg_header(context.stream);
|
context.header = TRY(decode_tinyvg_header(context.stream));
|
||||||
if (header_or_error.is_error()) {
|
|
||||||
context.state = TinyVGLoadingContext::State::Error;
|
|
||||||
return header_or_error.release_error();
|
|
||||||
}
|
|
||||||
context.state = TinyVGLoadingContext::State::HeaderDecoded;
|
context.state = TinyVGLoadingContext::State::HeaderDecoded;
|
||||||
context.header = header_or_error.release_value();
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,8 +529,6 @@ static ErrorOr<void> ensure_fully_decoded(TinyVGLoadingContext& context)
|
||||||
{
|
{
|
||||||
if (context.state == TinyVGLoadingContext::State::Error)
|
if (context.state == TinyVGLoadingContext::State::Error)
|
||||||
return Error::from_string_literal("TinyVGImageDecoderPlugin: Decoding failed!");
|
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)
|
if (context.state == TinyVGLoadingContext::State::HeaderDecoded)
|
||||||
TRY(decode_image_data_and_update_context(context));
|
TRY(decode_image_data_and_update_context(context));
|
||||||
VERIFY(context.state == TinyVGLoadingContext::State::ImageDecoded);
|
VERIFY(context.state == TinyVGLoadingContext::State::ImageDecoded);
|
||||||
|
@ -549,7 +542,9 @@ TinyVGImageDecoderPlugin::TinyVGImageDecoderPlugin(ReadonlyBytes bytes)
|
||||||
|
|
||||||
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> TinyVGImageDecoderPlugin::create(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)
|
bool TinyVGImageDecoderPlugin::sniff(ReadonlyBytes bytes)
|
||||||
|
@ -560,20 +555,9 @@ bool TinyVGImageDecoderPlugin::sniff(ReadonlyBytes bytes)
|
||||||
|
|
||||||
IntSize TinyVGImageDecoderPlugin::size()
|
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 };
|
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)
|
ErrorOr<ImageFrameDescriptor> TinyVGImageDecoderPlugin::frame(size_t, Optional<IntSize> ideal_size)
|
||||||
{
|
{
|
||||||
TRY(ensure_fully_decoded(*m_context));
|
TRY(ensure_fully_decoded(*m_context));
|
||||||
|
|
|
@ -81,7 +81,6 @@ public:
|
||||||
static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes);
|
static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes);
|
||||||
|
|
||||||
virtual IntSize size() override;
|
virtual IntSize size() override;
|
||||||
virtual ErrorOr<void> initialize() override;
|
|
||||||
virtual bool is_animated() override { return false; }
|
virtual bool is_animated() override { return false; }
|
||||||
virtual size_t loop_count() override { return 0; }
|
virtual size_t loop_count() override { return 0; }
|
||||||
virtual size_t frame_count() override { return 1; }
|
virtual size_t frame_count() override { return 1; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue