annotate src/image-load.c @ 1011:616b14da08c2

do not access image_loader directly
author nadvornik
date Fri, 29 Aug 2008 12:35:13 +0000
parents dd311dae857a
children fe82830ab8fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
196
f6e307c7bad6 rename GQview -> Geeqie over the code
nadvornik
parents: 176
diff changeset
2 * Geeqie
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
3 * (C) 2004 John Ellis
475
48c8e49b571c updated copyright in source files
nadvornik
parents: 446
diff changeset
4 * Copyright (C) 2008 The Geeqie Team
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 196
diff changeset
14 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15 #include "image-load.h"
507
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents: 506
diff changeset
16
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents: 506
diff changeset
17 #include "exif.h"
586
905688aa2317 split filelist.c to filefilter.c and filedata.c
nadvornik
parents: 507
diff changeset
18 #include "filedata.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21 #include <fcntl.h>
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
22 #include <sys/mman.h>
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25 static void image_loader_sync_pixbuf(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27 GdkPixbuf *pb;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
28
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
29 if (!il->loader) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31 pb = gdk_pixbuf_loader_get_pixbuf(il->loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 if (pb == il->pixbuf) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36 il->pixbuf = pb;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37 if (il->pixbuf) gdk_pixbuf_ref(il->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
40 static void image_loader_area_updated_cb(GdkPixbufLoader *loader,
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 guint x, guint y, guint w, guint h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46 if (il->func_area_ready)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 if (!il->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 image_loader_sync_pixbuf(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51 if (!il->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
53 log_printf("critical: area_ready signal with NULL pixbuf (out of mem?)\n");
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56 il->func_area_ready(il, x, y, w, h, il->data_area_ready);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
60 static void image_loader_area_prepared_cb(GdkPixbufLoader *loader, gpointer data)
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
61 {
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
62 GdkPixbuf *pb;
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
63 guchar *pix;
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
64 size_t h, rs;
961
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
65
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
66 /* a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669 */
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
67 gchar *format = gdk_pixbuf_format_get_name(gdk_pixbuf_loader_get_format(loader));
995
6ca2c5fd7b13 Whitespaces cleanup.
zas_
parents: 961
diff changeset
68 if (strcmp(format, "svg") == 0)
961
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
69 {
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
70 g_free(format);
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
71 return;
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
72 }
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
73
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
74 g_free(format);
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
75
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
76 pb = gdk_pixbuf_loader_get_pixbuf(loader);
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
77
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
78 h = gdk_pixbuf_get_height(pb);
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
79 rs = gdk_pixbuf_get_rowstride(pb);
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
80 pix = gdk_pixbuf_get_pixels(pb);
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
81
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
82 memset(pix, 0, rs * h); /*this should be faster than pixbuf_fill */
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
83
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
84 }
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
85
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86 static void image_loader_size_cb(GdkPixbufLoader *loader,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87 gint width, gint height, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
88 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90 GdkPixbufFormat *format;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91 gchar **mime_types;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92 gint scale = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 gint n;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 if (il->requested_width < 1 || il->requested_height < 1) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97 format = gdk_pixbuf_loader_get_format(loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 if (!format) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100 mime_types = gdk_pixbuf_format_get_mime_types(format);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 n = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102 while (mime_types[n])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 if (strstr(mime_types[n], "jpeg")) scale = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 n++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107 g_strfreev(mime_types);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
108
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 if (!scale) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111 if (width > il->requested_width || height > il->requested_height)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 gint nw, nh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117 nw = il->requested_width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 nh = (gdouble)nw / width * height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
119 if (nh < 1) nh = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
120 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123 nh = il->requested_height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 nw = (gdouble)nh / height * width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125 if (nw < 1) nw = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
127
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128 gdk_pixbuf_loader_set_size(loader, nw, nh);
14
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
129 il->shrunk = TRUE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 static void image_loader_stop(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
136
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 if (il->idle_id != -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139 g_source_remove(il->idle_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140 il->idle_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
143 if (il->loader)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
144 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 /* some loaders do not have a pixbuf till close, order is important here */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 gdk_pixbuf_loader_close(il->loader, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147 image_loader_sync_pixbuf(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 g_object_unref(G_OBJECT(il->loader));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149 il->loader = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
152 if (il->mapped_file)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 {
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
154 if (il->preview)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
155 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
156 exif_free_preview(il->mapped_file);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
157 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
158 else
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
159 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
160 munmap(il->mapped_file, il->bytes_total);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
161 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
162 il->mapped_file = NULL;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 il->done = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 static void image_loader_done(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172 if (il->func_done) il->func_done(il, il->data_done);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 static gint image_loader_done_delay_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179 il->idle_done_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 image_loader_done(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 static void image_loader_done_delay(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 if (il->idle_done_id == -1) il->idle_done_id = g_idle_add_full(il->idle_priority,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 image_loader_done_delay_cb, il, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 static void image_loader_error(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193
1009
dd311dae857a fixed thumbnail loader for the new raw preview interface
nadvornik
parents: 1008
diff changeset
194 DEBUG_1("pixbuf_loader reported load error for: %s", il->fd->path);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 if (il->func_error) il->func_error(il, il->data_error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 static gint image_loader_idle_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202 gint b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
203 gint c;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205 if (!il) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
206
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
207 if (il->idle_id == -1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
209 c = il->idle_read_loop_count ? il->idle_read_loop_count : 1;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
210 while (c > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
211 {
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
212 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214 if (b == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 image_loader_done(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
220 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL)))
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 image_loader_error(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 il->bytes_read += b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 c--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 if (il->func_percent && il->bytes_total > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 il->func_percent(il, (gdouble)il->bytes_read / il->bytes_total, il->data_percent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239 static gint image_loader_begin(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 {
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 995
diff changeset
241 gint b;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243 if (!il->loader || il->pixbuf) return FALSE;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
244
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
245 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
246
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 if (b < 1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
253 if (!gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL))
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
259 il->bytes_read += b;
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
260
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
261 /* read until size is known */
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
262 while (il->loader && !gdk_pixbuf_loader_get_pixbuf(il->loader) && b > 0)
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
263 {
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
264 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
265 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL)))
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
266 {
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
267 image_loader_stop(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
268 return FALSE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
269 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
270 il->bytes_read += b;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
271 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
272 if (!il->pixbuf) image_loader_sync_pixbuf(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
273
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
274 if (il->bytes_read == il->bytes_total || b < 1)
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
275 {
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
276 /* done, handle (broken) loaders that do not have pixbuf till close */
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
277 image_loader_stop(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
278
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
279 if (!il->pixbuf) return FALSE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
280
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
281 image_loader_done_delay(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
282 return TRUE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
283 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
284
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
285 if (!il->pixbuf)
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
286 {
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
287 image_loader_stop(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
288 return FALSE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
289 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
290
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
291 /* finally, progressive loading :) */
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
292 il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, NULL);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
293
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297 static gint image_loader_setup(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
302 if (!il || il->loader || il->mapped_file) return FALSE;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
303
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
304 il->mapped_file = NULL;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
305
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
306 if (il->fd)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
307 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
308 ExifData *exif = exif_read_fd(il->fd);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
309
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
310 il->mapped_file = exif_get_preview(exif, &il->bytes_total);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
311
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
312 if (il->mapped_file)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
313 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
314 il->preview = TRUE;
1009
dd311dae857a fixed thumbnail loader for the new raw preview interface
nadvornik
parents: 1008
diff changeset
315 DEBUG_1("Raw file %s contains embedded image", il->fd->path);
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
316 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
317 exif_free_fd(il->fd, exif);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
318 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
320
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
321 if (!il->mapped_file)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
322 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
323 /* normal file */
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
324 gint load_fd;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
325
1009
dd311dae857a fixed thumbnail loader for the new raw preview interface
nadvornik
parents: 1008
diff changeset
326 pathl = path_from_utf8(il->fd->path);
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
327 load_fd = open(pathl, O_RDONLY | O_NONBLOCK);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
328 g_free(pathl);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
329 if (load_fd == -1) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
331 if (fstat(load_fd, &st) == 0)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
332 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
333 il->bytes_total = st.st_size;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
334 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
335 else
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
336 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
337 close(load_fd);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
338 return FALSE;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
339 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
340
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
341 il->mapped_file = mmap(0, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
342 close(load_fd);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
343 if (il->mapped_file == MAP_FAILED)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
344 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
345 il->mapped_file = 0;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
346 return FALSE;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
347 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
348 il->preview = FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
351
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 il->loader = gdk_pixbuf_loader_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 g_signal_connect(G_OBJECT(il->loader), "area_updated",
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
354 G_CALLBACK(image_loader_area_updated_cb), il);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 g_signal_connect(G_OBJECT(il->loader), "size_prepared",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356 G_CALLBACK(image_loader_size_cb), il);
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
357 g_signal_connect(G_OBJECT(il->loader), "area_prepared",
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
358 G_CALLBACK(image_loader_area_prepared_cb), il);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359
14
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
360 il->shrunk = FALSE;
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
361
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362 return image_loader_begin(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364
1009
dd311dae857a fixed thumbnail loader for the new raw preview interface
nadvornik
parents: 1008
diff changeset
365 ImageLoader *image_loader_new(FileData *fd)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
367 ImageLoader *il;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368
1009
dd311dae857a fixed thumbnail loader for the new raw preview interface
nadvornik
parents: 1008
diff changeset
369 if (!fd) return NULL;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 il = g_new0(ImageLoader, 1);
1009
dd311dae857a fixed thumbnail loader for the new raw preview interface
nadvornik
parents: 1008
diff changeset
372 il->fd = file_data_ref(fd);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 il->pixbuf = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 il->idle_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 il->idle_priority = G_PRIORITY_DEFAULT_IDLE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 il->done = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377 il->loader = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 il->bytes_read = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 il->bytes_total = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 il->idle_done_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
384 il->idle_read_loop_count = options->image.idle_read_loop_count;
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
385 il->read_buffer_size = options->image.read_buffer_size;
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
386 il->mapped_file = NULL;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388 il->requested_width = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389 il->requested_height = 0;
14
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
390 il->shrunk = FALSE;
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 500
diff changeset
391 DEBUG_1("new image loader %p, bufsize=%u idle_loop=%u", il, il->read_buffer_size, il->idle_read_loop_count);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392 return il;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 void image_loader_free(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 if (il->idle_done_id != -1) g_source_remove(il->idle_done_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf);
1009
dd311dae857a fixed thumbnail loader for the new raw preview interface
nadvornik
parents: 1008
diff changeset
402 file_data_unref(il->fd);
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 500
diff changeset
403 DEBUG_1("freeing image loader %p bytes_read=%d", il, il->bytes_read);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 g_free(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407 /* don't forget to gdk_pixbuf_ref() it if you want to use it after image_loader_free() */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 if (!il) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 return il->pixbuf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 gchar *image_loader_get_format(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 GdkPixbufFormat *format;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 gchar **mimev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 gchar *mime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421 if (!il || !il->loader) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 format = gdk_pixbuf_loader_get_format(il->loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 if (!format) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 mimev = gdk_pixbuf_format_get_mime_types(format);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 if (!mimev) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 /* return first member of mimev, as GdkPixbufLoader has no way to tell us which exact one ? */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 mime = g_strdup(mimev[0]);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 g_strfreev(mimev);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 return mime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 void image_loader_set_area_ready_func(ImageLoader *il,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 void (*func_area_ready)(ImageLoader *, guint, guint, guint, guint, gpointer),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 gpointer data_area_ready)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442 il->func_area_ready = func_area_ready;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443 il->data_area_ready = data_area_ready;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 void image_loader_set_error_func(ImageLoader *il,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447 void (*func_error)(ImageLoader *, gpointer),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 gpointer data_error)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 il->func_error = func_error;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 il->data_error = data_error;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455
890
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
456 void image_loader_set_done_func(ImageLoader *il,
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
457 void (*func_done)(ImageLoader *, gpointer),
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
458 gpointer data_done)
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
459 {
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
460 if (!il) return;
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
461
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
462 il->func_done = func_done;
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
463 il->data_done = data_done;
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
464 }
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
465
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 void image_loader_set_percent_func(ImageLoader *il,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 void (*func_percent)(ImageLoader *, gdouble, gpointer),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
468 gpointer data_percent)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
470 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 il->func_percent = func_percent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 il->data_percent = data_percent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 void image_loader_set_requested_size(ImageLoader *il, gint width, gint height)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 il->requested_width = width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 il->requested_height = height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
484 void image_loader_set_buffer_size(ImageLoader *il, guint count)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
488 il->idle_read_loop_count = count ? count : 1;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491 void image_loader_set_priority(ImageLoader *il, gint priority)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495 il->idle_priority = priority;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498 gint image_loader_start(ImageLoader *il, void (*func_done)(ImageLoader *, gpointer), gpointer data_done)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500 if (!il) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501
1009
dd311dae857a fixed thumbnail loader for the new raw preview interface
nadvornik
parents: 1008
diff changeset
502 if (!il->fd) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
503
890
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
504 image_loader_set_done_func(il, func_done, data_done);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 return image_loader_setup(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 gdouble image_loader_get_percent(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 if (!il || il->bytes_total == 0) return 0.0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
513 return (gdouble)il->bytes_read / il->bytes_total;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
514 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
516 gint image_loader_get_is_done(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
517 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518 if (!il) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520 return il->done;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522
1011
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
523 FileData *image_loader_get_fd(ImageLoader *il)
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
524 {
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
525 if (!il) return NULL;
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
526
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
527 return il->fd;
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
528
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
529 }
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
530
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
531 gint image_loader_get_shrunk(ImageLoader *il)
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
532 {
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
533 if (!il) return FALSE;
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
534
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
535 return il->shrunk;
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
536
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
537 }
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
538
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
539
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
540 gint image_load_dimensions(FileData *fd, gint *width, gint *height)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542 ImageLoader *il;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 gint success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
545 il = image_loader_new(fd);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547 success = image_loader_start(il, NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
549 if (success && il->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
550 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 if (width) *width = gdk_pixbuf_get_width(il->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552 if (height) *height = gdk_pixbuf_get_height(il->pixbuf);;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556 if (width) *width = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
557 if (height) *height = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560 image_loader_free(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562 return success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 }