Mercurial > geeqie
annotate src/image-load.c @ 1009:dd311dae857a
fixed thumbnail loader for the new raw preview interface
author | nadvornik |
---|---|
date | Fri, 29 Aug 2008 09:38:10 +0000 |
parents | 68b0cb6ca8f0 |
children | 616b14da08c2 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
281 | 14 #include "main.h" |
9 | 15 #include "image-load.h" |
507 | 16 |
17 #include "exif.h" | |
586 | 18 #include "filedata.h" |
9 | 19 #include "ui_fileops.h" |
20 | |
21 #include <fcntl.h> | |
1008 | 22 #include <sys/mman.h> |
9 | 23 |
24 | |
25 static void image_loader_sync_pixbuf(ImageLoader *il) | |
26 { | |
27 GdkPixbuf *pb; | |
28 | |
29 if (!il->loader) return; | |
30 | |
31 pb = gdk_pixbuf_loader_get_pixbuf(il->loader); | |
32 | |
33 if (pb == il->pixbuf) return; | |
34 | |
35 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf); | |
36 il->pixbuf = pb; | |
37 if (il->pixbuf) gdk_pixbuf_ref(il->pixbuf); | |
38 } | |
39 | |
500 | 40 static void image_loader_area_updated_cb(GdkPixbufLoader *loader, |
9 | 41 guint x, guint y, guint w, guint h, |
42 gpointer data) | |
43 { | |
44 ImageLoader *il = data; | |
45 | |
46 if (il->func_area_ready) | |
47 { | |
48 if (!il->pixbuf) | |
49 { | |
50 image_loader_sync_pixbuf(il); | |
51 if (!il->pixbuf) | |
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 | 54 } |
55 } | |
56 il->func_area_ready(il, x, y, w, h, il->data_area_ready); | |
57 } | |
58 } | |
59 | |
500 | 60 static void image_loader_area_prepared_cb(GdkPixbufLoader *loader, gpointer data) |
61 { | |
62 GdkPixbuf *pb; | |
63 guchar *pix; | |
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 | 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 | 75 |
76 pb = gdk_pixbuf_loader_get_pixbuf(loader); | |
77 | |
78 h = gdk_pixbuf_get_height(pb); | |
79 rs = gdk_pixbuf_get_rowstride(pb); | |
80 pix = gdk_pixbuf_get_pixels(pb); | |
81 | |
82 memset(pix, 0, rs * h); /*this should be faster than pixbuf_fill */ | |
83 | |
84 } | |
85 | |
9 | 86 static void image_loader_size_cb(GdkPixbufLoader *loader, |
87 gint width, gint height, gpointer data) | |
88 { | |
89 ImageLoader *il = data; | |
90 GdkPixbufFormat *format; | |
91 gchar **mime_types; | |
92 gint scale = FALSE; | |
93 gint n; | |
94 | |
95 if (il->requested_width < 1 || il->requested_height < 1) return; | |
96 | |
97 format = gdk_pixbuf_loader_get_format(loader); | |
98 if (!format) return; | |
99 | |
100 mime_types = gdk_pixbuf_format_get_mime_types(format); | |
101 n = 0; | |
102 while (mime_types[n]) | |
103 { | |
104 if (strstr(mime_types[n], "jpeg")) scale = TRUE; | |
105 n++; | |
106 } | |
107 g_strfreev(mime_types); | |
442 | 108 |
9 | 109 if (!scale) return; |
110 | |
111 if (width > il->requested_width || height > il->requested_height) | |
112 { | |
113 gint nw, nh; | |
114 | |
115 if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height)) | |
116 { | |
117 nw = il->requested_width; | |
118 nh = (gdouble)nw / width * height; | |
119 if (nh < 1) nh = 1; | |
120 } | |
121 else | |
122 { | |
123 nh = il->requested_height; | |
124 nw = (gdouble)nh / height * width; | |
125 if (nw < 1) nw = 1; | |
126 } | |
442 | 127 |
9 | 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 | 130 } |
131 } | |
132 | |
133 static void image_loader_stop(ImageLoader *il) | |
134 { | |
135 if (!il) return; | |
136 | |
137 if (il->idle_id != -1) | |
138 { | |
139 g_source_remove(il->idle_id); | |
140 il->idle_id = -1; | |
141 } | |
142 | |
143 if (il->loader) | |
144 { | |
145 /* some loaders do not have a pixbuf till close, order is important here */ | |
146 gdk_pixbuf_loader_close(il->loader, NULL); | |
147 image_loader_sync_pixbuf(il); | |
148 g_object_unref(G_OBJECT(il->loader)); | |
149 il->loader = NULL; | |
150 } | |
151 | |
1008 | 152 if (il->mapped_file) |
9 | 153 { |
1008 | 154 if (il->preview) |
155 { | |
156 exif_free_preview(il->mapped_file); | |
157 } | |
158 else | |
159 { | |
160 munmap(il->mapped_file, il->bytes_total); | |
161 } | |
162 il->mapped_file = NULL; | |
9 | 163 } |
164 | |
165 il->done = TRUE; | |
166 } | |
167 | |
168 static void image_loader_done(ImageLoader *il) | |
169 { | |
170 image_loader_stop(il); | |
171 | |
172 if (il->func_done) il->func_done(il, il->data_done); | |
173 } | |
174 | |
175 static gint image_loader_done_delay_cb(gpointer data) | |
176 { | |
177 ImageLoader *il = data; | |
178 | |
179 il->idle_done_id = -1; | |
180 image_loader_done(il); | |
181 return FALSE; | |
182 } | |
183 | |
184 static void image_loader_done_delay(ImageLoader *il) | |
185 { | |
186 if (il->idle_done_id == -1) il->idle_done_id = g_idle_add_full(il->idle_priority, | |
187 image_loader_done_delay_cb, il, NULL); | |
188 } | |
189 | |
190 static void image_loader_error(ImageLoader *il) | |
191 { | |
192 image_loader_stop(il); | |
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 | 195 |
196 if (il->func_error) il->func_error(il, il->data_error); | |
197 } | |
198 | |
199 static gint image_loader_idle_cb(gpointer data) | |
200 { | |
201 ImageLoader *il = data; | |
202 gint b; | |
203 gint c; | |
204 | |
205 if (!il) return FALSE; | |
206 | |
207 if (il->idle_id == -1) return FALSE; | |
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 | 210 while (c > 0) |
211 { | |
1008 | 212 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read); |
9 | 213 |
214 if (b == 0) | |
215 { | |
216 image_loader_done(il); | |
217 return FALSE; | |
218 } | |
219 | |
1008 | 220 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL))) |
9 | 221 { |
222 image_loader_error(il); | |
223 return FALSE; | |
224 } | |
225 | |
226 il->bytes_read += b; | |
227 | |
228 c--; | |
229 } | |
230 | |
231 if (il->func_percent && il->bytes_total > 0) | |
232 { | |
233 il->func_percent(il, (gdouble)il->bytes_read / il->bytes_total, il->data_percent); | |
234 } | |
235 | |
236 return TRUE; | |
237 } | |
238 | |
239 static gint image_loader_begin(ImageLoader *il) | |
240 { | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
241 gint b; |
9 | 242 |
243 if (!il->loader || il->pixbuf) return FALSE; | |
442 | 244 |
1008 | 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 | 247 if (b < 1) |
248 { | |
249 image_loader_stop(il); | |
250 return FALSE; | |
251 } | |
252 | |
1008 | 253 if (!gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL)) |
9 | 254 { |
255 image_loader_stop(il); | |
256 return FALSE; | |
257 } | |
258 | |
1008 | 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 | 264 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read); |
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 | 294 return TRUE; |
295 } | |
296 | |
297 static gint image_loader_setup(ImageLoader *il) | |
298 { | |
299 struct stat st; | |
300 gchar *pathl; | |
301 | |
1008 | 302 if (!il || il->loader || il->mapped_file) return FALSE; |
303 | |
304 il->mapped_file = NULL; | |
305 | |
306 if (il->fd) | |
307 { | |
308 ExifData *exif = exif_read_fd(il->fd); | |
309 | |
310 il->mapped_file = exif_get_preview(exif, &il->bytes_total); | |
311 | |
312 if (il->mapped_file) | |
313 { | |
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 | 316 } |
317 exif_free_fd(il->fd, exif); | |
318 } | |
9 | 319 |
1008 | 320 |
321 if (!il->mapped_file) | |
322 { | |
323 /* normal file */ | |
324 gint load_fd; | |
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 | 327 load_fd = open(pathl, O_RDONLY | O_NONBLOCK); |
328 g_free(pathl); | |
329 if (load_fd == -1) return FALSE; | |
9 | 330 |
1008 | 331 if (fstat(load_fd, &st) == 0) |
332 { | |
333 il->bytes_total = st.st_size; | |
334 } | |
335 else | |
336 { | |
337 close(load_fd); | |
338 return FALSE; | |
339 } | |
340 | |
341 il->mapped_file = mmap(0, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0); | |
342 close(load_fd); | |
343 if (il->mapped_file == MAP_FAILED) | |
344 { | |
345 il->mapped_file = 0; | |
346 return FALSE; | |
347 } | |
348 il->preview = FALSE; | |
9 | 349 } |
350 | |
1008 | 351 |
9 | 352 il->loader = gdk_pixbuf_loader_new(); |
353 g_signal_connect(G_OBJECT(il->loader), "area_updated", | |
500 | 354 G_CALLBACK(image_loader_area_updated_cb), il); |
9 | 355 g_signal_connect(G_OBJECT(il->loader), "size_prepared", |
356 G_CALLBACK(image_loader_size_cb), il); | |
500 | 357 g_signal_connect(G_OBJECT(il->loader), "area_prepared", |
358 G_CALLBACK(image_loader_area_prepared_cb), il); | |
9 | 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 | 362 return image_loader_begin(il); |
363 } | |
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 | 366 { |
367 ImageLoader *il; | |
368 | |
1009
dd311dae857a
fixed thumbnail loader for the new raw preview interface
nadvornik
parents:
1008
diff
changeset
|
369 if (!fd) return NULL; |
9 | 370 |
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 | 373 il->pixbuf = NULL; |
374 il->idle_id = -1; | |
375 il->idle_priority = G_PRIORITY_DEFAULT_IDLE; | |
376 il->done = FALSE; | |
377 il->loader = NULL; | |
378 | |
379 il->bytes_read = 0; | |
380 il->bytes_total = 0; | |
381 | |
382 il->idle_done_id = -1; | |
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 | 386 il->mapped_file = NULL; |
9 | 387 |
388 il->requested_width = 0; | |
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 | 392 return il; |
393 } | |
394 | |
395 void image_loader_free(ImageLoader *il) | |
396 { | |
397 if (!il) return; | |
398 | |
399 image_loader_stop(il); | |
400 if (il->idle_done_id != -1) g_source_remove(il->idle_done_id); | |
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 | 404 g_free(il); |
405 } | |
406 | |
407 /* don't forget to gdk_pixbuf_ref() it if you want to use it after image_loader_free() */ | |
408 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il) | |
409 { | |
410 if (!il) return NULL; | |
411 | |
412 return il->pixbuf; | |
413 } | |
414 | |
415 gchar *image_loader_get_format(ImageLoader *il) | |
416 { | |
417 GdkPixbufFormat *format; | |
418 gchar **mimev; | |
419 gchar *mime; | |
420 | |
421 if (!il || !il->loader) return NULL; | |
422 | |
423 format = gdk_pixbuf_loader_get_format(il->loader); | |
424 if (!format) return NULL; | |
425 | |
426 mimev = gdk_pixbuf_format_get_mime_types(format); | |
427 if (!mimev) return NULL; | |
428 | |
429 /* return first member of mimev, as GdkPixbufLoader has no way to tell us which exact one ? */ | |
430 mime = g_strdup(mimev[0]); | |
431 g_strfreev(mimev); | |
432 | |
433 return mime; | |
434 } | |
435 | |
436 void image_loader_set_area_ready_func(ImageLoader *il, | |
437 void (*func_area_ready)(ImageLoader *, guint, guint, guint, guint, gpointer), | |
438 gpointer data_area_ready) | |
439 { | |
440 if (!il) return; | |
441 | |
442 il->func_area_ready = func_area_ready; | |
443 il->data_area_ready = data_area_ready; | |
444 } | |
445 | |
446 void image_loader_set_error_func(ImageLoader *il, | |
447 void (*func_error)(ImageLoader *, gpointer), | |
448 gpointer data_error) | |
449 { | |
450 if (!il) return; | |
451 | |
452 il->func_error = func_error; | |
453 il->data_error = data_error; | |
454 } | |
455 | |
890 | 456 void image_loader_set_done_func(ImageLoader *il, |
457 void (*func_done)(ImageLoader *, gpointer), | |
458 gpointer data_done) | |
459 { | |
460 if (!il) return; | |
461 | |
462 il->func_done = func_done; | |
463 il->data_done = data_done; | |
464 } | |
465 | |
9 | 466 void image_loader_set_percent_func(ImageLoader *il, |
467 void (*func_percent)(ImageLoader *, gdouble, gpointer), | |
468 gpointer data_percent) | |
469 { | |
470 if (!il) return; | |
471 | |
472 il->func_percent = func_percent; | |
473 il->data_percent = data_percent; | |
474 } | |
475 | |
476 void image_loader_set_requested_size(ImageLoader *il, gint width, gint height) | |
477 { | |
478 if (!il) return; | |
479 | |
480 il->requested_width = width; | |
481 il->requested_height = height; | |
482 } | |
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 | 485 { |
486 if (!il) return; | |
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 | 489 } |
490 | |
491 void image_loader_set_priority(ImageLoader *il, gint priority) | |
492 { | |
493 if (!il) return; | |
494 | |
495 il->idle_priority = priority; | |
496 } | |
497 | |
498 gint image_loader_start(ImageLoader *il, void (*func_done)(ImageLoader *, gpointer), gpointer data_done) | |
499 { | |
500 if (!il) return FALSE; | |
501 | |
1009
dd311dae857a
fixed thumbnail loader for the new raw preview interface
nadvornik
parents:
1008
diff
changeset
|
502 if (!il->fd) return FALSE; |
9 | 503 |
890 | 504 image_loader_set_done_func(il, func_done, data_done); |
9 | 505 |
506 return image_loader_setup(il); | |
507 } | |
508 | |
509 gdouble image_loader_get_percent(ImageLoader *il) | |
510 { | |
511 if (!il || il->bytes_total == 0) return 0.0; | |
512 | |
513 return (gdouble)il->bytes_read / il->bytes_total; | |
514 } | |
515 | |
516 gint image_loader_get_is_done(ImageLoader *il) | |
517 { | |
518 if (!il) return FALSE; | |
519 | |
520 return il->done; | |
521 } | |
522 | |
138 | 523 gint image_load_dimensions(FileData *fd, gint *width, gint *height) |
9 | 524 { |
525 ImageLoader *il; | |
526 gint success; | |
527 | |
138 | 528 il = image_loader_new(fd); |
9 | 529 |
530 success = image_loader_start(il, NULL, NULL); | |
531 | |
532 if (success && il->pixbuf) | |
533 { | |
534 if (width) *width = gdk_pixbuf_get_width(il->pixbuf); | |
535 if (height) *height = gdk_pixbuf_get_height(il->pixbuf);; | |
536 } | |
537 else | |
538 { | |
539 if (width) *width = -1; | |
540 if (height) *height = -1; | |
541 } | |
542 | |
543 image_loader_free(il); | |
544 | |
545 return success; | |
546 } |