This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository legacy-imlib2.

View the commit online.

commit b35de1b23d0f163147572c944c4a59a4f23e9aaa
Author: Kim Woelders <k...@woelders.dk>
AuthorDate: Mon Feb 17 18:05:43 2025 +0100

    SVG loader: Handle .svgz too
---
 src/lib/loaders.c                |  2 +-
 src/modules/loaders/loader_svg.c | 18 ++++++++++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/lib/loaders.c b/src/lib/loaders.c
index 9a3559d..dbdb38a 100644
--- a/src/lib/loaders.c
+++ b/src/lib/loaders.c
@@ -60,7 +60,7 @@ static const char *const ext_raw[] = { "raw",
 };
 #endif
 #ifdef BUILD_SVG_LOADER
-static const char *const ext_svg[] = { "svg", NULL };
+static const char *const ext_svg[] = { "svg", "svgz", NULL };
 #endif
 static const char *const ext_tga[] = { "tga", NULL };
 #ifdef BUILD_TIFF_LOADER
diff --git a/src/modules/loaders/loader_svg.c b/src/modules/loaders/loader_svg.c
index 2395b92..c66eb75 100644
--- a/src/modules/loaders/loader_svg.c
+++ b/src/modules/loaders/loader_svg.c
@@ -10,7 +10,7 @@
 
 #define DBG_PFX "LDR-svg"
 
-static const char *const _formats[] = { "svg" };
+static const char *const _formats[] = { "svg", "svgz" };
 
 #define DPI 96
 
@@ -18,9 +18,19 @@ static const char *const _formats[] = { "svg" };
 #define FINDSTR(ptr, len, str) (memmem(ptr, len, str, sizeof(str) - 1) != 0)
 
 static int
-_sig_check(const unsigned char *buf, unsigned int len)
+_sig_check(const char *name, const unsigned char *buf, unsigned int len)
 {
-    /* May also be compressed? - forget for now */
+    const char     *s;
+
+    if (len < 32)
+        return 1;               /* Not likely */
+
+    if (buf[0] == 0x1f && buf[1] == 0x8b)
+    {
+        /* Assume gzip compressed data */
+        s = strrchr(name, '.');
+        return !(s && strcmp(s, ".svgz") == 0);
+    }
 
     if (len > 4096)
         len = 4096;
@@ -85,7 +95,7 @@ _load(ImlibImage *im, int load_data)
     cr = NULL;
 
     /* Signature check */
-    if (_sig_check(im->fi->fdata, im->fi->fsize))
+    if (_sig_check(im->fi->name, im->fi->fdata, im->fi->fsize))
         goto quit;
 
     rsvg = rsvg_handle_new_from_data(im->fi->fdata, im->fi->fsize, &error);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to