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