[vlc-devel] [PATCH 07/10] demux/image.c: Detect SVG Scalable Vector Graphics Images

jpsaman at videolan.org jpsaman at videolan.org
Mon May 12 12:04:27 CEST 2014


From: Jean-Paul Saman <jpsaman at videolan.org>

---
 modules/demux/image.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/modules/demux/image.c b/modules/demux/image.c
index 672e7ba..5b56913 100644
--- a/modules/demux/image.c
+++ b/modules/demux/image.c
@@ -423,6 +423,53 @@ static bool IsExif(stream_t *s)
     return true;
 }
 
+static bool FindSVGmarker(int *position, const uint8_t *data, const int size, const char *marker)
+{
+    for( int i = *position; i < size; i++)
+    {
+        if (memcmp(&data[i], marker, strlen(marker)) == 0)
+        {
+            *position = i;
+            return true;
+        }
+    }
+    return false;
+}
+
+static bool IsSVG(stream_t *s)
+{
+    char *ext = strstr(s->psz_path, ".svg");
+    if (!ext) return false;
+
+    const uint8_t *header;
+    int size = stream_Peek(s, &header, 4096);
+    int position = 0;
+
+    const char xml[] = "<?xml version=\"";
+    if (!FindSVGmarker(&position, header, size, xml))
+        return false;
+    if (position != 0)
+        return false;
+
+    const char endxml[] = ">\0";
+    if (!FindSVGmarker(&position, header, size, endxml))
+        return false;
+    if (position <= 15)
+        return false;
+
+    const char svg[] = "<svg";
+    if (!FindSVGmarker(&position, header, size, svg))
+        return false;
+    if (position < 19)
+        return false;
+
+    /* SVG Scalable Vector Graphics image */
+
+    /* NOTE: some SVG images have the mimetype set in a meta data section
+     * and some do not */
+    return true;
+}
+
 static bool IsTarga(stream_t *s)
 {
     /* The header is not enough to ensure proper detection, we need
@@ -538,6 +585,9 @@ static const image_format_t formats[] = {
     { .codec = VLC_CODEC_JPEG,
       .detect = IsExif,
     },
+    { .codec = VLC_CODEC_SVG,
+      .detect = IsSVG,
+    },
     { .codec = VLC_CODEC_TARGA,
       .detect = IsTarga,
     },
-- 
1.9.0




More information about the vlc-devel mailing list