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 5b357a815b34487e70505e9b1a1b215fad6dcf9c
Author: Kim Woelders <k...@woelders.dk>
AuthorDate: Mon Mar 7 21:38:09 2022 +0100

    loading: New loader infrastructure
    
    Old loaders will no longer work.
    Should be no big deal to migrate though.
---
 src/lib/Imlib2_Loader.h           | 37 ++++++++++++---------
 src/lib/image.c                   | 24 ++++++--------
 src/lib/image.h                   |  8 ++---
 src/lib/loaders.c                 | 68 ++++++++++++++-------------------------
 src/lib/loaders.h                 | 23 +++++++------
 src/lib/types.h                   |  4 ---
 src/modules/loaders/loader_argb.c | 17 ++++------
 src/modules/loaders/loader_bmp.c  | 17 ++++------
 src/modules/loaders/loader_bz2.c  | 16 ++++-----
 src/modules/loaders/loader_ff.c   | 17 ++++------
 src/modules/loaders/loader_gif.c  | 13 +++-----
 src/modules/loaders/loader_heif.c | 16 ++++-----
 src/modules/loaders/loader_ico.c  | 13 +++-----
 src/modules/loaders/loader_id3.c  | 13 +++-----
 src/modules/loaders/loader_j2k.c  | 13 +++-----
 src/modules/loaders/loader_jpeg.c | 17 ++++------
 src/modules/loaders/loader_jxl.c  | 13 +++-----
 src/modules/loaders/loader_lbm.c  | 25 +++-----------
 src/modules/loaders/loader_lzma.c | 16 ++++-----
 src/modules/loaders/loader_png.c  | 17 ++++------
 src/modules/loaders/loader_pnm.c  | 18 ++++-------
 src/modules/loaders/loader_ps.c   | 13 +++-----
 src/modules/loaders/loader_svg.c  | 13 +++-----
 src/modules/loaders/loader_tga.c  | 17 ++++------
 src/modules/loaders/loader_tiff.c | 17 ++++------
 src/modules/loaders/loader_webp.c | 17 ++++------
 src/modules/loaders/loader_xbm.c  | 18 ++++-------
 src/modules/loaders/loader_xpm.c  | 13 +++-----
 src/modules/loaders/loader_zlib.c | 16 ++++-----
 29 files changed, 211 insertions(+), 318 deletions(-)

diff --git a/src/lib/Imlib2_Loader.h b/src/lib/Imlib2_Loader.h
index ad79c37..8808711 100644
--- a/src/lib/Imlib2_Loader.h
+++ b/src/lib/Imlib2_Loader.h
@@ -18,10 +18,6 @@ typedef struct _ImlibLoader ImlibLoader;
 
 typedef struct _ImlibImage ImlibImage;
 
-typedef int         (*ImlibProgressFunction)(ImlibImage * im, char percent,
-                                             int update_x, int update_y,
-                                             int update_w, int update_h);
-
 /* common.h */
 
 #undef __EXPORT__
@@ -156,10 +152,6 @@ struct _ImlibImage {
 #define FF_FRAME_DISPOSE_CLEAR  (1 << 2)        /* Clear before rendering next frame  */
 #define FF_FRAME_DISPOSE_PREV   (1 << 3)        /* Revert before rendering next frame */
 
-void                __imlib_LoaderSetFormats(ImlibLoader * l,
-                                             const char *const *fmt,
-                                             unsigned int num);
-
 ImlibLoader        *__imlib_FindBestLoader(const char *file, const char *format,
                                            int for_save);
 int                 __imlib_LoadEmbedded(ImlibLoader * l, ImlibImage * im,
@@ -186,14 +178,27 @@ int                 __imlib_LoadProgress(ImlibImage * im,
 int                 __imlib_LoadProgressRows(ImlibImage * im,
                                              int row, int nrows);
 
-/* Imlib2_Loader.h */
-
-__EXPORT__ char     load(ImlibImage * im, ImlibProgressFunction progress,
-                         char progress_granularity, char load_data);
-__EXPORT__ int      load2(ImlibImage * im, int load_data);
-__EXPORT__ char     save(ImlibImage * im, ImlibProgressFunction progress,
-                         char progress_granularity);
-__EXPORT__ void     formats(ImlibLoader * l);
+/* loader.h */
+
+#define IMLIB2_LOADER_VERSION 1
+
+typedef struct {
+   unsigned char       ldr_version;     /* Module ABI version */
+   unsigned char       rsvd;
+   unsigned short      num_formats;     /* Length og known extension list */
+   const char         *const *formats;  /* Known extension list */
+   int                 (*load)(ImlibImage * im, int load_data);
+   int                 (*save)(ImlibImage * im);
+} ImlibLoaderModule;
+
+#define IMLIB_LOADER(_fmts, _ldr, _svr) \
+    __EXPORT__ ImlibLoaderModule loader = { \
+        .ldr_version = IMLIB2_LOADER_VERSION, \
+        .num_formats = ARRAY_SIZE(_fmts), \
+        .formats = _fmts, \
+        .load = _ldr, \
+        .save = _svr, \
+    }
 
 typedef int         (imlib_decompress_load_f) (const void *fdata,
                                                unsigned int fsize, int dest);
diff --git a/src/lib/image.c b/src/lib/image.c
index fa50679..ac1222c 100644
--- a/src/lib/image.c
+++ b/src/lib/image.c
@@ -278,16 +278,13 @@ __imlib_LoadImageWrapper(const ImlibLoader * l, ImlibImage * im, int load_data)
    int                 rc;
 
    DP("%s: fmt='%s' file='%s'(%s), imm=%d\n", __func__,
-      l->formats[0], im->file, im->real_file, load_data);
+      l->name, im->file, im->real_file, load_data);
 
 #if IMLIB2_DEBUG
    unsigned int        t0 = __imlib_time_us();
 #endif
 
-   if (!im->format)
-      im->format = strdup(l->formats[0]);
-
-   if (l->load2)
+   if (l->module->load)
      {
         FILE               *fp = NULL;
 
@@ -297,25 +294,22 @@ __imlib_LoadImageWrapper(const ImlibLoader * l, ImlibImage * im, int load_data)
              if (!im->fp)
                 return 0;
           }
-        rc = l->load2(im, load_data);
+
+        if (!im->format)
+           im->format = strdup(l->name);
+
+        rc = l->module->load(im, load_data);
 
         if (fp)
            fclose(fp);
      }
-   else if (l->load)
-     {
-        if (im->lc)
-           rc = l->load(im, im->lc->progress, im->lc->granularity, 1);
-        else
-           rc = l->load(im, NULL, 0, load_data);
-     }
    else
      {
         return LOAD_FAIL;
      }
 
    DP("%s: %-4s: %s: Elapsed time: %.3f ms\n", __func__,
-      l->formats[0], im->file, 1e-3 * (__imlib_time_us() - t0));
+      l->name, im->file, 1e-3 * (__imlib_time_us() - t0));
 
    if (rc <= LOAD_FAIL)
      {
@@ -753,7 +747,7 @@ __imlib_SaveImage(ImlibImage * im, const char *file, ImlibLoadArgs * ila)
    im->real_file = strdup(file);
 
    /* call the saver */
-   loader_ret = l->save(im, ila->pfunc, ila->pgran);
+   loader_ret = l->module->save(im);
 
    /* set the filename back to the laoder image filename */
    free(im->real_file);
diff --git a/src/lib/image.h b/src/lib/image.h
index 2e24687..e3989a0 100644
--- a/src/lib/image.h
+++ b/src/lib/image.h
@@ -12,6 +12,10 @@ typedef struct _imlibldctx ImlibLdCtx;
 typedef void        (*ImlibDataDestructorFunction)(ImlibImage * im, void *data);
 typedef void       *(*ImlibImageDataMemoryFunction)(void *, size_t size);
 
+typedef int         (*ImlibProgressFunction)(ImlibImage * im, char percent,
+                                             int update_x, int update_y,
+                                             int update_w, int update_h);
+
 #define F_UNCACHEABLE           (1 << 1)
 #define F_ALWAYS_CHECK_DISK     (1 << 2)
 #define F_INVALID               (1 << 3)
@@ -87,10 +91,6 @@ typedef struct {
 ImlibLoader        *__imlib_FindBestLoader(const char *file, const char *format,
                                            int for_save);
 
-void                __imlib_LoaderSetFormats(ImlibLoader * l,
-                                             const char *const *fmt,
-                                             unsigned int num);
-
 ImlibImage         *__imlib_CreateImage(int w, int h, uint32_t * data);
 ImlibImage         *__imlib_LoadImage(const char *file, ImlibLoadArgs * ila);
 int                 __imlib_LoadEmbedded(ImlibLoader * l, ImlibImage * im,
diff --git a/src/lib/loaders.c b/src/lib/loaders.c
index 1e44d2e..e871883 100644
--- a/src/lib/loaders.c
+++ b/src/lib/loaders.c
@@ -152,41 +152,39 @@ static ImlibLoader *
 __imlib_ProduceLoader(const char *file)
 {
    ImlibLoader        *l;
-   void                (*l_formats)(ImlibLoader * l);
+   ImlibLoaderModule  *m;
 
    DP("%s: %s\n", __func__, file);
 
    l = malloc(sizeof(ImlibLoader));
-   l->num_formats = 0;
-   l->formats = NULL;
+
    l->handle = dlopen(file, RTLD_NOW | RTLD_LOCAL);
    if (!l->handle)
-     {
-        free(l);
-        return NULL;
-     }
-   l->load2 = dlsym(l->handle, "load2");
-   l->load = NULL;
-   if (!l->load2)
-      l->load = dlsym(l->handle, "load");
-   l->save = dlsym(l->handle, "save");
-   l_formats = dlsym(l->handle, "formats");
-
-   /* each loader must provide formats() and at least load() or save() */
-   if (!l_formats || !(l->load2 || l->load || l->save))
+      goto bail;
+
+   l->module = m = dlsym(l->handle, "loader");
+   if (!l->module)
+      goto bail;
+
+   /* Check version and that we have at least load() or save() */
+   if (m->ldr_version != IMLIB2_LOADER_VERSION ||
+       !m->formats || m->num_formats <= 0 || !(m->load || m->save))
      {
         dlclose(l->handle);
-        free(l);
-        return NULL;
+        goto bail;
      }
-   l_formats(l);
+
    l->file = strdup(file);
-   l->next = NULL;
+   l->name = m->formats[0];
 
    l->next = loaders;
    loaders = l;
 
    return l;
+
+ bail:
+   free(l);
+   return NULL;
 }
 
 /* fre the struct for a loader and close its dlopen'd handle */
@@ -196,14 +194,6 @@ __imlib_ConsumeLoader(ImlibLoader * l)
    free(l->file);
    if (l->handle)
       dlclose(l->handle);
-   if (l->formats)
-     {
-        int                 i;
-
-        for (i = 0; i < l->num_formats; i++)
-           free(l->formats[i]);
-        free(l->formats);
-     }
    free(l);
 }
 
@@ -295,13 +285,14 @@ __imlib_LookupKnownLoader(const char *format)
 static int
 _loader_ok_for(const ImlibLoader * l, int for_save)
 {
-   return (for_save && l->save) || (!for_save && (l->load2 || l->load));
+   return (for_save && l->module->save) || (!for_save && l->module->load);
 }
 
 static ImlibLoader *
 __imlib_LookupLoadedLoader(const char *format, int for_save)
 {
    ImlibLoader        *l;
+   ImlibLoaderModule  *m;
 
    DP("%s: fmt='%s'\n", __func__, format);
 
@@ -321,11 +312,13 @@ __imlib_LookupLoadedLoader(const char *format, int for_save)
      {
         int                 i;
 
+        m = l->module;
+
         /* go through all the formats that loader supports */
-        for (i = 0; i < l->num_formats; i++)
+        for (i = 0; i < m->num_formats; i++)
           {
              /* does it match ? */
-             if (strcasecmp(l->formats[i], format) == 0)
+             if (strcasecmp(m->formats[i], format) == 0)
                {
                   /* does it provide the function we need? */
                   if (_loader_ok_for(l, for_save))
@@ -372,16 +365,3 @@ __imlib_FindBestLoader(const char *file, const char *format, int for_save)
    DP("%s: fmt='%s': %s\n", __func__, format, l ? l->file : "-");
    return l;
 }
-
-__EXPORT__ void
-__imlib_LoaderSetFormats(ImlibLoader * l,
-                         const char *const *fmt, unsigned int num)
-{
-   unsigned int        i;
-
-   l->num_formats = num;
-   l->formats = malloc(sizeof(char *) * num);
-
-   for (i = 0; i < num; i++)
-      l->formats[i] = strdup(fmt[i]);
-}
diff --git a/src/lib/loaders.h b/src/lib/loaders.h
index faacf6c..f8c61ba 100644
--- a/src/lib/loaders.h
+++ b/src/lib/loaders.h
@@ -3,19 +3,24 @@
 
 #include "types.h"
 
+#define IMLIB2_LOADER_VERSION 1
+
+typedef struct {
+   unsigned char       ldr_version;     /* Module ABI version */
+   unsigned char       rsvd;
+   unsigned short      num_formats;     /* Length og known extension list */
+   const char         *const *formats;  /* Known extension list */
+   int                 (*load)(ImlibImage * im, int load_data);
+   int                 (*save)(ImlibImage * im);
+} ImlibLoaderModule;
+
 struct _ImlibLoader {
    char               *file;
-   int                 num_formats;
-   char              **formats;
    void               *handle;
-   char                (*load)(ImlibImage * im,
-                               ImlibProgressFunction progress,
-                               char progress_granularity, char load_data);
-   char                (*save)(ImlibImage * im,
-                               ImlibProgressFunction progress,
-                               char progress_granularity);
+   ImlibLoaderModule  *module;
    ImlibLoader        *next;
-   int                 (*load2)(ImlibImage * im, int load_data);
+
+   const char         *name;
 };
 
 void                __imlib_RemoveAllLoaders(void);
diff --git a/src/lib/types.h b/src/lib/types.h
index 30be920..c758ca1 100644
--- a/src/lib/types.h
+++ b/src/lib/types.h
@@ -8,10 +8,6 @@ typedef struct _ImlibLoader ImlibLoader;
 
 typedef struct _ImlibImage ImlibImage;
 
-typedef int         (*ImlibProgressFunction)(ImlibImage * im, char percent,
-                                             int update_x, int update_y,
-                                             int update_w, int update_h);
-
 typedef int         ImlibOp;
 
 typedef struct _ImlibColorModifier ImlibColorModifier;
diff --git a/src/modules/loaders/loader_argb.c b/src/modules/loaders/loader_argb.c
index 7e852f6..c66e923 100644
--- a/src/modules/loaders/loader_argb.c
+++ b/src/modules/loaders/loader_argb.c
@@ -1,6 +1,8 @@
 #include "config.h"
 #include "Imlib2_Loader.h"
 
+static const char  *const _formats[] = { "argb", "arg" };
+
 static struct {
    const unsigned char *data, *dptr;
    unsigned int        size;
@@ -31,8 +33,8 @@ mm_read(void *dst, unsigned int len)
    return 0;
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -110,8 +112,8 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-char
-save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
+static int
+_save(ImlibImage * im)
 {
    int                 rc;
    FILE               *f;
@@ -163,9 +165,4 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "argb", "arg" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, _save);
diff --git a/src/modules/loaders/loader_bmp.c b/src/modules/loaders/loader_bmp.c
index 4bfdde1..f651112 100644
--- a/src/modules/loaders/loader_bmp.c
+++ b/src/modules/loaders/loader_bmp.c
@@ -13,6 +13,8 @@
 #define DBG_PFX "LDR-bmp"
 #define Dx(fmt...)
 
+static const char  *const _formats[] = { "bmp" };
+
 static struct {
    const unsigned char *data, *dptr;
    unsigned int        size;
@@ -152,8 +154,8 @@ WriteleLong(FILE * file, unsigned long val)
    return 1;
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -762,8 +764,8 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-char
-save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
+static int
+_save(ImlibImage * im)
 {
    int                 rc;
    FILE               *f;
@@ -816,9 +818,4 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "bmp" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, _save);
diff --git a/src/modules/loaders/loader_bz2.c b/src/modules/loaders/loader_bz2.c
index 19b4309..d75cf90 100644
--- a/src/modules/loaders/loader_bz2.c
+++ b/src/modules/loaders/loader_bz2.c
@@ -6,6 +6,8 @@
 #define OUTBUF_SIZE 16384
 #define INBUF_SIZE 1024
 
+static const char  *const _formats[] = { "bz2" };
+
 static int
 uncompress_file(const void *fdata, unsigned int fsize, int dest)
 {
@@ -49,18 +51,12 @@ uncompress_file(const void *fdata, unsigned int fsize, int dest)
    return ok;
 }
 
-static const char  *const list_formats[] = { "bz2" };
-
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
 
-   return decompress_load(im, load_data, list_formats, ARRAY_SIZE(list_formats),
+   return decompress_load(im, load_data, _formats, ARRAY_SIZE(_formats),
                           uncompress_file);
 }
 
-void
-formats(ImlibLoader * l)
-{
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, NULL);
diff --git a/src/modules/loaders/loader_ff.c b/src/modules/loaders/loader_ff.c
index 7b266bc..4058886 100644
--- a/src/modules/loaders/loader_ff.c
+++ b/src/modules/loaders/loader_ff.c
@@ -4,6 +4,8 @@
 
 #include <arpa/inet.h>
 
+static const char  *const _formats[] = { "ff" };
+
 #define mm_check(p) ((const char *)(p) <= (const char *)fdata + im->fsize)
 
 typedef struct {
@@ -11,8 +13,8 @@ typedef struct {
    uint32_t            w, h;
 } ff_hdr_t;
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -85,8 +87,8 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-char
-save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
+static int
+_save(ImlibImage * im)
 {
    int                 rc;
    FILE               *f;
@@ -149,9 +151,4 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "ff" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, _save);
diff --git a/src/modules/loaders/loader_gif.c b/src/modules/loaders/loader_gif.c
index c69a263..0618fad 100644
--- a/src/modules/loaders/loader_gif.c
+++ b/src/modules/loaders/loader_gif.c
@@ -5,6 +5,8 @@
 
 #define DBG_PFX "LDR-gif"
 
+static const char  *const _formats[] = { "gif" };
+
 static struct {
    const unsigned char *data, *dptr;
    unsigned int        size;
@@ -51,8 +53,8 @@ make_colormap(uint32_t * cmi, ColorMapObject * cmg, int bg, int tr)
       cmi[tr] = bg >= 0 && bg < 256 ? cmi[bg] & 0x00ffffff : 0x00000000;
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc, err;
    void               *fdata;
@@ -304,9 +306,4 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "gif" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, NULL);
diff --git a/src/modules/loaders/loader_heif.c b/src/modules/loaders/loader_heif.c
index 221f558..a751d5d 100644
--- a/src/modules/loaders/loader_heif.c
+++ b/src/modules/loaders/loader_heif.c
@@ -9,12 +9,15 @@
 
 #include <libheif/heif.h>
 
+static const char  *const _formats[] =
+   { "heif", "heifs", "heic", "heics", "avci", "avcs", "avif", "avifs" };
+
 #define HEIF_BYTES_TO_CHECK 12L
 #define HEIF_8BIT_TO_PIXEL_ARGB(plane, has_alpha) \
    PIXEL_ARGB((has_alpha) ? (plane)[3] : 0xff, (plane)[0], (plane)[1], (plane)[2])
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -157,11 +160,4 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] =
-      { "heif", "heifs", "heic", "heics", "avci", "avcs", "avif", "avifs" };
-   __imlib_LoaderSetFormats(l, list_formats,
-                            sizeof(list_formats) / sizeof(char *));
-}
+IMLIB_LOADER(_formats, _load, NULL);
diff --git a/src/modules/loaders/loader_ico.c b/src/modules/loaders/loader_ico.c
index 7e9eff8..231d19f 100644
--- a/src/modules/loaders/loader_ico.c
+++ b/src/modules/loaders/loader_ico.c
@@ -12,6 +12,8 @@
 
 #define DBG_PFX "LDR-ico"
 
+static const char  *const _formats[] = { "ico" };
+
 static struct {
    const unsigned char *data, *dptr;
    unsigned int        size;
@@ -390,8 +392,8 @@ ico_load(ico_t * ico, ImlibImage * im, int load_data)
    return 1;
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -445,9 +447,4 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "ico" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, NULL);
diff --git a/src/modules/loaders/loader_id3.c b/src/modules/loaders/loader_id3.c
index c08e864..9c73caa 100644
--- a/src/modules/loaders/loader_id3.c
+++ b/src/modules/loaders/loader_id3.c
@@ -7,6 +7,8 @@
 
 #define USE_TAGS 0
 
+static const char  *const _formats[] = { "mp3" };
+
 typedef struct context {
    int                 id;
    char               *filename;
@@ -488,8 +490,8 @@ write_tags(ImlibImage * im, lopt * opt)
 }
 #endif
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    ImlibLoader        *loader;
@@ -597,9 +599,4 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "mp3" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, NULL);
diff --git a/src/modules/loaders/loader_j2k.c b/src/modules/loaders/loader_j2k.c
index eb709ce..16d98bb 100644
--- a/src/modules/loaders/loader_j2k.c
+++ b/src/modules/loaders/loader_j2k.c
@@ -10,6 +10,8 @@
 /* position 45: "\xff\x52" */
 #define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51"
 
+static const char  *const _formats[] = { "jp2", "j2k" };
+
 #if IMLIB2_DEBUG
 static void
 _j2k_cb(const char *type, const char *msg, void *data)
@@ -90,8 +92,8 @@ mm_seek_set(OPJ_OFF_T offs, void *data)
    return OPJ_TRUE;
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -278,9 +280,4 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "jp2", "j2k" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, NULL);
diff --git a/src/modules/loaders/loader_jpeg.c b/src/modules/loaders/loader_jpeg.c
index 63fb4ff..89751f6 100644
--- a/src/modules/loaders/loader_jpeg.c
+++ b/src/modules/loaders/loader_jpeg.c
@@ -7,6 +7,8 @@
 
 #define DBG_PFX "LDR-jpg"
 
+static const char  *const _formats[] = { "jpg", "jpeg", "jfif", "jfi" };
+
 typedef struct {
    struct jpeg_error_mgr jem;
    sigjmp_buf          setjmp_buffer;
@@ -62,8 +64,8 @@ _jdata_init(ImLib_JPEG_data * jd)
    return jem;
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 w, h, rc;
    void               *fdata;
@@ -254,8 +256,8 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-char
-save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
+static int
+_save(ImlibImage * im)
 {
    int                 rc;
    struct jpeg_compress_struct jcs;
@@ -362,9 +364,4 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "jpg", "jpeg", "jfif", "jfi" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, _save);
diff --git a/src/modules/loaders/loader_jxl.c b/src/modules/loaders/loader_jxl.c
index eb218e6..b3d4408 100644
--- a/src/modules/loaders/loader_jxl.c
+++ b/src/modules/loaders/loader_jxl.c
@@ -10,6 +10,8 @@
 
 #define DBG_PFX "LDR-jxl"
 
+static const char  *const _formats[] = { "jxl" };
+
 static void
 _scanline_cb(void *opaque, size_t x, size_t y,
              size_t num_pixels, const void *pixels)
@@ -31,8 +33,8 @@ _scanline_cb(void *opaque, size_t x, size_t y,
     * progress calbacks here. */
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    static const JxlPixelFormat pbuf_fmt = {
       .num_channels = 4,
@@ -216,9 +218,4 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "jxl" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, NULL);
diff --git a/src/modules/loaders/loader_lbm.c b/src/modules/loaders/loader_lbm.c
index b9393ed..ac78537 100644
--- a/src/modules/loaders/loader_lbm.c
+++ b/src/modules/loaders/loader_lbm.c
@@ -16,6 +16,8 @@
 
 #define DBG_PFX "LDR-lbm"
 
+static const char  *const _formats[] = { "iff", "ilbm", "lbm" };
+
 #define L2RLONG(a) ((((int)((a)[0]) & 0xff) << 24) + (((int)((a)[1]) & 0xff) << 16) + (((int)((a)[2]) & 0xff) << 8) + ((int)((a)[3]) & 0xff))
 #define L2RWORD(a) ((((int)((a)[0]) & 0xff) << 8) + ((int)((a)[1]) & 0xff))
 
@@ -437,8 +439,8 @@ deplane(uint32_t * row, int w, ILBM * ilbm, unsigned char *plane[])
  *
  * Imlib2 doesn't support reading comment chunks like ANNO.
  *------------------------------------------------------------------------------*/
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -571,21 +573,4 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-/*------------------------------------------------------------------------------
- * Perhaps save only in 32-bit format? The IFF ILBM format has pretty much gone
- * the way of the Amiga, who saves in this format any more?
- *------------------------------------------------------------------------------*/
-#if 0
-char
-save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
-{
-   return 0;
-}
-#endif
-
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "iff", "ilbm", "lbm" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, NULL);
diff --git a/src/modules/loaders/loader_lzma.c b/src/modules/loaders/loader_lzma.c
index a879507..277e5df 100644
--- a/src/modules/loaders/loader_lzma.c
+++ b/src/modules/loaders/loader_lzma.c
@@ -3,6 +3,8 @@
 
 #include <lzma.h>
 
+static const char  *const _formats[] = { "xz", "lzma" };
+
 #define OUTBUF_SIZE 16484
 
 static int
@@ -49,18 +51,12 @@ uncompress_file(const void *fdata, unsigned int fsize, int dest)
    return ok;
 }
 
-static const char  *const list_formats[] = { "xz", "lzma" };
-
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
 
-   return decompress_load(im, load_data, list_formats, ARRAY_SIZE(list_formats),
+   return decompress_load(im, load_data, _formats, ARRAY_SIZE(_formats),
                           uncompress_file);
 }
 
-void
-formats(ImlibLoader * l)
-{
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, NULL);
diff --git a/src/modules/loaders/loader_png.c b/src/modules/loaders/loader_png.c
index 32216bc..84cd7d4 100644
--- a/src/modules/loaders/loader_png.c
+++ b/src/modules/loaders/loader_png.c
@@ -6,6 +6,8 @@
 
 #define DBG_PFX "LDR-png"
 
+static const char  *const _formats[] = { "png" };
+
 #define USE_IMLIB2_COMMENT_TAG 0
 
 #define _PNG_MIN_SIZE	60      /* Min. PNG file size (8 + 3*12 + 13 (+3) */
@@ -284,8 +286,8 @@ row_callback(png_struct * png_ptr, png_byte * new_row,
      }
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -569,8 +571,8 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-char
-save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
+static int
+_save(ImlibImage * im)
 {
    int                 rc;
    FILE               *f;
@@ -733,9 +735,4 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "png" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, _save);
diff --git a/src/modules/loaders/loader_pnm.c b/src/modules/loaders/loader_pnm.c
index c48a25a..d6d297e 100644
--- a/src/modules/loaders/loader_pnm.c
+++ b/src/modules/loaders/loader_pnm.c
@@ -6,6 +6,8 @@
 
 #define DBG_PFX "LDR-pnm"
 
+static const char  *const _formats[] = { "pnm", "ppm", "pgm", "pbm", "pam" };
+
 static struct {
    const unsigned char *data, *dptr;
    unsigned int        size;
@@ -112,8 +114,8 @@ mm_getu(unsigned int *pui)
    return 0;                    /* Ok */
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -467,8 +469,8 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-char
-save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
+static int
+_save(ImlibImage * im)
 {
    int                 rc;
    FILE               *f;
@@ -550,10 +552,4 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
    goto quit;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] =
-      { "pnm", "ppm", "pgm", "pbm", "pam" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, _save);
diff --git a/src/modules/loaders/loader_ps.c b/src/modules/loaders/loader_ps.c
index 3001ce7..4e63ddf 100644
--- a/src/modules/loaders/loader_ps.c
+++ b/src/modules/loaders/loader_ps.c
@@ -5,8 +5,10 @@
 
 #define DBG_PFX "LDR-ps"
 
-int
-load2(ImlibImage * im, int load_data)
+static const char  *const _formats[] = { "ps", "eps" };
+
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -140,9 +142,4 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "ps", "eps" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, NULL);
diff --git a/src/modules/loaders/loader_svg.c b/src/modules/loaders/loader_svg.c
index ecc4792..c2cc802 100644
--- a/src/modules/loaders/loader_svg.c
+++ b/src/modules/loaders/loader_svg.c
@@ -10,6 +10,8 @@
 
 #define DBG_PFX "LDR-svg"
 
+static const char  *const _formats[] = { "svg" };
+
 #define DPI 96
 
 #define MATCHSTR(ptr, len, str) (len >= sizeof(str) && memcmp(ptr, str, sizeof(str) - 1) == 0)
@@ -66,8 +68,8 @@ _handle_error(GError * error)
    g_error_free(error);
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -244,9 +246,4 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "svg" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, NULL);
diff --git a/src/modules/loaders/loader_tga.c b/src/modules/loaders/loader_tga.c
index 1799e08..eaa9912 100644
--- a/src/modules/loaders/loader_tga.c
+++ b/src/modules/loaders/loader_tga.c
@@ -14,6 +14,8 @@
 
 #define DBG_PFX "LDR-tga"
 
+static const char  *const _formats[] = { "tga" };
+
 /* flip an inverted image - see RLE reading below */
 static void         tgaflip(uint32_t * in, int w, int h, int fliph, int flipv);
 
@@ -65,8 +67,8 @@ typedef struct {
  * There are several other (uncommon) Targa formats which this function can't currently handle
  */
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -498,8 +500,8 @@ tgaflip(uint32_t * in, int w, int h, int fliph, int flipv)
  * (If anyone wants to write a RLE saver, feel free =)
  */
 
-char
-save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
+static int
+_save(ImlibImage * im)
 {
    int                 rc;
    FILE               *f;
@@ -586,9 +588,4 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "tga" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, _save);
diff --git a/src/modules/loaders/loader_tiff.c b/src/modules/loaders/loader_tiff.c
index 014c4cf..2d2c000 100644
--- a/src/modules/loaders/loader_tiff.c
+++ b/src/modules/loaders/loader_tiff.c
@@ -6,6 +6,8 @@
 
 #define DBG_PFX "LDR-tiff"
 
+static const char  *const _formats[] = { "tiff", "tif" };
+
 #define DD(fmt...)  DC(0x80, fmt)
 
 static struct {
@@ -330,8 +332,8 @@ put_separate_and_raster(TIFFRGBAImage * img, uint32_t * rast,
    raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h);
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -455,8 +457,8 @@ load2(ImlibImage * im, int load_data)
 /* this seems to work, except the magic number isn't written. I'm guessing */
 /* this is a problem in libtiff */
 
-char
-save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
+static int
+_save(ImlibImage * im)
 {
    int                 rc;
    TIFF               *tif = NULL;
@@ -591,9 +593,4 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "tiff", "tif" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, _save);
diff --git a/src/modules/loaders/loader_webp.c b/src/modules/loaders/loader_webp.c
index 8911598..4b8a9bc 100644
--- a/src/modules/loaders/loader_webp.c
+++ b/src/modules/loaders/loader_webp.c
@@ -7,8 +7,10 @@
 
 #define DBG_PFX "LDR-webp"
 
-int
-load2(ImlibImage * im, int load_data)
+static const char  *const _formats[] = { "webp" };
+
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -104,8 +106,8 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-char
-save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
+static int
+_save(ImlibImage * im)
 {
    FILE               *f;
    int                 rc;
@@ -159,9 +161,4 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "webp" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, _save);
diff --git a/src/modules/loaders/loader_xbm.c b/src/modules/loaders/loader_xbm.c
index ea213a5..505e27f 100644
--- a/src/modules/loaders/loader_xbm.c
+++ b/src/modules/loaders/loader_xbm.c
@@ -7,6 +7,8 @@
 
 #define DBG_PFX "LDR-xbm"
 
+static const char  *const _formats[] = { "xbm" };
+
 static struct {
    const char         *data, *dptr;
    unsigned int        size;
@@ -79,8 +81,8 @@ _bitmap_dither(int x, int y, uint32_t pixel)
    return set;
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -214,8 +216,8 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-char
-save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
+static int
+_save(ImlibImage * im)
 {
    FILE               *f;
    int                 rc;
@@ -272,10 +274,4 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "xbm" };
-
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, _save);
diff --git a/src/modules/loaders/loader_xpm.c b/src/modules/loaders/loader_xpm.c
index 4deaca9..e8f138c 100644
--- a/src/modules/loaders/loader_xpm.c
+++ b/src/modules/loaders/loader_xpm.c
@@ -2,6 +2,8 @@
 #include "config.h"
 #include "Imlib2_Loader.h"
 
+static const char  *const _formats[] = { "xpm" };
+
 static struct {
    const char         *data, *dptr;
    unsigned int        size;
@@ -151,8 +153,8 @@ xpm_cmap_lookup(const cmap_t * cmap, int nc, int cpp, const char *s)
    return cmap[i1].pixel;
 }
 
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
    int                 rc;
    void               *fdata;
@@ -475,9 +477,4 @@ load2(ImlibImage * im, int load_data)
    return rc;
 }
 
-void
-formats(ImlibLoader * l)
-{
-   static const char  *const list_formats[] = { "xpm" };
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, NULL);
diff --git a/src/modules/loaders/loader_zlib.c b/src/modules/loaders/loader_zlib.c
index 244419d..3f7f520 100644
--- a/src/modules/loaders/loader_zlib.c
+++ b/src/modules/loaders/loader_zlib.c
@@ -3,6 +3,8 @@
 
 #include <zlib.h>
 
+static const char  *const _formats[] = { "gz" };
+
 #define OUTBUF_SIZE 16484
 
 static int
@@ -48,18 +50,12 @@ uncompress_file(const void *fdata, unsigned int fsize, int dest)
    return ok;
 }
 
-static const char  *const list_formats[] = { "gz" };
-
-int
-load2(ImlibImage * im, int load_data)
+static int
+_load(ImlibImage * im, int load_data)
 {
 
-   return decompress_load(im, load_data, list_formats, ARRAY_SIZE(list_formats),
+   return decompress_load(im, load_data, _formats, ARRAY_SIZE(_formats),
                           uncompress_file);
 }
 
-void
-formats(ImlibLoader * l)
-{
-   __imlib_LoaderSetFormats(l, list_formats, ARRAY_SIZE(list_formats));
-}
+IMLIB_LOADER(_formats, _load, NULL);

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

Reply via email to