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.
27 #include "collect-table.h"
28 #include "color-man.h"
31 #include "histogram.h"
32 #include "image-load.h"
33 #include "image-overlay.h"
35 #include "layout_image.h"
36 #include "pixbuf-renderer.h"
37 #include "pixbuf_util.h"
38 #include "ui_fileops.h"
41 #include "filecache.h"
45 static GList *image_list = NULL;
47 static void image_update_title(ImageWindow *imd);
48 static void image_read_ahead_start(ImageWindow *imd);
49 static void image_cache_set(ImageWindow *imd, FileData *fd);
51 // For draw rectangle function
52 static gint pixbuf_start_x;
53 static gint pixbuf_start_y;
54 static gint image_start_x;
55 static gint image_start_y;
56 static gint rect_x1, rect_x2, rect_y1, rect_y2;
57 static gint rect_id = 0;
60 *-------------------------------------------------------------------
62 *-------------------------------------------------------------------
65 static void image_click_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer data)
67 ImageWindow *imd = data;
68 if (!options->image_lm_click_nav && event->button == MOUSE_BUTTON_MIDDLE)
70 imd->mouse_wheel_mode = !imd->mouse_wheel_mode;
75 imd->func_button(imd, event, imd->data_button);
79 static void switch_coords_orientation(ImageWindow *imd, gint x, gint y, gint width, gint height)
81 switch (imd->orientation)
83 case EXIF_ORIENTATION_TOP_LEFT:
84 /* normal -- nothing to do */
85 rect_x1 = image_start_x;
86 rect_y1 = image_start_y;
90 case EXIF_ORIENTATION_TOP_RIGHT:
93 rect_y1 = image_start_y;
94 rect_x2 = width - image_start_x;
97 case EXIF_ORIENTATION_BOTTOM_RIGHT:
100 rect_y1 = height - y;
101 rect_x2 = width - image_start_x;
102 rect_y2 = height - image_start_y;
104 case EXIF_ORIENTATION_BOTTOM_LEFT:
106 rect_x1 = image_start_x;
107 rect_y1 = height - y;
109 rect_y2 = height - image_start_y;
111 case EXIF_ORIENTATION_LEFT_TOP:
113 rect_x1 = image_start_y;
114 rect_y1 = image_start_x;
118 case EXIF_ORIENTATION_RIGHT_TOP:
119 /* rotated -90 (270) */
120 rect_x1 = image_start_y;
123 rect_y2 = width - image_start_x;
125 case EXIF_ORIENTATION_RIGHT_BOTTOM:
127 rect_x1 = height - y;
129 rect_x2 = height - image_start_y;
130 rect_y2 = width - image_start_x;
132 case EXIF_ORIENTATION_LEFT_BOTTOM:
134 rect_x1 = height - y;
135 rect_y1 = image_start_x;
136 rect_x2 = height - image_start_y;
140 /* The other values are out of range */
145 static void image_press_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer data)
147 ImageWindow *imd = data;
149 gint x_pixel, y_pixel;
151 if(options->draw_rectangle)
153 pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
155 pixbuf_start_x = event->x;
156 pixbuf_start_y = event->y;
164 image_start_x = x_pixel;
173 image_start_y = y_pixel;
179 pixbuf_renderer_overlay_remove((PixbufRenderer *)imd->pr, rect_id);
182 lw = layout_find_by_image(imd);
183 if (lw && event->button == MOUSE_BUTTON_LEFT && event->type == GDK_2BUTTON_PRESS
184 && !options->image_lm_click_nav)
187 layout_image_full_screen_stop(lw);
191 static void image_drag_cb(PixbufRenderer *pr, GdkEventMotion *event, gpointer data)
193 ImageWindow *imd = data;
197 GdkPixbuf *rect_pixbuf;
198 gint x_pixel, y_pixel;
199 gint image_x_pixel, image_y_pixel;
201 if (options->draw_rectangle)
203 pixbuf_renderer_get_image_size(pr, &width, &height);
204 pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel);
208 image_x_pixel = width;
212 image_x_pixel = x_pixel;
217 image_y_pixel = height;
221 image_y_pixel = y_pixel;
224 switch_coords_orientation(imd, image_x_pixel, image_y_pixel, width, height);
227 pixbuf_renderer_overlay_remove((PixbufRenderer *)imd->pr, rect_id);
230 rect_width = pr->drag_last_x - pixbuf_start_x;
235 rect_height = pr->drag_last_y - pixbuf_start_y;
236 if (rect_height <= 0)
241 rect_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, rect_width, rect_height);
242 pixbuf_set_rect_fill(rect_pixbuf, 0, 0, rect_width, rect_height, 255, 255, 255, 0);
243 pixbuf_set_rect(rect_pixbuf, 1, 1, rect_width-2, rect_height - 2, 0, 0, 0, 255, 1, 1, 1, 1);
244 pixbuf_set_rect(rect_pixbuf, 2, 2, rect_width-4, rect_height - 4, 255, 255, 255, 255, 1, 1, 1, 1);
246 rect_id = pixbuf_renderer_overlay_add((PixbufRenderer *)imd->pr, rect_pixbuf, pixbuf_start_x, pixbuf_start_y, OVL_NORMAL);
249 pixbuf_renderer_get_scaled_size(pr, &width, &height);
253 imd->func_drag(imd, event,
254 (gfloat)(pr->drag_last_x - event->x) / width,
255 (gfloat)(pr->drag_last_y - event->y) / height,
260 static void image_scroll_notify_cb(PixbufRenderer *pr, gpointer data)
262 ImageWindow *imd = data;
264 if (imd->func_scroll_notify && pr->scale)
266 imd->func_scroll_notify(imd,
267 (gint)((gdouble)pr->x_scroll / pr->scale),
268 (gint)((gdouble)pr->y_scroll / pr->scale),
269 (gint)((gdouble)pr->image_width - pr->vis_width / pr->scale),
270 (gint)((gdouble)pr->image_height - pr->vis_height / pr->scale),
271 imd->data_scroll_notify);
275 static void image_update_util(ImageWindow *imd)
277 if (imd->func_update) imd->func_update(imd, imd->data_update);
281 static void image_complete_util(ImageWindow *imd, gboolean preload)
283 if (imd->il && image_get_pixbuf(imd) != image_loader_get_pixbuf(imd->il)) return;
285 DEBUG_1("%s image load completed \"%s\" (%s)", get_exec_time(),
286 (preload) ? (imd->read_ahead_fd ? imd->read_ahead_fd->path : "null") :
287 (imd->image_fd ? imd->image_fd->path : "null"),
288 (preload) ? "preload" : "current");
290 if (!preload) imd->completed = TRUE;
291 if (imd->func_complete) imd->func_complete(imd, preload, imd->data_complete);
294 static void image_render_complete_cb(PixbufRenderer *pr, gpointer data)
296 ImageWindow *imd = data;
298 image_complete_util(imd, FALSE);
301 static void image_state_set(ImageWindow *imd, ImageState state)
303 if (state == IMAGE_STATE_NONE)
311 if (imd->func_state) imd->func_state(imd, state, imd->data_state);
314 static void image_state_unset(ImageWindow *imd, ImageState state)
316 imd->state &= ~state;
317 if (imd->func_state) imd->func_state(imd, state, imd->data_state);
320 static void image_zoom_cb(PixbufRenderer *pr, gdouble zoom, gpointer data)
322 ImageWindow *imd = data;
324 if (imd->title_show_zoom) image_update_title(imd);
325 image_state_set(imd, IMAGE_STATE_IMAGE);
326 image_update_util(imd);
330 *-------------------------------------------------------------------
332 *-------------------------------------------------------------------
335 static void image_update_title(ImageWindow *imd)
339 gchar *collection = NULL;
341 gchar *lw_ident = NULL;
343 if (!imd->top_window) return;
345 if (imd->collection && collection_to_number(imd->collection) >= 0)
347 const gchar *name = imd->collection->name;
348 if (!name) name = _("Untitled");
349 collection = g_strdup_printf(_(" (Collection %s)"), name);
352 if (imd->title_show_zoom)
354 gchar *buf = image_zoom_get_as_text(imd);
355 zoom = g_strconcat(" [", buf, "]", NULL);
359 lw = layout_find_by_image(imd);
362 lw_ident = g_strconcat(" (", lw->options.id, ")", NULL);
365 title = g_strdup_printf("%s%s%s%s%s%s%s",
366 imd->title ? imd->title : "",
367 imd->image_fd ? imd->image_fd->name : "",
369 collection ? collection : "",
370 imd->image_fd ? " - " : "",
371 imd->title_right ? imd->title_right : "",
372 options->show_window_ids ? (lw_ident ? lw_ident : "") : ""
379 gtk_window_set_title(GTK_WINDOW(imd->top_window), title);
387 *-------------------------------------------------------------------
388 * rotation, flip, etc.
389 *-------------------------------------------------------------------
391 static gboolean image_get_x11_screen_profile(ImageWindow *imd, guchar **screen_profile, gint *screen_profile_len)
393 GdkScreen *screen = gtk_widget_get_screen(imd->widget);;
394 GdkAtom type = GDK_NONE;
397 return (gdk_property_get(gdk_screen_get_root_window(screen),
398 gdk_atom_intern ("_ICC_PROFILE", FALSE),
400 0, 64 * 1024 * 1024, FALSE,
401 &type, &format, screen_profile_len, screen_profile) && *screen_profile_len > 0);
404 static gboolean image_post_process_color(ImageWindow *imd, gint start_row, gboolean run_in_bg)
407 ColorManProfileType input_type;
408 ColorManProfileType screen_type;
409 const gchar *input_file = NULL;
410 const gchar *screen_file = NULL;
411 guchar *profile = NULL;
413 guchar *screen_profile = NULL;
414 gint screen_profile_len;
417 if (imd->cm) return FALSE;
419 if (imd->color_profile_input >= COLOR_PROFILE_FILE &&
420 imd->color_profile_input < COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS)
422 const gchar *file = options->color_profile.input_file[imd->color_profile_input - COLOR_PROFILE_FILE];
424 if (!is_readable_file(file)) return FALSE;
426 input_type = COLOR_PROFILE_FILE;
429 else if (imd->color_profile_input >= COLOR_PROFILE_SRGB &&
430 imd->color_profile_input < COLOR_PROFILE_FILE)
432 input_type = imd->color_profile_input;
440 if (options->color_profile.use_x11_screen_profile &&
441 image_get_x11_screen_profile(imd, &screen_profile, &screen_profile_len))
443 screen_type = COLOR_PROFILE_MEM;
444 DEBUG_1("Using X11 screen profile, length: %d", screen_profile_len);
446 else if (options->color_profile.screen_file &&
447 is_readable_file(options->color_profile.screen_file))
449 screen_type = COLOR_PROFILE_FILE;
450 screen_file = options->color_profile.screen_file;
454 screen_type = COLOR_PROFILE_SRGB;
459 imd->color_profile_from_image = COLOR_PROFILE_NONE;
461 exif = exif_read_fd(imd->image_fd);
465 profile = exif_get_color_profile(exif, &profile_len);
468 if (!imd->color_profile_use_image)
473 DEBUG_1("Found embedded color profile");
474 imd->color_profile_from_image = COLOR_PROFILE_MEM;
478 gchar *interop_index = exif_get_data_as_text(exif, "Exif.Iop.InteroperabilityIndex");
482 /* Exif 2.21 specification */
483 if (!strcmp(interop_index, "R98"))
485 imd->color_profile_from_image = COLOR_PROFILE_SRGB;
486 DEBUG_1("Found EXIF 2.21 ColorSpace of sRGB");
488 else if (!strcmp(interop_index, "R03"))
490 imd->color_profile_from_image = COLOR_PROFILE_ADOBERGB;
491 DEBUG_1("Found EXIF 2.21 ColorSpace of AdobeRGB");
493 g_free(interop_index);
499 /* ColorSpace == 1 specifies sRGB per EXIF 2.2 */
500 if (!exif_get_integer(exif, "Exif.Photo.ColorSpace", &cs)) cs = 0;
503 imd->color_profile_from_image = COLOR_PROFILE_SRGB;
504 DEBUG_1("Found EXIF 2.2 ColorSpace of sRGB");
508 /* non-standard way of specifying AdobeRGB (used by some software) */
509 imd->color_profile_from_image = COLOR_PROFILE_ADOBERGB;
510 DEBUG_1("Found EXIF 2.2 ColorSpace of AdobeRGB");
514 if (imd->color_profile_use_image && imd->color_profile_from_image != COLOR_PROFILE_NONE)
516 input_type = imd->color_profile_from_image;
521 exif_free_fd(imd->image_fd, exif);
527 cm = color_man_new_embedded(run_in_bg ? imd : NULL, NULL,
528 profile, profile_len,
529 screen_type, screen_file, screen_profile, screen_profile_len);
534 cm = color_man_new(run_in_bg ? imd : NULL, NULL,
535 input_type, input_file,
536 screen_type, screen_file, screen_profile, screen_profile_len);
544 cm->incremental_sync = TRUE;
547 imd->cm = (gpointer)cm;
550 image_update_util(imd);
554 g_free(screen_profile);
555 screen_profile = NULL;
562 static void image_post_process_tile_color_cb(PixbufRenderer *pr, GdkPixbuf **pixbuf, gint x, gint y, gint w, gint h, gpointer data)
564 ImageWindow *imd = (ImageWindow *)data;
565 if (imd->cm) color_man_correct_region(imd->cm, *pixbuf, x, y, w, h);
566 if (imd->desaturate) pixbuf_desaturate_rect(*pixbuf, x, y, w, h);
570 void image_alter_orientation(ImageWindow *imd, FileData *fd_n, AlterType type)
572 static const gint rotate_90[] = {1, 6, 7, 8, 5, 2, 3, 4, 1};
573 static const gint rotate_90_cc[] = {1, 8, 5, 6, 7, 4, 1, 2, 3};
574 static const gint rotate_180[] = {1, 3, 4, 1, 2, 7, 8, 5, 6};
575 static const gint mirror[] = {1, 2, 1, 4, 3, 6, 5, 8, 7};
576 static const gint flip[] = {1, 4, 3, 2, 1, 8, 7, 6, 5};
580 if (!imd || !imd->pr || !imd->image_fd || !fd_n) return;
582 orientation = EXIF_ORIENTATION_TOP_LEFT;
584 if (fd_n->user_orientation)
586 orientation = fd_n->user_orientation;
589 if (options->metadata.write_orientation)
591 orientation = metadata_read_int(fd_n, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
597 case ALTER_ROTATE_90:
598 orientation = rotate_90[orientation];
600 case ALTER_ROTATE_90_CC:
601 orientation = rotate_90_cc[orientation];
603 case ALTER_ROTATE_180:
604 orientation = rotate_180[orientation];
607 orientation = mirror[orientation];
610 orientation = flip[orientation];
613 orientation = fd_n->exif_orientation ? fd_n->exif_orientation : 1;
620 if (orientation != (fd_n->exif_orientation ? fd_n->exif_orientation : 1))
622 if (!options->metadata.write_orientation)
624 /* user_orientation does not work together with options->metadata.write_orientation,
625 use either one or the other.
626 we must however handle switching metadata.write_orientation on and off, therefore
627 we just disable referencing new fd's, not unreferencing the old ones
629 if (fd_n->user_orientation == 0) file_data_ref(fd_n);
630 fd_n->user_orientation = orientation;
635 if (fd_n->user_orientation != 0) file_data_unref(fd_n);
636 fd_n->user_orientation = 0;
639 if (options->metadata.write_orientation)
641 if (type == ALTER_NONE)
643 metadata_write_revert(fd_n, ORIENTATION_KEY);
647 metadata_write_int(fd_n, ORIENTATION_KEY, orientation);
651 if (imd->image_fd == fd_n && !(options->metadata.write_orientation && !options->image.exif_rotate_enable))
653 imd->orientation = orientation;
654 pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, orientation);
658 void image_set_desaturate(ImageWindow *imd, gboolean desaturate)
660 imd->desaturate = desaturate;
661 if (imd->cm || imd->desaturate)
662 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, image_post_process_tile_color_cb, (gpointer) imd, (imd->cm != NULL) );
664 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, NULL, NULL, TRUE);
665 pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation);
668 gboolean image_get_desaturate(ImageWindow *imd)
670 return imd->desaturate;
674 *-------------------------------------------------------------------
675 * read ahead (prebuffer)
676 *-------------------------------------------------------------------
679 static void image_read_ahead_cancel(ImageWindow *imd)
681 DEBUG_1("%s read ahead cancelled for :%s", get_exec_time(), imd->read_ahead_fd ? imd->read_ahead_fd->path : "null");
683 image_loader_free(imd->read_ahead_il);
684 imd->read_ahead_il = NULL;
686 file_data_unref(imd->read_ahead_fd);
687 imd->read_ahead_fd = NULL;
690 static void image_read_ahead_done_cb(ImageLoader *il, gpointer data)
692 ImageWindow *imd = data;
694 if (!imd->read_ahead_fd || !imd->read_ahead_il) return;
696 DEBUG_1("%s read ahead done for :%s", get_exec_time(), imd->read_ahead_fd->path);
698 if (!imd->read_ahead_fd->pixbuf)
700 imd->read_ahead_fd->pixbuf = image_loader_get_pixbuf(imd->read_ahead_il);
701 if (imd->read_ahead_fd->pixbuf)
703 g_object_ref(imd->read_ahead_fd->pixbuf);
704 image_cache_set(imd, imd->read_ahead_fd);
707 image_loader_free(imd->read_ahead_il);
708 imd->read_ahead_il = NULL;
710 image_complete_util(imd, TRUE);
713 static void image_read_ahead_error_cb(ImageLoader *il, gpointer data)
715 /* we even treat errors as success, maybe at least some of the file was ok */
716 image_read_ahead_done_cb(il, data);
719 static void image_read_ahead_start(ImageWindow *imd)
721 /* already started ? */
722 if (!imd->read_ahead_fd || imd->read_ahead_il || imd->read_ahead_fd->pixbuf) return;
724 /* still loading ?, do later */
725 if (imd->il /*|| imd->cm*/) return;
727 DEBUG_1("%s read ahead started for :%s", get_exec_time(), imd->read_ahead_fd->path);
729 imd->read_ahead_il = image_loader_new(imd->read_ahead_fd);
731 image_loader_delay_area_ready(imd->read_ahead_il, TRUE); /* we will need the area_ready signals later */
733 g_signal_connect(G_OBJECT(imd->read_ahead_il), "error", (GCallback)image_read_ahead_error_cb, imd);
734 g_signal_connect(G_OBJECT(imd->read_ahead_il), "done", (GCallback)image_read_ahead_done_cb, imd);
736 if (!image_loader_start(imd->read_ahead_il))
738 image_read_ahead_cancel(imd);
739 image_complete_util(imd, TRUE);
743 static void image_read_ahead_set(ImageWindow *imd, FileData *fd)
745 if (imd->read_ahead_fd && fd && imd->read_ahead_fd == fd) return;
747 image_read_ahead_cancel(imd);
749 imd->read_ahead_fd = file_data_ref(fd);
751 DEBUG_1("read ahead set to :%s", imd->read_ahead_fd->path);
753 image_read_ahead_start(imd);
757 *-------------------------------------------------------------------
759 *-------------------------------------------------------------------
762 static void image_cache_release_cb(FileData *fd)
764 g_object_unref(fd->pixbuf);
768 static FileCacheData *image_get_cache(void)
770 static FileCacheData *cache = NULL;
771 if (!cache) cache = file_cache_new(image_cache_release_cb, 1);
772 file_cache_set_max_size(cache, (gulong)options->image.image_cache_max * 1048576); /* update from options */
776 static void image_cache_set(ImageWindow *imd, FileData *fd)
778 g_assert(fd->pixbuf);
780 file_cache_put(image_get_cache(), fd, (gulong)gdk_pixbuf_get_rowstride(fd->pixbuf) * (gulong)gdk_pixbuf_get_height(fd->pixbuf));
781 file_data_send_notification(fd, NOTIFY_PIXBUF); /* to update histogram */
784 static gint image_cache_get(ImageWindow *imd)
788 success = file_cache_get(image_get_cache(), imd->image_fd);
791 g_assert(imd->image_fd->pixbuf);
792 image_change_pixbuf(imd, imd->image_fd->pixbuf, image_zoom_get(imd), FALSE);
795 // file_cache_dump(image_get_cache());
800 *-------------------------------------------------------------------
802 *-------------------------------------------------------------------
805 static void image_load_pixbuf_ready(ImageWindow *imd)
807 if (image_get_pixbuf(imd) || !imd->il) return;
809 image_change_pixbuf(imd, image_loader_get_pixbuf(imd->il), image_zoom_get(imd), FALSE);
812 static void image_load_area_cb(ImageLoader *il, guint x, guint y, guint w, guint h, gpointer data)
814 ImageWindow *imd = data;
817 pr = (PixbufRenderer *)imd->pr;
819 if (imd->delay_flip &&
820 pr->pixbuf != image_loader_get_pixbuf(il))
825 if (!pr->pixbuf) image_change_pixbuf(imd, image_loader_get_pixbuf(imd->il), image_zoom_get(imd), TRUE);
827 pixbuf_renderer_area_changed(pr, x, y, w, h);
830 static void image_load_done_cb(ImageLoader *il, gpointer data)
832 ImageWindow *imd = data;
834 DEBUG_1("%s image done", get_exec_time());
836 if (options->image.enable_read_ahead && imd->image_fd && !imd->image_fd->pixbuf && image_loader_get_pixbuf(imd->il))
838 imd->image_fd->pixbuf = g_object_ref(image_loader_get_pixbuf(imd->il));
839 image_cache_set(imd, imd->image_fd);
841 /* call the callback triggered by image_state after fd->pixbuf is set */
842 g_object_set(G_OBJECT(imd->pr), "loading", FALSE, NULL);
843 image_state_unset(imd, IMAGE_STATE_LOADING);
845 if (!image_loader_get_pixbuf(imd->il))
849 switch (imd->image_fd->format_class)
851 case FORMAT_CLASS_UNKNOWN:
852 pixbuf = pixbuf_inline(PIXBUF_INLINE_UNKNOWN);
854 case FORMAT_CLASS_META:
855 pixbuf = pixbuf_inline(PIXBUF_INLINE_METADATA);
857 case FORMAT_CLASS_VIDEO:
858 pixbuf = pixbuf_inline(PIXBUF_INLINE_VIDEO);
859 case FORMAT_CLASS_COLLECTION:
860 pixbuf = pixbuf_inline(PIXBUF_INLINE_COLLECTION);
862 case FORMAT_CLASS_PDF:
863 pixbuf = pixbuf_inline(PIXBUF_INLINE_ICON_PDF);
865 case FORMAT_CLASS_HEIF:
866 pixbuf = pixbuf_inline(PIXBUF_INLINE_ICON_HEIF);
869 pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN);
872 image_change_pixbuf(imd, pixbuf, image_zoom_get(imd), FALSE);
873 g_object_unref(pixbuf);
877 else if (imd->delay_flip &&
878 image_get_pixbuf(imd) != image_loader_get_pixbuf(imd->il))
880 g_object_set(G_OBJECT(imd->pr), "complete", FALSE, NULL);
881 image_change_pixbuf(imd, image_loader_get_pixbuf(imd->il), image_zoom_get(imd), FALSE);
884 image_loader_free(imd->il);
887 // image_post_process(imd, TRUE);
889 image_read_ahead_start(imd);
892 static void image_load_size_cb(ImageLoader *il, guint width, guint height, gpointer data)
894 ImageWindow *imd = data;
896 DEBUG_1("image_load_size_cb: %dx%d", width, height);
897 pixbuf_renderer_set_size_early((PixbufRenderer *)imd->pr, width, height);
900 static void image_load_error_cb(ImageLoader *il, gpointer data)
902 DEBUG_1("%s image error", get_exec_time());
904 /* even on error handle it like it was done,
905 * since we have a pixbuf with _something_ */
907 image_load_done_cb(il, data);
910 static void image_load_set_signals(ImageWindow *imd, gboolean override_old_signals)
913 if (override_old_signals)
915 /* override the old signals */
916 g_signal_handlers_disconnect_matched(G_OBJECT(imd->il), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, imd);
919 g_signal_connect(G_OBJECT(imd->il), "area_ready", (GCallback)image_load_area_cb, imd);
920 g_signal_connect(G_OBJECT(imd->il), "error", (GCallback)image_load_error_cb, imd);
921 g_signal_connect(G_OBJECT(imd->il), "done", (GCallback)image_load_done_cb, imd);
922 g_signal_connect(G_OBJECT(imd->il), "size_prepared", (GCallback)image_load_size_cb, imd);
925 /* this read ahead is located here merely for the callbacks, above */
927 static gboolean image_read_ahead_check(ImageWindow *imd)
929 if (!imd->read_ahead_fd) return FALSE;
930 if (imd->il) return FALSE;
932 if (!imd->image_fd || imd->read_ahead_fd != imd->image_fd)
934 image_read_ahead_cancel(imd);
938 if (imd->read_ahead_il)
940 imd->il = imd->read_ahead_il;
941 imd->read_ahead_il = NULL;
943 image_load_set_signals(imd, TRUE);
945 g_object_set(G_OBJECT(imd->pr), "loading", TRUE, NULL);
946 image_state_set(imd, IMAGE_STATE_LOADING);
948 if (!imd->delay_flip)
950 image_change_pixbuf(imd, image_loader_get_pixbuf(imd->il), image_zoom_get(imd), TRUE);
953 image_loader_delay_area_ready(imd->il, FALSE); /* send the delayed area_ready signals */
955 file_data_unref(imd->read_ahead_fd);
956 imd->read_ahead_fd = NULL;
959 else if (imd->read_ahead_fd->pixbuf)
961 image_change_pixbuf(imd, imd->read_ahead_fd->pixbuf, image_zoom_get(imd), FALSE);
963 file_data_unref(imd->read_ahead_fd);
964 imd->read_ahead_fd = NULL;
966 // image_post_process(imd, FALSE);
970 image_read_ahead_cancel(imd);
974 static gboolean image_load_begin(ImageWindow *imd, FileData *fd)
976 DEBUG_1("%s image begin", get_exec_time());
978 if (imd->il) return FALSE;
980 imd->completed = FALSE;
981 g_object_set(G_OBJECT(imd->pr), "complete", FALSE, NULL);
983 if (image_cache_get(imd))
985 DEBUG_1("from cache: %s", imd->image_fd->path);
989 if (image_read_ahead_check(imd))
991 DEBUG_1("from read ahead buffer: %s", imd->image_fd->path);
995 if (!imd->delay_flip && image_get_pixbuf(imd))
999 pr = PIXBUF_RENDERER(imd->pr);
1000 if (pr->pixbuf) g_object_unref(pr->pixbuf);
1004 g_object_set(G_OBJECT(imd->pr), "loading", TRUE, NULL);
1006 imd->il = image_loader_new(fd);
1008 image_load_set_signals(imd, FALSE);
1010 if (!image_loader_start(imd->il))
1012 DEBUG_1("image start error");
1014 g_object_set(G_OBJECT(imd->pr), "loading", FALSE, NULL);
1016 image_loader_free(imd->il);
1019 image_complete_util(imd, FALSE);
1024 image_state_set(imd, IMAGE_STATE_LOADING);
1027 if (!imd->delay_flip && !image_get_pixbuf(imd) && image_loader_get_pixbuf(imd->il))
1029 image_change_pixbuf(imd, image_loader_get_pixbuf(imd->il), image_zoom_get(imd), TRUE);
1035 static void image_reset(ImageWindow *imd)
1037 /* stops anything currently being done */
1039 DEBUG_1("%s image reset", get_exec_time());
1041 g_object_set(G_OBJECT(imd->pr), "loading", FALSE, NULL);
1043 image_loader_free(imd->il);
1046 color_man_free((ColorMan *)imd->cm);
1049 imd->delay_alter_type = ALTER_NONE;
1051 image_state_set(imd, IMAGE_STATE_NONE);
1055 *-------------------------------------------------------------------
1057 *-------------------------------------------------------------------
1060 static void image_change_complete(ImageWindow *imd, gdouble zoom)
1063 imd->unknown = TRUE;
1067 image_change_pixbuf(imd, NULL, zoom, FALSE);
1072 if (is_readable_file(imd->image_fd->path))
1076 pr = PIXBUF_RENDERER(imd->pr);
1077 pr->zoom = zoom; /* store the zoom, needed by the loader */
1079 if (image_load_begin(imd, imd->image_fd))
1081 imd->unknown = FALSE;
1085 if (imd->unknown == TRUE)
1089 pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN);
1090 image_change_pixbuf(imd, pixbuf, zoom, FALSE);
1091 g_object_unref(pixbuf);
1095 image_update_util(imd);
1098 static void image_change_real(ImageWindow *imd, FileData *fd,
1099 CollectionData *cd, CollectInfo *info, gdouble zoom)
1102 imd->collection = cd;
1103 imd->collection_info = info;
1105 if (imd->auto_refresh && imd->image_fd)
1106 file_data_unregister_real_time_monitor(imd->image_fd);
1108 file_data_unref(imd->image_fd);
1109 imd->image_fd = file_data_ref(fd);
1112 image_change_complete(imd, zoom);
1114 image_update_title(imd);
1115 image_state_set(imd, IMAGE_STATE_IMAGE);
1117 if (imd->auto_refresh && imd->image_fd)
1118 file_data_register_real_time_monitor(imd->image_fd);
1122 *-------------------------------------------------------------------
1124 *-------------------------------------------------------------------
1127 static gboolean image_focus_in_cb(GtkWidget *widget, GdkEventFocus *event, gpointer data)
1129 ImageWindow *imd = data;
1131 if (imd->func_focus_in)
1133 imd->func_focus_in(imd, imd->data_focus_in);
1139 static gboolean image_scroll_cb(GtkWidget *widget, GdkEventScroll *event, gpointer data)
1141 ImageWindow *imd = data;
1143 if (imd->func_scroll &&
1144 event && event->type == GDK_SCROLL)
1146 imd->func_scroll(imd, event, imd->data_scroll);
1154 *-------------------------------------------------------------------
1156 *-------------------------------------------------------------------
1159 void image_attach_window(ImageWindow *imd, GtkWidget *window,
1160 const gchar *title, const gchar *title_right, gboolean show_zoom)
1164 imd->top_window = window;
1166 imd->title = g_strdup(title);
1167 g_free(imd->title_right);
1168 imd->title_right = g_strdup(title_right);
1169 imd->title_show_zoom = show_zoom;
1171 lw = layout_find_by_image(imd);
1173 if (!(options->image.fit_window_to_image && lw && lw->options.tools_float)) window = NULL;
1175 pixbuf_renderer_set_parent((PixbufRenderer *)imd->pr, (GtkWindow *)window);
1177 image_update_title(imd);
1180 void image_set_update_func(ImageWindow *imd,
1181 void (*func)(ImageWindow *imd, gpointer data),
1184 imd->func_update = func;
1185 imd->data_update = data;
1188 void image_set_complete_func(ImageWindow *imd,
1189 void (*func)(ImageWindow *imd, gboolean preload, gpointer data),
1192 imd->func_complete = func;
1193 imd->data_complete = data;
1196 void image_set_state_func(ImageWindow *imd,
1197 void (*func)(ImageWindow *imd, ImageState state, gpointer data),
1200 imd->func_state = func;
1201 imd->data_state = data;
1205 void image_set_button_func(ImageWindow *imd,
1206 void (*func)(ImageWindow *, GdkEventButton *event, gpointer),
1209 imd->func_button = func;
1210 imd->data_button = data;
1213 void image_set_drag_func(ImageWindow *imd,
1214 void (*func)(ImageWindow *, GdkEventMotion *event, gdouble dx, gdouble dy, gpointer),
1217 imd->func_drag = func;
1218 imd->data_drag = data;
1221 void image_set_scroll_func(ImageWindow *imd,
1222 void (*func)(ImageWindow *, GdkEventScroll *event, gpointer),
1225 imd->func_scroll = func;
1226 imd->data_scroll = data;
1229 void image_set_scroll_notify_func(ImageWindow *imd,
1230 void (*func)(ImageWindow *imd, gint x, gint y, gint width, gint height, gpointer data),
1233 imd->func_scroll_notify = func;
1234 imd->data_scroll_notify = data;
1237 void image_set_focus_in_func(ImageWindow *imd,
1238 void (*func)(ImageWindow *, gpointer),
1241 imd->func_focus_in = func;
1242 imd->data_focus_in = data;
1247 const gchar *image_get_path(ImageWindow *imd)
1249 if (imd->image_fd == NULL) return NULL;
1250 return imd->image_fd->path;
1253 const gchar *image_get_name(ImageWindow *imd)
1255 if (imd->image_fd == NULL) return NULL;
1256 return imd->image_fd->name;
1259 FileData *image_get_fd(ImageWindow *imd)
1261 return imd->image_fd;
1264 /* merely changes path string, does not change the image! */
1265 void image_set_fd(ImageWindow *imd, FileData *fd)
1267 if (imd->auto_refresh && imd->image_fd)
1268 file_data_unregister_real_time_monitor(imd->image_fd);
1270 file_data_unref(imd->image_fd);
1271 imd->image_fd = file_data_ref(fd);
1273 image_update_title(imd);
1274 image_state_set(imd, IMAGE_STATE_IMAGE);
1276 if (imd->auto_refresh && imd->image_fd)
1277 file_data_register_real_time_monitor(imd->image_fd);
1280 /* load a new image */
1282 void image_change_fd(ImageWindow *imd, FileData *fd, gdouble zoom)
1284 if (imd->image_fd == fd) return;
1286 image_change_real(imd, fd, NULL, NULL, zoom);
1289 gboolean image_get_image_size(ImageWindow *imd, gint *width, gint *height)
1291 return pixbuf_renderer_get_image_size(PIXBUF_RENDERER(imd->pr), width, height);
1294 GdkPixbuf *image_get_pixbuf(ImageWindow *imd)
1296 return pixbuf_renderer_get_pixbuf((PixbufRenderer *)imd->pr);
1299 void image_change_pixbuf(ImageWindow *imd, GdkPixbuf *pixbuf, gdouble zoom, gboolean lazy)
1301 StereoPixbufData stereo_data = STEREO_PIXBUF_DEFAULT;
1302 /* read_exif and similar functions can actually notice that the file has changed and trigger
1303 a notification that removes the pixbuf from cache and unrefs it. Therefore we must ref it
1304 here before it is taken over by the renderer. */
1305 if (pixbuf) g_object_ref(pixbuf);
1307 imd->orientation = EXIF_ORIENTATION_TOP_LEFT;
1310 if (imd->image_fd->user_orientation)
1312 imd->orientation = imd->image_fd->user_orientation;
1314 else if (options->image.exif_rotate_enable)
1316 imd->orientation = metadata_read_int(imd->image_fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
1317 imd->image_fd->exif_orientation = imd->orientation;
1323 stereo_data = imd->user_stereo;
1324 if (stereo_data == STEREO_PIXBUF_DEFAULT)
1326 stereo_data = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(pixbuf), "stereo_data"));
1330 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, NULL, NULL, FALSE);
1333 color_man_free(imd->cm);
1339 pixbuf_renderer_set_pixbuf_lazy((PixbufRenderer *)imd->pr, pixbuf, zoom, imd->orientation, stereo_data);
1343 pixbuf_renderer_set_pixbuf((PixbufRenderer *)imd->pr, pixbuf, zoom);
1344 pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation);
1345 pixbuf_renderer_set_stereo_data((PixbufRenderer *)imd->pr, stereo_data);
1348 if (pixbuf) g_object_unref(pixbuf);
1350 if (imd->color_profile_enable)
1352 image_post_process_color(imd, 0, FALSE); /* TODO: error handling */
1355 if (imd->cm || imd->desaturate)
1356 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, image_post_process_tile_color_cb, (gpointer) imd, (imd->cm != NULL) );
1358 image_state_set(imd, IMAGE_STATE_IMAGE);
1361 void image_change_from_collection(ImageWindow *imd, CollectionData *cd, CollectInfo *info, gdouble zoom)
1365 if (!cd || !info || !g_list_find(cd->list, info)) return;
1367 image_change_real(imd, info->fd, cd, info, zoom);
1368 cw = collection_window_find(cd);
1371 collection_table_set_focus(cw->table, info);
1372 collection_table_unselect_all(cw->table);
1373 collection_table_select(cw->table,info);
1377 CollectionData *image_get_collection(ImageWindow *imd, CollectInfo **info)
1379 if (collection_to_number(imd->collection) >= 0)
1381 if (g_list_find(imd->collection->list, imd->collection_info) != NULL)
1383 if (info) *info = imd->collection_info;
1387 if (info) *info = NULL;
1389 return imd->collection;
1392 if (info) *info = NULL;
1396 static void image_loader_sync_read_ahead_data(ImageLoader *il, gpointer old_data, gpointer data)
1398 if (g_signal_handlers_disconnect_by_func(G_OBJECT(il), (GCallback)image_read_ahead_error_cb, old_data))
1399 g_signal_connect(G_OBJECT(il), "error", (GCallback)image_read_ahead_error_cb, data);
1401 if (g_signal_handlers_disconnect_by_func(G_OBJECT(il), (GCallback)image_read_ahead_done_cb, old_data))
1402 g_signal_connect(G_OBJECT(il), "done", (GCallback)image_read_ahead_done_cb, data);
1405 static void image_loader_sync_data(ImageLoader *il, gpointer old_data, gpointer data)
1407 if (g_signal_handlers_disconnect_by_func(G_OBJECT(il), (GCallback)image_load_area_cb, old_data))
1408 g_signal_connect(G_OBJECT(il), "area_ready", (GCallback)image_load_area_cb, data);
1410 if (g_signal_handlers_disconnect_by_func(G_OBJECT(il), (GCallback)image_load_error_cb, old_data))
1411 g_signal_connect(G_OBJECT(il), "error", (GCallback)image_load_error_cb, data);
1413 if (g_signal_handlers_disconnect_by_func(G_OBJECT(il), (GCallback)image_load_done_cb, old_data))
1414 g_signal_connect(G_OBJECT(il), "done", (GCallback)image_load_done_cb, data);
1417 /* this is more like a move function
1418 * it moves most data from source to imd
1420 void image_move_from_image(ImageWindow *imd, ImageWindow *source)
1422 if (imd == source) return;
1424 imd->unknown = source->unknown;
1426 imd->collection = source->collection;
1427 imd->collection_info = source->collection_info;
1429 image_loader_free(imd->il);
1432 image_set_fd(imd, image_get_fd(source));
1437 imd->il = source->il;
1440 image_loader_sync_data(imd->il, source, imd);
1442 imd->delay_alter_type = source->delay_alter_type;
1443 source->delay_alter_type = ALTER_NONE;
1446 imd->color_profile_enable = source->color_profile_enable;
1447 imd->color_profile_input = source->color_profile_input;
1448 imd->color_profile_use_image = source->color_profile_use_image;
1449 color_man_free((ColorMan *)imd->cm);
1455 imd->cm = source->cm;
1458 cm = (ColorMan *)imd->cm;
1460 cm->func_done_data = imd;
1463 file_data_unref(imd->read_ahead_fd);
1464 source->read_ahead_fd = NULL;
1466 imd->orientation = source->orientation;
1467 imd->desaturate = source->desaturate;
1469 imd->user_stereo = source->user_stereo;
1471 pixbuf_renderer_move(PIXBUF_RENDERER(imd->pr), PIXBUF_RENDERER(source->pr));
1473 if (imd->cm || imd->desaturate)
1474 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, image_post_process_tile_color_cb, (gpointer) imd, (imd->cm != NULL) );
1476 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, NULL, NULL, TRUE);
1480 /* this is a copy function
1481 * source stays unchanged
1483 void image_copy_from_image(ImageWindow *imd, ImageWindow *source)
1485 if (imd == source) return;
1487 imd->unknown = source->unknown;
1489 imd->collection = source->collection;
1490 imd->collection_info = source->collection_info;
1492 image_loader_free(imd->il);
1495 image_set_fd(imd, image_get_fd(source));
1498 imd->color_profile_enable = source->color_profile_enable;
1499 imd->color_profile_input = source->color_profile_input;
1500 imd->color_profile_use_image = source->color_profile_use_image;
1501 color_man_free((ColorMan *)imd->cm);
1507 imd->cm = source->cm;
1510 cm = (ColorMan *)imd->cm;
1512 cm->func_done_data = imd;
1515 image_loader_free(imd->read_ahead_il);
1516 imd->read_ahead_il = source->read_ahead_il;
1517 source->read_ahead_il = NULL;
1518 if (imd->read_ahead_il) image_loader_sync_read_ahead_data(imd->read_ahead_il, source, imd);
1520 file_data_unref(imd->read_ahead_fd);
1521 imd->read_ahead_fd = source->read_ahead_fd;
1522 source->read_ahead_fd = NULL;
1524 imd->completed = source->completed;
1525 imd->state = source->state;
1526 source->state = IMAGE_STATE_NONE;
1528 imd->orientation = source->orientation;
1529 imd->desaturate = source->desaturate;
1531 imd->user_stereo = source->user_stereo;
1533 pixbuf_renderer_copy(PIXBUF_RENDERER(imd->pr), PIXBUF_RENDERER(source->pr));
1535 if (imd->cm || imd->desaturate)
1536 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, image_post_process_tile_color_cb, (gpointer) imd, (imd->cm != NULL) );
1538 pixbuf_renderer_set_post_process_func((PixbufRenderer *)imd->pr, NULL, NULL, TRUE);
1545 void image_area_changed(ImageWindow *imd, gint x, gint y, gint width, gint height)
1547 pixbuf_renderer_area_changed((PixbufRenderer *)imd->pr, x, y, width, height);
1550 void image_reload(ImageWindow *imd)
1552 if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return;
1554 image_change_complete(imd, image_zoom_get(imd));
1557 void image_scroll(ImageWindow *imd, gint x, gint y)
1559 pixbuf_renderer_scroll((PixbufRenderer *)imd->pr, x, y);
1562 void image_scroll_to_point(ImageWindow *imd, gint x, gint y,
1563 gdouble x_align, gdouble y_align)
1565 pixbuf_renderer_scroll_to_point((PixbufRenderer *)imd->pr, x, y, x_align, y_align);
1568 void image_get_scroll_center(ImageWindow *imd, gdouble *x, gdouble *y)
1570 pixbuf_renderer_get_scroll_center(PIXBUF_RENDERER(imd->pr), x, y);
1573 void image_set_scroll_center(ImageWindow *imd, gdouble x, gdouble y)
1575 pixbuf_renderer_set_scroll_center(PIXBUF_RENDERER(imd->pr), x, y);
1578 void image_zoom_adjust(ImageWindow *imd, gdouble increment)
1580 pixbuf_renderer_zoom_adjust((PixbufRenderer *)imd->pr, increment);
1583 void image_zoom_adjust_at_point(ImageWindow *imd, gdouble increment, gint x, gint y)
1585 pixbuf_renderer_zoom_adjust_at_point((PixbufRenderer *)imd->pr, increment, x, y);
1588 void image_zoom_set_limits(ImageWindow *imd, gdouble min, gdouble max)
1590 pixbuf_renderer_zoom_set_limits((PixbufRenderer *)imd->pr, min, max);
1593 void image_zoom_set(ImageWindow *imd, gdouble zoom)
1595 pixbuf_renderer_zoom_set((PixbufRenderer *)imd->pr, zoom);
1598 void image_zoom_set_fill_geometry(ImageWindow *imd, gboolean vertical)
1604 pr = (PixbufRenderer *)imd->pr;
1606 if (!pixbuf_renderer_get_pixbuf(pr) ||
1607 !pixbuf_renderer_get_image_size(pr, &width, &height)) return;
1611 zoom = (gdouble)pr->viewport_height / height;
1615 zoom = (gdouble)pr->viewport_width / width;
1620 zoom = 0.0 - 1.0 / zoom;
1623 pixbuf_renderer_zoom_set(pr, zoom);
1626 gdouble image_zoom_get(ImageWindow *imd)
1628 return pixbuf_renderer_zoom_get((PixbufRenderer *)imd->pr);
1631 gdouble image_zoom_get_real(ImageWindow *imd)
1633 return pixbuf_renderer_zoom_get_scale((PixbufRenderer *)imd->pr);
1636 gchar *image_zoom_get_as_text(ImageWindow *imd)
1644 gchar *approx = " ";
1646 zoom = image_zoom_get(imd);
1647 scale = image_zoom_get_real(imd);
1653 else if (zoom < 0.0)
1657 else if (zoom == 0.0 && scale != 0.0)
1670 if (rint(l) != l) pl = 2;
1671 if (rint(r) != r) pr = 2;
1673 return g_strdup_printf("%.*f :%s%.*f", pl, l, approx, pr, r);
1676 gdouble image_zoom_get_default(ImageWindow *imd)
1680 switch (options->image.zoom_mode)
1682 case ZOOM_RESET_ORIGINAL:
1684 case ZOOM_RESET_FIT_WINDOW:
1687 case ZOOM_RESET_NONE:
1688 if (imd) zoom = image_zoom_get(imd);
1696 gint image_stereo_get(ImageWindow *imd)
1698 return pixbuf_renderer_stereo_get((PixbufRenderer *)imd->pr);
1701 void image_stereo_set(ImageWindow *imd, gint stereo_mode)
1703 DEBUG_1("Setting stereo mode %04x for imd %p", stereo_mode, imd);
1704 pixbuf_renderer_stereo_set((PixbufRenderer *)imd->pr, stereo_mode);
1707 void image_stereo_swap(ImageWindow *imd)
1709 gint stereo_mode = pixbuf_renderer_stereo_get((PixbufRenderer *)imd->pr);
1710 stereo_mode ^= PR_STEREO_SWAP;
1711 pixbuf_renderer_stereo_set((PixbufRenderer *)imd->pr, stereo_mode);
1714 StereoPixbufData image_stereo_pixbuf_get(ImageWindow *imd)
1716 return imd->user_stereo;
1719 void image_stereo_pixbuf_set(ImageWindow *imd, StereoPixbufData stereo_mode)
1721 imd->user_stereo = stereo_mode;
1727 void image_prebuffer_set(ImageWindow *imd, FileData *fd)
1729 if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return;
1733 if (!file_cache_get(image_get_cache(), fd))
1735 image_read_ahead_set(imd, fd);
1740 image_read_ahead_cancel(imd);
1744 static void image_notify_cb(FileData *fd, NotifyType type, gpointer data)
1746 ImageWindow *imd = data;
1748 if (!imd || !image_get_pixbuf(imd) ||
1749 /* imd->il || */ /* loading in progress - do not check - it should start from the beginning anyway */
1750 !imd->image_fd || /* nothing to reload */
1751 imd->state == IMAGE_STATE_NONE /* loading not started, no need to reload */
1754 if ((type & NOTIFY_REREAD) && fd == imd->image_fd)
1756 /* there is no need to reload on NOTIFY_CHANGE,
1757 modified files should be detacted anyway and NOTIFY_REREAD should be recieved
1758 or they are removed from the filelist completely on "move" and "delete"
1760 DEBUG_1("Notify image: %s %04x", fd->path, type);
1765 void image_auto_refresh_enable(ImageWindow *imd, gboolean enable)
1767 if (!enable && imd->auto_refresh && imd->image_fd)
1768 file_data_unregister_real_time_monitor(imd->image_fd);
1770 if (enable && !imd->auto_refresh && imd->image_fd)
1771 file_data_register_real_time_monitor(imd->image_fd);
1773 imd->auto_refresh = enable;
1776 void image_top_window_set_sync(ImageWindow *imd, gboolean allow_sync)
1778 imd->top_window_sync = allow_sync;
1780 g_object_set(G_OBJECT(imd->pr), "window_fit", allow_sync, NULL);
1783 void image_background_set_color(ImageWindow *imd, GdkColor *color)
1785 pixbuf_renderer_set_color((PixbufRenderer *)imd->pr, color);
1788 void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscreen)
1790 GdkColor *color = NULL;
1792 if ((options->image.use_custom_border_color && !fullscreen) ||
1793 (options->image.use_custom_border_color_in_fullscreen && fullscreen))
1795 color = &options->image.border_color;
1798 image_background_set_color(imd, color);
1801 void image_color_profile_set(ImageWindow *imd,
1807 if (input_type < 0 || input_type >= COLOR_PROFILE_FILE + COLOR_PROFILE_INPUTS)
1812 imd->color_profile_input = input_type;
1813 imd->color_profile_use_image = use_image;
1816 gboolean image_color_profile_get(ImageWindow *imd,
1818 gboolean *use_image)
1820 if (!imd) return FALSE;
1822 if (input_type) *input_type = imd->color_profile_input;
1823 if (use_image) *use_image = imd->color_profile_use_image;
1828 void image_color_profile_set_use(ImageWindow *imd, gboolean enable)
1832 if (imd->color_profile_enable == enable) return;
1834 imd->color_profile_enable = enable;
1837 gboolean image_color_profile_get_use(ImageWindow *imd)
1839 if (!imd) return FALSE;
1841 return imd->color_profile_enable;
1844 gboolean image_color_profile_get_status(ImageWindow *imd, gchar **image_profile, gchar **screen_profile)
1847 if (!imd) return FALSE;
1850 if (!cm) return FALSE;
1851 return color_man_get_status(cm, image_profile, screen_profile);
1855 void image_set_delay_flip(ImageWindow *imd, gboolean delay)
1858 imd->delay_flip == delay) return;
1860 imd->delay_flip = delay;
1862 g_object_set(G_OBJECT(imd->pr), "delay_flip", delay, NULL);
1864 if (!imd->delay_flip && imd->il)
1868 pr = PIXBUF_RENDERER(imd->pr);
1869 if (pr->pixbuf) g_object_unref(pr->pixbuf);
1872 image_load_pixbuf_ready(imd);
1876 void image_to_root_window(ImageWindow *imd, gboolean scaled)
1878 #if !GTK_CHECK_VERSION(3,0,0)
1880 GdkWindow *rootwindow;
1888 pixbuf = image_get_pixbuf(imd);
1889 if (!pixbuf) return;
1891 screen = gtk_widget_get_screen(imd->widget);
1892 rootwindow = gdk_screen_get_root_window(screen);
1893 if (gdk_window_get_visual(rootwindow) != gdk_visual_get_system()) return;
1897 width = gdk_screen_width();
1898 height = gdk_screen_height();
1902 pixbuf_renderer_get_scaled_size((PixbufRenderer *)imd->pr, &width, &height);
1905 pb = gdk_pixbuf_scale_simple(pixbuf, width, height, (GdkInterpType)options->image.zoom_quality);
1907 gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, NULL, 128);
1908 gdk_window_set_back_pixmap(rootwindow, pixmap, FALSE);
1909 gdk_window_clear(rootwindow);
1911 g_object_unref(pixmap);
1917 void image_select(ImageWindow *imd, gboolean select)
1919 if (!imd->has_frame) return;
1923 gtk_widget_set_state(imd->widget, GTK_STATE_SELECTED);
1924 gtk_widget_set_state(imd->pr, GTK_STATE_NORMAL); /* do not propagate */
1927 gtk_widget_set_state(imd->widget, GTK_STATE_NORMAL);
1930 void image_set_selectable(ImageWindow *imd, gboolean selectable)
1932 if (!imd->has_frame) return;
1934 gtk_frame_set_shadow_type(GTK_FRAME(imd->frame), GTK_SHADOW_NONE);
1935 gtk_container_set_border_width(GTK_CONTAINER(imd->frame), selectable ? 4 : 0);
1938 void image_grab_focus(ImageWindow *imd)
1942 gtk_widget_grab_focus(imd->frame);
1946 gtk_widget_grab_focus(imd->widget);
1952 *-------------------------------------------------------------------
1954 *-------------------------------------------------------------------
1957 static void image_options_set(ImageWindow *imd)
1959 g_object_set(G_OBJECT(imd->pr), "zoom_quality", options->image.zoom_quality,
1960 "zoom_2pass", options->image.zoom_2pass,
1961 "zoom_expand", options->image.zoom_to_fit_allow_expand,
1962 "scroll_reset", options->image.scroll_reset_method,
1963 "cache_display", options->image.tile_cache_max,
1964 "window_fit", (imd->top_window_sync && options->image.fit_window_to_image),
1965 "window_limit", options->image.limit_window_size,
1966 "window_limit_value", options->image.max_window_size,
1967 "autofit_limit", options->image.limit_autofit_size,
1968 "autofit_limit_value", options->image.max_autofit_size,
1969 "enlargement_limit_value", options->image.max_enlargement_size,
1973 pixbuf_renderer_set_parent((PixbufRenderer *)imd->pr, (GtkWindow *)imd->top_window);
1975 image_stereo_set(imd, options->stereo.mode);
1976 pixbuf_renderer_stereo_fixed_set((PixbufRenderer *)imd->pr,
1977 options->stereo.fixed_w, options->stereo.fixed_h,
1978 options->stereo.fixed_x1, options->stereo.fixed_y1,
1979 options->stereo.fixed_x2, options->stereo.fixed_y2);
1982 void image_options_sync(void)
1994 image_options_set(imd);
1999 *-------------------------------------------------------------------
2001 *-------------------------------------------------------------------
2004 static void image_free(ImageWindow *imd)
2006 image_list = g_list_remove(image_list, imd);
2008 if (imd->auto_refresh && imd->image_fd)
2009 file_data_unregister_real_time_monitor(imd->image_fd);
2011 file_data_unregister_notify_func(image_notify_cb, imd);
2015 image_read_ahead_cancel(imd);
2017 file_data_unref(imd->image_fd);
2019 g_free(imd->title_right);
2023 static void image_destroy_cb(GtkWidget *widget, gpointer data)
2025 ImageWindow *imd = data;
2028 #if GTK_CHECK_VERSION(3,0,0)
2029 gboolean selectable_frame_draw_cb(GtkWidget *widget, cairo_t *cr, gpointer data)
2031 GtkAllocation allocation;
2032 gtk_widget_get_allocation(widget, &allocation);
2033 gtk_paint_flat_box(gtk_widget_get_style(widget),
2035 gtk_widget_get_state(widget),
2036 gtk_frame_get_shadow_type(GTK_FRAME(widget)),
2039 allocation.x + 3, allocation.y + 3,
2040 allocation.width - 6, allocation.height - 6);
2042 if (gtk_widget_has_focus(widget))
2044 gtk_paint_focus(gtk_widget_get_style(widget), cr, GTK_STATE_ACTIVE,
2045 widget, "image_window",
2046 allocation.x, allocation.y,
2047 allocation.width - 1, allocation.height - 1);
2051 gtk_paint_shadow(gtk_widget_get_style(widget), cr, GTK_STATE_NORMAL, GTK_SHADOW_IN,
2052 widget, "image_window",
2053 allocation.x, allocation.y,
2054 allocation.width - 1, allocation.height - 1);
2060 gboolean selectable_frame_expose_cb(GtkWidget *widget, GdkEventExpose *event, gpointer data)
2062 GtkAllocation allocation;
2063 gtk_widget_get_allocation(widget, &allocation);
2064 gtk_paint_flat_box(gtk_widget_get_style(widget),
2065 gtk_widget_get_window(widget),
2066 gtk_widget_get_state(widget),
2067 gtk_frame_get_shadow_type(GTK_FRAME(widget)),
2071 allocation.x + 3, allocation.y + 3,
2072 allocation.width - 6, allocation.height - 6);
2074 if (gtk_widget_has_focus(widget))
2076 gtk_paint_focus(gtk_widget_get_style(widget), gtk_widget_get_window(widget), GTK_STATE_ACTIVE,
2077 &event->area, widget, "image_window",
2078 allocation.x, allocation.y,
2079 allocation.width - 1, allocation.height - 1);
2083 gtk_paint_shadow(gtk_widget_get_style(widget), gtk_widget_get_window(widget), GTK_STATE_NORMAL, GTK_SHADOW_IN,
2084 &event->area, widget, "image_window",
2085 allocation.x, allocation.y,
2086 allocation.width - 1, allocation.height - 1);
2093 void image_set_frame(ImageWindow *imd, gboolean frame)
2097 if (frame == imd->has_frame) return;
2099 gtk_widget_hide(imd->pr);
2103 imd->frame = gtk_frame_new(NULL);
2104 DEBUG_NAME(imd->frame);
2105 g_object_ref(imd->pr);
2106 if (imd->has_frame != -1) gtk_container_remove(GTK_CONTAINER(imd->widget), imd->pr);
2107 gtk_container_add(GTK_CONTAINER(imd->frame), imd->pr);
2109 g_object_unref(imd->pr);
2110 gtk_widget_set_can_focus(imd->frame, TRUE);
2111 gtk_widget_set_app_paintable(imd->frame, TRUE);
2113 #if GTK_CHECK_VERSION(3,0,0)
2114 g_signal_connect(G_OBJECT(imd->frame), "draw",
2115 G_CALLBACK(selectable_frame_draw_cb), NULL);
2117 g_signal_connect(G_OBJECT(imd->frame), "expose_event",
2118 G_CALLBACK(selectable_frame_expose_cb), NULL);
2120 g_signal_connect(G_OBJECT(imd->frame), "focus_in_event",
2121 G_CALLBACK(image_focus_in_cb), imd);
2123 gtk_box_pack_start(GTK_BOX(imd->widget), imd->frame, TRUE, TRUE, 0);
2124 gtk_widget_show(imd->frame);
2128 g_object_ref(imd->pr);
2131 gtk_container_remove(GTK_CONTAINER(imd->frame), imd->pr);
2132 gtk_widget_destroy(imd->frame);
2135 gtk_box_pack_start(GTK_BOX(imd->widget), imd->pr, TRUE, TRUE, 0);
2137 g_object_unref(imd->pr);
2140 gtk_widget_show(imd->pr);
2142 imd->has_frame = frame;
2145 ImageWindow *image_new(gboolean frame)
2149 imd = g_new0(ImageWindow, 1);
2151 imd->unknown = TRUE;
2152 imd->has_frame = -1; /* not initialized; for image_set_frame */
2153 imd->delay_alter_type = ALTER_NONE;
2154 imd->state = IMAGE_STATE_NONE;
2155 imd->color_profile_from_image = COLOR_PROFILE_NONE;
2156 imd->orientation = 1;
2158 imd->pr = GTK_WIDGET(pixbuf_renderer_new());
2159 DEBUG_NAME(imd->pr);
2161 image_options_set(imd);
2163 imd->widget = gtk_vbox_new(0, 0);
2164 DEBUG_NAME(imd->widget);
2166 image_set_frame(imd, frame);
2168 image_set_selectable(imd, 0);
2170 g_signal_connect(G_OBJECT(imd->pr), "clicked",
2171 G_CALLBACK(image_click_cb), imd);
2172 g_signal_connect(G_OBJECT(imd->pr), "button_press_event",
2173 G_CALLBACK(image_press_cb), imd);
2174 g_signal_connect(G_OBJECT(imd->pr), "scroll_notify",
2175 G_CALLBACK(image_scroll_notify_cb), imd);
2177 g_signal_connect(G_OBJECT(imd->pr), "scroll_event",
2178 G_CALLBACK(image_scroll_cb), imd);
2180 g_signal_connect(G_OBJECT(imd->pr), "destroy",
2181 G_CALLBACK(image_destroy_cb), imd);
2183 g_signal_connect(G_OBJECT(imd->pr), "zoom",
2184 G_CALLBACK(image_zoom_cb), imd);
2185 g_signal_connect(G_OBJECT(imd->pr), "render_complete",
2186 G_CALLBACK(image_render_complete_cb), imd);
2187 g_signal_connect(G_OBJECT(imd->pr), "drag",
2188 G_CALLBACK(image_drag_cb), imd);
2190 file_data_register_notify_func(image_notify_cb, imd, NOTIFY_PRIORITY_LOW);
2192 image_list = g_list_append(image_list, imd);
2197 void image_get_rectangle(gint *x1, gint *y1, gint *x2, gint *y2)
2205 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */