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