4 * Copyright (C) 2008 - 2012 The Geeqie Team
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!
15 #include "image-load.h"
16 #include "image_load_gdk.h"
17 #include "image_load_jpeg.h"
18 #include "image_load_tiff.h"
22 #include "ui_fileops.h"
23 #include "gq-marshal.h"
28 #define IMAGE_LOADER_READ_BUFFER_SIZE_DEFAULT 4096
29 #define IMAGE_LOADER_IDLE_READ_LOOP_COUNT_DEFAULT 1
32 /**************************************************************************************/
33 /* image loader class */
37 SIGNAL_AREA_READY = 0,
45 static guint signals[SIGNAL_COUNT] = { 0 };
47 static void image_loader_init(GTypeInstance *instance, gpointer g_class);
48 static void image_loader_class_init(ImageLoaderClass *class);
49 static void image_loader_finalize(GObject *object);
50 static void image_loader_stop(ImageLoader *il);
52 GType image_loader_get_type(void)
54 static GType type = 0;
57 static const GTypeInfo info = {
58 sizeof(ImageLoaderClass),
60 NULL, /* base_finalize */
61 (GClassInitFunc)image_loader_class_init, /* class_init */
62 NULL, /* class_finalize */
63 NULL, /* class_data */
66 (GInstanceInitFunc)image_loader_init, /* instance_init */
67 NULL /* value_table */
69 type = g_type_register_static(G_TYPE_OBJECT, "ImageLoaderType", &info, 0);
74 static void image_loader_init(GTypeInstance *instance, gpointer g_class)
76 ImageLoader *il = (ImageLoader *)instance;
80 il->idle_priority = G_PRIORITY_DEFAULT_IDLE;
89 il->idle_read_loop_count = IMAGE_LOADER_IDLE_READ_LOOP_COUNT_DEFAULT;
90 il->read_buffer_size = IMAGE_LOADER_READ_BUFFER_SIZE_DEFAULT;
91 il->mapped_file = NULL;
93 il->requested_width = 0;
94 il->requested_height = 0;
96 il->actual_height = 0;
99 il->can_destroy = TRUE;
102 il->data_mutex = g_mutex_new();
103 il->can_destroy_cond = g_cond_new();
105 DEBUG_1("new image loader %p, bufsize=%" G_GSIZE_FORMAT " idle_loop=%u", il, il->read_buffer_size, il->idle_read_loop_count);
108 static void image_loader_class_init(ImageLoaderClass *class)
110 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
112 // gobject_class->set_property = image_loader_set_property;
113 // gobject_class->get_property = image_loader_get_property;
115 gobject_class->finalize = image_loader_finalize;
118 signals[SIGNAL_AREA_READY] =
119 g_signal_new("area_ready",
120 G_OBJECT_CLASS_TYPE(gobject_class),
122 G_STRUCT_OFFSET(ImageLoaderClass, area_ready),
124 gq_marshal_VOID__INT_INT_INT_INT,
131 signals[SIGNAL_ERROR] =
132 g_signal_new("error",
133 G_OBJECT_CLASS_TYPE(gobject_class),
135 G_STRUCT_OFFSET(ImageLoaderClass, error),
137 g_cclosure_marshal_VOID__VOID,
140 signals[SIGNAL_DONE] =
142 G_OBJECT_CLASS_TYPE(gobject_class),
144 G_STRUCT_OFFSET(ImageLoaderClass, done),
146 g_cclosure_marshal_VOID__VOID,
149 signals[SIGNAL_PERCENT] =
150 g_signal_new("percent",
151 G_OBJECT_CLASS_TYPE(gobject_class),
153 G_STRUCT_OFFSET(ImageLoaderClass, percent),
155 g_cclosure_marshal_VOID__DOUBLE,
159 signals[SIGNAL_SIZE] =
160 g_signal_new("size_prepared",
161 G_OBJECT_CLASS_TYPE(gobject_class),
163 G_STRUCT_OFFSET(ImageLoaderClass, area_ready),
165 gq_marshal_VOID__INT_INT,
172 static void image_loader_finalize(GObject *object)
174 ImageLoader *il = (ImageLoader *)object;
176 image_loader_stop(il);
178 if (il->error) DEBUG_1("%s", image_loader_get_error(il));
180 DEBUG_1("freeing image loader %p bytes_read=%" G_GSIZE_FORMAT, il, il->bytes_read);
182 if (il->idle_done_id)
184 g_source_remove(il->idle_done_id);
185 il->idle_done_id = 0;
188 while (g_source_remove_by_user_data(il))
190 DEBUG_2("pending signals detected");
193 while (il->area_param_list)
195 DEBUG_1("pending area_ready signals detected");
196 while (g_source_remove_by_user_data(il->area_param_list->data)) {}
197 g_free(il->area_param_list->data);
198 il->area_param_list = g_list_delete_link(il->area_param_list, il->area_param_list);
201 while (il->area_param_delayed_list)
203 g_free(il->area_param_delayed_list->data);
204 il->area_param_delayed_list = g_list_delete_link(il->area_param_delayed_list, il->area_param_delayed_list);
207 if (il->pixbuf) g_object_unref(il->pixbuf);
209 if (il->error) g_error_free(il->error);
211 file_data_unref(il->fd);
213 g_mutex_free(il->data_mutex);
214 g_cond_free(il->can_destroy_cond);
218 void image_loader_free(ImageLoader *il)
221 g_object_unref(G_OBJECT(il));
225 ImageLoader *image_loader_new(FileData *fd)
229 if (!fd) return NULL;
231 il = (ImageLoader *) g_object_new(TYPE_IMAGE_LOADER, NULL);
233 il->fd = file_data_ref(fd);
238 /**************************************************************************************/
239 /* send signals via idle calbacks - the callback are executed in the main thread */
241 typedef struct _ImageLoaderAreaParam ImageLoaderAreaParam;
242 struct _ImageLoaderAreaParam {
251 static gboolean image_loader_emit_area_ready_cb(gpointer data)
253 ImageLoaderAreaParam *par = data;
254 ImageLoader *il = par->il;
256 g_mutex_lock(il->data_mutex);
257 il->area_param_list = g_list_remove(il->area_param_list, par);
263 g_mutex_unlock(il->data_mutex);
265 g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, x, y, w, h);
270 static gboolean image_loader_emit_done_cb(gpointer data)
272 ImageLoader *il = data;
273 g_signal_emit(il, signals[SIGNAL_DONE], 0);
277 static gboolean image_loader_emit_error_cb(gpointer data)
279 ImageLoader *il = data;
280 g_signal_emit(il, signals[SIGNAL_ERROR], 0);
284 static gboolean image_loader_emit_percent_cb(gpointer data)
286 ImageLoader *il = data;
287 g_signal_emit(il, signals[SIGNAL_PERCENT], 0, image_loader_get_percent(il));
291 static gboolean image_loader_emit_size_cb(gpointer data)
294 ImageLoader *il = data;
295 g_mutex_lock(il->data_mutex);
296 width = il->actual_width;
297 height = il->actual_height;
298 g_mutex_unlock(il->data_mutex);
299 g_signal_emit(il, signals[SIGNAL_SIZE], 0, width, height);
304 /* DONE and ERROR are emited only once, thus they can have normal priority
305 PERCENT and AREA_READY should be processed ASAP
308 static void image_loader_emit_done(ImageLoader *il)
310 g_idle_add_full(il->idle_priority, image_loader_emit_done_cb, il, NULL);
313 static void image_loader_emit_error(ImageLoader *il)
315 g_idle_add_full(il->idle_priority, image_loader_emit_error_cb, il, NULL);
318 static void image_loader_emit_percent(ImageLoader *il)
320 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_percent_cb, il, NULL);
323 static void image_loader_emit_size(ImageLoader *il)
325 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_size_cb, il, NULL);
328 static ImageLoaderAreaParam *image_loader_queue_area_ready(ImageLoader *il, GList **list, guint x, guint y, guint w, guint h)
332 ImageLoaderAreaParam *prev_par = (*list)->data;
333 if (prev_par->x == x && prev_par->w == w &&
334 prev_par->y + prev_par->h == y)
336 /* we can merge the notifications */
340 if (prev_par->x == x && prev_par->w == w &&
341 y + h == prev_par->y)
343 /* we can merge the notifications */
348 if (prev_par->y == y && prev_par->h == h &&
349 prev_par->x + prev_par->w == x)
351 /* we can merge the notifications */
355 if (prev_par->y == y && prev_par->h == h &&
356 x + w == prev_par->x)
358 /* we can merge the notifications */
365 ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1);
372 *list = g_list_prepend(*list, par);
376 /* this function expects that il->data_mutex is locked by caller */
377 static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
379 ImageLoaderAreaParam *par = image_loader_queue_area_ready(il, &il->area_param_list, x, y, w, h);
383 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL);
387 /**************************************************************************************/
388 /* the following functions may be executed in separate thread */
390 /* this function expects that il->data_mutex is locked by caller */
391 static void image_loader_queue_delayed_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
393 image_loader_queue_area_ready(il, &il->area_param_delayed_list, x, y, w, h);
398 static gboolean image_loader_get_stopping(ImageLoader *il)
401 if (!il) return FALSE;
403 g_mutex_lock(il->data_mutex);
405 g_mutex_unlock(il->data_mutex);
411 static void image_loader_sync_pixbuf(ImageLoader *il)
415 g_mutex_lock(il->data_mutex);
419 g_mutex_unlock(il->data_mutex);
423 pb = il->backend.get_pixbuf(il->loader);
425 if (pb == il->pixbuf)
427 g_mutex_unlock(il->data_mutex);
431 if (g_ascii_strcasecmp(".jps", il->fd->extension) == 0)
433 g_object_set_data(G_OBJECT(pb), "stereo_data", GINT_TO_POINTER(STEREO_PIXBUF_CROSS));
436 if (il->pixbuf) g_object_unref(il->pixbuf);
439 if (il->pixbuf) g_object_ref(il->pixbuf);
441 g_mutex_unlock(il->data_mutex);
444 static void image_loader_area_updated_cb(gpointer loader,
445 guint x, guint y, guint w, guint h,
448 ImageLoader *il = data;
450 if (!image_loader_get_pixbuf(il))
452 image_loader_sync_pixbuf(il);
453 if (!image_loader_get_pixbuf(il))
455 log_printf("critical: area_ready signal with NULL pixbuf (out of mem?)\n");
459 g_mutex_lock(il->data_mutex);
460 if (il->delay_area_ready)
461 image_loader_queue_delayed_area_ready(il, x, y, w, h);
463 image_loader_emit_area_ready(il, x, y, w, h);
465 if (il->stopping) il->backend.abort(il->loader);
467 g_mutex_unlock(il->data_mutex);
470 static void image_loader_area_prepared_cb(gpointer loader, gpointer data)
472 ImageLoader *il = data;
478 http://bugzilla.gnome.org/show_bug.cgi?id=547669
479 http://bugzilla.gnome.org/show_bug.cgi?id=589334
481 gchar *format = il->backend.get_format_name(loader);
482 if (strcmp(format, "svg") == 0 ||
483 strcmp(format, "xpm") == 0)
491 pb = il->backend.get_pixbuf(loader);
493 h = gdk_pixbuf_get_height(pb);
494 rs = gdk_pixbuf_get_rowstride(pb);
495 pix = gdk_pixbuf_get_pixels(pb);
497 memset(pix, 0, rs * h); /*this should be faster than pixbuf_fill */
501 static void image_loader_size_cb(gpointer loader,
502 gint width, gint height, gpointer data)
504 ImageLoader *il = data;
506 gboolean scale = FALSE;
509 g_mutex_lock(il->data_mutex);
510 il->actual_width = width;
511 il->actual_height = height;
512 if (il->requested_width < 1 || il->requested_height < 1)
514 g_mutex_unlock(il->data_mutex);
515 image_loader_emit_size(il);
518 g_mutex_unlock(il->data_mutex);
520 mime_types = il->backend.get_format_mime_types(loader);
522 while (mime_types[n])
524 if (strstr(mime_types[n], "jpeg")) scale = TRUE;
527 g_strfreev(mime_types);
531 image_loader_emit_size(il);
535 g_mutex_lock(il->data_mutex);
538 if (width > il->requested_width || height > il->requested_height)
541 if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height))
543 nw = il->requested_width;
544 nh = (gdouble)nw / width * height;
549 nh = il->requested_height;
550 nw = (gdouble)nh / height * width;
554 il->actual_width = nw;
555 il->actual_height = nh;
556 il->backend.set_size(loader, nw, nh);
560 g_mutex_unlock(il->data_mutex);
561 image_loader_emit_size(il);
564 static void image_loader_stop_loader(ImageLoader *il)
570 /* some loaders do not have a pixbuf till close, order is important here */
571 il->backend.close(il->loader, il->error ? NULL : &il->error); /* we are interested in the first error only */
572 image_loader_sync_pixbuf(il);
573 il->backend.free(il->loader);
576 g_mutex_lock(il->data_mutex);
578 g_mutex_unlock(il->data_mutex);
581 static void image_loader_setup_loader(ImageLoader *il)
583 g_mutex_lock(il->data_mutex);
585 if (il->bytes_total >= 2 && il->mapped_file[0] == 0xff && il->mapped_file[1] == 0xd8)
587 DEBUG_1("Using custom jpeg loader");
588 image_loader_backend_set_jpeg(&il->backend);
593 if (il->bytes_total >= 10 &&
594 (memcmp(il->mapped_file, "MM\0*", 4) == 0 ||
595 memcmp(il->mapped_file, "II*\0", 4) == 0))
597 DEBUG_1("Using custom tiff loader");
598 image_loader_backend_set_tiff(&il->backend);
602 image_loader_backend_set_default(&il->backend);
604 il->loader = il->backend.loader_new(image_loader_area_updated_cb, image_loader_size_cb, image_loader_area_prepared_cb, il);
605 g_mutex_unlock(il->data_mutex);
609 static void image_loader_done(ImageLoader *il)
611 image_loader_stop_loader(il);
613 image_loader_emit_done(il);
616 static void image_loader_error(ImageLoader *il)
618 image_loader_stop_loader(il);
620 DEBUG_1("pixbuf_loader reported load error for: %s", il->fd->path);
622 image_loader_emit_error(il);
625 static gboolean image_loader_continue(ImageLoader *il)
630 if (!il) return FALSE;
632 c = il->idle_read_loop_count ? il->idle_read_loop_count : 1;
633 while (c > 0 && !image_loader_get_stopping(il))
635 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
639 image_loader_done(il);
643 if (b < 0 || (b > 0 && !il->backend.write(il->loader, il->mapped_file + il->bytes_read, b, &il->error)))
645 image_loader_error(il);
654 if (il->bytes_total > 0)
656 image_loader_emit_percent(il);
662 static gboolean image_loader_begin(ImageLoader *il)
666 if (il->pixbuf) return FALSE;
668 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
669 if (b < 1) return FALSE;
671 image_loader_setup_loader(il);
673 g_assert(il->bytes_read == 0);
674 if (il->backend.load) {
676 if (!il->backend.load(il->loader, il->mapped_file, b, &il->error))
678 image_loader_stop_loader(il);
682 else if (!il->backend.write(il->loader, il->mapped_file, b, &il->error))
684 image_loader_stop_loader(il);
690 /* read until size is known */
691 while (il->loader && !il->backend.get_pixbuf(il->loader) && b > 0 && !image_loader_get_stopping(il))
693 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
694 if (b < 0 || (b > 0 && !il->backend.write(il->loader, il->mapped_file + il->bytes_read, b, &il->error)))
696 image_loader_stop_loader(il);
701 if (!il->pixbuf) image_loader_sync_pixbuf(il);
703 if (il->bytes_read == il->bytes_total || b < 1)
705 /* done, handle (broken) loaders that do not have pixbuf till close */
706 image_loader_stop_loader(il);
708 if (!il->pixbuf) return FALSE;
710 image_loader_done(il);
716 image_loader_stop_loader(il);
723 /**************************************************************************************/
724 /* the following functions are always executed in the main thread */
727 static gboolean image_loader_setup_source(ImageLoader *il)
732 if (!il || il->loader || il->mapped_file) return FALSE;
734 il->mapped_file = NULL;
738 ExifData *exif = exif_read_fd(il->fd);
740 if (options->thumbnails.use_exif)
741 il->mapped_file = exif_get_preview(exif, (guint *)&il->bytes_total, il->requested_width, il->requested_height);
743 il->mapped_file = exif_get_preview(exif, (guint *)&il->bytes_total, 0, 0); /* get the largest available preview image or NULL for normal images*/
748 DEBUG_1("Usable reduced size (preview) image loaded from file %s", il->fd->path);
750 exif_free_fd(il->fd, exif);
754 if (!il->mapped_file)
759 pathl = path_from_utf8(il->fd->path);
760 load_fd = open(pathl, O_RDONLY | O_NONBLOCK);
762 if (load_fd == -1) return FALSE;
764 if (fstat(load_fd, &st) == 0)
766 il->bytes_total = st.st_size;
774 il->mapped_file = mmap(0, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0);
776 if (il->mapped_file == MAP_FAILED)
787 static void image_loader_stop_source(ImageLoader *il)
795 exif_free_preview(il->mapped_file);
799 munmap(il->mapped_file, il->bytes_total);
801 il->mapped_file = NULL;
805 static void image_loader_stop(ImageLoader *il)
811 g_source_remove(il->idle_id);
817 /* stop loader in the other thread */
818 g_mutex_lock(il->data_mutex);
820 while (!il->can_destroy) g_cond_wait(il->can_destroy_cond, il->data_mutex);
821 g_mutex_unlock(il->data_mutex);
824 image_loader_stop_loader(il);
825 image_loader_stop_source(il);
829 void image_loader_delay_area_ready(ImageLoader *il, gboolean enable)
831 g_mutex_lock(il->data_mutex);
832 il->delay_area_ready = enable;
837 list = g_list_reverse(il->area_param_delayed_list);
838 il->area_param_delayed_list = NULL;
839 g_mutex_unlock(il->data_mutex);
845 ImageLoaderAreaParam *par = work->data;
848 g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h);
856 g_mutex_unlock(il->data_mutex);
861 /**************************************************************************************/
862 /* execution via idle calls */
864 static gboolean image_loader_idle_cb(gpointer data)
866 gboolean ret = FALSE;
867 ImageLoader *il = data;
871 ret = image_loader_continue(il);
876 image_loader_stop_source(il);
883 static gboolean image_loader_start_idle(ImageLoader *il)
887 if (!il) return FALSE;
889 if (!il->fd) return FALSE;
891 if (!image_loader_setup_source(il)) return FALSE;
893 ret = image_loader_begin(il);
895 if (ret && !il->done) il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, NULL);
899 /**************************************************************************************/
900 /* execution via thread */
903 static GThreadPool *image_loader_thread_pool = NULL;
905 static GCond *image_loader_prio_cond = NULL;
906 static GMutex *image_loader_prio_mutex = NULL;
907 static gint image_loader_prio_num = 0;
910 static void image_loader_thread_enter_high(void)
912 g_mutex_lock(image_loader_prio_mutex);
913 image_loader_prio_num++;
914 g_mutex_unlock(image_loader_prio_mutex);
917 static void image_loader_thread_leave_high(void)
919 g_mutex_lock(image_loader_prio_mutex);
920 image_loader_prio_num--;
921 if (image_loader_prio_num == 0) g_cond_broadcast(image_loader_prio_cond); /* wake up all low prio threads */
922 g_mutex_unlock(image_loader_prio_mutex);
925 static void image_loader_thread_wait_high(void)
927 g_mutex_lock(image_loader_prio_mutex);
928 while (image_loader_prio_num)
930 g_cond_wait(image_loader_prio_cond, image_loader_prio_mutex);
933 g_mutex_unlock(image_loader_prio_mutex);
937 static void image_loader_thread_run(gpointer data, gpointer user_data)
939 ImageLoader *il = data;
943 if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE)
945 /* low prio, wait untill high prio tasks finishes */
946 image_loader_thread_wait_high();
951 image_loader_thread_enter_high();
954 err = !image_loader_begin(il);
959 loader failed, we have to send signal
960 (idle mode returns the image_loader_begin return value directly)
961 (success is always reported indirectly from image_loader_begin)
963 image_loader_emit_error(il);
968 while (cont && !image_loader_get_is_done(il) && !image_loader_get_stopping(il))
970 if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE)
972 /* low prio, wait untill high prio tasks finishes */
973 image_loader_thread_wait_high();
975 cont = image_loader_continue(il);
977 image_loader_stop_loader(il);
979 if (il->idle_priority <= G_PRIORITY_DEFAULT_IDLE)
982 image_loader_thread_leave_high();
985 g_mutex_lock(il->data_mutex);
986 il->can_destroy = TRUE;
987 g_cond_signal(il->can_destroy_cond);
988 g_mutex_unlock(il->data_mutex);
993 static gboolean image_loader_start_thread(ImageLoader *il)
995 if (!il) return FALSE;
997 if (!il->fd) return FALSE;
1001 if (!image_loader_setup_source(il)) return FALSE;
1003 if (!image_loader_thread_pool)
1005 image_loader_thread_pool = g_thread_pool_new(image_loader_thread_run, NULL, -1, FALSE, NULL);
1006 image_loader_prio_cond = g_cond_new();
1007 image_loader_prio_mutex = g_mutex_new();
1010 il->can_destroy = FALSE; /* ImageLoader can't be freed until image_loader_thread_run finishes */
1012 g_thread_pool_push(image_loader_thread_pool, il, NULL);
1013 DEBUG_1("Thread pool num threads: %d", g_thread_pool_get_num_threads(image_loader_thread_pool));
1017 #endif /* HAVE_GTHREAD */
1020 /**************************************************************************************/
1021 /* public interface */
1024 gboolean image_loader_start(ImageLoader *il)
1026 if (!il) return FALSE;
1028 if (!il->fd) return FALSE;
1031 return image_loader_start_thread(il);
1033 return image_loader_start_idle(il);
1038 /* don't forget to gdk_pixbuf_ref() it if you want to use it after image_loader_free() */
1039 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il)
1042 if (!il) return NULL;
1044 g_mutex_lock(il->data_mutex);
1046 g_mutex_unlock(il->data_mutex);
1050 gchar *image_loader_get_format(ImageLoader *il)
1055 if (!il || !il->loader) return NULL;
1057 mimev = il->backend.get_format_mime_types(il->loader);
1058 if (!mimev) return NULL;
1060 /* return first member of mimev, as GdkPixbufLoader has no way to tell us which exact one ? */
1061 mime = g_strdup(mimev[0]);
1067 void image_loader_set_requested_size(ImageLoader *il, gint width, gint height)
1071 g_mutex_lock(il->data_mutex);
1072 il->requested_width = width;
1073 il->requested_height = height;
1074 g_mutex_unlock(il->data_mutex);
1077 void image_loader_set_buffer_size(ImageLoader *il, guint count)
1081 g_mutex_lock(il->data_mutex);
1082 il->idle_read_loop_count = count ? count : 1;
1083 g_mutex_unlock(il->data_mutex);
1086 void image_loader_set_priority(ImageLoader *il, gint priority)
1090 if (il->thread) return; /* can't change prio if the thread already runs */
1091 il->idle_priority = priority;
1095 gdouble image_loader_get_percent(ImageLoader *il)
1098 if (!il) return 0.0;
1100 g_mutex_lock(il->data_mutex);
1101 if (il->bytes_total == 0)
1107 ret = (gdouble)il->bytes_read / il->bytes_total;
1109 g_mutex_unlock(il->data_mutex);
1113 gboolean image_loader_get_is_done(ImageLoader *il)
1116 if (!il) return FALSE;
1118 g_mutex_lock(il->data_mutex);
1120 g_mutex_unlock(il->data_mutex);
1125 FileData *image_loader_get_fd(ImageLoader *il)
1128 if (!il) return NULL;
1130 g_mutex_lock(il->data_mutex);
1132 g_mutex_unlock(il->data_mutex);
1137 gboolean image_loader_get_shrunk(ImageLoader *il)
1140 if (!il) return FALSE;
1142 g_mutex_lock(il->data_mutex);
1144 g_mutex_unlock(il->data_mutex);
1148 const gchar *image_loader_get_error(ImageLoader *il)
1150 const gchar *ret = NULL;
1151 if (!il) return NULL;
1152 g_mutex_lock(il->data_mutex);
1153 if (il->error) ret = il->error->message;
1154 g_mutex_unlock(il->data_mutex);
1159 /* FIXME - this can be rather slow and blocks until the size is known */
1160 gboolean image_load_dimensions(FileData *fd, gint *width, gint *height)
1165 il = image_loader_new(fd);
1167 success = image_loader_start_idle(il);
1169 if (success && il->pixbuf)
1171 if (width) *width = gdk_pixbuf_get_width(il->pixbuf);
1172 if (height) *height = gdk_pixbuf_get_height(il->pixbuf);;
1176 if (width) *width = -1;
1177 if (height) *height = -1;
1180 image_loader_free(il);
1184 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */