Revision: 1535
          http://geeqie.svn.sourceforge.net/geeqie/?rev=1535&view=rev
Author:   nadvornik
Date:     2009-03-15 11:34:09 +0000 (Sun, 15 Mar 2009)

Log Message:
-----------
compute histogram in idle time

Modified Paths:
--------------
    trunk/src/bar_histogram.c
    trunk/src/filedata.c
    trunk/src/histogram.c
    trunk/src/histogram.h
    trunk/src/image-overlay.c

Modified: trunk/src/bar_histogram.c
===================================================================
--- trunk/src/bar_histogram.c   2009-03-15 09:06:13 UTC (rev 1534)
+++ trunk/src/bar_histogram.c   2009-03-15 11:34:09 UTC (rev 1535)
@@ -83,7 +83,11 @@
        
        histmap = histmap_get(phd->fd);
        
-       if (!histmap) return FALSE;
+       if (!histmap) 
+               {
+               histmap_start_idle(phd->fd);
+               return FALSE;
+               }
        
        phd->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 
phd->histogram_width, phd->histogram_height);
        gdk_pixbuf_fill(phd->pixbuf, 0xffffffff);
@@ -126,7 +130,7 @@
 static void bar_pane_histogram_notify_cb(FileData *fd, NotifyType type, 
gpointer data)
 {
        PaneHistogramData *phd = data;
-       if (fd == phd->fd) bar_pane_histogram_update(phd);
+       if ((type & (NOTIFY_REREAD | NOTIFY_CHANGE | NOTIFY_HISTMAP | 
NOTIFY_PIXBUF)) && fd == phd->fd) bar_pane_histogram_update(phd);
 }
 
 static gboolean bar_pane_histogram_expose_event_cb(GtkWidget *widget, 
GdkEventExpose *event, gpointer data)

Modified: trunk/src/filedata.c
===================================================================
--- trunk/src/filedata.c        2009-03-15 09:06:13 UTC (rev 1534)
+++ trunk/src/filedata.c        2009-03-15 11:34:09 UTC (rev 1535)
@@ -20,6 +20,7 @@
 #include "ui_fileops.h"
 #include "metadata.h"
 #include "trash.h"
+#include "histogram.h"
 
 
 static GHashTable *file_data_pool = NULL;
@@ -509,7 +510,7 @@
        g_free(fd->collate_key_name);
        g_free(fd->collate_key_name_nocase);
        if (fd->thumb_pixbuf) g_object_unref(fd->thumb_pixbuf);
-       g_free(fd->histmap);
+       histmap_free(fd->histmap);
        
        g_assert(fd->sidecar_files == NULL); /* sidecar files must be freed 
before calling this */
 

Modified: trunk/src/histogram.c
===================================================================
--- trunk/src/histogram.c       2009-03-15 09:06:13 UTC (rev 1534)
+++ trunk/src/histogram.c       2009-03-15 11:34:09 UTC (rev 1535)
@@ -14,6 +14,7 @@
 #include "histogram.h"
 
 #include "pixbuf_util.h"
+#include "filedata.h"
 
 #include <math.h>
 
@@ -30,6 +31,10 @@
        gulong g[HISTMAP_SIZE];
        gulong b[HISTMAP_SIZE];
        gulong max[HISTMAP_SIZE];
+       
+       gint idle_id;
+       GdkPixbuf *pixbuf;
+       gint y;
 };
 
 
@@ -123,22 +128,46 @@
        return t1;
 }
 
-static HistMap *histmap_read(GdkPixbuf *imgpixbuf)
+static HistMap *histmap_new(void)
 {
-       gint w, h, i, j, srs, has_alpha, step;
+       HistMap *histmap = g_new0(HistMap, 1);
+       histmap->idle_id = -1;
+       return histmap;
+}
+
+void histmap_free(HistMap *histmap)
+{
+       if (!histmap) return;
+       if (histmap->idle_id != -1) g_source_remove(histmap->idle_id);
+       if (histmap->pixbuf) g_object_unref(histmap->pixbuf);
+       g_free(histmap);
+}
+
+static gboolean histmap_read(HistMap *histmap, gboolean whole)
+{
+       gint w, h, i, j, srs, has_alpha, step, end_line;
        guchar *s_pix;
-       HistMap *histmap;
+       GdkPixbuf *imgpixbuf = histmap->pixbuf;
        
        w = gdk_pixbuf_get_width(imgpixbuf);
        h = gdk_pixbuf_get_height(imgpixbuf);
        srs = gdk_pixbuf_get_rowstride(imgpixbuf);
        s_pix = gdk_pixbuf_get_pixels(imgpixbuf);
        has_alpha = gdk_pixbuf_get_has_alpha(imgpixbuf);
+       
+       if (whole)
+               {
+               end_line = h;
+               }
+       else
+               {
+               gint lines = 1 + 16384 / w;
+               end_line = histmap->y + lines;
+               if (end_line > h) end_line = h;
+               }
 
-       histmap = g_new0(HistMap, 1);
-
        step = 3 + !!(has_alpha);
-       for (i = 0; i < h; i++)
+       for (i = histmap->y; i < end_line; i++)
                {
                guchar *sp = s_pix + (i * srs); /* 8bit */
                for (j = 0; j < w; j++)
@@ -155,22 +184,45 @@
                        sp += step;
                        }
                }
-       
-       return histmap;
+       histmap->y = end_line;
+       return end_line >= h;   
 }
 
 const HistMap *histmap_get(FileData *fd)
 {
-       if (fd->histmap) return fd->histmap;
+       if (fd->histmap && fd->histmap->idle_id == -1) return fd->histmap; /* 
histmap exists and is finished */
        
-       if (fd->pixbuf)
+       return NULL;
+}
+
+static gboolean histmap_idle_cb(gpointer data)
+{
+       FileData *fd = data;
+       if (histmap_read(fd->histmap, FALSE))
                {
-               fd->histmap = histmap_read(fd->pixbuf);
-               return fd->histmap;
+               /* finished */
+               g_object_unref(fd->histmap->pixbuf); /*pixbuf is no longer 
needed */
+               fd->histmap->pixbuf = NULL;
+               fd->histmap->idle_id = -1;
+               file_data_send_notification(fd, NOTIFY_HISTMAP);
+               return FALSE;
                }
-       return NULL;
+       return TRUE;
 }
 
+gboolean histmap_start_idle(FileData *fd)
+{
+       if (fd->histmap || !fd->pixbuf) return FALSE;
+
+       fd->histmap = histmap_new();
+       fd->histmap->pixbuf = fd->pixbuf;
+       g_object_ref(fd->histmap->pixbuf);
+
+       fd->histmap->idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, 
histmap_idle_cb, fd, NULL);
+       return TRUE;
+}
+
+
 static void histogram_vgrid(Histogram *histogram, GdkPixbuf *pixbuf, gint x, 
gint y, gint width, gint height)
 {
        guint i;
@@ -322,7 +374,7 @@
 {
        if ((type & (NOTIFY_CHANGE || NOTIFY_REREAD)) && fd->histmap)
                {
-               g_free(fd->histmap);
+               histmap_free(fd->histmap);
                fd->histmap = NULL;
                }
 }

Modified: trunk/src/histogram.h
===================================================================
--- trunk/src/histogram.h       2009-03-15 09:06:13 UTC (rev 1534)
+++ trunk/src/histogram.h       2009-03-15 11:34:09 UTC (rev 1535)
@@ -31,7 +31,12 @@
 gint histogram_toggle_channel(Histogram *histogram);
 gint histogram_toggle_mode(Histogram *histogram);
 const gchar *histogram_label(Histogram *histogram);
+
+void histmap_free(HistMap *histmap);
+
 const HistMap *histmap_get(FileData *fd);
+gboolean histmap_start_idle(FileData *fd);
+
 gboolean histogram_draw(Histogram *histogram, const HistMap *histmap, 
GdkPixbuf *pixbuf, gint x, gint y, gint width, gint height);
 
 void histogram_notify_cb(FileData *fd, NotifyType type, gpointer data);

Modified: trunk/src/image-overlay.c
===================================================================
--- trunk/src/image-overlay.c   2009-03-15 09:06:13 UTC (rev 1534)
+++ trunk/src/image-overlay.c   2009-03-15 11:34:09 UTC (rev 1535)
@@ -37,6 +37,7 @@
 struct _OverlayStateData {
        ImageWindow *imd;
        ImageState changed_states;
+       NotifyType notify;
 
        Histogram *histogram;
 
@@ -557,7 +558,11 @@
        if (with_hist)
                {
                histmap = histmap_get(imd->image_fd);
-               if (!histmap) with_hist = FALSE;
+               if (!histmap) 
+                       {
+                       histmap_start_idle(imd->image_fd);
+                       with_hist = FALSE;
+                       }
                }
        
        
@@ -829,7 +834,8 @@
                /* redraw when the image was changed, 
                   with histogram we have to redraw also when loading is 
finished */
                if (osd->changed_states & IMAGE_STATE_IMAGE ||
-                   (osd->changed_states & IMAGE_STATE_LOADING && osd->show & 
OSD_SHOW_HISTOGRAM)) 
+                   (osd->changed_states & IMAGE_STATE_LOADING && osd->show & 
OSD_SHOW_HISTOGRAM) ||
+                   osd->notify & NOTIFY_HISTMAP)
                        {
                        GdkPixbuf *pixbuf;
 
@@ -884,6 +890,7 @@
 
        if (osd->imd->il && image_loader_get_is_done(osd->imd->il))
                osd->changed_states = IMAGE_STATE_NONE;
+       osd->notify = 0;
        osd->idle_id = -1;
        return FALSE;
 }
@@ -958,6 +965,18 @@
        image_osd_update_schedule(osd, FALSE);
 }
 
+static void image_osd_notify_cb(FileData *fd, NotifyType type, gpointer data)
+{
+       OverlayStateData *osd = data;
+
+       if ((type & (NOTIFY_HISTMAP)) && osd->imd && fd == osd->imd->image_fd)
+               {
+               osd->notify |= type;
+               image_osd_update_schedule(osd, FALSE);
+               }
+}
+
+
 static void image_osd_free(OverlayStateData *osd)
 {
        if (!osd) return;
@@ -965,6 +984,8 @@
        if (osd->idle_id != -1) g_source_remove(osd->idle_id);
        if (osd->timer_id != -1) g_source_remove(osd->timer_id);
 
+       file_data_unregister_notify_func(image_osd_notify_cb, osd);
+
        if (osd->imd)
                {
                image_set_osd_data(osd->imd, NULL);
@@ -1017,6 +1038,7 @@
                image_set_osd_data(imd, osd);
 
                image_set_state_func(osd->imd, image_osd_state_cb, osd);
+               file_data_register_notify_func(image_osd_notify_cb, osd, 
NOTIFY_PRIORITY_LOW);
                }
 
        if (show & OSD_SHOW_STATUS)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Geeqie-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geeqie-svn

Reply via email to