4 * Copyright (C) 2008 - 2012 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 void set_image_overlay_font_string(gchar **font_string, const gchar *value)
105 g_assert(font_string);
107 g_free(*font_string);
108 *font_string = g_strdup(value);
111 static OverlayStateData *image_get_osd_data(ImageWindow *imd)
113 OverlayStateData *osd;
115 if (!imd) return NULL;
119 osd = g_object_get_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA");
123 static void image_set_osd_data(ImageWindow *imd, OverlayStateData *osd)
127 g_object_set_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA", osd);
131 *----------------------------------------------------------------------------
133 *----------------------------------------------------------------------------
137 void image_osd_histogram_toggle_channel(ImageWindow *imd)
139 OverlayStateData *osd = image_get_osd_data(imd);
141 if (!osd || !osd->histogram) return;
143 histogram_toggle_channel(osd->histogram);
144 image_osd_update(imd);
147 void image_osd_histogram_toggle_mode(ImageWindow *imd)
149 OverlayStateData *osd = image_get_osd_data(imd);
151 if (!osd || !osd->histogram) return;
153 histogram_toggle_mode(osd->histogram);
154 image_osd_update(imd);
157 void image_osd_histogram_set_channel(ImageWindow *imd, gint chan)
159 OverlayStateData *osd = image_get_osd_data(imd);
161 if (!osd || !osd->histogram) return;
163 histogram_set_channel(osd->histogram, chan);
164 image_osd_update(imd);
167 void image_osd_histogram_set_mode(ImageWindow *imd, gint mode)
169 OverlayStateData *osd = image_get_osd_data(imd);
171 if (!osd || !osd->histogram) return;
173 histogram_set_mode(osd->histogram, mode);
174 image_osd_update(imd);
177 gint image_osd_histogram_get_channel(ImageWindow *imd)
179 OverlayStateData *osd = image_get_osd_data(imd);
181 if (!osd || !osd->histogram) return HCHAN_DEFAULT;
183 return histogram_get_channel(osd->histogram);
186 gint image_osd_histogram_get_mode(ImageWindow *imd)
188 OverlayStateData *osd = image_get_osd_data(imd);
190 if (!osd || !osd->histogram) return 0;
192 return histogram_get_mode(osd->histogram);
195 void image_osd_toggle(ImageWindow *imd)
201 show = image_osd_get(imd);
202 if (show == OSD_SHOW_NOTHING)
204 image_osd_set(imd, OSD_SHOW_INFO | OSD_SHOW_STATUS);
209 if (show & OSD_SHOW_HISTOGRAM)
211 image_osd_set(imd, OSD_SHOW_NOTHING);
215 image_osd_set(imd, show | OSD_SHOW_HISTOGRAM);
220 static gchar *keywords_to_string(FileData *fd)
223 GString *kwstr = NULL;
228 keywords = metadata_read_list(fd, KEYWORD_KEY, METADATA_PLAIN);
232 GList *work = keywords;
236 gchar *kw = work->data;
241 kwstr = g_string_new("");
243 g_string_append(kwstr, ", ");
245 g_string_append(kwstr, kw);
247 string_list_free(keywords);
253 g_string_free(kwstr, FALSE);
259 static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *vars)
261 gchar delim = '%', imp = '|', sep[] = " - ";
264 gboolean want_separator = FALSE;
269 if (!str || !*str) return g_strdup("");
271 new = g_string_new(str);
279 gchar *limpos = NULL;
281 gchar *extrapos = NULL;
284 start = strchr(new->str + (prev + 1), delim);
287 end = strchr(start+1, delim);
291 /* Search for optionnal modifiers
292 * %name:99:extra% -> name = "name", limit=99, extra = "extra"
294 for (p = start + 1; p < end; p++)
298 if (g_ascii_isdigit(p[1]) && !limpos)
301 if (!trunc) trunc = p;
306 if (!trunc) trunc = p;
313 limit = (guint) atoi(limpos);
316 extra = g_strndup(extrapos, end - extrapos);
318 name = g_strndup(start+1, (trunc ? trunc : end)-start-1);
319 pos = start - new->str;
322 if (strcmp(name, "keywords") == 0)
324 data = keywords_to_string(imd->image_fd);
326 else if (strcmp(name, "comment") == 0)
328 data = metadata_read_string(imd->image_fd, COMMENT_KEY, METADATA_PLAIN);
331 else if (strncmp(name, "lua/", 4) == 0)
334 tmp = strchr(name+4, '/');
338 data = lua_callvalue(imd->image_fd, name+4, tmp+1);
343 data = g_strdup(g_hash_table_lookup(vars, name));
345 data = metadata_read_string(imd->image_fd, name, METADATA_FORMATTED);
348 if (data && *data && limit > 0 && strlen(data) > limit + 3)
350 gchar *new_data = g_strdup_printf("%-*.*s...", limit, limit, data);
357 /* Since we use pango markup to display, we need to escape here */
358 gchar *escaped = g_markup_escape_text(data, -1);
367 /* Display data between left and right parts of extra string
368 * the data is expressed by a '*' character. A '*' may be escaped
369 * by a \. You should escape all '*' characters, do not rely on the
370 * current implementation which only replaces the first unescaped '*'.
371 * If no "*" is present, the extra string is just appended to data string.
372 * Pango mark up is accepted in left and right parts.
373 * Any \n is replaced by a newline
375 * "<i>*</i>\n" -> data is displayed in italics ended with a newline
376 * "\n" -> ended with newline
377 * "ISO *" -> prefix data with "ISO " (ie. "ISO 100")
378 * "\**\*" -> prefix data with a star, and append a star (ie. "*100*")
379 * "\\*" -> prefix data with an anti slash (ie "\100")
380 * "Collection <b>*</b>\n" -> display data in bold prefixed by "Collection " and a newline is appended
382 * FIXME: using background / foreground colors lead to weird results.
386 gchar *right = extra;
388 guint len = strlen(extra);
390 /* Search for left and right parts and unescape characters */
391 for (p = extra; *p; p++, len--)
396 memmove(p+1, p+2, --len);
399 else if (p[1] != '\0')
400 memmove(p, p+1, len--); // includes \0
402 else if (p[0] == '*' && !left)
408 if (left) right[-1] = '\0';
410 new_data = g_strdup_printf("%s%s%s", left ? left : "", data, right);
417 g_string_erase(new, pos, end-start+1);
422 /* insert separator */
423 g_string_insert(new, pos, sep);
425 want_separator = FALSE;
428 g_string_insert(new, pos, data);
432 if (pos-prev >= 1 && new->str[pos] == imp)
434 /* pipe character is replaced by a separator, delete it
435 * and raise a flag if needed */
436 g_string_erase(new, pos--, 1);
437 want_separator |= (data && *data);
440 if (new->str[pos] == '\n') want_separator = FALSE;
448 /* search and destroy empty lines */
450 while ((start = strchr(end, '\n')))
453 while (*++(end) == '\n')
455 g_string_erase(new, start-new->str, end-start-1);
458 g_strchomp(new->str);
461 g_string_free(new, FALSE);
472 static void osd_template_insert(GHashTable *vars, gchar *keyword, gchar *value, OsdTemplateFlags flags)
476 g_hash_table_insert(vars, keyword, g_strdup(""));
480 if (flags & OSDT_NO_DUP)
482 g_hash_table_insert(vars, keyword, value);
487 g_hash_table_insert(vars, keyword, g_strdup(value));
490 if (flags & OSDT_FREE) g_free((gpointer) value);
493 static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
495 GdkPixbuf *pixbuf = NULL;
501 const HistMap *histmap = NULL;
502 ImageWindow *imd = osd->imd;
503 FileData *fd = image_get_fd(imd);
504 PangoFontDescription *font_desc;
506 if (!fd) return NULL;
508 name = image_get_name(imd);
516 vars = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
518 cd = image_get_collection(imd, &info);
521 t = g_list_length(cd->list);
522 n = g_list_index(cd->list, info) + 1;
525 if (file_extension_match(cd->name, GQ_COLLECTION_EXT))
526 osd_template_insert(vars, "collection", remove_extension_from_path(cd->name), OSDT_FREE);
528 osd_template_insert(vars, "collection", cd->name, OSDT_NONE);
532 osd_template_insert(vars, "collection", _("Untitled"), OSDT_NONE);
537 LayoutWindow *lw = layout_find_by_image(imd);
542 n = g_list_length(lw->slideshow->list_done);
543 t = n + g_list_length(lw->slideshow->list);
548 t = layout_list_count(lw, NULL);
549 n = layout_list_get_index(lw, image_get_fd(lw->image)) + 1;
552 else if (view_window_find_image(imd, &n, &t))
565 osd_template_insert(vars, "collection", NULL, OSDT_NONE);
568 osd_template_insert(vars, "number", g_strdup_printf("%d", n), OSDT_NO_DUP);
569 osd_template_insert(vars, "total", g_strdup_printf("%d", t), OSDT_NO_DUP);
570 osd_template_insert(vars, "name", (gchar *) name, OSDT_NONE);
571 osd_template_insert(vars, "date", imd->image_fd ? ((gchar *) text_from_time(imd->image_fd->date)) : "", OSDT_NONE);
572 osd_template_insert(vars, "size", imd->image_fd ? (text_from_size_abrev(imd->image_fd->size)) : g_strdup(""), OSDT_FREE);
573 osd_template_insert(vars, "zoom", image_zoom_get_as_text(imd), OSDT_FREE);
578 GdkPixbuf *load_pixbuf = image_loader_get_pixbuf(imd->il);
580 if (imd->delay_flip &&
581 imd->il && load_pixbuf &&
582 image_get_pixbuf(imd) != load_pixbuf)
584 w = gdk_pixbuf_get_width(load_pixbuf);
585 h = gdk_pixbuf_get_height(load_pixbuf);
589 image_get_image_size(imd, &w, &h);
593 osd_template_insert(vars, "width", g_strdup_printf("%d", w), OSDT_NO_DUP);
594 osd_template_insert(vars, "height", g_strdup_printf("%d", h), OSDT_NO_DUP);
595 osd_template_insert(vars, "res", g_strdup_printf("%d × %d", w, h), OSDT_FREE);
599 osd_template_insert(vars, "width", NULL, OSDT_NONE);
600 osd_template_insert(vars, "height", NULL, OSDT_NONE);
601 osd_template_insert(vars, "res", NULL, OSDT_NONE);
604 text = image_osd_mkinfo(options->image_overlay.template_string, imd, vars);
605 g_hash_table_destroy(vars);
608 /* When does this occur ?? */
609 text = g_markup_escape_text(_("Untitled"), -1);
612 with_hist = ((osd->show & OSD_SHOW_HISTOGRAM) && osd->histogram);
615 histmap = histmap_get(imd->image_fd);
618 histmap_start_idle(imd->image_fd);
625 gint active_marks = 0;
629 for (mark = 0; mark < FILEDATA_MARKS_SIZE; mark++)
631 active_marks += file_data_get_mark(fd, mark);
634 if (active_marks > 0)
636 GString *buf = g_string_sized_new(FILEDATA_MARKS_SIZE * 2);
638 for (mark = 0; mark < FILEDATA_MARKS_SIZE; mark++)
640 g_string_append_printf(buf, file_data_get_mark(fd, mark) ? " <span background='#FF00FF'>%c</span>" : " %c", '1' + mark);
644 text2 = g_strdup_printf("%s\n%s", text, buf->str);
646 text2 = g_strdup(buf->str);
647 g_string_free(buf, TRUE);
654 gchar *escaped_histogram_label = g_markup_escape_text(histogram_label(osd->histogram), -1);
656 text2 = g_strdup_printf("%s\n%s", text, escaped_histogram_label);
658 text2 = g_strdup(escaped_histogram_label);
659 g_free(escaped_histogram_label);
665 font_desc = pango_font_description_from_string(options->image_overlay.font);
666 layout = gtk_widget_create_pango_layout(imd->pr, NULL);
667 pango_layout_set_font_description(layout, font_desc);
669 pango_layout_set_markup(layout, text, -1);
672 pango_layout_get_pixel_size(layout, &width, &height);
673 /* with empty text width is set to 0, but not height) */
676 else if (height == 0)
678 if (width > 0) width += 10;
679 if (height > 0) height += 10;
683 if (width < HISTOGRAM_WIDTH + 10) width = HISTOGRAM_WIDTH + 10;
684 height += HISTOGRAM_HEIGHT + 5;
687 if (width > 0 && height > 0)
689 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
690 pixbuf_set_rect_fill(pixbuf, 3, 3, width-6, height-6, options->image_overlay.background_red, options->image_overlay.background_green,
691 options->image_overlay.background_blue, options->image_overlay.background_alpha);
692 pixbuf_set_rect(pixbuf, 0, 0, width, height, 240, 240, 240, 80, 1, 1, 1, 1);
693 pixbuf_set_rect(pixbuf, 1, 1, width-2, height-2, 240, 240, 240, 130, 1, 1, 1, 1);
694 pixbuf_set_rect(pixbuf, 2, 2, width-4, height-4, 240, 240, 240, 180, 1, 1, 1, 1);
695 pixbuf_pixel_set(pixbuf, 0, 0, 0, 0, 0, 0);
696 pixbuf_pixel_set(pixbuf, width - 1, 0, 0, 0, 0, 0);
697 pixbuf_pixel_set(pixbuf, 0, height - 1, 0, 0, 0, 0);
698 pixbuf_pixel_set(pixbuf, width - 1, height - 1, 0, 0, 0, 0);
703 gint y = height - HISTOGRAM_HEIGHT - 5;
706 pixbuf_set_rect_fill(pixbuf, x, y, w, HISTOGRAM_HEIGHT, 220, 220, 220, 210);
707 histogram_draw(osd->histogram, histmap, pixbuf, x, y, w, HISTOGRAM_HEIGHT);
709 pixbuf_draw_layout(pixbuf, layout, imd->pr, 5, 5, options->image_overlay.text_red, options->image_overlay.text_green,
710 options->image_overlay.text_blue, options->image_overlay.text_alpha);
713 g_object_unref(G_OBJECT(layout));
718 static GdkPixbuf *image_osd_icon_pixbuf(ImageOSDFlag flag)
720 static GdkPixbuf **icons = NULL;
721 GdkPixbuf *icon = NULL;
723 if (!icons) icons = g_new0(GdkPixbuf *, IMAGE_OSD_COUNT);
724 if (icons[flag]) return icons[flag];
726 if (osd_icons[flag].key)
728 icon = pixbuf_inline(osd_icons[flag].key);
733 icon = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 24, 24);
734 pixbuf_set_rect_fill(icon, 1, 1, 22, 22, 255, 255, 255, 200);
735 pixbuf_set_rect(icon, 0, 0, 24, 24, 0, 0, 0, 128, 1, 1, 1, 1);
738 case IMAGE_OSD_ROTATE_AUTO:
739 pixbuf_set_rect(icon, 3, 8, 11, 12,
742 pixbuf_draw_triangle(icon, 14, 3, 6, 12,
743 20, 9, 14, 15, 14, 3,
746 case IMAGE_OSD_ROTATE_USER:
748 case IMAGE_OSD_COLOR:
749 pixbuf_set_rect_fill(icon, 3, 3, 18, 6, 200, 0, 0, 255);
750 pixbuf_set_rect_fill(icon, 3, 9, 18, 6, 0, 200, 0, 255);
751 pixbuf_set_rect_fill(icon, 3, 15, 18, 6, 0, 0, 200, 255);
753 case IMAGE_OSD_FIRST:
754 pixbuf_set_rect(icon, 3, 3, 18, 18, 0, 0, 0, 200, 3, 3, 3, 0);
755 pixbuf_draw_triangle(icon, 6, 5, 12, 6,
756 12, 5, 18, 11, 6, 11,
760 pixbuf_set_rect(icon, 3, 3, 18, 18, 0, 0, 0, 200, 3, 3, 0, 3);
761 pixbuf_draw_triangle(icon, 6, 12, 12, 6,
762 12, 18, 6, 12, 18, 12,
766 pixbuf_set_rect_fill(icon, 11, 3, 3, 12, 0, 0, 0, 255);
767 pixbuf_set_rect_fill(icon, 11, 17, 3, 3, 0, 0, 0, 255);
779 static gint image_overlay_add(ImageWindow *imd, GdkPixbuf *pixbuf, gint x, gint y,
780 OverlayRendererFlags flags)
782 return pixbuf_renderer_overlay_add((PixbufRenderer *)imd->pr, pixbuf, x, y, flags);
785 static void image_overlay_set(ImageWindow *imd, gint id, GdkPixbuf *pixbuf, gint x, gint y)
787 pixbuf_renderer_overlay_set((PixbufRenderer *)imd->pr, id, pixbuf, x, y);
790 static void image_overlay_remove(ImageWindow *imd, gint id)
792 pixbuf_renderer_overlay_remove((PixbufRenderer *)imd->pr, id);
795 static void image_osd_icon_show(OverlayStateData *osd, ImageOSDFlag flag)
799 if (osd->icon_id[flag]) return;
801 pixbuf = image_osd_icon_pixbuf(flag);
804 osd->icon_id[flag] = image_overlay_add(osd->imd, pixbuf,
805 osd_icons[flag].x, osd_icons[flag].y,
809 static void image_osd_icon_hide(OverlayStateData *osd, ImageOSDFlag flag)
811 if (osd->icon_id[flag])
813 image_overlay_remove(osd->imd, osd->icon_id[flag]);
814 osd->icon_id[flag] = 0;
818 static void image_osd_icons_reset_time(OverlayStateData *osd)
822 for (i = 0; i < IMAGE_OSD_COUNT; i++)
824 if (osd_icons[i].reset)
826 osd->icon_time[i] = 0;
831 static void image_osd_icons_update(OverlayStateData *osd)
835 for (i = 0; i < IMAGE_OSD_COUNT; i++)
837 if (osd->icon_time[i] > 0)
839 image_osd_icon_show(osd, i);
843 image_osd_icon_hide(osd, i);
848 static void image_osd_icons_hide(OverlayStateData *osd)
852 for (i = 0; i < IMAGE_OSD_COUNT; i++)
854 image_osd_icon_hide(osd, i);
858 static void image_osd_info_show(OverlayStateData *osd, GdkPixbuf *pixbuf)
860 if (osd->ovl_info == 0)
862 osd->ovl_info = image_overlay_add(osd->imd, pixbuf, osd->x, osd->y, OVL_RELATIVE);
866 image_overlay_set(osd->imd, osd->ovl_info, pixbuf, osd->x, osd->y);
870 static void image_osd_info_hide(OverlayStateData *osd)
872 if (osd->ovl_info == 0) return;
874 image_overlay_remove(osd->imd, osd->ovl_info);
878 static gboolean image_osd_update_cb(gpointer data)
880 OverlayStateData *osd = data;
882 if (osd->show & OSD_SHOW_INFO)
884 /* redraw when the image was changed,
885 with histogram we have to redraw also when loading is finished */
886 if (osd->changed_states & IMAGE_STATE_IMAGE ||
887 (osd->changed_states & IMAGE_STATE_LOADING && osd->show & OSD_SHOW_HISTOGRAM) ||
888 osd->notify & NOTIFY_HISTMAP)
892 pixbuf = image_osd_info_render(osd);
895 image_osd_info_show(osd, pixbuf);
896 g_object_unref(pixbuf);
900 image_osd_info_hide(osd);
906 image_osd_info_hide(osd);
909 if (osd->show & OSD_SHOW_STATUS)
911 if (osd->changed_states & IMAGE_STATE_IMAGE)
912 image_osd_icons_reset_time(osd);
914 if (osd->changed_states & IMAGE_STATE_COLOR_ADJ)
916 osd->icon_time[IMAGE_OSD_COLOR] = IMAGE_OSD_DEFAULT_DURATION + 1;
917 image_osd_timer_schedule(osd);
920 if (osd->changed_states & IMAGE_STATE_ROTATE_AUTO)
924 if (osd->imd->state & IMAGE_STATE_ROTATE_AUTO)
927 if (!osd->imd->cm) n += IMAGE_OSD_DEFAULT_DURATION;
930 osd->icon_time[IMAGE_OSD_ROTATE_AUTO] = n;
931 image_osd_timer_schedule(osd);
934 image_osd_icons_update(osd);
938 image_osd_icons_hide(osd);
941 osd->changed_states = IMAGE_STATE_NONE;
947 static void image_osd_update_schedule(OverlayStateData *osd, gboolean force)
949 if (force) osd->changed_states |= IMAGE_STATE_IMAGE;
953 osd->idle_id = g_idle_add_full(G_PRIORITY_HIGH, image_osd_update_cb, osd, NULL);
957 void image_osd_update(ImageWindow *imd)
959 OverlayStateData *osd = image_get_osd_data(imd);
963 image_osd_update_schedule(osd, TRUE);
966 static gboolean image_osd_timer_cb(gpointer data)
968 OverlayStateData *osd = data;
969 gboolean done = TRUE;
970 gboolean changed = FALSE;
973 for (i = 0; i < IMAGE_OSD_COUNT; i++)
975 if (osd->icon_time[i] > 1)
978 if (osd->icon_time[i] < 2)
980 osd->icon_time[i] = 0;
990 if (changed) image_osd_update_schedule(osd, FALSE);
1001 static void image_osd_timer_schedule(OverlayStateData *osd)
1005 osd->timer_id = g_timeout_add(100, image_osd_timer_cb, osd);
1009 static void image_osd_state_cb(ImageWindow *imd, ImageState state, gpointer data)
1011 OverlayStateData *osd = data;
1013 osd->changed_states |= state;
1014 image_osd_update_schedule(osd, FALSE);
1017 static void image_osd_notify_cb(FileData *fd, NotifyType type, gpointer data)
1019 OverlayStateData *osd = data;
1021 if ((type & (NOTIFY_HISTMAP)) && osd->imd && fd == osd->imd->image_fd)
1023 DEBUG_1("Notify osd: %s %04x", fd->path, type);
1024 osd->notify |= type;
1025 image_osd_update_schedule(osd, FALSE);
1030 static void image_osd_free(OverlayStateData *osd)
1034 if (osd->idle_id) g_source_remove(osd->idle_id);
1035 if (osd->timer_id) g_source_remove(osd->timer_id);
1037 file_data_unregister_notify_func(image_osd_notify_cb, osd);
1041 image_set_osd_data(osd->imd, NULL);
1042 g_signal_handler_disconnect(osd->imd->pr, osd->destroy_id);
1044 image_set_state_func(osd->imd, NULL, NULL);
1046 image_osd_info_hide(osd);
1047 image_osd_icons_hide(osd);
1050 if (osd->histogram) histogram_free(osd->histogram);
1055 static void image_osd_destroy_cb(GtkWidget *widget, gpointer data)
1057 OverlayStateData *osd = data;
1060 image_osd_free(osd);
1063 static void image_osd_enable(ImageWindow *imd, OsdShowFlags show)
1065 OverlayStateData *osd = image_get_osd_data(imd);
1069 osd = g_new0(OverlayStateData, 1);
1071 osd->show = OSD_SHOW_NOTHING;
1072 osd->x = options->image_overlay.x;
1073 osd->y = options->image_overlay.y;
1075 osd->histogram = histogram_new();
1077 osd->destroy_id = g_signal_connect(G_OBJECT(imd->pr), "destroy",
1078 G_CALLBACK(image_osd_destroy_cb), osd);
1079 image_set_osd_data(imd, osd);
1081 image_set_state_func(osd->imd, image_osd_state_cb, osd);
1082 file_data_register_notify_func(image_osd_notify_cb, osd, NOTIFY_PRIORITY_LOW);
1085 if (show & OSD_SHOW_STATUS)
1086 image_osd_icon(imd, IMAGE_OSD_ICON, -1);
1088 if (show != osd->show)
1089 image_osd_update_schedule(osd, TRUE);
1094 void image_osd_set(ImageWindow *imd, OsdShowFlags show)
1098 image_osd_enable(imd, show);
1101 OsdShowFlags image_osd_get(ImageWindow *imd)
1103 OverlayStateData *osd = image_get_osd_data(imd);
1105 return osd ? osd->show : OSD_SHOW_NOTHING;
1108 Histogram *image_osd_get_histogram(ImageWindow *imd)
1110 OverlayStateData *osd = image_get_osd_data(imd);
1112 return osd ? osd->histogram : NULL;
1115 void image_osd_copy_status(ImageWindow *src, ImageWindow *dest)
1117 Histogram *h_src, *h_dest;
1118 image_osd_set(dest, image_osd_get(src));
1120 h_src = image_osd_get_histogram(src);
1121 h_dest = image_osd_get_histogram(dest);
1123 h_dest->histogram_mode = h_src->histogram_mode;
1124 h_dest->histogram_channel = h_src->histogram_channel;
1131 2+ = show for duration tenths of a second
1132 -1 = use default duration
1134 void image_osd_icon(ImageWindow *imd, ImageOSDFlag flag, gint duration)
1136 OverlayStateData *osd = image_get_osd_data(imd);
1140 if (flag >= IMAGE_OSD_COUNT) return;
1141 if (duration < 0) duration = IMAGE_OSD_DEFAULT_DURATION;
1142 if (duration > 1) duration += 1;
1144 osd->icon_time[flag] = duration;
1146 image_osd_update_schedule(osd, FALSE);
1147 image_osd_timer_schedule(osd);
1149 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */