Revert "FIXME: this can be rather slow and blocks until the size is known"
[geeqie.git] / src / image-load.cc
index fd75cc8..03582d1 100644 (file)
@@ -33,7 +33,6 @@
 #include "image-load-heif.h"
 #include "image-load-ffmpegthumbnailer.h"
 #include "image-load-collection.h"
-#include "image-load-webp.h"
 #include "image-load-zxscr.h"
 #include "image-load-j2k.h"
 #include "image-load-jpegxl.h"
@@ -89,7 +88,7 @@ GType image_loader_get_type(void)
                        (GInstanceInitFunc)image_loader_init, /* instance_init */
                        NULL    /* value_table */
                        };
-               type = g_type_register_static(G_TYPE_OBJECT, "ImageLoaderType", &info, 0);
+               type = g_type_register_static(G_TYPE_OBJECT, "ImageLoaderType", &info, GTypeFlags(0));
                }
        return type;
 }
@@ -132,7 +131,7 @@ static void image_loader_init(GTypeInstance *instance, gpointer UNUSED(g_class))
 
 static void image_loader_class_init_wrapper(void *data, void *UNUSED(user_data))
 {
-       image_loader_class_init(data);
+       image_loader_class_init(static_cast<ImageLoaderClass *>(data));
 }
 
 static void image_loader_class_init(ImageLoaderClass *loader_class)
@@ -281,7 +280,7 @@ struct _ImageLoaderAreaParam {
 
 static gboolean image_loader_emit_area_ready_cb(gpointer data)
 {
-       ImageLoaderAreaParam *par = data;
+       ImageLoaderAreaParam *par = static_cast<ImageLoaderAreaParam *>(data);
        ImageLoader *il = par->il;
        guint x, y, w, h;
        g_mutex_lock(il->data_mutex);
@@ -300,21 +299,21 @@ static gboolean image_loader_emit_area_ready_cb(gpointer data)
 
 static gboolean image_loader_emit_done_cb(gpointer data)
 {
-       ImageLoader *il = data;
+       ImageLoader *il = static_cast<ImageLoader *>(data);
        g_signal_emit(il, signals[SIGNAL_DONE], 0);
        return FALSE;
 }
 
 static gboolean image_loader_emit_error_cb(gpointer data)
 {
-       ImageLoader *il = data;
+       ImageLoader *il = static_cast<ImageLoader *>(data);
        g_signal_emit(il, signals[SIGNAL_ERROR], 0);
        return FALSE;
 }
 
 static gboolean image_loader_emit_percent_cb(gpointer data)
 {
-       ImageLoader *il = data;
+       ImageLoader *il = static_cast<ImageLoader *>(data);
        g_signal_emit(il, signals[SIGNAL_PERCENT], 0, image_loader_get_percent(il));
        return FALSE;
 }
@@ -322,7 +321,7 @@ static gboolean image_loader_emit_percent_cb(gpointer data)
 static gboolean image_loader_emit_size_cb(gpointer data)
 {
        gint width, height;
-       ImageLoader *il = data;
+       ImageLoader *il = static_cast<ImageLoader *>(data);
        g_mutex_lock(il->data_mutex);
        width = il->actual_width;
        height = il->actual_height;
@@ -360,7 +359,7 @@ static ImageLoaderAreaParam *image_loader_queue_area_ready(ImageLoader *il, GLis
 {
        if (*list)
                {
-               ImageLoaderAreaParam *prev_par = (*list)->data;
+               ImageLoaderAreaParam *prev_par = static_cast<ImageLoaderAreaParam *>((*list)->data);
                if (prev_par->x == x && prev_par->w == w &&
                    prev_par->y + prev_par->h == y)
                        {
@@ -476,7 +475,7 @@ static void image_loader_area_updated_cb(gpointer UNUSED(loader),
                                 guint x, guint y, guint w, guint h,
                                 gpointer data)
 {
-       ImageLoader *il = data;
+       ImageLoader *il = static_cast<ImageLoader *>(data);
 
        if (!image_loader_get_pixbuf(il))
                {
@@ -500,7 +499,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;
+       ImageLoader *il = static_cast<ImageLoader *>(data);
        GdkPixbuf *pb;
        guchar *pix;
        size_t h, rs;
@@ -532,7 +531,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;
+       ImageLoader *il = static_cast<ImageLoader *>(data);
        gchar **mime_types;
        gboolean scale = FALSE;
        gint n;
@@ -673,16 +672,6 @@ static void image_loader_setup_loader(ImageLoader *il)
                }
        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) &&
@@ -782,7 +771,7 @@ static void image_loader_setup_loader(ImageLoader *il)
        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);
@@ -1008,7 +997,7 @@ static gboolean image_loader_setup_source(ImageLoader *il)
                        }
                else
                        {
-                       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 = libraw_get_preview(il, (guint *)&il->bytes_total);
 
                        if (il->mapped_file)
                                {
@@ -1020,25 +1009,27 @@ static gboolean image_loader_setup_source(ImageLoader *il)
                                        }
                                else
                                        {
-                                       il->preview = IMAGE_LOADER_PREVIEW_EXIF;
+                                       il->preview = IMAGE_LOADER_PREVIEW_LIBRAW;
                                        }
                                }
                        }
 
-               /* If exiv2 does not find a thumbnail, try libraw (which may be slower) */
+               /* If libraw does not find a thumbnail, try exiv2 */
                if (!il->mapped_file)
                        {
-                       il->mapped_file = libraw_get_preview(il, (guint *)&il->bytes_total);
+                       il->mapped_file = exif_get_preview(exif, (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))
                                        {
                                        il->mapped_file = NULL;
                                        }
                                else
                                        {
-                                       il->preview = IMAGE_LOADER_PREVIEW_LIBRAW;
+                                       il->preview = IMAGE_LOADER_PREVIEW_EXIF;
                                        }
                                }
                        }
@@ -1071,7 +1062,7 @@ 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(0, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0));
                close(load_fd);
                if (il->mapped_file == MAP_FAILED)
                        {
@@ -1146,7 +1137,7 @@ void image_loader_delay_area_ready(ImageLoader *il, gboolean enable)
 
                while (work)
                        {
-                       ImageLoaderAreaParam *par = work->data;
+                       ImageLoaderAreaParam *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);
@@ -1165,40 +1156,40 @@ void image_loader_delay_area_ready(ImageLoader *il, gboolean enable)
 /**************************************************************************************/
 /* execution via idle calls */
 
-static gboolean image_loader_idle_cb(gpointer data)
-{
-       gboolean ret = FALSE;
-       ImageLoader *il = data;
+//static gboolean image_loader_idle_cb(gpointer data)
+//{
+       //gboolean ret = FALSE;
+       //ImageLoader *il = static_cast<ImageLoader *>(data);
 
-       if (il->idle_id)
-               {
-               ret = image_loader_continue(il);
-               }
+       //if (il->idle_id)
+               //{
+               //ret = image_loader_continue(il);
+               //}
 
-       if (!ret)
-               {
-               image_loader_stop_source(il);
-               }
+       //if (!ret)
+               //{
+               //image_loader_stop_source(il);
+               //}
 
-       return ret;
-}
+       //return ret;
+//}
 
 
-static gboolean image_loader_start_idle(ImageLoader *il)
-{
-       gboolean ret;
+//static gboolean image_loader_start_idle(ImageLoader *il)
+//{
+       //gboolean ret;
 
-       if (!il) return FALSE;
+       //if (!il) return FALSE;
 
-       if (!il->fd) return FALSE;
+       //if (!il->fd) return FALSE;
 
-       if (!image_loader_setup_source(il)) return FALSE;
+       //if (!image_loader_setup_source(il)) return FALSE;
 
-       ret = image_loader_begin(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);
-       return ret;
-}
+       //if (ret && !il->done) il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, NULL);
+       //return ret;
+//}
 
 /**************************************************************************************/
 /* execution via thread */
@@ -1239,7 +1230,7 @@ static void image_loader_thread_wait_high(void)
 
 static void image_loader_thread_run(gpointer data, gpointer UNUSED(user_data))
 {
-       ImageLoader *il = data;
+       ImageLoader *il = static_cast<ImageLoader *>(data);
        gboolean cont;
        gboolean err;