LibGfx: Add support for animated images to ImageDecoder{Plugin}
Adds methods to determine whether an image is animated, how many times the animation loops, the number of frames, and to get individual frames. Implements stubs of these methods for PNGImageDecoderPlugin and GIFImageDecoderPlugin.
This commit is contained in:
parent
eec99b23a0
commit
d22bb92764
Notes:
sideshowbarker
2024-07-19 06:49:23 +09:00
Author: https://github.com/peterdn Commit: https://github.com/SerenityOS/serenity/commit/d22bb927645 Pull-request: https://github.com/SerenityOS/serenity/pull/2158 Reviewed-by: https://github.com/awesomekling
5 changed files with 71 additions and 2 deletions
Libraries/LibGfx
|
@ -528,4 +528,28 @@ bool GIFImageDecoderPlugin::sniff()
|
|||
BufferStream stream(buffer);
|
||||
return decode_gif_header(stream).has_value();
|
||||
}
|
||||
|
||||
bool GIFImageDecoderPlugin::is_animated()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t GIFImageDecoderPlugin::loop_count()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t GIFImageDecoderPlugin::frame_count()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
ImageFrameDescriptor GIFImageDecoderPlugin::frame(size_t i)
|
||||
{
|
||||
if (i > 0) {
|
||||
return { bitmap(), 0 };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,10 @@ public:
|
|||
virtual void set_volatile() override;
|
||||
[[nodiscard]] virtual bool set_nonvolatile() override;
|
||||
virtual bool sniff() override;
|
||||
virtual bool is_animated() override;
|
||||
virtual size_t loop_count() override;
|
||||
virtual size_t frame_count() override;
|
||||
virtual ImageFrameDescriptor frame(size_t i) override;
|
||||
|
||||
private:
|
||||
OwnPtr<GIFLoadingContext> m_context;
|
||||
|
|
|
@ -26,15 +26,20 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <LibGfx/Size.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
class Bitmap;
|
||||
|
||||
struct ImageFrameDescriptor {
|
||||
RefPtr<Bitmap> image;
|
||||
int duration { 0 };
|
||||
};
|
||||
|
||||
class ImageDecoderPlugin {
|
||||
public:
|
||||
virtual ~ImageDecoderPlugin() {}
|
||||
|
@ -47,6 +52,11 @@ public:
|
|||
|
||||
virtual bool sniff() = 0;
|
||||
|
||||
virtual bool is_animated() = 0;
|
||||
virtual size_t loop_count() = 0;
|
||||
virtual size_t frame_count() = 0;
|
||||
virtual ImageFrameDescriptor frame(size_t i) = 0;
|
||||
|
||||
protected:
|
||||
ImageDecoderPlugin() {}
|
||||
};
|
||||
|
@ -62,7 +72,11 @@ public:
|
|||
RefPtr<Gfx::Bitmap> bitmap() const;
|
||||
void set_volatile() { m_plugin->set_volatile(); }
|
||||
[[nodiscard]] bool set_nonvolatile() { return m_plugin->set_nonvolatile(); }
|
||||
bool sniff() { return m_plugin->sniff(); };
|
||||
bool sniff() const { return m_plugin->sniff(); }
|
||||
bool is_animated() const { return m_plugin->is_animated(); }
|
||||
size_t loop_count() const { return m_plugin->loop_count(); }
|
||||
size_t frame_count() const { return m_plugin->frame_count(); }
|
||||
ImageFrameDescriptor frame(size_t i) const { return m_plugin->frame(i); }
|
||||
|
||||
private:
|
||||
ImageDecoder(const u8*, size_t);
|
||||
|
|
|
@ -834,4 +834,27 @@ bool PNGImageDecoderPlugin::sniff()
|
|||
return decode_png_header(*m_context);
|
||||
}
|
||||
|
||||
bool PNGImageDecoderPlugin::is_animated()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t PNGImageDecoderPlugin::loop_count()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t PNGImageDecoderPlugin::frame_count()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
ImageFrameDescriptor PNGImageDecoderPlugin::frame(size_t i)
|
||||
{
|
||||
if (i > 0) {
|
||||
return { bitmap(), 0 };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,10 @@ public:
|
|||
virtual void set_volatile() override;
|
||||
[[nodiscard]] virtual bool set_nonvolatile() override;
|
||||
virtual bool sniff() override;
|
||||
virtual bool is_animated() override;
|
||||
virtual size_t loop_count() override;
|
||||
virtual size_t frame_count() override;
|
||||
virtual ImageFrameDescriptor frame(size_t i) override;
|
||||
|
||||
private:
|
||||
OwnPtr<PNGLoadingContext> m_context;
|
||||
|
|
Loading…
Add table
Reference in a new issue