2 * Copyright (C) 2006 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "image-overlay.h"
28 #include "histogram.h"
33 #include "pixbuf-renderer.h"
34 #include "pixbuf_util.h"
35 #include "ui_fileops.h"
36 #include "image-load.h"
40 *----------------------------------------------------------------------------
42 *----------------------------------------------------------------------------
46 typedef struct _OverlayStateData OverlayStateData;
47 struct _OverlayStateData {
49 ImageState changed_states;
61 gint icon_time[IMAGE_OSD_COUNT];
62 gint icon_id[IMAGE_OSD_COUNT];
64 guint idle_id; /* event source id */
65 guint timer_id; /* event source id */
70 typedef struct _OSDIcon OSDIcon;
72 gboolean reset; /* reset on new image */
73 gint x; /* x, y offset */
75 gchar *key; /* inline pixbuf */
78 static OSDIcon osd_icons[] = {
79 { TRUE, 0, 0, NULL }, /* none */
80 { TRUE, -10, -10, NULL }, /* auto rotated */
81 { TRUE, -10, -10, NULL }, /* user rotated */
82 { TRUE, -40, -10, NULL }, /* color embedded */
83 { TRUE, -70, -10, NULL }, /* first image */
84 { TRUE, -70, -10, NULL }, /* last image */
85 { FALSE, -70, -10, NULL }, /* osd enabled */
89 #define OSD_DATA "overlay-data"
91 #define IMAGE_OSD_DEFAULT_DURATION 30
93 #define HISTOGRAM_HEIGHT 140
94 #define HISTOGRAM_WIDTH 256
96 static void image_osd_timer_schedule(OverlayStateData *osd);
98 void set_image_overlay_template_string(gchar **template_string, const gchar *value)
100 g_assert(template_string);
102 g_free(*template_string);
103 *template_string = g_strdup(value);
107 void set_default_image_overlay_template_string(gchar **template_string)
109 set_image_overlay_template_string(template_string, DEFAULT_OVERLAY_INFO);
112 void set_image_overlay_font_string(gchar **font_string, const gchar *value)
114 g_assert(font_string);
116 g_free(*font_string);
117 *font_string = g_strdup(value);
120 static OverlayStateData *image_get_osd_data(ImageWindow *imd)
122 OverlayStateData *osd;
124 if (!imd) return NULL;
128 osd = g_object_get_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA");
132 static void image_set_osd_data(ImageWindow *imd, OverlayStateData *osd)
136 g_object_set_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA", osd);
140 *----------------------------------------------------------------------------
142 *----------------------------------------------------------------------------
146 void image_osd_histogram_toggle_channel(ImageWindow *imd)
148 OverlayStateData *osd = image_get_osd_data(imd);
150 if (!osd || !osd->histogram) return;
152 histogram_toggle_channel(osd->histogram);
153 image_osd_update(imd);
156 void image_osd_histogram_toggle_mode(ImageWindow *imd)
158 OverlayStateData *osd = image_get_osd_data(imd);
160 if (!osd || !osd->histogram) return;
162 histogram_toggle_mode(osd->histogram);
163 image_osd_update(imd);
166 void image_osd_histogram_set_channel(ImageWindow *imd, gint chan)
168 OverlayStateData *osd = image_get_osd_data(imd);
170 if (!osd || !osd->histogram) return;
172 histogram_set_channel(osd->histogram, chan);
173 image_osd_update(imd);
176 void image_osd_histogram_set_mode(ImageWindow *imd, gint mode)
178 OverlayStateData *osd = image_get_osd_data(imd);
180 if (!osd || !osd->histogram) return;
182 histogram_set_mode(osd->histogram, mode);
183 image_osd_update(imd);
186 gint image_osd_histogram_get_channel(ImageWindow *imd)
188 OverlayStateData *osd = image_get_osd_data(imd);
190 if (!osd || !osd->histogram) return HCHAN_DEFAULT;
192 return histogram_get_channel(osd->histogram);
195 gint image_osd_histogram_get_mode(ImageWindow *imd)
197 OverlayStateData *osd = image_get_osd_data(imd);
199 if (!osd || !osd->histogram) return 0;
201 return histogram_get_mode(osd->histogram);
204 void image_osd_toggle(ImageWindow *imd)
210 show = image_osd_get(imd);
211 if (show == OSD_SHOW_NOTHING)
213 image_osd_set(imd, OSD_SHOW_INFO | OSD_SHOW_STATUS);
218 if (show & OSD_SHOW_HISTOGRAM)
220 image_osd_set(imd, OSD_SHOW_NOTHING);
224 image_osd_set(imd, show | OSD_SHOW_HISTOGRAM);
229 static gchar *keywords_to_string(FileData *fd)
232 GString *kwstr = NULL;
237 keywords = metadata_read_list(fd, KEYWORD_KEY, METADATA_PLAIN);
241 GList *work = keywords;
245 gchar *kw = work->data;
250 kwstr = g_string_new("");
252 g_string_append(kwstr, ", ");
254 g_string_append(kwstr, kw);
256 string_list_free(keywords);
262 g_string_free(kwstr, FALSE);
268 static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *vars)
270 gchar delim = '%', imp = '|', sep[] = " - ";
273 gboolean want_separator = FALSE;
278 if (!str || !*str) return g_strdup("");
280 new = g_string_new(str);
288 gchar *limpos = NULL;
290 gchar *extrapos = NULL;
293 start = strchr(new->str + (prev + 1), delim);
296 end = strchr(start+1, delim);
300 /* Search for optionnal modifiers
301 * %name:99:extra% -> name = "name", limit=99, extra = "extra"
303 for (p = start + 1; p < end; p++)
307 if (g_ascii_isdigit(p[1]) && !limpos)
310 if (!trunc) trunc = p;
315 if (!trunc) trunc = p;
322 limit = (guint) atoi(limpos);
325 extra = g_strndup(extrapos, end - extrapos);
327 name = g_strndup(start+1, (trunc ? trunc : end)-start-1);
328 pos = start - new->str;
331 if (strcmp(name, "keywords") == 0)
333 data = keywords_to_string(imd->image_fd);
335 else if (strcmp(name, "comment") == 0)
337 data = metadata_read_string(imd->image_fd, COMMENT_KEY, METADATA_PLAIN);
339 else if (strcmp(name, "imagecomment") == 0)
341 data = exif_get_image_comment(imd->image_fd);
344 else if (strncmp(name, "lua/", 4) == 0)
347 tmp = strchr(name+4, '/');
351 data = lua_callvalue(imd->image_fd, name+4, tmp+1);
356 data = g_strdup(g_hash_table_lookup(vars, name));
358 data = metadata_read_string(imd->image_fd, name, METADATA_FORMATTED);
361 if (data && *data && limit > 0 && strlen(data) > limit + 3)
363 gchar *new_data = g_strdup_printf("%-*.*s...", limit, limit, data);
370 /* Since we use pango markup to display, we need to escape here */
371 gchar *escaped = g_markup_escape_text(data, -1);
380 /* Display data between left and right parts of extra string
381 * the data is expressed by a '*' character. A '*' may be escaped
382 * by a \. You should escape all '*' characters, do not rely on the
383 * current implementation which only replaces the first unescaped '*'.
384 * If no "*" is present, the extra string is just appended to data string.
385 * Pango mark up is accepted in left and right parts.
386 * Any \n is replaced by a newline
388 * "<i>*</i>\n" -> data is displayed in italics ended with a newline
389 * "\n" -> ended with newline
390 * "ISO *" -> prefix data with "ISO " (ie. "ISO 100")
391 * "\**\*" -> prefix data with a star, and append a star (ie. "*100*")
392 * "\\*" -> prefix data with an anti slash (ie "\100")
393 * "Collection <b>*</b>\n" -> display data in bold prefixed by "Collection " and a newline is appended
395 * FIXME: using background / foreground colors lead to weird results.
399 gchar *right = extra;
401 guint len = strlen(extra);
403 /* Search for left and right parts and unescape characters */
404 for (p = extra; *p; p++, len--)
409 memmove(p+1, p+2, --len);
412 else if (p[1] != '\0')
413 memmove(p, p+1, len--); // includes \0
415 else if (p[0] == '*' && !left)
421 if (left) right[-1] = '\0';
423 new_data = g_strdup_printf("%s%s%s", left ? left : "", data, right);
430 g_string_erase(new, pos, end-start+1);
435 /* insert separator */
436 g_string_insert(new, pos, sep);
438 want_separator = FALSE;
441 g_string_insert(new, pos, data);
445 if (pos-prev >= 1 && new->str[pos] == imp)
447 /* pipe character is replaced by a separator, delete it
448 * and raise a flag if needed */
449 g_string_erase(new, pos--, 1);
450 want_separator |= (data && *data);
453 if (new->str[pos] == '\n') want_separator = FALSE;
461 /* search and destroy empty lines */
463 while ((start = strchr(end, '\n')))
466 while (*++(end) == '\n')
468 g_string_erase(new, start-new->str, end-start-1);
471 g_strchomp(new->str);
474 g_string_free(new, FALSE);
485 static void osd_template_insert(GHashTable *vars, gchar *keyword, gchar *value, OsdTemplateFlags flags)
489 g_hash_table_insert(vars, keyword, g_strdup(""));
493 if (flags & OSDT_NO_DUP)
495 g_hash_table_insert(vars, keyword, value);
500 g_hash_table_insert(vars, keyword, g_strdup(value));
503 if (flags & OSDT_FREE) g_free((gpointer) value);
506 static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
508 GdkPixbuf *pixbuf = NULL;
514 const HistMap *histmap = NULL;
515 ImageWindow *imd = osd->imd;
516 FileData *fd = image_get_fd(imd);
517 PangoFontDescription *font_desc;
519 if (!fd) return NULL;
521 name = image_get_name(imd);
529 vars = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
531 cd = image_get_collection(imd, &info);
534 t = g_list_length(cd->list);
535 n = g_list_index(cd->list, info) + 1;
538 if (file_extension_match(cd->name, GQ_COLLECTION_EXT))
539 osd_template_insert(vars, "collection", remove_extension_from_path(cd->name), OSDT_FREE);
541 osd_template_insert(vars, "collection", cd->name, OSDT_NONE);
545 osd_template_insert(vars, "collection", _("Untitled"), OSDT_NONE);
550 LayoutWindow *lw = layout_find_by_image(imd);
555 n = g_list_length(lw->slideshow->list_done);
556 t = n + g_list_length(lw->slideshow->list);
561 t = layout_list_count(lw, NULL);
562 n = layout_list_get_index(lw, image_get_fd(lw->image)) + 1;
565 else if (view_window_find_image(imd, &n, &t))
578 osd_template_insert(vars, "collection", NULL, OSDT_NONE);
581 osd_template_insert(vars, "number", g_strdup_printf("%d", n), OSDT_NO_DUP);
582 osd_template_insert(vars, "total", g_strdup_printf("%d", t), OSDT_NO_DUP);
583 osd_template_insert(vars, "name", (gchar *) name, OSDT_NONE);
584 osd_template_insert(vars, "date", imd->image_fd ? ((gchar *) text_from_time(imd->image_fd->date)) : "", OSDT_NONE);
585 osd_template_insert(vars, "size", imd->image_fd ? (text_from_size_abrev(imd->image_fd->size)) : g_strdup(""), OSDT_FREE);
586 osd_template_insert(vars, "zoom", image_zoom_get_as_text(imd), OSDT_FREE);
591 GdkPixbuf *load_pixbuf = image_loader_get_pixbuf(imd->il);
593 if (imd->delay_flip &&
594 imd->il && load_pixbuf &&
595 image_get_pixbuf(imd) != load_pixbuf)
597 w = gdk_pixbuf_get_width(load_pixbuf);
598 h = gdk_pixbuf_get_height(load_pixbuf);
602 image_get_image_size(imd, &w, &h);
606 osd_template_insert(vars, "width", g_strdup_printf("%d", w), OSDT_NO_DUP);
607 osd_template_insert(vars, "height", g_strdup_printf("%d", h), OSDT_NO_DUP);
608 osd_template_insert(vars, "res", g_strdup_printf("%d × %d", w, h), OSDT_FREE);
612 osd_template_insert(vars, "width", NULL, OSDT_NONE);
613 osd_template_insert(vars, "height", NULL, OSDT_NONE);
614 osd_template_insert(vars, "res", NULL, OSDT_NONE);
617 text = image_osd_mkinfo(options->image_overlay.template_string, imd, vars);
618 g_hash_table_destroy(vars);
621 /* When does this occur ?? */
622 text = g_markup_escape_text(_("Untitled"), -1);
625 with_hist = ((osd->show & OSD_SHOW_HISTOGRAM) && osd->histogram);
628 histmap = histmap_get(imd->image_fd);
631 histmap_start_idle(imd->image_fd);
638 gint active_marks = 0;
642 for (mark = 0; mark < FILEDATA_MARKS_SIZE; mark++)
644 active_marks += file_data_get_mark(fd, mark);
647 if (active_marks > 0)
649 GString *buf = g_string_sized_new(FILEDATA_MARKS_SIZE * 2);
651 for (mark = 0; mark < FILEDATA_MARKS_SIZE; mark++)
653 g_string_append_printf(buf, file_data_get_mark(fd, mark) ? " <span background='#FF00FF'>%c</span>" : " %c", '1' + mark);
657 text2 = g_strdup_printf("%s\n%s", text, buf->str);
659 text2 = g_strdup(buf->str);
660 g_string_free(buf, TRUE);
667 gchar *escaped_histogram_label = g_markup_escape_text(histogram_label(osd->histogram), -1);
669 text2 = g_strdup_printf("%s\n%s", text, escaped_histogram_label);
671 text2 = g_strdup(escaped_histogram_label);
672 g_free(escaped_histogram_label);
678 font_desc = pango_font_description_from_string(options->image_overlay.font);
679 layout = gtk_widget_create_pango_layout(imd->pr, NULL);
680 pango_layout_set_font_description(layout, font_desc);
682 pango_layout_set_markup(layout, text, -1);
685 pango_layout_get_pixel_size(layout, &width, &height);
686 /* with empty text width is set to 0, but not height) */
689 else if (height == 0)
691 if (width > 0) width += 10;
692 if (height > 0) height += 10;
696 if (width < HISTOGRAM_WIDTH + 10) width = HISTOGRAM_WIDTH + 10;
697 height += HISTOGRAM_HEIGHT + 5;
700 if (width > 0 && height > 0)
702 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
703 pixbuf_set_rect_fill(pixbuf, 3, 3, width-6, height-6, options->image_overlay.background_red, options->image_overlay.background_green,
704 options->image_overlay.background_blue, options->image_overlay.background_alpha);
705 pixbuf_set_rect(pixbuf, 0, 0, width, height, 240, 240, 240, 80, 1, 1, 1, 1);
706 pixbuf_set_rect(pixbuf, 1, 1, width-2, height-2, 240, 240, 240, 130, 1, 1, 1, 1);
707 pixbuf_set_rect(pixbuf, 2, 2, width-4, height-4, 240, 240, 240, 180, 1, 1, 1, 1);
708 pixbuf_pixel_set(pixbuf, 0, 0, 0, 0, 0, 0);
709 pixbuf_pixel_set(pixbuf, width - 1, 0, 0, 0, 0, 0);
710 pixbuf_pixel_set(pixbuf, 0, height - 1, 0, 0, 0, 0);
711 pixbuf_pixel_set(pixbuf, width - 1, height - 1, 0, 0, 0, 0);
716 gint y = height - HISTOGRAM_HEIGHT - 5;
719 pixbuf_set_rect_fill(pixbuf, x, y, w, HISTOGRAM_HEIGHT, 220, 220, 220, 210);
720 histogram_draw(osd->histogram, histmap, pixbuf, x, y, w, HISTOGRAM_HEIGHT);
722 pixbuf_draw_layout(pixbuf, layout, imd->pr, 5, 5, options->image_overlay.text_red, options->image_overlay.text_green,
723 options->image_overlay.text_blue, options->image_overlay.text_alpha);
726 g_object_unref(G_OBJECT(layout));
731 static GdkPixbuf *image_osd_icon_pixbuf(ImageOSDFlag flag)
733 static GdkPixbuf **icons = NULL;
734 GdkPixbuf *icon = NULL;
736 if (!icons) icons = g_new0(GdkPixbuf *, IMAGE_OSD_COUNT);
737 if (icons[flag]) return icons[flag];
739 if (osd_icons[flag].key)
741 icon = pixbuf_inline(osd_icons[flag].key);
746 icon = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 24, 24);
747 pixbuf_set_rect_fill(icon, 1, 1, 22, 22, 255, 255, 255, 200);
748 pixbuf_set_rect(icon, 0, 0, 24, 24, 0, 0, 0, 128, 1, 1, 1, 1);
751 case IMAGE_OSD_ROTATE_AUTO:
752 pixbuf_set_rect(icon, 3, 8, 11, 12,
755 pixbuf_draw_triangle(icon, 14, 3, 6, 12,
756 20, 9, 14, 15, 14, 3,
759 case IMAGE_OSD_ROTATE_USER:
761 case IMAGE_OSD_COLOR:
762 pixbuf_set_rect_fill(icon, 3, 3, 18, 6, 200, 0, 0, 255);
763 pixbuf_set_rect_fill(icon, 3, 9, 18, 6, 0, 200, 0, 255);
764 pixbuf_set_rect_fill(icon, 3, 15, 18, 6, 0, 0, 200, 255);
766 case IMAGE_OSD_FIRST:
767 pixbuf_set_rect(icon, 3, 3, 18, 18, 0, 0, 0, 200, 3, 3, 3, 0);
768 pixbuf_draw_triangle(icon, 6, 5, 12, 6,
769 12, 5, 18, 11, 6, 11,
773 pixbuf_set_rect(icon, 3, 3, 18, 18, 0, 0, 0, 200, 3, 3, 0, 3);
774 pixbuf_draw_triangle(icon, 6, 12, 12, 6,
775 12, 18, 6, 12, 18, 12,
779 pixbuf_set_rect_fill(icon, 11, 3, 3, 12, 0, 0, 0, 255);
780 pixbuf_set_rect_fill(icon, 11, 17, 3, 3, 0, 0, 0, 255);
792 static gint image_overlay_add(ImageWindow *imd, GdkPixbuf *pixbuf, gint x, gint y,
793 OverlayRendererFlags flags)
795 return pixbuf_renderer_overlay_add((PixbufRenderer *)imd->pr, pixbuf, x, y, flags);
798 static void image_overlay_set(ImageWindow *imd, gint id, GdkPixbuf *pixbuf, gint x, gint y)
800 pixbuf_renderer_overlay_set((PixbufRenderer *)imd->pr, id, pixbuf, x, y);
803 static void image_overlay_remove(ImageWindow *imd, gint id)
805 pixbuf_renderer_overlay_remove((PixbufRenderer *)imd->pr, id);
808 static void image_osd_icon_show(OverlayStateData *osd, ImageOSDFlag flag)
812 if (osd->icon_id[flag]) return;
814 pixbuf = image_osd_icon_pixbuf(flag);
817 osd->icon_id[flag] = image_overlay_add(osd->imd, pixbuf,
818 osd_icons[flag].x, osd_icons[flag].y,
822 static void image_osd_icon_hide(OverlayStateData *osd, ImageOSDFlag flag)
824 if (osd->icon_id[flag])
826 image_overlay_remove(osd->imd, osd->icon_id[flag]);
827 osd->icon_id[flag] = 0;
831 static void image_osd_icons_reset_time(OverlayStateData *osd)
835 for (i = 0; i < IMAGE_OSD_COUNT; i++)
837 if (osd_icons[i].reset)
839 osd->icon_time[i] = 0;
844 static void image_osd_icons_update(OverlayStateData *osd)
848 for (i = 0; i < IMAGE_OSD_COUNT; i++)
850 if (osd->icon_time[i] > 0)
852 image_osd_icon_show(osd, i);
856 image_osd_icon_hide(osd, i);
861 static void image_osd_icons_hide(OverlayStateData *osd)
865 for (i = 0; i < IMAGE_OSD_COUNT; i++)
867 image_osd_icon_hide(osd, i);
871 static void image_osd_info_show(OverlayStateData *osd, GdkPixbuf *pixbuf)
873 if (osd->ovl_info == 0)
875 osd->ovl_info = image_overlay_add(osd->imd, pixbuf, osd->x, osd->y, OVL_RELATIVE);
879 image_overlay_set(osd->imd, osd->ovl_info, pixbuf, osd->x, osd->y);
883 static void image_osd_info_hide(OverlayStateData *osd)
885 if (osd->ovl_info == 0) return;
887 image_overlay_remove(osd->imd, osd->ovl_info);
891 static gboolean image_osd_update_cb(gpointer data)
893 OverlayStateData *osd = data;
895 if (osd->show & OSD_SHOW_INFO)
897 /* redraw when the image was changed,
898 with histogram we have to redraw also when loading is finished */
899 if (osd->changed_states & IMAGE_STATE_IMAGE ||
900 (osd->changed_states & IMAGE_STATE_LOADING && osd->show & OSD_SHOW_HISTOGRAM) ||
901 osd->notify & NOTIFY_HISTMAP)
905 pixbuf = image_osd_info_render(osd);
908 image_osd_info_show(osd, pixbuf);
909 g_object_unref(pixbuf);
913 image_osd_info_hide(osd);
919 image_osd_info_hide(osd);
922 if (osd->show & OSD_SHOW_STATUS)
924 if (osd->changed_states & IMAGE_STATE_IMAGE)
925 image_osd_icons_reset_time(osd);
927 if (osd->changed_states & IMAGE_STATE_COLOR_ADJ)
929 osd->icon_time[IMAGE_OSD_COLOR] = IMAGE_OSD_DEFAULT_DURATION + 1;
930 image_osd_timer_schedule(osd);
933 if (osd->changed_states & IMAGE_STATE_ROTATE_AUTO)
937 if (osd->imd->state & IMAGE_STATE_ROTATE_AUTO)
940 if (!osd->imd->cm) n += IMAGE_OSD_DEFAULT_DURATION;
943 osd->icon_time[IMAGE_OSD_ROTATE_AUTO] = n;
944 image_osd_timer_schedule(osd);
947 image_osd_icons_update(osd);
951 image_osd_icons_hide(osd);
954 osd->changed_states = IMAGE_STATE_NONE;
960 static void image_osd_update_schedule(OverlayStateData *osd, gboolean force)
962 if (force) osd->changed_states |= IMAGE_STATE_IMAGE;
966 osd->idle_id = g_idle_add_full(G_PRIORITY_HIGH, image_osd_update_cb, osd, NULL);
970 void image_osd_update(ImageWindow *imd)
972 OverlayStateData *osd = image_get_osd_data(imd);
976 image_osd_update_schedule(osd, TRUE);
979 static gboolean image_osd_timer_cb(gpointer data)
981 OverlayStateData *osd = data;
982 gboolean done = TRUE;
983 gboolean changed = FALSE;
986 for (i = 0; i < IMAGE_OSD_COUNT; i++)
988 if (osd->icon_time[i] > 1)
991 if (osd->icon_time[i] < 2)
993 osd->icon_time[i] = 0;
1003 if (changed) image_osd_update_schedule(osd, FALSE);
1014 static void image_osd_timer_schedule(OverlayStateData *osd)
1018 osd->timer_id = g_timeout_add(100, image_osd_timer_cb, osd);
1022 static void image_osd_state_cb(ImageWindow *imd, ImageState state, gpointer data)
1024 OverlayStateData *osd = data;
1026 osd->changed_states |= state;
1027 image_osd_update_schedule(osd, FALSE);
1030 static void image_osd_notify_cb(FileData *fd, NotifyType type, gpointer data)
1032 OverlayStateData *osd = data;
1034 if ((type & (NOTIFY_HISTMAP)) && osd->imd && fd == osd->imd->image_fd)
1036 DEBUG_1("Notify osd: %s %04x", fd->path, type);
1037 osd->notify |= type;
1038 image_osd_update_schedule(osd, FALSE);
1043 static void image_osd_free(OverlayStateData *osd)
1047 if (osd->idle_id) g_source_remove(osd->idle_id);
1048 if (osd->timer_id) g_source_remove(osd->timer_id);
1050 file_data_unregister_notify_func(image_osd_notify_cb, osd);
1054 image_set_osd_data(osd->imd, NULL);
1055 g_signal_handler_disconnect(osd->imd->pr, osd->destroy_id);
1057 image_set_state_func(osd->imd, NULL, NULL);
1059 image_osd_info_hide(osd);
1060 image_osd_icons_hide(osd);
1063 if (osd->histogram) histogram_free(osd->histogram);
1068 static void image_osd_destroy_cb(GtkWidget *widget, gpointer data)
1070 OverlayStateData *osd = data;
1073 image_osd_free(osd);
1076 static void image_osd_enable(ImageWindow *imd, OsdShowFlags show)
1078 OverlayStateData *osd = image_get_osd_data(imd);
1082 osd = g_new0(OverlayStateData, 1);
1084 osd->show = OSD_SHOW_NOTHING;
1085 osd->x = options->image_overlay.x;
1086 osd->y = options->image_overlay.y;
1088 osd->histogram = histogram_new();
1090 osd->destroy_id = g_signal_connect(G_OBJECT(imd->pr), "destroy",
1091 G_CALLBACK(image_osd_destroy_cb), osd);
1092 image_set_osd_data(imd, osd);
1094 image_set_state_func(osd->imd, image_osd_state_cb, osd);
1095 file_data_register_notify_func(image_osd_notify_cb, osd, NOTIFY_PRIORITY_LOW);
1098 if (show & OSD_SHOW_STATUS)
1099 image_osd_icon(imd, IMAGE_OSD_ICON, -1);
1101 if (show != osd->show)
1102 image_osd_update_schedule(osd, TRUE);
1107 void image_osd_set(ImageWindow *imd, OsdShowFlags show)
1111 image_osd_enable(imd, show);
1114 OsdShowFlags image_osd_get(ImageWindow *imd)
1116 OverlayStateData *osd = image_get_osd_data(imd);
1118 return osd ? osd->show : OSD_SHOW_NOTHING;
1121 Histogram *image_osd_get_histogram(ImageWindow *imd)
1123 OverlayStateData *osd = image_get_osd_data(imd);
1125 return osd ? osd->histogram : NULL;
1128 void image_osd_copy_status(ImageWindow *src, ImageWindow *dest)
1130 Histogram *h_src, *h_dest;
1131 image_osd_set(dest, image_osd_get(src));
1133 h_src = image_osd_get_histogram(src);
1134 h_dest = image_osd_get_histogram(dest);
1136 h_dest->histogram_mode = h_src->histogram_mode;
1137 h_dest->histogram_channel = h_src->histogram_channel;
1144 2+ = show for duration tenths of a second
1145 -1 = use default duration
1147 void image_osd_icon(ImageWindow *imd, ImageOSDFlag flag, gint duration)
1149 OverlayStateData *osd = image_get_osd_data(imd);
1153 if (flag >= IMAGE_OSD_COUNT) return;
1154 if (duration < 0) duration = IMAGE_OSD_DEFAULT_DURATION;
1155 if (duration > 1) duration += 1;
1157 osd->icon_time[flag] = duration;
1159 image_osd_update_schedule(osd, FALSE);
1160 image_osd_timer_schedule(osd);
1162 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */