From d22bb9276454937aa19a9bc867839e02434b0c30 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 3 May 2020 17:12:54 +0100 Subject: 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. --- Libraries/LibGfx/ImageDecoder.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'Libraries/LibGfx/ImageDecoder.h') diff --git a/Libraries/LibGfx/ImageDecoder.h b/Libraries/LibGfx/ImageDecoder.h index f300cb4871..bcc08c675c 100644 --- a/Libraries/LibGfx/ImageDecoder.h +++ b/Libraries/LibGfx/ImageDecoder.h @@ -26,15 +26,20 @@ #pragma once -#include #include #include +#include #include namespace Gfx { class Bitmap; +struct ImageFrameDescriptor { + RefPtr 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 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); -- cgit v1.2.3