LibGfx/ICO: Decode the header in create() and remove initialize()

This is done as a part of #19893.
This commit is contained in:
Lucas CHOLLET 2023-07-17 12:24:16 -04:00 committed by Sam Atkins
parent a8587fe54e
commit 38dd4168be
Notes: sideshowbarker 2024-07-17 18:23:22 +09:00
3 changed files with 5 additions and 31 deletions

View File

@ -77,14 +77,7 @@ TEST_CASE(test_not_ico)
{
auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie.png"sv)));
EXPECT(!Gfx::ICOImageDecoderPlugin::sniff(file->bytes()));
auto plugin_decoder = MUST(Gfx::ICOImageDecoderPlugin::create(file->bytes()));
EXPECT(plugin_decoder->initialize().is_error());
EXPECT(plugin_decoder->frame_count());
EXPECT(!plugin_decoder->is_animated());
EXPECT(!plugin_decoder->loop_count());
EXPECT(plugin_decoder->frame(0).is_error());
EXPECT(Gfx::ICOImageDecoderPlugin::create(file->bytes()).is_error());
}
TEST_CASE(test_bmp_embedded_in_ico)

View File

@ -138,8 +138,7 @@ static ErrorOr<void> load_ico_directory(ICOLoadingContext& context)
ErrorOr<void> ICOImageDecoderPlugin::load_ico_bitmap(ICOLoadingContext& context, Optional<size_t> index)
{
if (context.state < ICOLoadingContext::State::DirectoryDecoded)
TRY(load_ico_directory(context));
VERIFY(context.state >= ICOLoadingContext::State::DirectoryDecoded);
size_t real_index = context.largest_index;
if (index.has_value())
@ -186,7 +185,9 @@ bool ICOImageDecoderPlugin::sniff(ReadonlyBytes data)
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> ICOImageDecoderPlugin::create(ReadonlyBytes data)
{
return adopt_nonnull_own_or_enomem(new (nothrow) ICOImageDecoderPlugin(data.data(), data.size()));
auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) ICOImageDecoderPlugin(data.data(), data.size())));
TRY(load_ico_directory(*plugin->m_context));
return plugin;
}
ICOImageDecoderPlugin::ICOImageDecoderPlugin(u8 const* data, size_t size)
@ -200,28 +201,9 @@ ICOImageDecoderPlugin::~ICOImageDecoderPlugin() = default;
IntSize ICOImageDecoderPlugin::size()
{
if (m_context->state == ICOLoadingContext::State::Error) {
return {};
}
if (m_context->state < ICOLoadingContext::State::DirectoryDecoded) {
if (load_ico_directory(*m_context).is_error()) {
m_context->state = ICOLoadingContext::State::Error;
return {};
}
m_context->state = ICOLoadingContext::State::DirectoryDecoded;
}
return { m_context->images[m_context->largest_index].width, m_context->images[m_context->largest_index].height };
}
ErrorOr<void> ICOImageDecoderPlugin::initialize()
{
FixedMemoryStream stream { { m_context->data, m_context->data_size } };
TRY(decode_ico_header(stream));
return {};
}
bool ICOImageDecoderPlugin::is_animated()
{
return false;

View File

@ -21,7 +21,6 @@ public:
virtual IntSize size() override;
virtual ErrorOr<void> initialize() override;
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;