4 * Copyright (C) 2008 - 2010 The Geeqie Team
8 * This software is released under the GNU General Public License (GNU GPL).
9 * Please read the included file COPYING for more information.
10 * This software comes with no warranty of any kind, use at your own risk!
14 #include "image-overlay.h"
19 #include "histogram.h"
24 #include "pixbuf-renderer.h"
25 #include "pixbuf_util.h"
26 #include "ui_fileops.h"
27 #include "image-load.h"
31 *----------------------------------------------------------------------------
33 *----------------------------------------------------------------------------
37 typedef struct _OverlayStateData OverlayStateData;
38 struct _OverlayStateData {
40 ImageState changed_states;
52 gint icon_time[IMAGE_OSD_COUNT];
53 gint icon_id[IMAGE_OSD_COUNT];
55 guint idle_id; /* event source id */
56 guint timer_id; /* event source id */
61 typedef struct _OSDIcon OSDIcon;
63 gboolean reset; /* reset on new image */
64 gint x; /* x, y offset */
66 gchar *key; /* inline pixbuf */
69 static OSDIcon osd_icons[] = {
70 { TRUE, 0, 0, NULL }, /* none */
71 { TRUE, -10, -10, NULL }, /* auto rotated */
72 { TRUE, -10, -10, NULL }, /* user rotated */
73 { TRUE, -40, -10, NULL }, /* color embedded */
74 { TRUE, -70, -10, NULL }, /* first image */
75 { TRUE, -70, -10, NULL }, /* last image */
76 { FALSE, -70, -10, NULL }, /* osd enabled */
80 #define OSD_DATA "overlay-data"
82 #define IMAGE_OSD_DEFAULT_DURATION 30
84 #define HISTOGRAM_HEIGHT 140
85 #define HISTOGRAM_WIDTH 256
87 static void image_osd_timer_schedule(OverlayStateData *osd);
89 void set_image_overlay_template_string(gchar **template_string, const gchar *value)
91 g_assert(template_string);
93 g_free(*template_string);
94 *template_string = g_strdup(value);
98 void set_default_image_overlay_template_string(gchar **template_string)
100 set_image_overlay_template_string(template_string, DEFAULT_OVERLAY_INFO);
103 static OverlayStateData *image_get_osd_data(ImageWindow *imd)
105 OverlayStateData *osd;
107 if (!imd) return NULL;
111 osd = g_object_get_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA");
115 static void image_set_osd_data(ImageWindow *imd, OverlayStateData *osd)
119 g_object_set_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA", osd);
123 *----------------------------------------------------------------------------
125 *----------------------------------------------------------------------------
129 void image_osd_histogram_toggle_channel(ImageWindow *imd)
131 OverlayStateData *osd = image_get_osd_data(imd);
133 if (!osd || !osd->histogram) return;
135 histogram_toggle_channel(osd->histogram);
136 image_osd_update(imd);
139 void image_osd_histogram_toggle_mode(ImageWindow *imd)
141 OverlayStateData *osd = image_get_osd_data(imd);
143 if (!osd || !osd->histogram) return;
145 histogram_toggle_mode(osd->histogram);
146 image_osd_update(imd);
149 void image_osd_histogram_set_channel(ImageWindow *imd, gint chan)
151 OverlayStateData *osd = image_get_osd_data(imd);
153 if (!osd || !osd->histogram) return;
155 histogram_set_channel(osd->histogram, chan);
156 image_osd_update(imd);
159 void image_osd_histogram_set_mode(ImageWindow *imd, gint mode)
161 OverlayStateData *osd = image_get_osd_data(imd);
163 if (!osd || !osd->histogram) return;
165 histogram_set_mode(osd->histogram, mode);
166 image_osd_update(imd);
169 gint image_osd_histogram_get_channel(ImageWindow *imd)
171 OverlayStateData *osd = image_get_osd_data(imd);
173 if (!osd || !osd->histogram) return HCHAN_DEFAULT;
175 return histogram_get_channel(osd->histogram);
178 gint image_osd_histogram_get_mode(ImageWindow *imd)
180 OverlayStateData *osd = image_get_osd_data(imd);
182 if (!osd || !osd->histogram) return 0;
184 return histogram_get_mode(osd->histogram);
187 void image_osd_toggle(ImageWindow *imd)
193 show = image_osd_get(imd);
194 if (show == OSD_SHOW_NOTHING)
196 image_osd_set(imd, OSD_SHOW_INFO | OSD_SHOW_STATUS);
201 if (show & OSD_SHOW_HISTOGRAM)
203 image_osd_set(imd, OSD_SHOW_NOTHING);
207 image_osd_set(imd, show | OSD_SHOW_HISTOGRAM);
212 static gchar *keywords_to_string(FileData *fd)
215 GString *kwstr = NULL;
220 keywords = metadata_read_list(fd, KEYWORD_KEY, METADATA_PLAIN);
224 GList *work = keywords;
228 gchar *kw = work->data;
233 kwstr = g_string_new("");
235 g_string_append(kwstr, ", ");
237 g_string_append(kwstr, kw);
239 string_list_free(keywords);
245 g_string_free(kwstr, FALSE);
251 static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *vars)
253 gchar delim = '%', imp = '|', sep[] = " - ";
256 gboolean want_separator = FALSE;
261 if (!str || !*str) return g_strdup("");
263 new = g_string_new(str);
271 gchar *limpos = NULL;
273 gchar *extrapos = NULL;
276 start = strchr(new->str, delim);
279 end = strchr(start+1, delim);
283 /* Search for optionnal modifiers
284 * %name:99:extra% -> name = "name", limit=99, extra = "extra"
286 for (p = start + 1; p < end; p++)
290 if (g_ascii_isdigit(p[1]) && !limpos)
293 if (!trunc) trunc = p;
298 if (!trunc) trunc = p;
305 limit = (guint) atoi(limpos);
308 extra = g_strndup(extrapos, end - extrapos);
310 name = g_strndup(start+1, (trunc ? trunc : end)-start-1);
311 pos = start - new->str;
314 if (strcmp(name, "keywords") == 0)
316 data = keywords_to_string(imd->image_fd);
318 else if (strcmp(name, "comment") == 0)
320 data = metadata_read_string(imd->image_fd, COMMENT_KEY, METADATA_PLAIN);
323 else if (strncmp(name, "lua/", 4) == 0)
326 tmp = strchr(name+4, '/');
330 data = lua_callvalue(name+4, tmp+1);
335 data = g_strdup(g_hash_table_lookup(vars, name));
337 data = metadata_read_string(imd->image_fd, name, METADATA_FORMATTED);
340 if (data && *data && limit > 0 && strlen(data) > limit + 3)
342 gchar *new_data = g_strdup_printf("%-*.*s...", limit, limit, data);
349 /* Since we use pango markup to display, we need to escape here */
350 gchar *escaped = g_markup_escape_text(data, -1);
359 /* Display data between left and right parts of extra string
360 * the data is expressed by a '*' character. A '*' may be escaped
361 * by a \. You should escape all '*' characters, do not rely on the
362 * current implementation which only replaces the first unescaped '*'.
363 * If no "*" is present, the extra string is just appended to data string.
364 * Pango mark up is accepted in left and right parts.
365 * Any \n is replaced by a newline
367 * "<i>*</i>\n" -> data is displayed in italics ended with a newline
368 * "\n" -> ended with newline
369 * "ISO *" -> prefix data with "ISO " (ie. "ISO 100")
370 * "\**\*" -> prefix data with a star, and append a star (ie. "*100*")
371 * "\\*" -> prefix data with an anti slash (ie "\100")
372 * "Collection <b>*</b>\n" -> display data in bold prefixed by "Collection " and a newline is appended
374 * FIXME: using background / foreground colors lead to weird results.
378 gchar *right = extra;
380 guint len = strlen(extra);
382 /* Search for left and right parts and unescape characters */
383 for (p = extra; *p; p++, len--)
388 memmove(p+1, p+2, --len);
391 else if (p[1] != '\0')
392 memmove(p, p+1, len--); // includes \0
394 else if (p[0] == '*' && !left)
400 if (left) right[-1] = '\0';
402 new_data = g_strdup_printf("%s%s%s", left ? left : "", data, right);
409 g_string_erase(new, pos, end-start+1);
414 /* insert separator */
415 g_string_insert(new, pos, sep);
417 want_separator = FALSE;
420 g_string_insert(new, pos, data);
424 if (pos-prev >= 1 && new->str[pos] == imp)
426 /* pipe character is replaced by a separator, delete it
427 * and raise a flag if needed */
428 g_string_erase(new, pos--, 1);
429 want_separator |= (data && *data);
432 if (new->str[pos] == '\n') want_separator = FALSE;
440 /* search and destroy empty lines */
442 while ((start = strchr(end, '\n')))
445 while (*++(end) == '\n')
447 g_string_erase(new, start-new->str, end-start-1);
450 g_strchomp(new->str);
453 g_string_free(new, FALSE);
464 static void osd_template_insert(GHashTable *vars, gchar *keyword, gchar *value, OsdTemplateFlags flags)
468 g_hash_table_insert(vars, keyword, g_strdup(""));
472 if (flags & OSDT_NO_DUP)
474 g_hash_table_insert(vars, keyword, value);
479 g_hash_table_insert(vars, keyword, g_strdup(value));
482 if (flags & OSDT_FREE) g_free((gpointer) value);
485 static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
487 GdkPixbuf *pixbuf = NULL;
492 GdkPixbuf *imgpixbuf = NULL;
494 const HistMap *histmap;
495 ImageWindow *imd = osd->imd;
496 FileData *fd = image_get_fd(imd);
498 if (!fd) return NULL;
500 name = image_get_name(imd);
508 vars = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
510 cd = image_get_collection(imd, &info);
513 t = g_list_length(cd->list);
514 n = g_list_index(cd->list, info) + 1;
517 if (file_extension_match(cd->name, GQ_COLLECTION_EXT))
518 osd_template_insert(vars, "collection", remove_extension_from_path(cd->name), OSDT_FREE);
520 osd_template_insert(vars, "collection", cd->name, OSDT_NONE);
524 osd_template_insert(vars, "collection", _("Untitled"), OSDT_NONE);
529 LayoutWindow *lw = layout_find_by_image(imd);
534 n = g_list_length(lw->slideshow->list_done);
535 t = n + g_list_length(lw->slideshow->list);
540 t = layout_list_count(lw, NULL);
541 n = layout_list_get_index(lw, image_get_fd(lw->image)) + 1;
544 else if (view_window_find_image(imd, &n, &t))
557 osd_template_insert(vars, "collection", NULL, OSDT_NONE);
560 osd_template_insert(vars, "number", g_strdup_printf("%d", n), OSDT_NO_DUP);
561 osd_template_insert(vars, "total", g_strdup_printf("%d", t), OSDT_NO_DUP);
562 osd_template_insert(vars, "name", (gchar *) name, OSDT_NONE);
563 osd_template_insert(vars, "date", imd->image_fd ? ((gchar *) text_from_time(imd->image_fd->date)) : "", OSDT_NONE);
564 osd_template_insert(vars, "size", imd->image_fd ? (text_from_size_abrev(imd->image_fd->size)) : g_strdup(""), OSDT_FREE);
565 osd_template_insert(vars, "zoom", image_zoom_get_as_text(imd), OSDT_FREE);
570 GdkPixbuf *load_pixbuf = image_loader_get_pixbuf(imd->il);
572 if (imd->delay_flip &&
573 imd->il && load_pixbuf &&
574 image_get_pixbuf(imd) != load_pixbuf)
576 w = gdk_pixbuf_get_width(load_pixbuf);
577 h = gdk_pixbuf_get_height(load_pixbuf);
578 imgpixbuf = load_pixbuf;
582 image_get_image_size(imd, &w, &h);
583 imgpixbuf = (PIXBUF_RENDERER(imd->pr))->pixbuf;
587 osd_template_insert(vars, "width", g_strdup_printf("%d", w), OSDT_NO_DUP);
588 osd_template_insert(vars, "height", g_strdup_printf("%d", h), OSDT_NO_DUP);
589 osd_template_insert(vars, "res", g_strdup_printf("%d × %d", w, h), OSDT_FREE);
593 osd_template_insert(vars, "width", NULL, OSDT_NONE);
594 osd_template_insert(vars, "height", NULL, OSDT_NONE);
595 osd_template_insert(vars, "res", NULL, OSDT_NONE);
598 text = image_osd_mkinfo(options->image_overlay.template_string, imd, vars);
599 g_hash_table_destroy(vars);
602 /* When does this occur ?? */
603 text = g_markup_escape_text(_("Untitled"), -1);
606 with_hist = ((osd->show & OSD_SHOW_HISTOGRAM) && osd->histogram);
609 histmap = histmap_get(imd->image_fd);
612 histmap_start_idle(imd->image_fd);
619 gint active_marks = 0;
623 for (mark = 0; mark < FILEDATA_MARKS_SIZE; mark++)
625 active_marks += file_data_get_mark(fd, mark);
628 if (active_marks > 0)
630 GString *buf = g_string_sized_new(FILEDATA_MARKS_SIZE * 2);
632 for (mark = 0; mark < FILEDATA_MARKS_SIZE; mark++)
634 g_string_append_printf(buf, file_data_get_mark(fd, mark) ? " <span background='#FF00FF'>%c</span>" : " %c", '1' + mark);
638 text2 = g_strdup_printf("%s\n%s", text, buf->str);
640 text2 = g_strdup(buf->str);
641 g_string_free(buf, TRUE);
648 gchar *escaped_histogram_label = g_markup_escape_text(histogram_label(osd->histogram), -1);
650 text2 = g_strdup_printf("%s\n%s", text, escaped_histogram_label);
652 text2 = g_strdup(escaped_histogram_label);
653 g_free(escaped_histogram_label);
659 layout = gtk_widget_create_pango_layout(imd->pr, NULL);
660 pango_layout_set_markup(layout, text, -1);
663 pango_layout_get_pixel_size(layout, &width, &height);
664 /* with empty text width is set to 0, but not height) */
667 else if (height == 0)
669 if (width > 0) width += 10;
670 if (height > 0) height += 10;
674 if (width < HISTOGRAM_WIDTH + 10) width = HISTOGRAM_WIDTH + 10;
675 height += HISTOGRAM_HEIGHT + 5;
678 if (width > 0 && height > 0)
680 /* TODO: make osd color configurable --Zas */
681 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
682 pixbuf_set_rect_fill(pixbuf, 3, 3, width-6, height-6, 240, 240, 240, 210);
683 pixbuf_set_rect(pixbuf, 0, 0, width, height, 240, 240, 240, 80, 1, 1, 1, 1);
684 pixbuf_set_rect(pixbuf, 1, 1, width-2, height-2, 240, 240, 240, 130, 1, 1, 1, 1);
685 pixbuf_set_rect(pixbuf, 2, 2, width-4, height-4, 240, 240, 240, 180, 1, 1, 1, 1);
686 pixbuf_pixel_set(pixbuf, 0, 0, 0, 0, 0, 0);
687 pixbuf_pixel_set(pixbuf, width - 1, 0, 0, 0, 0, 0);
688 pixbuf_pixel_set(pixbuf, 0, height - 1, 0, 0, 0, 0);
689 pixbuf_pixel_set(pixbuf, width - 1, height - 1, 0, 0, 0, 0);
694 gint y = height - HISTOGRAM_HEIGHT - 5;
697 pixbuf_set_rect_fill(pixbuf, x, y, w, HISTOGRAM_HEIGHT, 220, 220, 220, 210);
698 histogram_draw(osd->histogram, histmap, pixbuf, x, y, w, HISTOGRAM_HEIGHT);
700 pixbuf_draw_layout(pixbuf, layout, imd->pr, 5, 5, 0, 0, 0, 255);
703 g_object_unref(G_OBJECT(layout));
708 static GdkPixbuf *image_osd_icon_pixbuf(ImageOSDFlag flag)
710 static GdkPixbuf **icons = NULL;
711 GdkPixbuf *icon = NULL;
713 if (!icons) icons = g_new0(GdkPixbuf *, IMAGE_OSD_COUNT);
714 if (icons[flag]) return icons[flag];
716 if (osd_icons[flag].key)
718 icon = pixbuf_inline(osd_icons[flag].key);
723 icon = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 24, 24);
724 pixbuf_set_rect_fill(icon, 1, 1, 22, 22, 255, 255, 255, 200);
725 pixbuf_set_rect(icon, 0, 0, 24, 24, 0, 0, 0, 128, 1, 1, 1, 1);
728 case IMAGE_OSD_ROTATE_AUTO:
729 pixbuf_set_rect(icon, 3, 8, 11, 12,
732 pixbuf_draw_triangle(icon, 14, 3, 6, 12,
733 20, 9, 14, 15, 14, 3,
736 case IMAGE_OSD_ROTATE_USER:
738 case IMAGE_OSD_COLOR:
739 pixbuf_set_rect_fill(icon, 3, 3, 18, 6, 200, 0, 0, 255);
740 pixbuf_set_rect_fill(icon, 3, 9, 18, 6, 0, 200, 0, 255);
741 pixbuf_set_rect_fill(icon, 3, 15, 18, 6, 0, 0, 200, 255);
743 case IMAGE_OSD_FIRST:
744 pixbuf_set_rect(icon, 3, 3, 18, 18, 0, 0, 0, 200, 3, 3, 3, 0);
745 pixbuf_draw_triangle(icon, 6, 5, 12, 6,
746 12, 5, 18, 11, 6, 11,
750 pixbuf_set_rect(icon, 3, 3, 18, 18, 0, 0, 0, 200, 3, 3, 0, 3);
751 pixbuf_draw_triangle(icon, 6, 12, 12, 6,
752 12, 18, 6, 12, 18, 12,
756 pixbuf_set_rect_fill(icon, 11, 3, 3, 12, 0, 0, 0, 255);
757 pixbuf_set_rect_fill(icon, 11, 17, 3, 3, 0, 0, 0, 255);
769 static gint image_overlay_add(ImageWindow *imd, GdkPixbuf *pixbuf, gint x, gint y,
770 OverlayRendererFlags flags)
772 return pixbuf_renderer_overlay_add((PixbufRenderer *)imd->pr, pixbuf, x, y, flags);
775 static void image_overlay_set(ImageWindow *imd, gint id, GdkPixbuf *pixbuf, gint x, gint y)
777 pixbuf_renderer_overlay_set((PixbufRenderer *)imd->pr, id, pixbuf, x, y);
780 #if 0 /* unused for now */
781 static gint image_overlay_get(ImageWindow *imd, gint id, GdkPixbuf **pixbuf, gint *x, gint *y)
783 return pixbuf_renderer_overlay_get((PixbufRenderer *)imd->pr, id, pixbuf, x, y);
787 static void image_overlay_remove(ImageWindow *imd, gint id)
789 pixbuf_renderer_overlay_remove((PixbufRenderer *)imd->pr, id);
792 static void image_osd_icon_show(OverlayStateData *osd, ImageOSDFlag flag)
796 if (osd->icon_id[flag]) return;
798 pixbuf = image_osd_icon_pixbuf(flag);
801 osd->icon_id[flag] = image_overlay_add(osd->imd, pixbuf,
802 osd_icons[flag].x, osd_icons[flag].y,
806 static void image_osd_icon_hide(OverlayStateData *osd, ImageOSDFlag flag)
808 if (osd->icon_id[flag])
810 image_overlay_remove(osd->imd, osd->icon_id[flag]);
811 osd->icon_id[flag] = 0;
815 static void image_osd_icons_reset_time(OverlayStateData *osd)
819 for (i = 0; i < IMAGE_OSD_COUNT; i++)
821 if (osd_icons[i].reset)
823 osd->icon_time[i] = 0;
828 static void image_osd_icons_update(OverlayStateData *osd)
832 for (i = 0; i < IMAGE_OSD_COUNT; i++)
834 if (osd->icon_time[i] > 0)
836 image_osd_icon_show(osd, i);
840 image_osd_icon_hide(osd, i);
845 static void image_osd_icons_hide(OverlayStateData *osd)
849 for (i = 0; i < IMAGE_OSD_COUNT; i++)
851 image_osd_icon_hide(osd, i);
855 static void image_osd_info_show(OverlayStateData *osd, GdkPixbuf *pixbuf)
857 if (osd->ovl_info == 0)
859 osd->ovl_info = image_overlay_add(osd->imd, pixbuf, osd->x, osd->y, OVL_RELATIVE);
863 image_overlay_set(osd->imd, osd->ovl_info, pixbuf, osd->x, osd->y);
867 static void image_osd_info_hide(OverlayStateData *osd)
869 if (osd->ovl_info == 0) return;
871 image_overlay_remove(osd->imd, osd->ovl_info);
875 static gboolean image_osd_update_cb(gpointer data)
877 OverlayStateData *osd = data;
879 if (osd->show & OSD_SHOW_INFO)
881 /* redraw when the image was changed,
882 with histogram we have to redraw also when loading is finished */
883 if (osd->changed_states & IMAGE_STATE_IMAGE ||
884 (osd->changed_states & IMAGE_STATE_LOADING && osd->show & OSD_SHOW_HISTOGRAM) ||
885 osd->notify & NOTIFY_HISTMAP)
889 pixbuf = image_osd_info_render(osd);
892 image_osd_info_show(osd, pixbuf);
893 g_object_unref(pixbuf);
897 image_osd_info_hide(osd);
903 image_osd_info_hide(osd);
906 if (osd->show & OSD_SHOW_STATUS)
908 if (osd->changed_states & IMAGE_STATE_IMAGE)
909 image_osd_icons_reset_time(osd);
911 if (osd->changed_states & IMAGE_STATE_COLOR_ADJ)
913 osd->icon_time[IMAGE_OSD_COLOR] = IMAGE_OSD_DEFAULT_DURATION + 1;
914 image_osd_timer_schedule(osd);
917 if (osd->changed_states & IMAGE_STATE_ROTATE_AUTO)
921 if (osd->imd->state & IMAGE_STATE_ROTATE_AUTO)
924 if (!osd->imd->cm) n += IMAGE_OSD_DEFAULT_DURATION;
927 osd->icon_time[IMAGE_OSD_ROTATE_AUTO] = n;
928 image_osd_timer_schedule(osd);
931 image_osd_icons_update(osd);
935 image_osd_icons_hide(osd);
938 osd->changed_states = IMAGE_STATE_NONE;
944 static void image_osd_update_schedule(OverlayStateData *osd, gboolean force)
946 if (force) osd->changed_states |= IMAGE_STATE_IMAGE;
950 osd->idle_id = g_idle_add_full(G_PRIORITY_HIGH, image_osd_update_cb, osd, NULL);
954 void image_osd_update(ImageWindow *imd)
956 OverlayStateData *osd = image_get_osd_data(imd);
960 image_osd_update_schedule(osd, TRUE);
963 static gboolean image_osd_timer_cb(gpointer data)
965 OverlayStateData *osd = data;
966 gboolean done = TRUE;
967 gboolean changed = FALSE;
970 for (i = 0; i < IMAGE_OSD_COUNT; i++)
972 if (osd->icon_time[i] > 1)
975 if (osd->icon_time[i] < 2)
977 osd->icon_time[i] = 0;
987 if (changed) image_osd_update_schedule(osd, FALSE);
998 static void image_osd_timer_schedule(OverlayStateData *osd)
1002 osd->timer_id = g_timeout_add(100, image_osd_timer_cb, osd);
1006 static void image_osd_state_cb(ImageWindow *imd, ImageState state, gpointer data)
1008 OverlayStateData *osd = data;
1010 osd->changed_states |= state;
1011 image_osd_update_schedule(osd, FALSE);
1014 static void image_osd_notify_cb(FileData *fd, NotifyType type, gpointer data)
1016 OverlayStateData *osd = data;
1018 if ((type & (NOTIFY_HISTMAP)) && osd->imd && fd == osd->imd->image_fd)
1020 DEBUG_1("Notify osd: %s %04x", fd->path, type);
1021 osd->notify |= type;
1022 image_osd_update_schedule(osd, FALSE);
1027 static void image_osd_free(OverlayStateData *osd)
1031 if (osd->idle_id) g_source_remove(osd->idle_id);
1032 if (osd->timer_id) g_source_remove(osd->timer_id);
1034 file_data_unregister_notify_func(image_osd_notify_cb, osd);
1038 image_set_osd_data(osd->imd, NULL);
1039 g_signal_handler_disconnect(osd->imd->pr, osd->destroy_id);
1041 image_set_state_func(osd->imd, NULL, NULL);
1043 image_osd_info_hide(osd);
1044 image_osd_icons_hide(osd);
1047 if (osd->histogram) histogram_free(osd->histogram);
1053 static void image_osd_remove(ImageWindow *imd)
1055 OverlayStateData *osd = image_get_osd_data(imd);
1057 if (osd) image_osd_free(osd);
1061 static void image_osd_destroy_cb(GtkWidget *widget, gpointer data)
1063 OverlayStateData *osd = data;
1066 image_osd_free(osd);
1069 static void image_osd_enable(ImageWindow *imd, OsdShowFlags show)
1071 OverlayStateData *osd = image_get_osd_data(imd);
1075 osd = g_new0(OverlayStateData, 1);
1077 osd->show = OSD_SHOW_NOTHING;
1078 osd->x = options->image_overlay.x;
1079 osd->y = options->image_overlay.y;
1081 osd->histogram = histogram_new();
1083 osd->destroy_id = g_signal_connect(G_OBJECT(imd->pr), "destroy",
1084 G_CALLBACK(image_osd_destroy_cb), osd);
1085 image_set_osd_data(imd, osd);
1087 image_set_state_func(osd->imd, image_osd_state_cb, osd);
1088 file_data_register_notify_func(image_osd_notify_cb, osd, NOTIFY_PRIORITY_LOW);
1091 if (show & OSD_SHOW_STATUS)
1092 image_osd_icon(imd, IMAGE_OSD_ICON, -1);
1094 if (show != osd->show)
1095 image_osd_update_schedule(osd, TRUE);
1100 void image_osd_set(ImageWindow *imd, OsdShowFlags show)
1104 image_osd_enable(imd, show);
1107 OsdShowFlags image_osd_get(ImageWindow *imd)
1109 OverlayStateData *osd = image_get_osd_data(imd);
1111 return osd ? osd->show : OSD_SHOW_NOTHING;
1114 Histogram *image_osd_get_histogram(ImageWindow *imd)
1116 OverlayStateData *osd = image_get_osd_data(imd);
1118 return osd ? osd->histogram : NULL;
1121 void image_osd_copy_status(ImageWindow *src, ImageWindow *dest)
1123 Histogram *h_src, *h_dest;
1124 image_osd_set(dest, image_osd_get(src));
1126 h_src = image_osd_get_histogram(src);
1127 h_dest = image_osd_get_histogram(dest);
1129 h_dest->histogram_mode = h_src->histogram_mode;
1130 h_dest->histogram_channel = h_src->histogram_channel;
1137 2+ = show for duration tenths of a second
1138 -1 = use default duration
1140 void image_osd_icon(ImageWindow *imd, ImageOSDFlag flag, gint duration)
1142 OverlayStateData *osd = image_get_osd_data(imd);
1146 if (flag >= IMAGE_OSD_COUNT) return;
1147 if (duration < 0) duration = IMAGE_OSD_DEFAULT_DURATION;
1148 if (duration > 1) duration += 1;
1150 osd->icon_time[flag] = duration;
1152 image_osd_update_schedule(osd, FALSE);
1153 image_osd_timer_schedule(osd);
1155 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */