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);
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)
#include "ui_fileops.h"
#include "metadata.h"
#include "trash.h"
+#include "histogram.h"
static GHashTable *file_data_pool = NULL;
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 */
#include "histogram.h"
#include "pixbuf_util.h"
+#include "filedata.h"
#include <math.h>
gulong g[HISTMAP_SIZE];
gulong b[HISTMAP_SIZE];
gulong max[HISTMAP_SIZE];
+
+ gint idle_id;
+ GdkPixbuf *pixbuf;
+ gint y;
};
return t1;
}
-static HistMap *histmap_read(GdkPixbuf *imgpixbuf)
+static HistMap *histmap_new(void)
+{
+ 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;
+ 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);
-
- histmap = g_new0(HistMap, 1);
+
+ if (whole)
+ {
+ end_line = h;
+ }
+ else
+ {
+ gint lines = 1 + 16384 / w;
+ end_line = histmap->y + lines;
+ if (end_line > h) end_line = h;
+ }
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++)
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;
{
if ((type & (NOTIFY_CHANGE || NOTIFY_REREAD)) && fd->histmap)
{
- g_free(fd->histmap);
+ histmap_free(fd->histmap);
fd->histmap = NULL;
}
}
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);
struct _OverlayStateData {
ImageWindow *imd;
ImageState changed_states;
+ NotifyType notify;
Histogram *histogram;
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;
+ }
}
/* 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;
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;
}
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;
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);
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)