Fix #381: Feature-Request: Make JPEG comment available for overlays
[geeqie.git] / src / image-overlay.c
index c7b9188..7afe1a4 100644 (file)
@@ -1,19 +1,27 @@
 /*
- * Geeqie
- * (C) 2006 John Ellis
- * Copyright (C) 2008 The Geeqie Team
+ * Copyright (C) 2006 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include "main.h"
 #include "image-overlay.h"
 
-#include "bar_info.h"
 #include "collect.h"
 #include "exif.h"
 #include "filedata.h"
 #include "image.h"
 #include "img-view.h"
 #include "layout.h"
+#include "metadata.h"
 #include "pixbuf-renderer.h"
 #include "pixbuf_util.h"
 #include "ui_fileops.h"
 #include "image-load.h"
+#include "glua.h"
 
 /*
  *----------------------------------------------------------------------------
@@ -37,28 +47,29 @@ typedef struct _OverlayStateData OverlayStateData;
 struct _OverlayStateData {
        ImageWindow *imd;
        ImageState changed_states;
+       NotifyType notify;
 
        Histogram *histogram;
 
        OsdShowFlags show;
 
        gint ovl_info;
-       
+
        gint x;
        gint y;
 
        gint icon_time[IMAGE_OSD_COUNT];
        gint icon_id[IMAGE_OSD_COUNT];
 
-       gint idle_id;
-       gint timer_id;
+       guint idle_id; /* event source id */
+       guint timer_id; /* event source id */
        gulong destroy_id;
 };
 
 
 typedef struct _OSDIcon OSDIcon;
 struct _OSDIcon {
-       gint reset;     /* reset on new image */
+       gboolean reset; /* reset on new image */
        gint x;         /* x, y offset */
        gint y;
        gchar *key;     /* inline pixbuf */
@@ -98,6 +109,14 @@ void set_default_image_overlay_template_string(gchar **template_string)
        set_image_overlay_template_string(template_string, DEFAULT_OVERLAY_INFO);
 }
 
+void set_image_overlay_font_string(gchar **font_string, const gchar *value)
+{
+       g_assert(font_string);
+
+       g_free(*font_string);
+       *font_string = g_strdup(value);
+}
+
 static OverlayStateData *image_get_osd_data(ImageWindow *imd)
 {
        OverlayStateData *osd;
@@ -124,48 +143,85 @@ static void image_set_osd_data(ImageWindow *imd, OverlayStateData *osd)
  */
 
 
-void image_osd_histogram_chan_toggle(ImageWindow *imd)
+void image_osd_histogram_toggle_channel(ImageWindow *imd)
+{
+       OverlayStateData *osd = image_get_osd_data(imd);
+
+       if (!osd || !osd->histogram) return;
+
+       histogram_toggle_channel(osd->histogram);
+       image_osd_update(imd);
+}
+
+void image_osd_histogram_toggle_mode(ImageWindow *imd)
 {
        OverlayStateData *osd = image_get_osd_data(imd);
 
        if (!osd || !osd->histogram) return;
 
-       histogram_set_channel(osd->histogram, (histogram_get_channel(osd->histogram) +1)%HCHAN_COUNT);
+       histogram_toggle_mode(osd->histogram);
        image_osd_update(imd);
 }
 
-void image_osd_histogram_log_toggle(ImageWindow *imd)
+void image_osd_histogram_set_channel(ImageWindow *imd, gint chan)
 {
        OverlayStateData *osd = image_get_osd_data(imd);
 
        if (!osd || !osd->histogram) return;
 
-       histogram_set_mode(osd->histogram, !histogram_get_mode(osd->histogram));
+       histogram_set_channel(osd->histogram, chan);
        image_osd_update(imd);
 }
 
+void image_osd_histogram_set_mode(ImageWindow *imd, gint mode)
+{
+       OverlayStateData *osd = image_get_osd_data(imd);
+
+       if (!osd || !osd->histogram) return;
+
+       histogram_set_mode(osd->histogram, mode);
+       image_osd_update(imd);
+}
+
+gint image_osd_histogram_get_channel(ImageWindow *imd)
+{
+       OverlayStateData *osd = image_get_osd_data(imd);
+
+       if (!osd || !osd->histogram) return HCHAN_DEFAULT;
+
+       return histogram_get_channel(osd->histogram);
+}
+
+gint image_osd_histogram_get_mode(ImageWindow *imd)
+{
+       OverlayStateData *osd = image_get_osd_data(imd);
+
+       if (!osd || !osd->histogram) return 0;
+
+       return histogram_get_mode(osd->histogram);
+}
+
 void image_osd_toggle(ImageWindow *imd)
 {
-       OverlayStateData *osd;
+       OsdShowFlags show;
 
        if (!imd) return;
 
-       osd = image_get_osd_data(imd);
-       if (!osd)
+       show = image_osd_get(imd);
+       if (show == OSD_SHOW_NOTHING)
                {
                image_osd_set(imd, OSD_SHOW_INFO | OSD_SHOW_STATUS);
                return;
                }
-
-       if (osd->show != OSD_SHOW_NOTHING)
+       else
                {
-               if (osd->show & OSD_SHOW_HISTOGRAM)
+               if (show & OSD_SHOW_HISTOGRAM)
                        {
                        image_osd_set(imd, OSD_SHOW_NOTHING);
                        }
                else
                        {
-                       image_osd_set(imd, osd->show | OSD_SHOW_HISTOGRAM);
+                       image_osd_set(imd, show | OSD_SHOW_HISTOGRAM);
                        }
                }
 }
@@ -178,7 +234,9 @@ static gchar *keywords_to_string(FileData *fd)
 
        g_assert(fd);
 
-       if (comment_read(fd, &keywords, NULL))
+       keywords = metadata_read_list(fd, KEYWORD_KEY, METADATA_PLAIN);
+
+       if (keywords)
                {
                GList *work = keywords;
 
@@ -186,15 +244,16 @@ static gchar *keywords_to_string(FileData *fd)
                        {
                        gchar *kw = work->data;
                        work = work->next;
-                       
+
                        if (!kw) continue;
                        if (!kwstr)
                                kwstr = g_string_new("");
                        else
                                g_string_append(kwstr, ", ");
-                       
+
                        g_string_append(kwstr, kw);
                        }
+               string_list_free(keywords);
                }
 
        if (kwstr)
@@ -220,7 +279,7 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
 
        new = g_string_new(str);
 
-       prev = 0;
+       prev = -1;
 
        while (TRUE)
                {
@@ -231,7 +290,7 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
                gchar *extrapos = NULL;
                gchar *p;
 
-               start = strchr(new->str, delim);
+               start = strchr(new->str + (prev + 1), delim);
                if (!start)
                        break;
                end = strchr(start+1, delim);
@@ -264,7 +323,7 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
 
                if (extrapos)
                        extra = g_strndup(extrapos, end - extrapos);
-                                       
+
                name = g_strndup(start+1, (trunc ? trunc : end)-start-1);
                pos = start - new->str;
                data = NULL;
@@ -275,33 +334,37 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
                        }
                else if (strcmp(name, "comment") == 0)
                        {
-                       comment_read(imd->image_fd, NULL, &data);
+                       data = metadata_read_string(imd->image_fd, COMMENT_KEY, METADATA_PLAIN);
+                       }
+               else if (strcmp(name, "imagecomment") == 0)
+                       {
+                       data = exif_get_image_comment(imd->image_fd);
                        }
+#ifdef HAVE_LUA
+               else if (strncmp(name, "lua/", 4) == 0)
+                       {
+                       gchar *tmp;
+                       tmp = strchr(name+4, '/');
+                       if (!tmp)
+                               break;
+                       *tmp = '\0';
+                       data = lua_callvalue(imd->image_fd, name+4, tmp+1);
+                       }
+#endif
                else
                        {
-                       /*
-                          keywords and comment can't be read between exif_read_fd and exif_free_fd calls
-                          because fd->exif does not count references
-                          on the other hand, it is OK to call it in the loop because it is cached
-                       */
-                          
-                       ExifData *exif;
-                       exif = exif_read_fd(imd->image_fd);
-
                        data = g_strdup(g_hash_table_lookup(vars, name));
-                       if (data && strcmp(name, "zoom") == 0) imd->overlay_show_zoom = TRUE;
-                       if (!data && exif)
-                               data = exif_get_data_as_text(exif, name);
-                       exif_free_fd(imd->image_fd, exif);
+                       if (!data)
+                               data = metadata_read_string(imd->image_fd, name, METADATA_FORMATTED);
                        }
-       
+
                if (data && *data && limit > 0 && strlen(data) > limit + 3)
                        {
                        gchar *new_data = g_strdup_printf("%-*.*s...", limit, limit, data);
                        g_free(data);
                        data = new_data;
                        }
-       
+
                if (data)
                        {
                        /* Since we use pango markup to display, we need to escape here */
@@ -336,7 +399,7 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
                                gchar *right = extra;
                                gchar *p;
                                guint len = strlen(extra);
-                               
+
                                /* Search for left and right parts and unescape characters */
                                for (p = extra; *p; p++, len--)
                                        if (p[0] == '\\')
@@ -447,10 +510,11 @@ static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
        PangoLayout *layout;
        const gchar *name;
        gchar *text;
-       GdkPixbuf *imgpixbuf = NULL;
        gboolean with_hist;
+       const HistMap *histmap = NULL;
        ImageWindow *imd = osd->imd;
        FileData *fd = image_get_fd(imd);
+       PangoFontDescription *font_desc;
 
        if (!fd) return NULL;
 
@@ -507,20 +571,20 @@ static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
                                t = 1;
                                n = 1;
                                }
-       
+
                        if (n < 1) n = 1;
                        if (t < 1) t = 1;
-       
+
                        osd_template_insert(vars, "collection", NULL, OSDT_NONE);
                        }
-               
+
                osd_template_insert(vars, "number", g_strdup_printf("%d", n), OSDT_NO_DUP);
                osd_template_insert(vars, "total", g_strdup_printf("%d", t), OSDT_NO_DUP);
                osd_template_insert(vars, "name", (gchar *) name, OSDT_NONE);
                osd_template_insert(vars, "date", imd->image_fd ? ((gchar *) text_from_time(imd->image_fd->date)) : "", OSDT_NONE);
                osd_template_insert(vars, "size", imd->image_fd ? (text_from_size_abrev(imd->image_fd->size)) : g_strdup(""), OSDT_FREE);
                osd_template_insert(vars, "zoom", image_zoom_get_as_text(imd), OSDT_FREE);
-       
+
                if (!imd->unknown)
                        {
                        gint w, h;
@@ -532,15 +596,13 @@ static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
                                {
                                w = gdk_pixbuf_get_width(load_pixbuf);
                                h = gdk_pixbuf_get_height(load_pixbuf);
-                               imgpixbuf = load_pixbuf;
                                }
                        else
                                {
                                image_get_image_size(imd, &w, &h);
-                               imgpixbuf = (PIXBUF_RENDERER(imd->pr))->pixbuf;
                                }
-               
-                       
+
+
                        osd_template_insert(vars, "width", g_strdup_printf("%d", w), OSDT_NO_DUP);
                        osd_template_insert(vars, "height", g_strdup_printf("%d", h), OSDT_NO_DUP);
                        osd_template_insert(vars, "res", g_strdup_printf("%d × %d", w, h), OSDT_FREE);
@@ -552,7 +614,7 @@ static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
                        osd_template_insert(vars, "res", NULL, OSDT_NONE);
                        }
 
-               text = image_osd_mkinfo(options->image_overlay.common.template_string, imd, vars);
+               text = image_osd_mkinfo(options->image_overlay.template_string, imd, vars);
                g_hash_table_destroy(vars);
 
        } else {
@@ -560,8 +622,18 @@ static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
                text = g_markup_escape_text(_("Untitled"), -1);
        }
 
-       with_hist = (imgpixbuf && (osd->show & OSD_SHOW_HISTOGRAM) && osd->histogram && (!imd->il || image_loader_get_is_done(imd->il)));
-       
+       with_hist = ((osd->show & OSD_SHOW_HISTOGRAM) && osd->histogram);
+       if (with_hist)
+               {
+               histmap = histmap_get(imd->image_fd);
+               if (!histmap)
+                       {
+                       histmap_start_idle(imd->image_fd);
+                       with_hist = FALSE;
+                       }
+               }
+
+
        {
                gint active_marks = 0;
                gint mark;
@@ -603,7 +675,10 @@ static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
                        }
        }
 
+       font_desc = pango_font_description_from_string(options->image_overlay.font);
        layout = gtk_widget_create_pango_layout(imd->pr, NULL);
+       pango_layout_set_font_description(layout, font_desc);
+
        pango_layout_set_markup(layout, text, -1);
        g_free(text);
 
@@ -618,16 +693,15 @@ static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
 
        if (with_hist)
                {
-               histogram_read(osd->histogram, imgpixbuf);
                if (width < HISTOGRAM_WIDTH + 10) width = HISTOGRAM_WIDTH + 10;
                height += HISTOGRAM_HEIGHT + 5;
                }
 
        if (width > 0 && height > 0)
                {
-               /* TODO: make osd color configurable --Zas */
                pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
-               pixbuf_set_rect_fill(pixbuf, 3, 3, width-6, height-6, 240, 240, 240, 210);
+               pixbuf_set_rect_fill(pixbuf, 3, 3, width-6, height-6, options->image_overlay.background_red, options->image_overlay.background_green,
+                                                                                                                       options->image_overlay.background_blue, options->image_overlay.background_alpha);
                pixbuf_set_rect(pixbuf, 0, 0, width, height, 240, 240, 240, 80, 1, 1, 1, 1);
                pixbuf_set_rect(pixbuf, 1, 1, width-2, height-2, 240, 240, 240, 130, 1, 1, 1, 1);
                pixbuf_set_rect(pixbuf, 2, 2, width-4, height-4, 240, 240, 240, 180, 1, 1, 1, 1);
@@ -641,24 +715,12 @@ static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
                        gint x = 5;
                        gint y = height - HISTOGRAM_HEIGHT - 5;
                        gint w = width - 10;
-                       float xoffset = 0;
-                       gint subdiv = 5;
-                       gint c = 160;
-                       gint alpha = 250;
-                       gint i;
-                       float add = w / (float)subdiv;
-
-                       for (i = 0; i < subdiv; i++)
-                               {
-                               gint d = (i > 0 ? 0 : 1);
 
-                               pixbuf_set_rect(pixbuf, x + xoffset + 0.5, y, add + d + 0.5, HISTOGRAM_HEIGHT, c, c, c, alpha, d, 1, 1, 1);
-                               xoffset += add+d;
-                               }
-                                               
-                       histogram_draw(osd->histogram, pixbuf, x, y, w, HISTOGRAM_HEIGHT);
+                       pixbuf_set_rect_fill(pixbuf, x, y, w, HISTOGRAM_HEIGHT, 220, 220, 220, 210);
+                       histogram_draw(osd->histogram, histmap, pixbuf, x, y, w, HISTOGRAM_HEIGHT);
                        }
-               pixbuf_draw_layout(pixbuf, layout, imd->pr, 5, 5, 0, 0, 0, 255);
+               pixbuf_draw_layout(pixbuf, layout, imd->pr, 5, 5, options->image_overlay.text_red, options->image_overlay.text_green,
+                                                                                                                       options->image_overlay.text_blue, options->image_overlay.text_alpha);
        }
 
        g_object_unref(G_OBJECT(layout));
@@ -738,13 +800,6 @@ static void image_overlay_set(ImageWindow *imd, gint id, GdkPixbuf *pixbuf, gint
        pixbuf_renderer_overlay_set((PixbufRenderer *)imd->pr, id, pixbuf, x, y);
 }
 
-#if 0 /* unused for now */
-static gint image_overlay_get(ImageWindow *imd, gint id, GdkPixbuf **pixbuf, gint *x, gint *y)
-{
-       return pixbuf_renderer_overlay_get((PixbufRenderer *)imd->pr, id, pixbuf, x, y);
-}
-#endif
-
 static void image_overlay_remove(ImageWindow *imd, gint id)
 {
        pixbuf_renderer_overlay_remove((PixbufRenderer *)imd->pr, id);
@@ -833,15 +888,17 @@ static void image_osd_info_hide(OverlayStateData *osd)
        osd->ovl_info = 0;
 }
 
-static gint image_osd_update_cb(gpointer data)
+static gboolean image_osd_update_cb(gpointer data)
 {
        OverlayStateData *osd = data;
 
-       osd->imd->overlay_show_zoom = FALSE;
-
        if (osd->show & OSD_SHOW_INFO)
                {
-               if (osd->changed_states & IMAGE_STATE_IMAGE)
+               /* 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->notify & NOTIFY_HISTMAP)
                        {
                        GdkPixbuf *pixbuf;
 
@@ -866,7 +923,7 @@ static gint image_osd_update_cb(gpointer data)
                {
                if (osd->changed_states & IMAGE_STATE_IMAGE)
                        image_osd_icons_reset_time(osd);
-       
+
                if (osd->changed_states & IMAGE_STATE_COLOR_ADJ)
                        {
                        osd->icon_time[IMAGE_OSD_COLOR] = IMAGE_OSD_DEFAULT_DURATION + 1;
@@ -894,17 +951,17 @@ static gint image_osd_update_cb(gpointer data)
                image_osd_icons_hide(osd);
                }
 
-       if (osd->imd->il && image_loader_get_is_done(osd->imd->il))
-               osd->changed_states = IMAGE_STATE_NONE;
-       osd->idle_id = -1;
+       osd->changed_states = IMAGE_STATE_NONE;
+       osd->notify = 0;
+       osd->idle_id = 0;
        return FALSE;
 }
 
-static void image_osd_update_schedule(OverlayStateData *osd, gint force)
+static void image_osd_update_schedule(OverlayStateData *osd, gboolean force)
 {
        if (force) osd->changed_states |= IMAGE_STATE_IMAGE;
 
-       if (osd->idle_id == -1)
+       if (!osd->idle_id)
                {
                osd->idle_id = g_idle_add_full(G_PRIORITY_HIGH, image_osd_update_cb, osd, NULL);
                }
@@ -919,11 +976,11 @@ void image_osd_update(ImageWindow *imd)
        image_osd_update_schedule(osd, TRUE);
 }
 
-static gint image_osd_timer_cb(gpointer data)
+static gboolean image_osd_timer_cb(gpointer data)
 {
        OverlayStateData *osd = data;
-       gint done = TRUE;
-       gint changed = FALSE;
+       gboolean done = TRUE;
+       gboolean changed = FALSE;
        gint i;
 
        for (i = 0; i < IMAGE_OSD_COUNT; i++)
@@ -947,7 +1004,7 @@ static gint image_osd_timer_cb(gpointer data)
 
        if (done)
                {
-               osd->timer_id = -1;
+               osd->timer_id = 0;
                return FALSE;
                }
 
@@ -956,7 +1013,7 @@ static gint image_osd_timer_cb(gpointer data)
 
 static void image_osd_timer_schedule(OverlayStateData *osd)
 {
-       if (osd->timer_id == -1)
+       if (!osd->timer_id)
                {
                osd->timer_id = g_timeout_add(100, image_osd_timer_cb, osd);
                }
@@ -970,12 +1027,27 @@ static void image_osd_state_cb(ImageWindow *imd, ImageState state, gpointer data
        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)
+               {
+               DEBUG_1("Notify osd: %s %04x", fd->path, type);
+               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);
+       if (osd->idle_id) g_source_remove(osd->idle_id);
+       if (osd->timer_id) g_source_remove(osd->timer_id);
+
+       file_data_unregister_notify_func(image_osd_notify_cb, osd);
 
        if (osd->imd)
                {
@@ -993,13 +1065,6 @@ static void image_osd_free(OverlayStateData *osd)
        g_free(osd);
 }
 
-static void image_osd_remove(ImageWindow *imd)
-{
-       OverlayStateData *osd = image_get_osd_data(imd);
-
-       if (osd) image_osd_free(osd);
-}
-
 static void image_osd_destroy_cb(GtkWidget *widget, gpointer data)
 {
        OverlayStateData *osd = data;
@@ -1016,26 +1081,18 @@ static void image_osd_enable(ImageWindow *imd, OsdShowFlags show)
                {
                osd = g_new0(OverlayStateData, 1);
                osd->imd = imd;
-               osd->idle_id = -1;
-               osd->timer_id = -1;
                osd->show = OSD_SHOW_NOTHING;
-               osd->histogram = NULL;
-               osd->x = options->image_overlay.common.x;
-               osd->y = options->image_overlay.common.y;
-               
+               osd->x = options->image_overlay.x;
+               osd->y = options->image_overlay.y;
+
+               osd->histogram = histogram_new();
+
                osd->destroy_id = g_signal_connect(G_OBJECT(imd->pr), "destroy",
                                                   G_CALLBACK(image_osd_destroy_cb), osd);
                image_set_osd_data(imd, osd);
 
                image_set_state_func(osd->imd, image_osd_state_cb, osd);
-               }
-
-       if (show & OSD_SHOW_HISTOGRAM)
-               osd->histogram = histogram_new();
-       else if (osd->histogram)
-               {
-               histogram_free(osd->histogram);
-               osd->histogram = NULL;
+               file_data_register_notify_func(image_osd_notify_cb, osd, NOTIFY_PRIORITY_LOW);
                }
 
        if (show & OSD_SHOW_STATUS)
@@ -1051,12 +1108,6 @@ void image_osd_set(ImageWindow *imd, OsdShowFlags show)
 {
        if (!imd) return;
 
-       if (show == OSD_SHOW_NOTHING)
-               {
-               image_osd_remove(imd);
-               return;
-               }
-
        image_osd_enable(imd, show);
 }
 
@@ -1067,6 +1118,26 @@ OsdShowFlags image_osd_get(ImageWindow *imd)
        return osd ? osd->show : OSD_SHOW_NOTHING;
 }
 
+Histogram *image_osd_get_histogram(ImageWindow *imd)
+{
+       OverlayStateData *osd = image_get_osd_data(imd);
+
+       return osd ? osd->histogram : NULL;
+}
+
+void image_osd_copy_status(ImageWindow *src, ImageWindow *dest)
+{
+       Histogram *h_src, *h_dest;
+       image_osd_set(dest, image_osd_get(src));
+
+       h_src = image_osd_get_histogram(src);
+       h_dest = image_osd_get_histogram(dest);
+
+       h_dest->histogram_mode = h_src->histogram_mode;
+       h_dest->histogram_channel = h_src->histogram_channel;
+
+}
+
 /* duration:
     0 = hide
     1 = show
@@ -1079,7 +1150,7 @@ void image_osd_icon(ImageWindow *imd, ImageOSDFlag flag, gint duration)
 
        if (!osd) return;
 
-       if (flag < IMAGE_OSD_NONE || flag >= IMAGE_OSD_COUNT) return;
+       if (flag >= IMAGE_OSD_COUNT) return;
        if (duration < 0) duration = IMAGE_OSD_DEFAULT_DURATION;
        if (duration > 1) duration += 1;
 
@@ -1088,3 +1159,4 @@ void image_osd_icon(ImageWindow *imd, ImageOSDFlag flag, gint duration)
        image_osd_update_schedule(osd, FALSE);
        image_osd_timer_schedule(osd);
 }
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */