mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 10:57:35 +00:00
LibGfx/ICO: Decode the header in create()
and remove initialize()
This is done as a part of #19893.
This commit is contained in:
parent
a8587fe54e
commit
38dd4168be
3 changed files with 5 additions and 31 deletions
|
@ -77,14 +77,7 @@ TEST_CASE(test_not_ico)
|
||||||
{
|
{
|
||||||
auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie.png"sv)));
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("buggie.png"sv)));
|
||||||
EXPECT(!Gfx::ICOImageDecoderPlugin::sniff(file->bytes()));
|
EXPECT(!Gfx::ICOImageDecoderPlugin::sniff(file->bytes()));
|
||||||
auto plugin_decoder = MUST(Gfx::ICOImageDecoderPlugin::create(file->bytes()));
|
EXPECT(Gfx::ICOImageDecoderPlugin::create(file->bytes()).is_error());
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(test_bmp_embedded_in_ico)
|
TEST_CASE(test_bmp_embedded_in_ico)
|
||||||
|
|
|
@ -138,8 +138,7 @@ static ErrorOr<void> load_ico_directory(ICOLoadingContext& context)
|
||||||
|
|
||||||
ErrorOr<void> ICOImageDecoderPlugin::load_ico_bitmap(ICOLoadingContext& context, Optional<size_t> index)
|
ErrorOr<void> ICOImageDecoderPlugin::load_ico_bitmap(ICOLoadingContext& context, Optional<size_t> index)
|
||||||
{
|
{
|
||||||
if (context.state < ICOLoadingContext::State::DirectoryDecoded)
|
VERIFY(context.state >= ICOLoadingContext::State::DirectoryDecoded);
|
||||||
TRY(load_ico_directory(context));
|
|
||||||
|
|
||||||
size_t real_index = context.largest_index;
|
size_t real_index = context.largest_index;
|
||||||
if (index.has_value())
|
if (index.has_value())
|
||||||
|
@ -186,7 +185,9 @@ bool ICOImageDecoderPlugin::sniff(ReadonlyBytes data)
|
||||||
|
|
||||||
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> ICOImageDecoderPlugin::create(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)
|
ICOImageDecoderPlugin::ICOImageDecoderPlugin(u8 const* data, size_t size)
|
||||||
|
@ -200,28 +201,9 @@ ICOImageDecoderPlugin::~ICOImageDecoderPlugin() = default;
|
||||||
|
|
||||||
IntSize ICOImageDecoderPlugin::size()
|
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 };
|
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()
|
bool ICOImageDecoderPlugin::is_animated()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -21,7 +21,6 @@ public:
|
||||||
|
|
||||||
virtual IntSize size() override;
|
virtual IntSize size() override;
|
||||||
|
|
||||||
virtual ErrorOr<void> initialize() override;
|
|
||||||
virtual bool is_animated() override;
|
virtual bool is_animated() override;
|
||||||
virtual size_t loop_count() override;
|
virtual size_t loop_count() override;
|
||||||
virtual size_t frame_count() override;
|
virtual size_t frame_count() override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue