diff --git a/Libraries/LibGfx/GIFLoader.cpp b/Libraries/LibGfx/GIFLoader.cpp index 6b5a0b5d66..a89f06ef90 100644 --- a/Libraries/LibGfx/GIFLoader.cpp +++ b/Libraries/LibGfx/GIFLoader.cpp @@ -447,6 +447,31 @@ bool load_gif_impl(GIFLoadingContext& context) return true; } +GIFImageDecoderPlugin::GIFImageDecoderPlugin(const u8* data, size_t size) +{ + m_context = make(); + m_context->data = data; + m_context->data_size = size; +} + +GIFImageDecoderPlugin::~GIFImageDecoderPlugin() {} + +Size GIFImageDecoderPlugin::size() +{ + if (m_context->state == GIFLoadingContext::State::Error) { + return {}; + } + + if (m_context->state < GIFLoadingContext::State::BitmapDecoded) { + if (!load_gif_impl(*m_context)) { + m_context->state = GIFLoadingContext::State::Error; + return {}; + } + } + + return { m_context->width, m_context->height }; +} + RefPtr GIFImageDecoderPlugin::bitmap() { if (m_context->state == GIFLoadingContext::State::Error) { @@ -467,4 +492,24 @@ RefPtr GIFImageDecoderPlugin::bitmap() return m_context->frames.first(); } +void GIFImageDecoderPlugin::set_volatile() +{ + for (auto& frame : m_context->frames) { + frame->set_volatile(); + } +} + +bool GIFImageDecoderPlugin::set_nonvolatile() +{ + if (m_context->frames.is_empty()) { + return false; + } + + bool success = true; + for (auto& frame : m_context->frames) { + success &= frame->set_nonvolatile(); + } + return success; +} + }