Remove commented out code.
[geeqie.git] / src / image-load.c
index 167ca89..c2a7fdf 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Geeqie
  * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2010 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: John Ellis
  *
@@ -92,6 +92,8 @@ static void image_loader_init(GTypeInstance *instance, gpointer g_class)
 
        il->requested_width = 0;
        il->requested_height = 0;
+       il->actual_width = 0;
+       il->actual_height = 0;
        il->shrunk = FALSE;
 
        il->can_destroy = TRUE;
@@ -250,11 +252,17 @@ static gboolean image_loader_emit_area_ready_cb(gpointer data)
 {
        ImageLoaderAreaParam *par = data;
        ImageLoader *il = par->il;
-       g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h);
+       guint x, y, w, h;
        g_mutex_lock(il->data_mutex);
        il->area_param_list = g_list_remove(il->area_param_list, par);
+       x = par->x;
+       y = par->y;
+       w = par->w;
+       h = par->h;
        g_free(par);
        g_mutex_unlock(il->data_mutex);
+
+       g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, x, y, w, h);
        
        return FALSE;
 }
@@ -280,6 +288,19 @@ static gboolean image_loader_emit_percent_cb(gpointer data)
        return FALSE;
 }
 
+static gboolean image_loader_emit_size_cb(gpointer data)
+{
+       gint width, height;
+       ImageLoader *il = 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;
+}
+
+
 /* DONE and ERROR are emited only once, thus they can have normal priority
    PERCENT and AREA_READY should be processed ASAP
 */
@@ -299,9 +320,48 @@ static void image_loader_emit_percent(ImageLoader *il)
        g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_percent_cb, il, NULL);
 }
 
-/* this function expects that il->data_mutex is locked by caller */
-static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
+static void image_loader_emit_size(ImageLoader *il)
 {
+       g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_size_cb, il, NULL);
+}
+
+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;
+               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;
+                       }
+               if (prev_par->x == x && prev_par->w == w &&
+                   y + h == prev_par->y)
+                       {
+                       /* we can merge the notifications */
+                       prev_par->h += h;
+                       prev_par->y = y;
+                       return NULL;
+                       }
+               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;
+                       }
+               if (prev_par->y == y && prev_par->h == h &&
+                   x + w == prev_par->x)
+                       {
+                       /* we can merge the notifications */
+                       prev_par->w += w;
+                       prev_par->x = x;
+                       return NULL;
+                       }
+               }
+       
        ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1);
        par->il = il;
        par->x = x;
@@ -309,9 +369,19 @@ static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guin
        par->w = w;
        par->h = h;
        
-       il->area_param_list = g_list_prepend(il->area_param_list, par);
+       *list = g_list_prepend(*list, par);
+       return par;
+}
+
+/* this function expects that il->data_mutex is locked by caller */
+static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
+{
+       ImageLoaderAreaParam *par = image_loader_queue_area_ready(il, &il->area_param_list, x, y, w, h);
        
-       g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL);
+       if (par)
+               {
+               g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL);
+               }
 }
 
 /**************************************************************************************/
@@ -320,14 +390,7 @@ static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guin
 /* this function expects that il->data_mutex is locked by caller */
 static void image_loader_queue_delayed_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
 {
-       ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1);
-       par->il = il;
-       par->x = x;
-       par->y = y;
-       par->w = w;
-       par->h = h;
-       
-       il->area_param_delayed_list = g_list_prepend(il->area_param_delayed_list, par);
+       image_loader_queue_area_ready(il, &il->area_param_delayed_list, x, y, w, h);
 }
 
 
@@ -444,10 +507,12 @@ static void image_loader_size_cb(gpointer loader,
        gint n;
 
        g_mutex_lock(il->data_mutex);
+       il->actual_width = width;
+       il->actual_height = height;
        if (il->requested_width < 1 || il->requested_height < 1) 
                {
                g_mutex_unlock(il->data_mutex);
-               g_signal_emit(il, signals[SIGNAL_SIZE], 0, width, height);
+               image_loader_emit_size(il);
                return;
                }
        g_mutex_unlock(il->data_mutex);
@@ -463,7 +528,7 @@ static void image_loader_size_cb(gpointer loader,
 
        if (!scale)
                {
-               g_signal_emit(il, signals[SIGNAL_SIZE], 0, width, height);
+               image_loader_emit_size(il);
                return;
                }
 
@@ -486,12 +551,14 @@ static void image_loader_size_cb(gpointer loader,
                        if (nw < 1) nw = 1;
                        }
 
+               il->actual_width = nw;
+               il->actual_height = nh;
                il->backend.set_size(loader, nw, nh);
                il->shrunk = TRUE;
                }
-       g_mutex_unlock(il->data_mutex);
 
-       g_signal_emit(il, signals[SIGNAL_SIZE], 0, nw, nh);
+       g_mutex_unlock(il->data_mutex);
+       image_loader_emit_size(il);
 }
 
 static void image_loader_stop_loader(ImageLoader *il)