Mercurial > geeqie
annotate src/image-load.c @ 503:e5023cced4e5
Fix image overlay displayed only on second "I" press in layout view.
author | zas_ |
---|---|
date | Wed, 23 Apr 2008 23:47:53 +0000 |
parents | 01fe7ca55c69 |
children | fc9c8a3e1a8b |
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" |
138 | 16 #include "filelist.h" |
9 | 17 |
176
695e1ad3b169
simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents:
138
diff
changeset
|
18 #include "exif.h" |
9 | 19 #include "ui_fileops.h" |
20 | |
21 #include <fcntl.h> | |
22 | |
23 | |
138 | 24 static const gchar *image_loader_path(ImageLoader *il) |
25 { | |
26 if (il->fd) | |
27 return il->fd->path; | |
28 return il->path; | |
29 } | |
30 | |
9 | 31 static void image_loader_sync_pixbuf(ImageLoader *il) |
32 { | |
33 GdkPixbuf *pb; | |
34 | |
35 if (!il->loader) return; | |
36 | |
37 pb = gdk_pixbuf_loader_get_pixbuf(il->loader); | |
38 | |
39 if (pb == il->pixbuf) return; | |
40 | |
41 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf); | |
42 il->pixbuf = pb; | |
43 if (il->pixbuf) gdk_pixbuf_ref(il->pixbuf); | |
44 } | |
45 | |
500 | 46 static void image_loader_area_updated_cb(GdkPixbufLoader *loader, |
9 | 47 guint x, guint y, guint w, guint h, |
48 gpointer data) | |
49 { | |
50 ImageLoader *il = data; | |
51 | |
52 if (il->func_area_ready) | |
53 { | |
54 if (!il->pixbuf) | |
55 { | |
56 image_loader_sync_pixbuf(il); | |
57 if (!il->pixbuf) | |
58 { | |
59 printf("critical: area_ready signal with NULL pixbuf (out of mem?)\n"); | |
60 } | |
61 } | |
62 il->func_area_ready(il, x, y, w, h, il->data_area_ready); | |
63 } | |
64 } | |
65 | |
500 | 66 static void image_loader_area_prepared_cb(GdkPixbufLoader *loader, gpointer data) |
67 { | |
68 GdkPixbuf *pb; | |
69 guchar *pix; | |
70 size_t h, rs; | |
71 | |
72 pb = gdk_pixbuf_loader_get_pixbuf(loader); | |
73 | |
74 h = gdk_pixbuf_get_height(pb); | |
75 rs = gdk_pixbuf_get_rowstride(pb); | |
76 pix = gdk_pixbuf_get_pixels(pb); | |
77 | |
78 memset(pix, 0, rs * h); /*this should be faster than pixbuf_fill */ | |
79 | |
80 } | |
81 | |
9 | 82 static void image_loader_size_cb(GdkPixbufLoader *loader, |
83 gint width, gint height, gpointer data) | |
84 { | |
85 ImageLoader *il = data; | |
86 GdkPixbufFormat *format; | |
87 gchar **mime_types; | |
88 gint scale = FALSE; | |
89 gint n; | |
90 | |
91 if (il->requested_width < 1 || il->requested_height < 1) return; | |
92 | |
93 format = gdk_pixbuf_loader_get_format(loader); | |
94 if (!format) return; | |
95 | |
96 mime_types = gdk_pixbuf_format_get_mime_types(format); | |
97 n = 0; | |
98 while (mime_types[n]) | |
99 { | |
100 if (strstr(mime_types[n], "jpeg")) scale = TRUE; | |
101 n++; | |
102 } | |
103 g_strfreev(mime_types); | |
442 | 104 |
9 | 105 if (!scale) return; |
106 | |
107 if (width > il->requested_width || height > il->requested_height) | |
108 { | |
109 gint nw, nh; | |
110 | |
111 if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height)) | |
112 { | |
113 nw = il->requested_width; | |
114 nh = (gdouble)nw / width * height; | |
115 if (nh < 1) nh = 1; | |
116 } | |
117 else | |
118 { | |
119 nh = il->requested_height; | |
120 nw = (gdouble)nh / height * width; | |
121 if (nw < 1) nw = 1; | |
122 } | |
442 | 123 |
9 | 124 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
|
125 il->shrunk = TRUE; |
9 | 126 } |
127 } | |
128 | |
129 static void image_loader_stop(ImageLoader *il) | |
130 { | |
131 if (!il) return; | |
132 | |
133 if (il->idle_id != -1) | |
134 { | |
135 g_source_remove(il->idle_id); | |
136 il->idle_id = -1; | |
137 } | |
138 | |
139 if (il->loader) | |
140 { | |
141 /* some loaders do not have a pixbuf till close, order is important here */ | |
142 gdk_pixbuf_loader_close(il->loader, NULL); | |
143 image_loader_sync_pixbuf(il); | |
144 g_object_unref(G_OBJECT(il->loader)); | |
145 il->loader = NULL; | |
146 } | |
147 | |
148 if (il->load_fd != -1) | |
149 { | |
150 close(il->load_fd); | |
151 il->load_fd = -1; | |
152 } | |
153 | |
154 il->done = TRUE; | |
155 } | |
156 | |
157 static void image_loader_done(ImageLoader *il) | |
158 { | |
159 image_loader_stop(il); | |
160 | |
161 if (il->func_done) il->func_done(il, il->data_done); | |
162 } | |
163 | |
164 static gint image_loader_done_delay_cb(gpointer data) | |
165 { | |
166 ImageLoader *il = data; | |
167 | |
168 il->idle_done_id = -1; | |
169 image_loader_done(il); | |
170 return FALSE; | |
171 } | |
172 | |
173 static void image_loader_done_delay(ImageLoader *il) | |
174 { | |
175 if (il->idle_done_id == -1) il->idle_done_id = g_idle_add_full(il->idle_priority, | |
176 image_loader_done_delay_cb, il, NULL); | |
177 } | |
178 | |
179 static void image_loader_error(ImageLoader *il) | |
180 { | |
181 image_loader_stop(il); | |
182 | |
495 | 183 DEBUG_1("pixbuf_loader reported load error for: %s\n", image_loader_path(il)); |
9 | 184 |
185 if (il->func_error) il->func_error(il, il->data_error); | |
186 } | |
187 | |
188 static gint image_loader_idle_cb(gpointer data) | |
189 { | |
190 ImageLoader *il = data; | |
191 gint b; | |
192 gint c; | |
193 | |
194 if (!il) return FALSE; | |
195 | |
196 if (il->idle_id == -1) return FALSE; | |
197 | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
198 c = il->idle_read_loop_count ? il->idle_read_loop_count : 1; |
9 | 199 while (c > 0) |
200 { | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
201 b = read(il->load_fd, il->read_buffer, il->read_buffer_size); |
9 | 202 |
203 if (b == 0) | |
204 { | |
205 image_loader_done(il); | |
206 return FALSE; | |
207 } | |
208 | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
209 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->read_buffer, b, NULL))) |
9 | 210 { |
211 image_loader_error(il); | |
212 return FALSE; | |
213 } | |
214 | |
215 il->bytes_read += b; | |
216 | |
217 c--; | |
218 } | |
219 | |
220 if (il->func_percent && il->bytes_total > 0) | |
221 { | |
222 il->func_percent(il, (gdouble)il->bytes_read / il->bytes_total, il->data_percent); | |
223 } | |
224 | |
225 return TRUE; | |
226 } | |
227 | |
228 static gint image_loader_begin(ImageLoader *il) | |
229 { | |
230 int b; | |
43
ee03f36e9e4b
Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents:
14
diff
changeset
|
231 unsigned int offset = 0; |
9 | 232 |
233 if (!il->loader || il->pixbuf) return FALSE; | |
442 | 234 |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
235 b = read(il->load_fd, il->read_buffer, il->read_buffer_size); |
9 | 236 |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
237 if (b > 0 && |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
238 format_raw_img_exif_offsets_fd(il->load_fd, image_loader_path(il), il->read_buffer, b, &offset, NULL)) |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
239 { |
495 | 240 DEBUG_1("Raw file %s contains embedded image\n", image_loader_path(il)); |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
241 |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
242 b = read(il->load_fd, il->read_buffer, il->read_buffer_size); |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
243 } |
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
244 |
9 | 245 if (b < 1) |
246 { | |
247 image_loader_stop(il); | |
248 return FALSE; | |
249 } | |
250 | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
251 if (!gdk_pixbuf_loader_write(il->loader, il->read_buffer, b, NULL)) |
9 | 252 { |
253 image_loader_stop(il); | |
254 return FALSE; | |
255 } | |
256 | |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
257 il->bytes_read += b + offset; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
258 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
259 /* read until size is known */ |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
260 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
|
261 { |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
262 b = read(il->load_fd, il->read_buffer, il->read_buffer_size); |
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
263 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->read_buffer, b, NULL))) |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
264 { |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
265 image_loader_stop(il); |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
266 return FALSE; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
267 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
268 il->bytes_read += b; |
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 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
|
271 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
272 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
|
273 { |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
274 /* 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
|
275 image_loader_stop(il); |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
276 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
277 if (!il->pixbuf) return FALSE; |
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 image_loader_done_delay(il); |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
280 return TRUE; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
281 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
282 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
283 if (!il->pixbuf) |
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 image_loader_stop(il); |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
286 return FALSE; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
287 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
288 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
289 /* finally, progressive loading :) */ |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
290 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
|
291 |
9 | 292 return TRUE; |
293 } | |
294 | |
295 static gint image_loader_setup(ImageLoader *il) | |
296 { | |
297 struct stat st; | |
298 gchar *pathl; | |
299 | |
300 if (!il || il->load_fd != -1 || il->loader) return FALSE; | |
301 | |
138 | 302 pathl = path_from_utf8(image_loader_path(il)); |
9 | 303 il->load_fd = open(pathl, O_RDONLY | O_NONBLOCK); |
304 g_free(pathl); | |
305 if (il->load_fd == -1) return FALSE; | |
306 | |
307 if (fstat(il->load_fd, &st) == 0) | |
308 { | |
309 il->bytes_total = st.st_size; | |
310 } | |
311 | |
312 il->loader = gdk_pixbuf_loader_new(); | |
313 g_signal_connect(G_OBJECT(il->loader), "area_updated", | |
500 | 314 G_CALLBACK(image_loader_area_updated_cb), il); |
9 | 315 g_signal_connect(G_OBJECT(il->loader), "size_prepared", |
316 G_CALLBACK(image_loader_size_cb), il); | |
500 | 317 g_signal_connect(G_OBJECT(il->loader), "area_prepared", |
318 G_CALLBACK(image_loader_area_prepared_cb), il); | |
9 | 319 |
14
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
320 il->shrunk = FALSE; |
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
321 |
9 | 322 return image_loader_begin(il); |
323 } | |
324 | |
138 | 325 static ImageLoader *image_loader_new_real(FileData *fd, const gchar *path) |
9 | 326 { |
327 ImageLoader *il; | |
328 | |
138 | 329 if (!fd && !path) return NULL; |
9 | 330 |
331 il = g_new0(ImageLoader, 1); | |
138 | 332 if (fd) il->fd = file_data_ref(fd); |
9 | 333 if (path) il->path = g_strdup(path); |
334 il->pixbuf = NULL; | |
335 il->idle_id = -1; | |
336 il->idle_priority = G_PRIORITY_DEFAULT_IDLE; | |
337 il->done = FALSE; | |
338 il->loader = NULL; | |
339 il->load_fd = -1; | |
340 | |
341 il->bytes_read = 0; | |
342 il->bytes_total = 0; | |
343 | |
344 il->idle_done_id = -1; | |
345 | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
346 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
|
347 il->read_buffer_size = options->image.read_buffer_size; |
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
348 il->read_buffer = g_new(guchar, il->read_buffer_size); |
9 | 349 |
350 il->requested_width = 0; | |
351 il->requested_height = 0; | |
14
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
352 il->shrunk = FALSE; |
495 | 353 DEBUG_1("new image loader %p, bufsize=%u idle_loop=%u\n", il, il->read_buffer_size, il->idle_read_loop_count); |
9 | 354 return il; |
355 } | |
356 | |
138 | 357 ImageLoader *image_loader_new(FileData *fd) |
358 { | |
359 return image_loader_new_real(fd, NULL); | |
360 } | |
361 | |
362 ImageLoader *image_loader_new_from_path(const gchar *path) | |
363 { | |
364 return image_loader_new_real(NULL, path); | |
365 } | |
366 | |
9 | 367 void image_loader_free(ImageLoader *il) |
368 { | |
369 if (!il) return; | |
370 | |
371 image_loader_stop(il); | |
372 if (il->idle_done_id != -1) g_source_remove(il->idle_done_id); | |
373 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf); | |
138 | 374 if (il->fd) file_data_unref(il->fd); |
375 if (il->path) g_free(il->path); | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
376 if (il->read_buffer) g_free(il->read_buffer); |
495 | 377 DEBUG_1("freeing image loader %p bytes_read=%d\n", il, il->bytes_read); |
9 | 378 g_free(il); |
379 } | |
380 | |
381 /* don't forget to gdk_pixbuf_ref() it if you want to use it after image_loader_free() */ | |
382 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il) | |
383 { | |
384 if (!il) return NULL; | |
385 | |
386 return il->pixbuf; | |
387 } | |
388 | |
389 gchar *image_loader_get_format(ImageLoader *il) | |
390 { | |
391 GdkPixbufFormat *format; | |
392 gchar **mimev; | |
393 gchar *mime; | |
394 | |
395 if (!il || !il->loader) return NULL; | |
396 | |
397 format = gdk_pixbuf_loader_get_format(il->loader); | |
398 if (!format) return NULL; | |
399 | |
400 mimev = gdk_pixbuf_format_get_mime_types(format); | |
401 if (!mimev) return NULL; | |
402 | |
403 /* return first member of mimev, as GdkPixbufLoader has no way to tell us which exact one ? */ | |
404 mime = g_strdup(mimev[0]); | |
405 g_strfreev(mimev); | |
406 | |
407 return mime; | |
408 } | |
409 | |
410 void image_loader_set_area_ready_func(ImageLoader *il, | |
411 void (*func_area_ready)(ImageLoader *, guint, guint, guint, guint, gpointer), | |
412 gpointer data_area_ready) | |
413 { | |
414 if (!il) return; | |
415 | |
416 il->func_area_ready = func_area_ready; | |
417 il->data_area_ready = data_area_ready; | |
418 } | |
419 | |
420 void image_loader_set_error_func(ImageLoader *il, | |
421 void (*func_error)(ImageLoader *, gpointer), | |
422 gpointer data_error) | |
423 { | |
424 if (!il) return; | |
425 | |
426 il->func_error = func_error; | |
427 il->data_error = data_error; | |
428 } | |
429 | |
430 void image_loader_set_percent_func(ImageLoader *il, | |
431 void (*func_percent)(ImageLoader *, gdouble, gpointer), | |
432 gpointer data_percent) | |
433 { | |
434 if (!il) return; | |
435 | |
436 il->func_percent = func_percent; | |
437 il->data_percent = data_percent; | |
438 } | |
439 | |
440 void image_loader_set_requested_size(ImageLoader *il, gint width, gint height) | |
441 { | |
442 if (!il) return; | |
443 | |
444 il->requested_width = width; | |
445 il->requested_height = height; | |
446 } | |
447 | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
448 void image_loader_set_buffer_size(ImageLoader *il, guint count) |
9 | 449 { |
450 if (!il) return; | |
451 | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
452 il->idle_read_loop_count = count ? count : 1; |
9 | 453 } |
454 | |
455 void image_loader_set_priority(ImageLoader *il, gint priority) | |
456 { | |
457 if (!il) return; | |
458 | |
459 il->idle_priority = priority; | |
460 } | |
461 | |
462 gint image_loader_start(ImageLoader *il, void (*func_done)(ImageLoader *, gpointer), gpointer data_done) | |
463 { | |
464 if (!il) return FALSE; | |
465 | |
138 | 466 if (!image_loader_path(il)) return FALSE; |
9 | 467 |
468 il->func_done = func_done; | |
469 il->data_done = data_done; | |
470 | |
471 return image_loader_setup(il); | |
472 } | |
473 | |
474 gdouble image_loader_get_percent(ImageLoader *il) | |
475 { | |
476 if (!il || il->bytes_total == 0) return 0.0; | |
477 | |
478 return (gdouble)il->bytes_read / il->bytes_total; | |
479 } | |
480 | |
481 gint image_loader_get_is_done(ImageLoader *il) | |
482 { | |
483 if (!il) return FALSE; | |
484 | |
485 return il->done; | |
486 } | |
487 | |
138 | 488 gint image_load_dimensions(FileData *fd, gint *width, gint *height) |
9 | 489 { |
490 ImageLoader *il; | |
491 gint success; | |
492 | |
138 | 493 il = image_loader_new(fd); |
9 | 494 |
495 success = image_loader_start(il, NULL, NULL); | |
496 | |
497 if (success && il->pixbuf) | |
498 { | |
499 if (width) *width = gdk_pixbuf_get_width(il->pixbuf); | |
500 if (height) *height = gdk_pixbuf_get_height(il->pixbuf);; | |
501 } | |
502 else | |
503 { | |
504 if (width) *width = -1; | |
505 if (height) *height = -1; | |
506 } | |
507 | |
508 image_loader_free(il); | |
509 | |
510 return success; | |
511 } |