LibGfx: implement remaining GIFImageDecoderPlugin methods

This commit is contained in:
Peter Nelson 2020-04-25 13:29:12 +01:00 committed by Andreas Kling
parent e06518211b
commit d5af7b220c
Notes: sideshowbarker 2024-07-19 07:18:47 +09:00

View file

@ -447,6 +447,31 @@ bool load_gif_impl(GIFLoadingContext& context)
return true;
}
GIFImageDecoderPlugin::GIFImageDecoderPlugin(const u8* data, size_t size)
{
m_context = make<GIFLoadingContext>();
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<Gfx::Bitmap> GIFImageDecoderPlugin::bitmap()
{
if (m_context->state == GIFLoadingContext::State::Error) {
@ -467,4 +492,24 @@ RefPtr<Gfx::Bitmap> 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;
}
}