summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Libraries/LibGfx/GIFLoader.cpp6
-rw-r--r--Libraries/LibGfx/GIFLoader.h1
-rw-r--r--Libraries/LibGfx/ImageDecoder.h3
-rw-r--r--Libraries/LibGfx/PNGLoader.cpp5
-rw-r--r--Libraries/LibGfx/PNGLoader.h1
5 files changed, 16 insertions, 0 deletions
diff --git a/Libraries/LibGfx/GIFLoader.cpp b/Libraries/LibGfx/GIFLoader.cpp
index c2a2890d87..eec95768cd 100644
--- a/Libraries/LibGfx/GIFLoader.cpp
+++ b/Libraries/LibGfx/GIFLoader.cpp
@@ -519,4 +519,10 @@ bool GIFImageDecoderPlugin::set_nonvolatile()
return success;
}
+bool GIFImageDecoderPlugin::sniff()
+{
+ auto buffer = ByteBuffer::wrap(m_context->data, m_context->data_size);
+ BufferStream stream(buffer);
+ return decode_gif_header(stream).has_value();
+}
}
diff --git a/Libraries/LibGfx/GIFLoader.h b/Libraries/LibGfx/GIFLoader.h
index 5f509402a3..b6599e4b7b 100644
--- a/Libraries/LibGfx/GIFLoader.h
+++ b/Libraries/LibGfx/GIFLoader.h
@@ -45,6 +45,7 @@ public:
virtual RefPtr<Gfx::Bitmap> bitmap() override;
virtual void set_volatile() override;
[[nodiscard]] virtual bool set_nonvolatile() override;
+ virtual bool sniff() override;
private:
OwnPtr<GIFLoadingContext> m_context;
diff --git a/Libraries/LibGfx/ImageDecoder.h b/Libraries/LibGfx/ImageDecoder.h
index 6feb4e693b..f300cb4871 100644
--- a/Libraries/LibGfx/ImageDecoder.h
+++ b/Libraries/LibGfx/ImageDecoder.h
@@ -45,6 +45,8 @@ public:
virtual void set_volatile() = 0;
[[nodiscard]] virtual bool set_nonvolatile() = 0;
+ virtual bool sniff() = 0;
+
protected:
ImageDecoderPlugin() {}
};
@@ -60,6 +62,7 @@ public:
RefPtr<Gfx::Bitmap> bitmap() const;
void set_volatile() { m_plugin->set_volatile(); }
[[nodiscard]] bool set_nonvolatile() { return m_plugin->set_nonvolatile(); }
+ bool sniff() { return m_plugin->sniff(); };
private:
ImageDecoder(const u8*, size_t);
diff --git a/Libraries/LibGfx/PNGLoader.cpp b/Libraries/LibGfx/PNGLoader.cpp
index 5389ae0b47..bd11ceafe6 100644
--- a/Libraries/LibGfx/PNGLoader.cpp
+++ b/Libraries/LibGfx/PNGLoader.cpp
@@ -725,4 +725,9 @@ bool PNGImageDecoderPlugin::set_nonvolatile()
return m_context->bitmap->set_nonvolatile();
}
+bool PNGImageDecoderPlugin::sniff()
+{
+ return decode_png_header(*m_context);
+}
+
}
diff --git a/Libraries/LibGfx/PNGLoader.h b/Libraries/LibGfx/PNGLoader.h
index ec2e1ec03c..7403cdeba5 100644
--- a/Libraries/LibGfx/PNGLoader.h
+++ b/Libraries/LibGfx/PNGLoader.h
@@ -45,6 +45,7 @@ public:
virtual RefPtr<Gfx::Bitmap> bitmap() override;
virtual void set_volatile() override;
[[nodiscard]] virtual bool set_nonvolatile() override;
+ virtual bool sniff() override;
private:
OwnPtr<PNGLoadingContext> m_context;