clang-tidy: readability-suspicious-call-argument
[geeqie.git] / src / image-load.cc
index 247ffc5..da06b41 100644 (file)
 
 #include "main.h"
 #include "image-load.h"
-#include "image-load-cr3.h"
-#include "image-load-gdk.h"
-#include "image-load-jpeg.h"
-#include "image-load-tiff.h"
+
+#include "exif.h"
+#include "filedata.h"
+#include "gq-marshal.h"
+#include "image-load-collection.h"
 #include "image-load-dds.h"
-#include "image-load-djvu.h"
 #include "image-load-external.h"
-#include "image-load-pdf.h"
-#include "image-load-psd.h"
-#include "image-load-heif.h"
-#include "image-load-ffmpegthumbnailer.h"
-#include "image-load-collection.h"
-#include "image-load-zxscr.h"
-#include "image-load-j2k.h"
-#include "image-load-jpegxl.h"
+#include "image-load-gdk.h"
 #include "image-load-libraw.h"
+#include "image-load-psd.h"
 #include "image-load-svgz.h"
+#include "image-load-webp.h"
+#include "image-load-zxscr.h"
 #include "misc.h"
-
-#include "exif.h"
-#include "filedata.h"
 #include "ui-fileops.h"
-#include "gq-marshal.h"
+
+#ifdef HAVE_DJVU
+       #include "image-load-djvu.h"
+#endif
+#ifdef HAVE_FFMPEGTHUMBNAILER
+       #include "image-load-ffmpegthumbnailer.h"
+#endif
+#ifdef HAVE_HEIF
+       #include "image-load-heif.h"
+#endif
+#ifdef HAVE_J2K
+       #include "image-load-j2k.h"
+#endif
+#ifdef HAVE_JPEG
+       #include "image-load-cr3.h"
+       #include "image-load-jpeg.h"
+#endif
+#ifdef HAVE_JPEGXL
+       #include "image-load-jpegxl.h"
+#endif
+#ifdef HAVE_PDF
+       #include "image-load-pdf.h"
+#endif
+#ifdef HAVE_TIFF
+       #include "image-load-tiff.h"
+#endif
 
 #include <fcntl.h>
 #include <sys/mman.h>
@@ -71,37 +89,37 @@ static void image_loader_class_init(ImageLoaderClass *loader_class);
 static void image_loader_finalize(GObject *object);
 static void image_loader_stop(ImageLoader *il);
 
-GType image_loader_get_type(void)
+GType image_loader_get_type()
 {
        static GType type = 0;
        if (type == 0)
                {
                static const GTypeInfo info = {
                        sizeof(ImageLoaderClass),
-                       NULL,   /* base_init */
-                       NULL,   /* base_finalize */
-                       (GClassInitFunc)image_loader_class_init_wrapper, /* class_init */
-                       NULL,   /* class_finalize */
-                       NULL,   /* class_data */
+                       nullptr,   /* base_init */
+                       nullptr,   /* base_finalize */
+                       static_cast<GClassInitFunc>(image_loader_class_init_wrapper), /* class_init */
+                       nullptr,   /* class_finalize */
+                       nullptr,   /* class_data */
                        sizeof(ImageLoader),
                        0,      /* n_preallocs */
-                       (GInstanceInitFunc)image_loader_init, /* instance_init */
-                       NULL    /* value_table */
+                       static_cast<GInstanceInitFunc>(image_loader_init), /* instance_init */
+                       nullptr /* value_table */
                        };
-               type = g_type_register_static(G_TYPE_OBJECT, "ImageLoaderType", &info, 0);
+               type = g_type_register_static(G_TYPE_OBJECT, "ImageLoaderType", &info, static_cast<GTypeFlags>(0));
                }
        return type;
 }
 
-static void image_loader_init(GTypeInstance *instance, gpointer UNUSED(g_class))
+static void image_loader_init(GTypeInstance *instance, gpointer)
 {
-       ImageLoader *il = (ImageLoader *)instance;
+       auto il = reinterpret_cast<ImageLoader *>(instance);
 
-       il->pixbuf = NULL;
+       il->pixbuf = nullptr;
        il->idle_id = 0;
        il->idle_priority = G_PRIORITY_DEFAULT_IDLE;
        il->done = FALSE;
-       il->loader = NULL;
+       il->loader = nullptr;
 
        il->bytes_read = 0;
        il->bytes_total = 0;
@@ -110,7 +128,7 @@ static void image_loader_init(GTypeInstance *instance, gpointer UNUSED(g_class))
 
        il->idle_read_loop_count = IMAGE_LOADER_IDLE_READ_LOOP_COUNT_DEFAULT;
        il->read_buffer_size = IMAGE_LOADER_READ_BUFFER_SIZE_DEFAULT;
-       il->mapped_file = NULL;
+       il->mapped_file = nullptr;
        il->preview = IMAGE_LOADER_PREVIEW_NONE;
 
        il->requested_width = 0;
@@ -129,18 +147,15 @@ static void image_loader_init(GTypeInstance *instance, gpointer UNUSED(g_class))
        DEBUG_1("new image loader %p, bufsize=%" G_GSIZE_FORMAT " idle_loop=%u", (void *)il, il->read_buffer_size, il->idle_read_loop_count);
 }
 
-static void image_loader_class_init_wrapper(void *data, void *UNUSED(user_data))
+static void image_loader_class_init_wrapper(void *data, void *)
 {
-       image_loader_class_init(data);
+       image_loader_class_init(static_cast<ImageLoaderClass *>(data));
 }
 
 static void image_loader_class_init(ImageLoaderClass *loader_class)
 {
        GObjectClass *gobject_class = G_OBJECT_CLASS (loader_class);
 
-//     gobject_class->set_property = image_loader_set_property;
-//     gobject_class->get_property = image_loader_get_property;
-
        gobject_class->finalize = image_loader_finalize;
 
 
@@ -149,7 +164,7 @@ static void image_loader_class_init(ImageLoaderClass *loader_class)
                             G_OBJECT_CLASS_TYPE(gobject_class),
                             G_SIGNAL_RUN_LAST,
                             G_STRUCT_OFFSET(ImageLoaderClass, area_ready),
-                            NULL, NULL,
+                            nullptr, nullptr,
                             gq_marshal_VOID__INT_INT_INT_INT,
                             G_TYPE_NONE, 4,
                             G_TYPE_INT,
@@ -162,7 +177,7 @@ static void image_loader_class_init(ImageLoaderClass *loader_class)
                             G_OBJECT_CLASS_TYPE(gobject_class),
                             G_SIGNAL_RUN_LAST,
                             G_STRUCT_OFFSET(ImageLoaderClass, error),
-                            NULL, NULL,
+                            nullptr, nullptr,
                             g_cclosure_marshal_VOID__VOID,
                             G_TYPE_NONE, 0);
 
@@ -171,7 +186,7 @@ static void image_loader_class_init(ImageLoaderClass *loader_class)
                             G_OBJECT_CLASS_TYPE(gobject_class),
                             G_SIGNAL_RUN_LAST,
                             G_STRUCT_OFFSET(ImageLoaderClass, done),
-                            NULL, NULL,
+                            nullptr, nullptr,
                             g_cclosure_marshal_VOID__VOID,
                             G_TYPE_NONE, 0);
 
@@ -180,7 +195,7 @@ static void image_loader_class_init(ImageLoaderClass *loader_class)
                             G_OBJECT_CLASS_TYPE(gobject_class),
                             G_SIGNAL_RUN_LAST,
                             G_STRUCT_OFFSET(ImageLoaderClass, percent),
-                            NULL, NULL,
+                            nullptr, nullptr,
                             g_cclosure_marshal_VOID__DOUBLE,
                             G_TYPE_NONE, 1,
                             G_TYPE_DOUBLE);
@@ -190,7 +205,7 @@ static void image_loader_class_init(ImageLoaderClass *loader_class)
                             G_OBJECT_CLASS_TYPE(gobject_class),
                             G_SIGNAL_RUN_LAST,
                             G_STRUCT_OFFSET(ImageLoaderClass, area_ready),
-                            NULL, NULL,
+                            nullptr, nullptr,
                             gq_marshal_VOID__INT_INT,
                             G_TYPE_NONE, 2,
                             G_TYPE_INT,
@@ -200,7 +215,7 @@ static void image_loader_class_init(ImageLoaderClass *loader_class)
 
 static void image_loader_finalize(GObject *object)
 {
-       ImageLoader *il = (ImageLoader *)object;
+       auto il = reinterpret_cast<ImageLoader *>(object);
 
        image_loader_stop(il);
 
@@ -256,9 +271,9 @@ ImageLoader *image_loader_new(FileData *fd)
 {
        ImageLoader *il;
 
-       if (!fd) return NULL;
+       if (!fd) return nullptr;
 
-       il = (ImageLoader *) g_object_new(TYPE_IMAGE_LOADER, NULL);
+       il = static_cast<ImageLoader *>(g_object_new(TYPE_IMAGE_LOADER, nullptr));
 
        il->fd = file_data_ref(fd);
 
@@ -268,8 +283,7 @@ ImageLoader *image_loader_new(FileData *fd)
 /**************************************************************************************/
 /* send signals via idle calbacks - the callback are executed in the main thread */
 
-typedef struct _ImageLoaderAreaParam ImageLoaderAreaParam;
-struct _ImageLoaderAreaParam {
+struct ImageLoaderAreaParam {
        ImageLoader *il;
        guint x;
        guint y;
@@ -280,7 +294,7 @@ struct _ImageLoaderAreaParam {
 
 static gboolean image_loader_emit_area_ready_cb(gpointer data)
 {
-       ImageLoaderAreaParam *par = data;
+       auto par = static_cast<ImageLoaderAreaParam *>(data);
        ImageLoader *il = par->il;
        guint x, y, w, h;
        g_mutex_lock(il->data_mutex);
@@ -294,40 +308,40 @@ static gboolean image_loader_emit_area_ready_cb(gpointer data)
 
        g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, x, y, w, h);
 
-       return FALSE;
+       return G_SOURCE_REMOVE;
 }
 
 static gboolean image_loader_emit_done_cb(gpointer data)
 {
-       ImageLoader *il = data;
+       auto il = static_cast<ImageLoader *>(data);
        g_signal_emit(il, signals[SIGNAL_DONE], 0);
-       return FALSE;
+       return G_SOURCE_REMOVE;
 }
 
 static gboolean image_loader_emit_error_cb(gpointer data)
 {
-       ImageLoader *il = data;
+       auto il = static_cast<ImageLoader *>(data);
        g_signal_emit(il, signals[SIGNAL_ERROR], 0);
-       return FALSE;
+       return G_SOURCE_REMOVE;
 }
 
 static gboolean image_loader_emit_percent_cb(gpointer data)
 {
-       ImageLoader *il = data;
+       auto il = static_cast<ImageLoader *>(data);
        g_signal_emit(il, signals[SIGNAL_PERCENT], 0, image_loader_get_percent(il));
-       return FALSE;
+       return G_SOURCE_REMOVE;
 }
 
 static gboolean image_loader_emit_size_cb(gpointer data)
 {
        gint width, height;
-       ImageLoader *il = data;
+       auto il = static_cast<ImageLoader *>(data);
        g_mutex_lock(il->data_mutex);
        width = il->actual_width;
        height = il->actual_height;
        g_mutex_unlock(il->data_mutex);
        g_signal_emit(il, signals[SIGNAL_SIZE], 0, width, height);
-       return FALSE;
+       return G_SOURCE_REMOVE;
 }
 
 
@@ -337,35 +351,35 @@ static gboolean image_loader_emit_size_cb(gpointer data)
 
 static void image_loader_emit_done(ImageLoader *il)
 {
-       g_idle_add_full(il->idle_priority, image_loader_emit_done_cb, il, NULL);
+       g_idle_add_full(il->idle_priority, image_loader_emit_done_cb, il, nullptr);
 }
 
 static void image_loader_emit_error(ImageLoader *il)
 {
-       g_idle_add_full(il->idle_priority, image_loader_emit_error_cb, il, NULL);
+       g_idle_add_full(il->idle_priority, image_loader_emit_error_cb, il, nullptr);
 }
 
 static void image_loader_emit_percent(ImageLoader *il)
 {
-       g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_percent_cb, il, NULL);
+       g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_percent_cb, il, nullptr);
 }
 
 static void image_loader_emit_size(ImageLoader *il)
 {
-       g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_size_cb, il, NULL);
+       g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_size_cb, il, nullptr);
 }
 
 static ImageLoaderAreaParam *image_loader_queue_area_ready(ImageLoader *il, GList **list, guint x, guint y, guint w, guint h)
 {
        if (*list)
                {
-               ImageLoaderAreaParam *prev_par = (*list)->data;
+               auto prev_par = static_cast<ImageLoaderAreaParam *>((*list)->data);
                if (prev_par->x == x && prev_par->w == w &&
                    prev_par->y + prev_par->h == y)
                        {
                        /* we can merge the notifications */
                        prev_par->h += h;
-                       return NULL;
+                       return nullptr;
                        }
                if (prev_par->x == x && prev_par->w == w &&
                    y + h == prev_par->y)
@@ -373,14 +387,14 @@ static ImageLoaderAreaParam *image_loader_queue_area_ready(ImageLoader *il, GLis
                        /* we can merge the notifications */
                        prev_par->h += h;
                        prev_par->y = y;
-                       return NULL;
+                       return nullptr;
                        }
                if (prev_par->y == y && prev_par->h == h &&
                    prev_par->x + prev_par->w == x)
                        {
                        /* we can merge the notifications */
                        prev_par->w += w;
-                       return NULL;
+                       return nullptr;
                        }
                if (prev_par->y == y && prev_par->h == h &&
                    x + w == prev_par->x)
@@ -388,11 +402,11 @@ static ImageLoaderAreaParam *image_loader_queue_area_ready(ImageLoader *il, GLis
                        /* we can merge the notifications */
                        prev_par->w += w;
                        prev_par->x = x;
-                       return NULL;
+                       return nullptr;
                        }
                }
 
-       ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1);
+       auto par = g_new0(ImageLoaderAreaParam, 1);
        par->il = il;
        par->x = x;
        par->y = y;
@@ -410,7 +424,7 @@ static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guin
 
        if (par)
                {
-               g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL);
+               g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, nullptr);
                }
 }
 
@@ -471,11 +485,11 @@ static void image_loader_sync_pixbuf(ImageLoader *il)
        g_mutex_unlock(il->data_mutex);
 }
 
-static void image_loader_area_updated_cb(gpointer UNUSED(loader),
+static void image_loader_area_updated_cb(gpointer,
                                 guint x, guint y, guint w, guint h,
                                 gpointer data)
 {
-       ImageLoader *il = data;
+       auto il = static_cast<ImageLoader *>(data);
 
        if (!image_loader_get_pixbuf(il))
                {
@@ -499,7 +513,7 @@ static void image_loader_area_updated_cb(gpointer UNUSED(loader),
 
 static void image_loader_area_prepared_cb(gpointer loader, gpointer data)
 {
-       ImageLoader *il = data;
+       auto il = static_cast<ImageLoader *>(data);
        GdkPixbuf *pb;
        guchar *pix;
        size_t h, rs;
@@ -531,7 +545,7 @@ static void image_loader_area_prepared_cb(gpointer loader, gpointer data)
 static void image_loader_size_cb(gpointer loader,
                                 gint width, gint height, gpointer data)
 {
-       ImageLoader *il = data;
+       auto il = static_cast<ImageLoader *>(data);
        gchar **mime_types;
        gboolean scale = FALSE;
        gint n;
@@ -572,16 +586,16 @@ static void image_loader_size_cb(gpointer loader,
        if (width > il->requested_width || height > il->requested_height)
                {
 
-               if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height))
+               if ((static_cast<gdouble>(il->requested_width) / width) < (static_cast<gdouble>(il->requested_height) / height))
                        {
                        nw = il->requested_width;
-                       nh = (gdouble)nw / width * height;
+                       nh = static_cast<gdouble>(nw) / width * height;
                        if (nh < 1) nh = 1;
                        }
                else
                        {
                        nh = il->requested_height;
-                       nw = (gdouble)nh / height * width;
+                       nw = static_cast<gdouble>(nh) / height * width;
                        if (nw < 1) nw = 1;
                        }
 
@@ -602,10 +616,10 @@ static void image_loader_stop_loader(ImageLoader *il)
        if (il->loader)
                {
                /* some loaders do not have a pixbuf till close, order is important here */
-               il->backend.close(il->loader, il->error ? NULL : &il->error); /* we are interested in the first error only */
+               il->backend.close(il->loader, il->error ? nullptr : &il->error); /* we are interested in the first error only */
                image_loader_sync_pixbuf(il);
                il->backend.free(il->loader);
-               il->loader = NULL;
+               il->loader = nullptr;
                }
        g_mutex_lock(il->data_mutex);
        il->done = TRUE;
@@ -642,136 +656,148 @@ static void image_loader_setup_loader(ImageLoader *il)
                image_loader_backend_set_external(&il->backend);
                }
        else
-
-#ifdef HAVE_FFMPEGTHUMBNAILER
-       if (il->fd->format_class == FORMAT_CLASS_VIDEO)
                {
-               DEBUG_1("Using custom ffmpegthumbnailer loader");
-               image_loader_backend_set_ft(&il->backend);
-               }
-       else
+#ifdef HAVE_FFMPEGTHUMBNAILER
+               if (il->fd->format_class == FORMAT_CLASS_VIDEO)
+                       {
+                       DEBUG_1("Using custom ffmpegthumbnailer loader");
+                       image_loader_backend_set_ft(&il->backend);
+                       }
+               else
 #endif
 #ifdef HAVE_PDF
-       if (il->bytes_total >= 4 &&
-           (memcmp(il->mapped_file + 0, "%PDF", 4) == 0))
-               {
-               DEBUG_1("Using custom pdf loader");
-               image_loader_backend_set_pdf(&il->backend);
-               }
-       else
+               if (il->bytes_total >= 4 &&
+                   (memcmp(il->mapped_file + 0, "%PDF", 4) == 0))
+                       {
+                       DEBUG_1("Using custom pdf loader");
+                       image_loader_backend_set_pdf(&il->backend);
+                       }
+               else
 #endif
 #ifdef HAVE_HEIF
-       if (il->bytes_total >= 12 &&
-               ((memcmp(il->mapped_file + 4, "ftypheic", 8) == 0) ||
-               (memcmp(il->mapped_file + 4, "ftypmsf1", 8) == 0) ||
-               (memcmp(il->mapped_file + 4, "ftypmif1", 8) == 0) ||
-               (memcmp(il->mapped_file + 4, "ftypavif", 8) == 0)))
-               {
-               DEBUG_1("Using custom heif loader");
-               image_loader_backend_set_heif(&il->backend);
-               }
-       else
+               if (il->bytes_total >= 12 &&
+                       ((memcmp(il->mapped_file + 4, "ftypheic", 8) == 0) ||
+                       (memcmp(il->mapped_file + 4, "ftypheix", 8) == 0) ||
+                       (memcmp(il->mapped_file + 4, "ftypmsf1", 8) == 0) ||
+                       (memcmp(il->mapped_file + 4, "ftypmif1", 8) == 0) ||
+                       (memcmp(il->mapped_file + 4, "ftypavif", 8) == 0)))
+                       {
+                       DEBUG_1("Using custom heif loader");
+                       image_loader_backend_set_heif(&il->backend);
+                       }
+               else
+       #endif
+       #ifdef HAVE_WEBP
+               if (il->bytes_total >= 12 &&
+                       (memcmp(il->mapped_file, "RIFF", 4) == 0) &&
+                       (memcmp(il->mapped_file + 8, "WEBP", 4) == 0))
+                       {
+                       DEBUG_1("Using custom webp loader");
+                       image_loader_backend_set_webp(&il->backend);
+                       }
+               else
 #endif
 #ifdef HAVE_DJVU
-       if (il->bytes_total >= 16 &&
-               (memcmp(il->mapped_file, "AT&TFORM", 8) == 0) &&
-               (memcmp(il->mapped_file + 12, "DJV", 3) == 0))
-               {
-               DEBUG_1("Using custom djvu loader");
-               image_loader_backend_set_djvu(&il->backend);
-               }
-       else
+               if (il->bytes_total >= 16 &&
+                       (memcmp(il->mapped_file, "AT&TFORM", 8) == 0) &&
+                       (memcmp(il->mapped_file + 12, "DJV", 3) == 0))
+                       {
+                       DEBUG_1("Using custom djvu loader");
+                       image_loader_backend_set_djvu(&il->backend);
+                       }
+               else
 #endif
 #ifdef HAVE_JPEG
-       if (il->bytes_total >= 2 && il->mapped_file[0] == 0xff && il->mapped_file[1] == 0xd8)
-               {
-               DEBUG_1("Using custom jpeg loader");
-               image_loader_backend_set_jpeg(&il->backend);
-               }
+               if (il->bytes_total >= 2 && il->mapped_file[0] == 0xff && il->mapped_file[1] == 0xd8)
+                       {
+                       DEBUG_1("Using custom jpeg loader");
+                       image_loader_backend_set_jpeg(&il->backend);
+                       }
 #ifndef HAVE_RAW
-       else
-       if (il->bytes_total >= 11 &&
-               (memcmp(il->mapped_file + 4, "ftypcrx", 7) == 0) &&
-               (memcmp(il->mapped_file + 64, "CanonCR3", 8) == 0))
-               {
-               DEBUG_1("Using custom cr3 loader");
-               image_loader_backend_set_cr3(&il->backend);
-               }
+               else
+               if (il->bytes_total >= 11 &&
+                       (memcmp(il->mapped_file + 4, "ftypcrx", 7) == 0) &&
+                       (memcmp(il->mapped_file + 64, "CanonCR3", 8) == 0))
+                       {
+                       DEBUG_1("Using custom cr3 loader");
+                       image_loader_backend_set_cr3(&il->backend);
+                       }
 #endif
-       else
+               else
 #endif
 #ifdef HAVE_TIFF
-       if (il->bytes_total >= 10 &&
-           (memcmp(il->mapped_file, "MM\0*", 4) == 0 ||
-            memcmp(il->mapped_file, "MM\0+\0\x08\0\0", 8) == 0 ||
-            memcmp(il->mapped_file, "II+\0\x08\0\0\0", 8) == 0 ||
-            memcmp(il->mapped_file, "II*\0", 4) == 0))
-               {
-               DEBUG_1("Using custom tiff loader");
-               image_loader_backend_set_tiff(&il->backend);
-               }
-       else
+               if (il->bytes_total >= 10 &&
+                   (memcmp(il->mapped_file, "MM\0*", 4) == 0 ||
+                    memcmp(il->mapped_file, "MM\0+\0\x08\0\0", 8) == 0 ||
+                    memcmp(il->mapped_file, "II+\0\x08\0\0\0", 8) == 0 ||
+                    memcmp(il->mapped_file, "II*\0", 4) == 0))
+                       {
+                       DEBUG_1("Using custom tiff loader");
+                       image_loader_backend_set_tiff(&il->backend);
+                       }
+               else
 #endif
-       if (il->bytes_total >= 3 && il->mapped_file[0] == 0x44 && il->mapped_file[1] == 0x44 && il->mapped_file[2] == 0x53)
-               {
-               DEBUG_1("Using dds loader");
-               image_loader_backend_set_dds(&il->backend);
-               }
-       else
-       if (il->bytes_total >= 6 &&
-               (memcmp(il->mapped_file, "8BPS\0\x01", 6) == 0))
-               {
-               DEBUG_1("Using custom psd loader");
-               image_loader_backend_set_psd(&il->backend);
-               }
-       else
+               if (il->bytes_total >= 3 && il->mapped_file[0] == 0x44 && il->mapped_file[1] == 0x44 && il->mapped_file[2] == 0x53)
+                       {
+                       DEBUG_1("Using dds loader");
+                       image_loader_backend_set_dds(&il->backend);
+                       }
+               else
+               if (il->bytes_total >= 6 &&
+                       (memcmp(il->mapped_file, "8BPS\0\x01", 6) == 0))
+                       {
+                       DEBUG_1("Using custom psd loader");
+                       image_loader_backend_set_psd(&il->backend);
+                       }
+               else
 #ifdef HAVE_J2K
-       if (il->bytes_total >= 12 &&
-               (memcmp(il->mapped_file, "\0\0\0\x0CjP\x20\x20\x0D\x0A\x87\x0A", 12) == 0))
-               {
-               DEBUG_1("Using custom j2k loader");
-               image_loader_backend_set_j2k(&il->backend);
-               }
-       else
+               if (il->bytes_total >= 12 &&
+                       (memcmp(il->mapped_file, "\0\0\0\x0CjP\x20\x20\x0D\x0A\x87\x0A", 12) == 0))
+                       {
+                       DEBUG_1("Using custom j2k loader");
+                       image_loader_backend_set_j2k(&il->backend);
+                       }
+               else
 #endif
 #ifdef HAVE_JPEGXL
-       if (il->bytes_total >= 12 &&
-               (memcmp(il->mapped_file, "\0\0\0\x0C\x4A\x58\x4C\x20\x0D\x0A\x87\x0A", 12) == 0))
-               {
-               DEBUG_1("Using custom jpeg xl loader");
-               image_loader_backend_set_jpegxl(&il->backend);
-               }
-       else
-       if (il->bytes_total >= 2 &&
-               (memcmp(il->mapped_file, "\xFF\x0A", 2) == 0))
-               {
-               DEBUG_1("Using custom jpeg xl loader");
-               image_loader_backend_set_jpegxl(&il->backend);
-               }
-       else
+               if (il->bytes_total >= 12 &&
+                       (memcmp(il->mapped_file, "\0\0\0\x0C\x4A\x58\x4C\x20\x0D\x0A\x87\x0A", 12) == 0))
+                       {
+                       DEBUG_1("Using custom jpeg xl loader");
+                       image_loader_backend_set_jpegxl(&il->backend);
+                       }
+               else
+               if (il->bytes_total >= 2 &&
+                       (memcmp(il->mapped_file, "\xFF\x0A", 2) == 0))
+                       {
+                       DEBUG_1("Using custom jpeg xl loader");
+                       image_loader_backend_set_jpegxl(&il->backend);
+                       }
+               else
 #endif
-       if ((il->bytes_total == 6144 || il->bytes_total == 6912) &&
-               (file_extension_match(il->fd->path, ".scr")))
-               {
-               DEBUG_1("Using custom zxscr loader");
-               image_loader_backend_set_zxscr(&il->backend);
-               }
-       else
-       if (il->fd->format_class == FORMAT_CLASS_COLLECTION)
-               {
-               DEBUG_1("Using custom collection loader");
-               image_loader_backend_set_collection(&il->backend);
-               }
-       else
-       if (g_strcmp0(strrchr(il->fd->path, '.'), ".svgz") == 0)
-               {
-               DEBUG_1("Using custom svgz loader");
-               image_loader_backend_set_svgz(&il->backend);
+               if ((il->bytes_total == 6144 || il->bytes_total == 6912) &&
+                       (file_extension_match(il->fd->path, ".scr")))
+                       {
+                       DEBUG_1("Using custom zxscr loader");
+                       image_loader_backend_set_zxscr(&il->backend);
+                       }
+               else
+               if (il->fd->format_class == FORMAT_CLASS_COLLECTION)
+                       {
+                       DEBUG_1("Using custom collection loader");
+                       image_loader_backend_set_collection(&il->backend);
+                       }
+               else
+               if (g_strcmp0(strrchr(il->fd->path, '.'), ".svgz") == 0)
+                       {
+                       DEBUG_1("Using custom svgz loader");
+                       image_loader_backend_set_svgz(&il->backend);
+                       }
+               else
+                       image_loader_backend_set_default(&il->backend);
                }
-       else
-               image_loader_backend_set_default(&il->backend);
 
-       il->loader = il->backend.loader_new(image_loader_area_updated_cb, image_loader_size_cb, image_loader_area_prepared_cb, il);
+       il->loader = static_cast<void **>(il->backend.loader_new(image_loader_area_updated_cb, image_loader_size_cb, image_loader_area_prepared_cb, il));
 
 #ifdef HAVE_TIFF
        format = il->backend.get_format_name(il->loader);
@@ -836,7 +862,7 @@ static gboolean image_loader_continue(ImageLoader *il)
        gint b;
        gint c;
 
-       if (!il) return FALSE;
+       if (!il) return G_SOURCE_REMOVE;
 
        c = il->idle_read_loop_count ? il->idle_read_loop_count : 1;
        while (c > 0 && !image_loader_get_stopping(il))
@@ -846,13 +872,13 @@ static gboolean image_loader_continue(ImageLoader *il)
                if (b == 0)
                        {
                        image_loader_done(il);
-                       return FALSE;
+                       return G_SOURCE_REMOVE;
                        }
 
                if (b < 0 || (b > 0 && !il->backend.write(il->loader, il->mapped_file + il->bytes_read, b, &il->error)))
                        {
                        image_loader_error(il);
-                       return FALSE;
+                       return G_SOURCE_REMOVE;
                        }
 
                il->bytes_read += b;
@@ -865,7 +891,7 @@ static gboolean image_loader_continue(ImageLoader *il)
                image_loader_emit_percent(il);
                }
 
-       return TRUE;
+       return G_SOURCE_CONTINUE;
 }
 
 static gboolean image_loader_begin(ImageLoader *il)
@@ -980,7 +1006,7 @@ static gboolean image_loader_setup_source(ImageLoader *il)
 
        if (!il || il->loader || il->mapped_file) return FALSE;
 
-       il->mapped_file = NULL;
+       il->mapped_file = nullptr;
 
        if (il->fd)
                {
@@ -988,7 +1014,7 @@ static gboolean image_loader_setup_source(ImageLoader *il)
 
                if (options->thumbnails.use_exif)
                        {
-                       il->mapped_file = exif_get_preview(exif, (guint *)&il->bytes_total, il->requested_width, il->requested_height);
+                       il->mapped_file = exif_get_preview(exif, reinterpret_cast<guint *>(&il->bytes_total), il->requested_width, il->requested_height);
 
                        if (il->mapped_file)
                                {
@@ -997,15 +1023,15 @@ static gboolean image_loader_setup_source(ImageLoader *il)
                        }
                else
                        {
-                       il->mapped_file = libraw_get_preview(il, (guint *)&il->bytes_total);
+                       il->mapped_file = libraw_get_preview(il, reinterpret_cast<guint *>(&il->bytes_total));
 
                        if (il->mapped_file)
                                {
                                /* Both exiv2 and libraw sometimes return a pointer to a file
                                 * section that is not a jpeg */
-                               if (!(il->mapped_file[0] == 0xFF && il->mapped_file[1] == 0xD8))
+                               if (il->mapped_file[0] != 0xFF || il->mapped_file[1] != 0xD8)
                                        {
-                                       il->mapped_file = NULL;
+                                       il->mapped_file = nullptr;
                                        }
                                else
                                        {
@@ -1017,15 +1043,15 @@ static gboolean image_loader_setup_source(ImageLoader *il)
                /* If libraw does not find a thumbnail, try exiv2 */
                if (!il->mapped_file)
                        {
-                       il->mapped_file = exif_get_preview(exif, (guint *)&il->bytes_total, 0, 0); /* get the largest available preview image or NULL for normal images*/
+                       il->mapped_file = exif_get_preview(exif, reinterpret_cast<guint *>(&il->bytes_total), 0, 0); /* get the largest available preview image or NULL for normal images*/
 
                        if (il->mapped_file)
                                {
                                /* Both exiv2 and libraw sometimes return a pointer to a file
                                 * section that is not a jpeg */
-                               if (!(il->mapped_file[0] == 0xFF && il->mapped_file[1] == 0xD8))
+                               if (il->mapped_file[0] != 0xFF || il->mapped_file[1] != 0xD8)
                                        {
-                                       il->mapped_file = NULL;
+                                       il->mapped_file = nullptr;
                                        }
                                else
                                        {
@@ -1062,11 +1088,11 @@ static gboolean image_loader_setup_source(ImageLoader *il)
                        return FALSE;
                        }
 
-               il->mapped_file = mmap(0, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0);
+               il->mapped_file = static_cast<guchar *>(mmap(nullptr, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0));
                close(load_fd);
                if (il->mapped_file == MAP_FAILED)
                        {
-                       il->mapped_file = 0;
+                       il->mapped_file = nullptr;
                        return FALSE;
                        }
                il->preview = IMAGE_LOADER_PREVIEW_NONE;
@@ -1093,7 +1119,7 @@ static void image_loader_stop_source(ImageLoader *il)
                        {
                        munmap(il->mapped_file, il->bytes_total);
                        }
-               il->mapped_file = NULL;
+               il->mapped_file = nullptr;
                }
 }
 
@@ -1130,20 +1156,19 @@ void image_loader_delay_area_ready(ImageLoader *il, gboolean enable)
                /* send delayed */
                GList *list, *work;
                list = g_list_reverse(il->area_param_delayed_list);
-               il->area_param_delayed_list = NULL;
+               il->area_param_delayed_list = nullptr;
                g_mutex_unlock(il->data_mutex);
 
                work = list;
 
                while (work)
                        {
-                       ImageLoaderAreaParam *par = work->data;
+                       auto par = static_cast<ImageLoaderAreaParam *>(work->data);
                        work = work->next;
 
                        g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h);
-                       g_free(par);
                        }
-               g_list_free(list);
+               g_list_free_full(list, g_free);
                }
        else
                {
@@ -1158,8 +1183,8 @@ void image_loader_delay_area_ready(ImageLoader *il, gboolean enable)
 
 static gboolean image_loader_idle_cb(gpointer data)
 {
-       gboolean ret = FALSE;
-       ImageLoader *il = data;
+       gboolean ret = G_SOURCE_REMOVE;
+       auto il = static_cast<ImageLoader *>(data);
 
        if (il->idle_id)
                {
@@ -1174,7 +1199,6 @@ static gboolean image_loader_idle_cb(gpointer data)
        return ret;
 }
 
-
 static gboolean image_loader_start_idle(ImageLoader *il)
 {
        gboolean ret;
@@ -1187,28 +1211,28 @@ static gboolean image_loader_start_idle(ImageLoader *il)
 
        ret = image_loader_begin(il);
 
-       if (ret && !il->done) il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, NULL);
+       if (ret && !il->done) il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, nullptr);
        return ret;
 }
 
 /**************************************************************************************/
 /* execution via thread */
 
-static GThreadPool *image_loader_thread_pool = NULL;
+static GThreadPool *image_loader_thread_pool = nullptr;
 
-static GCond *image_loader_prio_cond = NULL;
-static GMutex *image_loader_prio_mutex = NULL;
+static GCond *image_loader_prio_cond = nullptr;
+static GMutex *image_loader_prio_mutex = nullptr;
 static gint image_loader_prio_num = 0;
 
 
-static void image_loader_thread_enter_high(void)
+static void image_loader_thread_enter_high()
 {
        g_mutex_lock(image_loader_prio_mutex);
        image_loader_prio_num++;
        g_mutex_unlock(image_loader_prio_mutex);
 }
 
-static void image_loader_thread_leave_high(void)
+static void image_loader_thread_leave_high()
 {
        g_mutex_lock(image_loader_prio_mutex);
        image_loader_prio_num--;
@@ -1216,7 +1240,7 @@ static void image_loader_thread_leave_high(void)
        g_mutex_unlock(image_loader_prio_mutex);
 }
 
-static void image_loader_thread_wait_high(void)
+static void image_loader_thread_wait_high()
 {
        g_mutex_lock(image_loader_prio_mutex);
        while (image_loader_prio_num)
@@ -1228,9 +1252,9 @@ static void image_loader_thread_wait_high(void)
 }
 
 
-static void image_loader_thread_run(gpointer data, gpointer UNUSED(user_data))
+static void image_loader_thread_run(gpointer data, gpointer)
 {
-       ImageLoader *il = data;
+       auto il = static_cast<ImageLoader *>(data);
        gboolean cont;
        gboolean err;
 
@@ -1296,7 +1320,7 @@ static gboolean image_loader_start_thread(ImageLoader *il)
 
         if (!image_loader_thread_pool)
                {
-               image_loader_thread_pool = g_thread_pool_new(image_loader_thread_run, NULL, -1, FALSE, NULL);
+               image_loader_thread_pool = g_thread_pool_new(image_loader_thread_run, nullptr, -1, FALSE, nullptr);
                if (!image_loader_prio_cond) image_loader_prio_cond = g_new(GCond, 1);
                g_cond_init(image_loader_prio_cond);
                if (!image_loader_prio_mutex) image_loader_prio_mutex = g_new(GMutex, 1);
@@ -1305,7 +1329,7 @@ static gboolean image_loader_start_thread(ImageLoader *il)
 
        il->can_destroy = FALSE; /* ImageLoader can't be freed until image_loader_thread_run finishes */
 
-       g_thread_pool_push(image_loader_thread_pool, il, NULL);
+       g_thread_pool_push(image_loader_thread_pool, il, nullptr);
        DEBUG_1("Thread pool num threads: %d", g_thread_pool_get_num_threads(image_loader_thread_pool));
 
        return TRUE;
@@ -1330,7 +1354,7 @@ gboolean image_loader_start(ImageLoader *il)
 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il)
 {
        GdkPixbuf *ret;
-       if (!il) return NULL;
+       if (!il) return nullptr;
 
        g_mutex_lock(il->data_mutex);
        ret = il->pixbuf;
@@ -1378,7 +1402,7 @@ gdouble image_loader_get_percent(ImageLoader *il)
                }
        else
                {
-               ret = (gdouble)il->bytes_read / il->bytes_total;
+               ret = static_cast<gdouble>(il->bytes_read) / il->bytes_total;
                }
        g_mutex_unlock(il->data_mutex);
        return ret;
@@ -1399,7 +1423,7 @@ gboolean image_loader_get_is_done(ImageLoader *il)
 FileData *image_loader_get_fd(ImageLoader *il)
 {
        FileData *ret;
-       if (!il) return NULL;
+       if (!il) return nullptr;
 
        g_mutex_lock(il->data_mutex);
        ret = il->fd;
@@ -1421,35 +1445,40 @@ gboolean image_loader_get_shrunk(ImageLoader *il)
 
 const gchar *image_loader_get_error(ImageLoader *il)
 {
-       const gchar *ret = NULL;
-       if (!il) return NULL;
+       const gchar *ret = nullptr;
+       if (!il) return nullptr;
        g_mutex_lock(il->data_mutex);
        if (il->error) ret = il->error->message;
        g_mutex_unlock(il->data_mutex);
        return ret;
 }
 
+
+/**
+ *  @FIXME this can be rather slow and blocks until the size is known
+ */
 gboolean image_load_dimensions(FileData *fd, gint *width, gint *height)
 {
+       ImageLoader *il;
        gboolean success;
-       gint width_file = 0;
-       gint height_file = 0;
 
-       gdk_pixbuf_get_file_info(fd->path, &width_file, &height_file);
+       il = image_loader_new(fd);
 
-       if (width_file && height_file)
+       success = image_loader_start_idle(il);
+
+       if (success && il->pixbuf)
                {
-               *width = width_file;
-               *height = height_file;
-               success = TRUE;
+               if (width) *width = gdk_pixbuf_get_width(il->pixbuf);
+               if (height) *height = gdk_pixbuf_get_height(il->pixbuf);;
                }
        else
                {
-               *width = -1;
-               *height = -1;
-               success = FALSE;
+               if (width) *width = -1;
+               if (height) *height = -1;
                }
 
+       image_loader_free(il);
+
        return success;
 }
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */