summaryrefslogtreecommitdiff
path: root/Libraries/LibGfx/ImageDecoder.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-13 15:28:04 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-13 15:29:29 +0200
commitdc0ed5c860c93f523297cf79ead1be350548c7de (patch)
tree64281f9eab24dc25796a5dbb292298890003575a /Libraries/LibGfx/ImageDecoder.cpp
parente46ee46ed69990e89871aece4800e8f1bcf7f645 (diff)
downloadserenity-dc0ed5c860c93f523297cf79ead1be350548c7de.zip
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. :^)
Diffstat (limited to 'Libraries/LibGfx/ImageDecoder.cpp')
-rw-r--r--Libraries/LibGfx/ImageDecoder.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/Libraries/LibGfx/ImageDecoder.cpp b/Libraries/LibGfx/ImageDecoder.cpp
index c079921996..558656cabb 100644
--- a/Libraries/LibGfx/ImageDecoder.cpp
+++ b/Libraries/LibGfx/ImageDecoder.cpp
@@ -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();
}