1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:37:35 +00:00

LibGfx: Provide a default implementation for animation-related methods

Most image decoders that we have only support non-animated images,
providing a default implementation for them allows to remove quite some
code.
This commit is contained in:
Lucas CHOLLET 2023-07-17 13:29:12 -04:00 committed by Sam Atkins
parent 7acb656826
commit 806808f406
14 changed files with 6 additions and 160 deletions

View file

@ -1500,26 +1500,6 @@ bool BMPImageDecoderPlugin::sniff_dib()
return !decode_bmp_dib(*m_context).is_error();
}
bool BMPImageDecoderPlugin::is_animated()
{
return false;
}
size_t BMPImageDecoderPlugin::loop_count()
{
return 0;
}
size_t BMPImageDecoderPlugin::frame_count()
{
return 1;
}
size_t BMPImageDecoderPlugin::first_animated_frame_index()
{
return 0;
}
ErrorOr<ImageFrameDescriptor> BMPImageDecoderPlugin::frame(size_t index, Optional<IntSize>)
{
if (index > 0)

View file

@ -30,10 +30,6 @@ public:
virtual IntSize size() override;
bool sniff_dib();
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
virtual size_t first_animated_frame_index() override;
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;

View file

@ -655,26 +655,6 @@ ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> DDSImageDecoderPlugin::create(Readonl
return plugin;
}
bool DDSImageDecoderPlugin::is_animated()
{
return false;
}
size_t DDSImageDecoderPlugin::loop_count()
{
return 0;
}
size_t DDSImageDecoderPlugin::frame_count()
{
return 1;
}
size_t DDSImageDecoderPlugin::first_animated_frame_index()
{
return 0;
}
ErrorOr<ImageFrameDescriptor> DDSImageDecoderPlugin::frame(size_t index, Optional<IntSize>)
{
if (index > 0)

View file

@ -243,10 +243,6 @@ public:
virtual IntSize size() override;
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
virtual size_t first_animated_frame_index() override;
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;

View file

@ -203,26 +203,6 @@ IntSize ICOImageDecoderPlugin::size()
return { m_context->images[m_context->largest_index].width, m_context->images[m_context->largest_index].height };
}
bool ICOImageDecoderPlugin::is_animated()
{
return false;
}
size_t ICOImageDecoderPlugin::loop_count()
{
return 0;
}
size_t ICOImageDecoderPlugin::frame_count()
{
return 1;
}
size_t ICOImageDecoderPlugin::first_animated_frame_index()
{
return 0;
}
ErrorOr<ImageFrameDescriptor> ICOImageDecoderPlugin::frame(size_t index, Optional<IntSize>)
{
if (index > 0)

View file

@ -21,10 +21,6 @@ public:
virtual IntSize size() override;
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
virtual size_t first_animated_frame_index() override;
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;

View file

@ -47,10 +47,12 @@ public:
// This should always be available as gathered in create()
virtual IntSize size() = 0;
virtual bool is_animated() = 0;
virtual size_t loop_count() = 0;
virtual size_t frame_count() = 0;
virtual size_t first_animated_frame_index() = 0;
// Override this if the format supports animated images
virtual bool is_animated() { return false; }
virtual size_t loop_count() { return 0; }
virtual size_t frame_count() { return 1; }
virtual size_t first_animated_frame_index() { return 0; }
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) = 0;
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() = 0;

View file

@ -1937,26 +1937,6 @@ ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> JPEGImageDecoderPlugin::create(Readon
return plugin;
}
bool JPEGImageDecoderPlugin::is_animated()
{
return false;
}
size_t JPEGImageDecoderPlugin::loop_count()
{
return 0;
}
size_t JPEGImageDecoderPlugin::frame_count()
{
return 1;
}
size_t JPEGImageDecoderPlugin::first_animated_frame_index()
{
return 0;
}
ErrorOr<ImageFrameDescriptor> JPEGImageDecoderPlugin::frame(size_t index, Optional<IntSize>)
{
if (index > 0)

View file

@ -24,10 +24,6 @@ public:
virtual ~JPEGImageDecoderPlugin() override;
virtual IntSize size() override;
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
virtual size_t first_animated_frame_index() override;
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;

View file

@ -60,10 +60,6 @@ public:
virtual IntSize size() override;
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
virtual size_t first_animated_frame_index() override;
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;
@ -110,30 +106,6 @@ bool PortableImageDecoderPlugin<TContext>::sniff(ReadonlyBytes data)
return false;
}
template<typename TContext>
bool PortableImageDecoderPlugin<TContext>::is_animated()
{
return false;
}
template<typename TContext>
size_t PortableImageDecoderPlugin<TContext>::loop_count()
{
return 0;
}
template<typename TContext>
size_t PortableImageDecoderPlugin<TContext>::frame_count()
{
return 1;
}
template<typename TContext>
size_t PortableImageDecoderPlugin<TContext>::first_animated_frame_index()
{
return 0;
}
template<typename TContext>
ErrorOr<ImageFrameDescriptor> PortableImageDecoderPlugin<TContext>::frame(size_t index, Optional<IntSize>)
{

View file

@ -45,10 +45,6 @@ public:
virtual IntSize size() override;
virtual bool is_animated() override { return false; }
virtual size_t loop_count() override { return 0; }
virtual size_t frame_count() override { return 1; }
virtual size_t first_animated_frame_index() override { return 0; }
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;

View file

@ -225,26 +225,6 @@ ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> TGAImageDecoderPlugin::create(Readonl
return plugin;
}
bool TGAImageDecoderPlugin::is_animated()
{
return false;
}
size_t TGAImageDecoderPlugin::loop_count()
{
return 0;
}
size_t TGAImageDecoderPlugin::frame_count()
{
return 1;
}
size_t TGAImageDecoderPlugin::first_animated_frame_index()
{
return 0;
}
ErrorOr<ImageFrameDescriptor> TGAImageDecoderPlugin::frame(size_t index, Optional<IntSize>)
{
auto bits_per_pixel = m_context->header.bits_per_pixel;

View file

@ -22,10 +22,6 @@ public:
virtual IntSize size() override;
virtual bool is_animated() override;
virtual size_t loop_count() override;
virtual size_t frame_count() override;
virtual size_t first_animated_frame_index() override;
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;

View file

@ -81,10 +81,6 @@ public:
static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes);
virtual IntSize size() override;
virtual bool is_animated() override { return false; }
virtual size_t loop_count() override { return 0; }
virtual size_t frame_count() override { return 1; }
virtual size_t first_animated_frame_index() override { return 0; }
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override { return OptionalNone {}; }