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;
55 OverlayRendererFlags origin;
62 gint icon_time[IMAGE_OSD_COUNT];
63 gint icon_id[IMAGE_OSD_COUNT];
65 guint idle_id; /* event source id */
66 guint timer_id; /* event source id */
71 typedef struct _OSDIcon OSDIcon;
73 gboolean reset; /* reset on new image */
74 gint x; /* x, y offset */
76 gchar *key; /* inline pixbuf */
79 static OSDIcon osd_icons[] = {
80 { TRUE, 0, 0, NULL }, /* none */
81 { TRUE, -10, -10, NULL }, /* auto rotated */
82 { TRUE, -10, -10, NULL }, /* user rotated */
83 { TRUE, -40, -10, NULL }, /* color embedded */
84 { TRUE, -70, -10, NULL }, /* first image */
85 { TRUE, -70, -10, NULL }, /* last image */
86 { FALSE, -70, -10, NULL }, /* osd enabled */
90 #define OSD_DATA "overlay-data"
92 #define IMAGE_OSD_DEFAULT_DURATION 30
94 #define HISTOGRAM_HEIGHT 140
95 #define HISTOGRAM_WIDTH 256
97 static void image_osd_timer_schedule(OverlayStateData *osd);
99 void set_image_overlay_template_string(gchar **template_string, const gchar *value)
101 g_assert(template_string);
103 g_free(*template_string);
104 *template_string = g_strdup(value);
108 void set_default_image_overlay_template_string(gchar **template_string)
110 set_image_overlay_template_string(template_string, DEFAULT_OVERLAY_INFO);
113 void set_image_overlay_font_string(gchar **font_string, const gchar *value)
115 g_assert(font_string);
117 g_free(*font_string);
118 *font_string = g_strdup(value);
121 static OverlayStateData *image_get_osd_data(ImageWindow *imd)
123 OverlayStateData *osd;
125 if (!imd) return NULL;
129 osd = g_object_get_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA");
133 static void image_set_osd_data(ImageWindow *imd, OverlayStateData *osd)
137 g_object_set_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA", osd);
141 *----------------------------------------------------------------------------
143 *----------------------------------------------------------------------------
147 void image_osd_histogram_toggle_channel(ImageWindow *imd)
149 OverlayStateData *osd = image_get_osd_data(imd);
151 if (!osd || !osd->histogram) return;
153 histogram_toggle_channel(osd->histogram);
154 image_osd_update(imd);
157 void image_osd_histogram_toggle_mode(ImageWindow *imd)
159 OverlayStateData *osd = image_get_osd_data(imd);
161 if (!osd || !osd->histogram) return;
163 histogram_toggle_mode(osd->histogram);
164 image_osd_update(imd);
167 void image_osd_histogram_set_channel(ImageWindow *imd, gint chan)
169 OverlayStateData *osd = image_get_osd_data(imd);
171 if (!osd || !osd->histogram) return;
173 histogram_set_channel(osd->histogram, chan);
174 image_osd_update(imd);
177 void image_osd_histogram_set_mode(ImageWindow *imd, gint mode)
179 OverlayStateData *osd = image_get_osd_data(imd);
181 if (!osd || !osd->histogram) return;
183 histogram_set_mode(osd->histogram, mode);
184 image_osd_update(imd);
187 gint image_osd_histogram_get_channel(ImageWindow *imd)
189 OverlayStateData *osd = image_get_osd_data(imd);
191 if (!osd || !osd->histogram) return HCHAN_DEFAULT;
193 return histogram_get_channel(osd->histogram);
196 gint image_osd_histogram_get_mode(ImageWindow *imd)
198 OverlayStateData *osd = image_get_osd_data(imd);
200 if (!osd || !osd->histogram) return 0;
202 return histogram_get_mode(osd->histogram);
205 void image_osd_toggle(ImageWindow *imd)
211 show = image_osd_get(imd);
212 if (show == OSD_SHOW_NOTHING)
214 image_osd_set(imd, OSD_SHOW_INFO | OSD_SHOW_STATUS);
219 if (show & OSD_SHOW_GUIDELINES)
221 image_osd_set(imd, OSD_SHOW_NOTHING);
223 else if (show & OSD_SHOW_HISTOGRAM)
225 image_osd_set(imd, OSD_SHOW_GUIDELINES);
226 image_osd_set(imd, show | ~OSD_SHOW_HISTOGRAM);
230 image_osd_set(imd, show | OSD_SHOW_HISTOGRAM);
235 static gchar *keywords_to_string(FileData *fd)
238 GString *kwstr = NULL;
243 keywords = metadata_read_list(fd, KEYWORD_KEY, METADATA_PLAIN);
247 GList *work = keywords;
251 gchar *kw = work->data;
256 kwstr = g_string_new("");
258 g_string_append(kwstr, ", ");
260 g_string_append(kwstr, kw);
262 string_list_free(keywords);
268 g_string_free(kwstr, FALSE);
274 static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *vars)
276 gchar delim = '%', imp = '|', sep[] = " - ";
279 gboolean want_separator = FALSE;
284 if (!str || !*str) return g_strdup("");
286 new = g_string_new(str);
294 gchar *limpos = NULL;
296 gchar *extrapos = NULL;
299 start = strchr(new->str + (prev + 1), delim);
302 end = strchr(start+1, delim);
306 /* Search for optionnal modifiers
307 * %name:99:extra% -> name = "name", limit=99, extra = "extra"
309 for (p = start + 1; p < end; p++)
313 if (g_ascii_isdigit(p[1]) && !limpos)
316 if (!trunc) trunc = p;
321 if (!trunc) trunc = p;
328 limit = (guint) atoi(limpos);
331 extra = g_strndup(extrapos, end - extrapos);
333 name = g_strndup(start+1, (trunc ? trunc : end)-start-1);
334 pos = start - new->str;
337 if (strcmp(name, "keywords") == 0)
339 data = keywords_to_string(imd->image_fd);
341 else if (strcmp(name, "comment") == 0)
343 data = metadata_read_string(imd->image_fd, COMMENT_KEY, METADATA_PLAIN);
345 else if (strcmp(name, "imagecomment") == 0)
347 data = exif_get_image_comment(imd->image_fd);
349 else if (strcmp(name, "rating") == 0)
351 data = metadata_read_string(imd->image_fd, RATING_KEY, METADATA_PLAIN);
354 else if (strncmp(name, "lua/", 4) == 0)
357 tmp = strchr(name+4, '/');
361 data = lua_callvalue(imd->image_fd, name+4, tmp+1);
366 data = g_strdup(g_hash_table_lookup(vars, name));
368 data = metadata_read_string(imd->image_fd, name, METADATA_FORMATTED);
371 if (data && *data && limit > 0 && strlen(data) > limit + 3)
373 gchar *new_data = g_strdup_printf("%-*.*s...", limit, limit, data);
380 /* Since we use pango markup to display, we need to escape here */
381 gchar *escaped = g_markup_escape_text(data, -1);
390 /* Display data between left and right parts of extra string
391 * the data is expressed by a '*' character. A '*' may be escaped
392 * by a \. You should escape all '*' characters, do not rely on the
393 * current implementation which only replaces the first unescaped '*'.
394 * If no "*" is present, the extra string is just appended to data string.
395 * Pango mark up is accepted in left and right parts.
396 * Any \n is replaced by a newline
398 * "<i>*</i>\n" -> data is displayed in italics ended with a newline
399 * "\n" -> ended with newline
400 * "ISO *" -> prefix data with "ISO " (ie. "ISO 100")
401 * "\**\*" -> prefix data with a star, and append a star (ie. "*100*")
402 * "\\*" -> prefix data with an anti slash (ie "\100")
403 * "Collection <b>*</b>\n" -> display data in bold prefixed by "Collection " and a newline is appended
405 * FIXME: using background / foreground colors lead to weird results.
409 gchar *right = extra;
411 guint len = strlen(extra);
413 /* Search for left and right parts and unescape characters */
414 for (p = extra; *p; p++, len--)
419 memmove(p+1, p+2, --len);
422 else if (p[1] != '\0')
423 memmove(p, p+1, len--); // includes \0
425 else if (p[0] == '*' && !left)
431 if (left) right[-1] = '\0';
433 new_data = g_strdup_printf("%s%s%s", left ? left : "", data, right);
440 g_string_erase(new, pos, end-start+1);
445 /* insert separator */
446 g_string_insert(new, pos, sep);
448 want_separator = FALSE;
451 g_string_insert(new, pos, data);
455 if (pos-prev >= 1 && new->str[pos] == imp)
457 /* pipe character is replaced by a separator, delete it
458 * and raise a flag if needed */
459 g_string_erase(new, pos--, 1);
460 want_separator |= (data && *data);
463 if (new->str[pos] == '\n') want_separator = FALSE;
471 /* search and destroy empty lines */
473 while ((start = strchr(end, '\n')))
476 while (*++(end) == '\n')
478 g_string_erase(new, start-new->str, end-start-1);
481 g_strchomp(new->str);
484 g_string_free(new, FALSE);
495 static void osd_template_insert(GHashTable *vars, gchar *keyword, gchar *value, OsdTemplateFlags flags)
499 g_hash_table_insert(vars, keyword, g_strdup(""));
503 if (flags & OSDT_NO_DUP)
505 g_hash_table_insert(vars, keyword, value);
510 g_hash_table_insert(vars, keyword, g_strdup(value));
513 if (flags & OSDT_FREE) g_free((gpointer) value);
516 static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
518 GdkPixbuf *pixbuf = NULL;
524 const HistMap *histmap = NULL;
525 ImageWindow *imd = osd->imd;
526 FileData *fd = image_get_fd(imd);
527 PangoFontDescription *font_desc;
529 if (!fd) return NULL;
531 name = image_get_name(imd);
539 vars = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
541 cd = image_get_collection(imd, &info);
544 t = g_list_length(cd->list);
545 n = g_list_index(cd->list, info) + 1;
548 if (file_extension_match(cd->name, GQ_COLLECTION_EXT))
549 osd_template_insert(vars, "collection", remove_extension_from_path(cd->name), OSDT_FREE);
551 osd_template_insert(vars, "collection", cd->name, OSDT_NONE);
555 osd_template_insert(vars, "collection", _("Untitled"), OSDT_NONE);
560 LayoutWindow *lw = layout_find_by_image(imd);
565 n = g_list_length(lw->slideshow->list_done);
566 t = n + g_list_length(lw->slideshow->list);
571 t = layout_list_count(lw, NULL);
572 n = layout_list_get_index(lw, image_get_fd(lw->image)) + 1;
575 else if (view_window_find_image(imd, &n, &t))
588 osd_template_insert(vars, "collection", NULL, OSDT_NONE);
591 osd_template_insert(vars, "number", g_strdup_printf("%d", n), OSDT_NO_DUP);
592 osd_template_insert(vars, "total", g_strdup_printf("%d", t), OSDT_NO_DUP);
593 osd_template_insert(vars, "name", (gchar *) name, OSDT_NONE);
594 osd_template_insert(vars, "date", imd->image_fd ? ((gchar *) text_from_time(imd->image_fd->date)) : "", OSDT_NONE);
595 osd_template_insert(vars, "size", imd->image_fd ? (text_from_size_abrev(imd->image_fd->size)) : g_strdup(""), OSDT_FREE);
596 osd_template_insert(vars, "zoom", image_zoom_get_as_text(imd), OSDT_FREE);
601 GdkPixbuf *load_pixbuf = image_loader_get_pixbuf(imd->il);
603 if (imd->delay_flip &&
604 imd->il && load_pixbuf &&
605 image_get_pixbuf(imd) != load_pixbuf)
607 w = gdk_pixbuf_get_width(load_pixbuf);
608 h = gdk_pixbuf_get_height(load_pixbuf);
612 image_get_image_size(imd, &w, &h);
616 osd_template_insert(vars, "width", g_strdup_printf("%d", w), OSDT_NO_DUP);
617 osd_template_insert(vars, "height", g_strdup_printf("%d", h), OSDT_NO_DUP);
618 osd_template_insert(vars, "res", g_strdup_printf("%d × %d", w, h), OSDT_FREE);
622 osd_template_insert(vars, "width", NULL, OSDT_NONE);
623 osd_template_insert(vars, "height", NULL, OSDT_NONE);
624 osd_template_insert(vars, "res", NULL, OSDT_NONE);
627 text = image_osd_mkinfo(options->image_overlay.template_string, imd, vars);
628 g_hash_table_destroy(vars);
631 /* When does this occur ?? */
632 text = g_markup_escape_text(_("Untitled"), -1);
635 with_hist = ((osd->show & OSD_SHOW_HISTOGRAM) && osd->histogram);
638 histmap = histmap_get(imd->image_fd);
641 histmap_start_idle(imd->image_fd);
648 gint active_marks = 0;
652 for (mark = 0; mark < FILEDATA_MARKS_SIZE; mark++)
654 active_marks += file_data_get_mark(fd, mark);
657 if (active_marks > 0)
659 GString *buf = g_string_sized_new(FILEDATA_MARKS_SIZE * 2);
661 for (mark = 0; mark < FILEDATA_MARKS_SIZE; mark++)
663 g_string_append_printf(buf, file_data_get_mark(fd, mark) ? " <span background='#FF00FF'>%c</span>" : " %c", '1' + (mark < 9 ? mark : -1) );
667 text2 = g_strdup_printf("%s\n%s", text, buf->str);
669 text2 = g_strdup(buf->str);
670 g_string_free(buf, TRUE);
677 gchar *escaped_histogram_label = g_markup_escape_text(histogram_label(osd->histogram), -1);
679 text2 = g_strdup_printf("%s\n%s", text, escaped_histogram_label);
681 text2 = g_strdup(escaped_histogram_label);
682 g_free(escaped_histogram_label);
688 font_desc = pango_font_description_from_string(options->image_overlay.font);
689 layout = gtk_widget_create_pango_layout(imd->pr, NULL);
690 pango_layout_set_font_description(layout, font_desc);
692 pango_layout_set_markup(layout, text, -1);
695 pango_layout_get_pixel_size(layout, &width, &height);
696 /* with empty text width is set to 0, but not height) */
699 else if (height == 0)
701 if (width > 0) width += 10;
702 if (height > 0) height += 10;
706 if (width < HISTOGRAM_WIDTH + 10) width = HISTOGRAM_WIDTH + 10;
707 height += HISTOGRAM_HEIGHT + 5;
710 if (width > 0 && height > 0)
712 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
713 pixbuf_set_rect_fill(pixbuf, 3, 3, width-6, height-6, options->image_overlay.background_red, options->image_overlay.background_green,
714 options->image_overlay.background_blue, options->image_overlay.background_alpha);
715 pixbuf_set_rect(pixbuf, 0, 0, width, height, 240, 240, 240, 80, 1, 1, 1, 1);
716 pixbuf_set_rect(pixbuf, 1, 1, width-2, height-2, 240, 240, 240, 130, 1, 1, 1, 1);
717 pixbuf_set_rect(pixbuf, 2, 2, width-4, height-4, 240, 240, 240, 180, 1, 1, 1, 1);
718 pixbuf_pixel_set(pixbuf, 0, 0, 0, 0, 0, 0);
719 pixbuf_pixel_set(pixbuf, width - 1, 0, 0, 0, 0, 0);
720 pixbuf_pixel_set(pixbuf, 0, height - 1, 0, 0, 0, 0);
721 pixbuf_pixel_set(pixbuf, width - 1, height - 1, 0, 0, 0, 0);
726 gint y = height - HISTOGRAM_HEIGHT - 5;
729 pixbuf_set_rect_fill(pixbuf, x, y, w, HISTOGRAM_HEIGHT, 220, 220, 220, 210);
730 histogram_draw(osd->histogram, histmap, pixbuf, x, y, w, HISTOGRAM_HEIGHT);
732 pixbuf_draw_layout(pixbuf, layout, imd->pr, 5, 5, options->image_overlay.text_red, options->image_overlay.text_green,
733 options->image_overlay.text_blue, options->image_overlay.text_alpha);
736 g_object_unref(G_OBJECT(layout));
741 static GdkPixbuf *image_osd_icon_pixbuf(ImageOSDFlag flag)
743 static GdkPixbuf **icons = NULL;
744 GdkPixbuf *icon = NULL;
746 if (!icons) icons = g_new0(GdkPixbuf *, IMAGE_OSD_COUNT);
747 if (icons[flag]) return icons[flag];
749 if (osd_icons[flag].key)
751 icon = pixbuf_inline(osd_icons[flag].key);
756 icon = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 24, 24);
757 pixbuf_set_rect_fill(icon, 1, 1, 22, 22, 255, 255, 255, 200);
758 pixbuf_set_rect(icon, 0, 0, 24, 24, 0, 0, 0, 128, 1, 1, 1, 1);
761 case IMAGE_OSD_ROTATE_AUTO:
762 pixbuf_set_rect(icon, 3, 8, 11, 12,
765 pixbuf_draw_triangle(icon, 14, 3, 6, 12,
766 20, 9, 14, 15, 14, 3,
769 case IMAGE_OSD_ROTATE_USER:
771 case IMAGE_OSD_COLOR:
772 pixbuf_set_rect_fill(icon, 3, 3, 18, 6, 200, 0, 0, 255);
773 pixbuf_set_rect_fill(icon, 3, 9, 18, 6, 0, 200, 0, 255);
774 pixbuf_set_rect_fill(icon, 3, 15, 18, 6, 0, 0, 200, 255);
776 case IMAGE_OSD_FIRST:
777 pixbuf_set_rect(icon, 3, 3, 18, 18, 0, 0, 0, 200, 3, 3, 3, 0);
778 pixbuf_draw_triangle(icon, 6, 5, 12, 6,
779 12, 5, 18, 11, 6, 11,
783 pixbuf_set_rect(icon, 3, 3, 18, 18, 0, 0, 0, 200, 3, 3, 0, 3);
784 pixbuf_draw_triangle(icon, 6, 12, 12, 6,
785 12, 18, 6, 12, 18, 12,
789 pixbuf_set_rect_fill(icon, 11, 3, 3, 12, 0, 0, 0, 255);
790 pixbuf_set_rect_fill(icon, 11, 17, 3, 3, 0, 0, 0, 255);
802 static GdkPixbuf *image_osd_guidelines_render(OverlayStateData *osd)
805 GdkPixbuf *rectangles;
806 ImageWindow *imd = osd->imd;
808 pixbuf_renderer_get_scaled_size((PixbufRenderer *)imd->pr, &width, &height);
812 rectangles = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
815 pixbuf_set_rect_fill(rectangles, 0, 0, width, height, 255, 255, 255, 0);
816 pixbuf_set_rect(rectangles, 0, 0 + (height / 3), width, height / 3,
819 pixbuf_set_rect(rectangles, 0, 0 + (height / 3 + 1), width, height / 3 - 2,
823 pixbuf_set_rect(rectangles, 0 + width / 3, 0 , width / 3, height,
826 pixbuf_set_rect(rectangles, 0 + width / 3 + 1, 0, width / 3 - 2, height,
836 static gint image_overlay_add(ImageWindow *imd, GdkPixbuf *pixbuf, gint x, gint y,
837 OverlayRendererFlags flags)
839 return pixbuf_renderer_overlay_add((PixbufRenderer *)imd->pr, pixbuf, x, y, flags);
842 static void image_overlay_set(ImageWindow *imd, gint id, GdkPixbuf *pixbuf, gint x, gint y)
844 pixbuf_renderer_overlay_set((PixbufRenderer *)imd->pr, id, pixbuf, x, y);
847 static void image_overlay_remove(ImageWindow *imd, gint id)
849 pixbuf_renderer_overlay_remove((PixbufRenderer *)imd->pr, id);
852 static void image_osd_icon_show(OverlayStateData *osd, ImageOSDFlag flag)
856 if (osd->icon_id[flag]) return;
858 pixbuf = image_osd_icon_pixbuf(flag);
861 osd->icon_id[flag] = image_overlay_add(osd->imd, pixbuf,
862 osd_icons[flag].x, osd_icons[flag].y,
866 static void image_osd_icon_hide(OverlayStateData *osd, ImageOSDFlag flag)
868 if (osd->icon_id[flag])
870 image_overlay_remove(osd->imd, osd->icon_id[flag]);
871 osd->icon_id[flag] = 0;
875 static void image_osd_icons_reset_time(OverlayStateData *osd)
879 for (i = 0; i < IMAGE_OSD_COUNT; i++)
881 if (osd_icons[i].reset)
883 osd->icon_time[i] = 0;
888 static void image_osd_icons_update(OverlayStateData *osd)
892 for (i = 0; i < IMAGE_OSD_COUNT; i++)
894 if (osd->icon_time[i] > 0)
896 image_osd_icon_show(osd, i);
900 image_osd_icon_hide(osd, i);
905 static void image_osd_icons_hide(OverlayStateData *osd)
909 for (i = 0; i < IMAGE_OSD_COUNT; i++)
911 image_osd_icon_hide(osd, i);
915 static void image_osd_info_show(OverlayStateData *osd, GdkPixbuf *pixbuf)
917 if (osd->ovl_info == 0)
919 osd->ovl_info = image_overlay_add(osd->imd, pixbuf, osd->x, osd->y, osd->origin);
923 image_overlay_set(osd->imd, osd->ovl_info, pixbuf, osd->x, osd->y);
927 static void image_osd_info_hide(OverlayStateData *osd)
929 if (osd->ovl_info == 0) return;
931 image_overlay_remove(osd->imd, osd->ovl_info);
935 static gboolean image_osd_update_cb(gpointer data)
937 OverlayStateData *osd = data;
939 if (osd->show & OSD_SHOW_INFO)
941 /* redraw when the image was changed,
942 with histogram we have to redraw also when loading is finished */
943 if (osd->changed_states & IMAGE_STATE_IMAGE ||
944 (osd->changed_states & IMAGE_STATE_LOADING && osd->show & OSD_SHOW_HISTOGRAM) ||
945 (osd->changed_states & IMAGE_STATE_LOADING && osd->show & OSD_SHOW_GUIDELINES) ||
946 osd->notify & NOTIFY_HISTMAP)
950 if (osd->show & OSD_SHOW_GUIDELINES)
952 ImageWindow *imd = osd->imd;
953 osd->x = ((PixbufRenderer *)imd->pr)->x_offset;
954 osd->y = ((PixbufRenderer *)imd->pr)->y_offset;
955 osd->origin = OVL_NORMAL;
957 pixbuf = image_osd_guidelines_render(osd);
960 image_osd_info_show(osd, pixbuf);
961 g_object_unref(pixbuf);
964 osd->x = options->image_overlay.x;
965 osd->y = options->image_overlay.y;
966 osd->origin = OVL_RELATIVE;
970 pixbuf = image_osd_info_render(osd);
973 image_osd_info_show(osd, pixbuf);
974 g_object_unref(pixbuf);
978 image_osd_info_hide(osd);
985 image_osd_info_hide(osd);
988 if (osd->show & OSD_SHOW_STATUS)
990 if (osd->changed_states & IMAGE_STATE_IMAGE)
991 image_osd_icons_reset_time(osd);
993 if (osd->changed_states & IMAGE_STATE_COLOR_ADJ)
995 osd->icon_time[IMAGE_OSD_COLOR] = IMAGE_OSD_DEFAULT_DURATION + 1;
996 image_osd_timer_schedule(osd);
999 if (osd->changed_states & IMAGE_STATE_ROTATE_AUTO)
1003 if (osd->imd->state & IMAGE_STATE_ROTATE_AUTO)
1006 if (!osd->imd->cm) n += IMAGE_OSD_DEFAULT_DURATION;
1009 osd->icon_time[IMAGE_OSD_ROTATE_AUTO] = n;
1010 image_osd_timer_schedule(osd);
1013 image_osd_icons_update(osd);
1017 image_osd_icons_hide(osd);
1020 osd->changed_states = IMAGE_STATE_NONE;
1026 static void image_osd_update_schedule(OverlayStateData *osd, gboolean force)
1028 if (force) osd->changed_states |= IMAGE_STATE_IMAGE;
1032 osd->idle_id = g_idle_add_full(G_PRIORITY_HIGH, image_osd_update_cb, osd, NULL);
1036 void image_osd_update(ImageWindow *imd)
1038 OverlayStateData *osd = image_get_osd_data(imd);
1042 image_osd_update_schedule(osd, TRUE);
1045 static gboolean image_osd_timer_cb(gpointer data)
1047 OverlayStateData *osd = data;
1048 gboolean done = TRUE;
1049 gboolean changed = FALSE;
1052 for (i = 0; i < IMAGE_OSD_COUNT; i++)
1054 if (osd->icon_time[i] > 1)
1056 osd->icon_time[i]--;
1057 if (osd->icon_time[i] < 2)
1059 osd->icon_time[i] = 0;
1069 if (changed) image_osd_update_schedule(osd, FALSE);
1080 static void image_osd_timer_schedule(OverlayStateData *osd)
1084 osd->timer_id = g_timeout_add(100, image_osd_timer_cb, osd);
1088 static void image_osd_state_cb(ImageWindow *imd, ImageState state, gpointer data)
1090 OverlayStateData *osd = data;
1092 osd->changed_states |= state;
1093 image_osd_update_schedule(osd, FALSE);
1096 static void image_osd_notify_cb(FileData *fd, NotifyType type, gpointer data)
1098 OverlayStateData *osd = data;
1100 if ((type & (NOTIFY_HISTMAP)) && osd->imd && fd == osd->imd->image_fd)
1102 DEBUG_1("Notify osd: %s %04x", fd->path, type);
1103 osd->notify |= type;
1104 image_osd_update_schedule(osd, FALSE);
1109 static void image_osd_free(OverlayStateData *osd)
1113 if (osd->idle_id) g_source_remove(osd->idle_id);
1114 if (osd->timer_id) g_source_remove(osd->timer_id);
1116 file_data_unregister_notify_func(image_osd_notify_cb, osd);
1120 image_set_osd_data(osd->imd, NULL);
1121 g_signal_handler_disconnect(osd->imd->pr, osd->destroy_id);
1123 image_set_state_func(osd->imd, NULL, NULL);
1125 image_osd_info_hide(osd);
1126 image_osd_icons_hide(osd);
1129 if (osd->histogram) histogram_free(osd->histogram);
1134 static void image_osd_destroy_cb(GtkWidget *widget, gpointer data)
1136 OverlayStateData *osd = data;
1139 image_osd_free(osd);
1142 static void image_osd_enable(ImageWindow *imd, OsdShowFlags show)
1144 OverlayStateData *osd = image_get_osd_data(imd);
1148 osd = g_new0(OverlayStateData, 1);
1150 osd->show = OSD_SHOW_NOTHING;
1151 osd->x = options->image_overlay.x;
1152 osd->y = options->image_overlay.y;
1153 osd->origin = OVL_RELATIVE;
1155 osd->histogram = histogram_new();
1157 osd->destroy_id = g_signal_connect(G_OBJECT(imd->pr), "destroy",
1158 G_CALLBACK(image_osd_destroy_cb), osd);
1159 image_set_osd_data(imd, osd);
1161 image_set_state_func(osd->imd, image_osd_state_cb, osd);
1162 file_data_register_notify_func(image_osd_notify_cb, osd, NOTIFY_PRIORITY_LOW);
1165 if (show & OSD_SHOW_STATUS)
1166 image_osd_icon(imd, IMAGE_OSD_ICON, -1);
1168 if (show != osd->show)
1169 image_osd_update_schedule(osd, TRUE);
1174 void image_osd_set(ImageWindow *imd, OsdShowFlags show)
1178 image_osd_enable(imd, show);
1181 OsdShowFlags image_osd_get(ImageWindow *imd)
1183 OverlayStateData *osd = image_get_osd_data(imd);
1185 return osd ? osd->show : OSD_SHOW_NOTHING;
1188 Histogram *image_osd_get_histogram(ImageWindow *imd)
1190 OverlayStateData *osd = image_get_osd_data(imd);
1192 return osd ? osd->histogram : NULL;
1195 void image_osd_copy_status(ImageWindow *src, ImageWindow *dest)
1197 Histogram *h_src, *h_dest;
1198 image_osd_set(dest, image_osd_get(src));
1200 h_src = image_osd_get_histogram(src);
1201 h_dest = image_osd_get_histogram(dest);
1203 h_dest->histogram_mode = h_src->histogram_mode;
1204 h_dest->histogram_channel = h_src->histogram_channel;
1211 2+ = show for duration tenths of a second
1212 -1 = use default duration
1214 void image_osd_icon(ImageWindow *imd, ImageOSDFlag flag, gint duration)
1216 OverlayStateData *osd = image_get_osd_data(imd);
1220 if (flag >= IMAGE_OSD_COUNT) return;
1221 if (duration < 0) duration = IMAGE_OSD_DEFAULT_DURATION;
1222 if (duration > 1) duration += 1;
1224 osd->icon_time[flag] = duration;
1226 image_osd_update_schedule(osd, FALSE);
1227 image_osd_timer_schedule(osd);
1229 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */