LibGfx: Don't keep an unused GIF decoder plugin in failed ImageDecoders

If we can't decode the input data, just have a null decoder. In this
state we simply return a null bitmap and whatever empty values make
sense for each API.

This way, we don't try to decode the same thing over and over since
it's not gonna work anyway. :^)
This commit is contained in:
Andreas Kling 2020-06-13 15:28:04 +02:00
commit dc0ed5c860
Notes: sideshowbarker 2024-07-19 05:40:18 +09:00
2 changed files with 20 additions and 12 deletions

View file

@ -33,14 +33,14 @@ namespace Gfx {
ImageDecoder::ImageDecoder(const u8* data, size_t size)
{
m_plugin = make<PNGImageDecoderPlugin>(data, size);
if (m_plugin->sniff()) {
if (m_plugin->sniff())
return;
}
m_plugin = make<GIFImageDecoderPlugin>(data, size);
if (m_plugin->sniff()) {
if (m_plugin->sniff())
return;
}
m_plugin = nullptr;
}
ImageDecoder::~ImageDecoder()
@ -49,6 +49,8 @@ ImageDecoder::~ImageDecoder()
RefPtr<Gfx::Bitmap> ImageDecoder::bitmap() const
{
if (!m_plugin)
return nullptr;
return m_plugin->bitmap();
}