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;
255 g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h);
256 g_mutex_lock(il->data_mutex);
257 il->area_param_list = g_list_remove(il->area_param_list, par);
259 g_mutex_unlock(il->data_mutex);
264 static gboolean image_loader_emit_done_cb(gpointer data)
266 ImageLoader *il = data;
267 g_signal_emit(il, signals[SIGNAL_DONE], 0);
271 static gboolean image_loader_emit_error_cb(gpointer data)
273 ImageLoader *il = data;
274 g_signal_emit(il, signals[SIGNAL_ERROR], 0);
278 static gboolean image_loader_emit_percent_cb(gpointer data)
280 ImageLoader *il = data;
281 g_signal_emit(il, signals[SIGNAL_PERCENT], 0, image_loader_get_percent(il));
285 static gboolean image_loader_emit_size_cb(gpointer data)
288 ImageLoader *il = data;
289 g_mutex_lock(il->data_mutex);
290 width = il->actual_width;
291 height = il->actual_height;
292 g_mutex_unlock(il->data_mutex);
293 g_signal_emit(il, signals[SIGNAL_SIZE], 0, width, height);
298 /* DONE and ERROR are emited only once, thus they can have normal priority
299 PERCENT and AREA_READY should be processed ASAP
302 static void image_loader_emit_done(ImageLoader *il)
304 g_idle_add_full(il->idle_priority, image_loader_emit_done_cb, il, NULL);
307 static void image_loader_emit_error(ImageLoader *il)
309 g_idle_add_full(il->idle_priority, image_loader_emit_error_cb, il, NULL);
312 static void image_loader_emit_percent(ImageLoader *il)
314 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_percent_cb, il, NULL);
317 static void image_loader_emit_size(ImageLoader *il)
319 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_size_cb, il, NULL);
322 /* this function expects that il->data_mutex is locked by caller */
323 static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
325 ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1);
332 il->area_param_list = g_list_prepend(il->area_param_list, par);
334 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL);
337 /**************************************************************************************/
338 /* the following functions may be executed in separate thread */
340 /* this function expects that il->data_mutex is locked by caller */
341 static void image_loader_queue_delayed_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
343 ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1);
350 il->area_param_delayed_list = g_list_prepend(il->area_param_delayed_list, par);
355 static gboolean image_loader_get_stopping(ImageLoader *il)
358 if (!il) return FALSE;
360 g_mutex_lock(il->data_mutex);
362 g_mutex_unlock(il->data_mutex);
368 static void image_loader_sync_pixbuf(ImageLoader *il)
372 g_mutex_lock(il->data_mutex);
376 g_mutex_unlock(il->data_mutex);
380 pb = il->backend.get_pixbuf(il->loader);
382 if (pb == il->pixbuf)
384 g_mutex_unlock(il->data_mutex);
388 if (g_ascii_strcasecmp(".jps", il->fd->extension) == 0)
390 g_object_set_data(G_OBJECT(pb), "stereo_data", GINT_TO_POINTER(STEREO_PIXBUF_CROSS));
393 if (il->pixbuf) g_object_unref(il->pixbuf);
396 if (il->pixbuf) g_object_ref(il->pixbuf);
398 g_mutex_unlock(il->data_mutex);
401 static void image_loader_area_updated_cb(gpointer loader,
402 guint x, guint y, guint w, guint h,
405 ImageLoader *il = data;
407 if (!image_loader_get_pixbuf(il))
409 image_loader_sync_pixbuf(il);
410 if (!image_loader_get_pixbuf(il))
412 log_printf("critical: area_ready signal with NULL pixbuf (out of mem?)\n");
416 g_mutex_lock(il->data_mutex);
417 if (il->delay_area_ready)
418 image_loader_queue_delayed_area_ready(il, x, y, w, h);
420 image_loader_emit_area_ready(il, x, y, w, h);
422 if (il->stopping) il->backend.abort(il->loader);
424 g_mutex_unlock(il->data_mutex);
427 static void image_loader_area_prepared_cb(gpointer loader, gpointer data)
429 ImageLoader *il = data;
435 http://bugzilla.gnome.org/show_bug.cgi?id=547669
436 http://bugzilla.gnome.org/show_bug.cgi?id=589334
438 gchar *format = il->backend.get_format_name(loader);
439 if (strcmp(format, "svg") == 0 ||
440 strcmp(format, "xpm") == 0)
448 pb = il->backend.get_pixbuf(loader);
450 h = gdk_pixbuf_get_height(pb);
451 rs = gdk_pixbuf_get_rowstride(pb);
452 pix = gdk_pixbuf_get_pixels(pb);
454 memset(pix, 0, rs * h); /*this should be faster than pixbuf_fill */
458 static void image_loader_size_cb(gpointer loader,
459 gint width, gint height, gpointer data)
461 ImageLoader *il = data;
463 gboolean scale = FALSE;
466 g_mutex_lock(il->data_mutex);
467 il->actual_width = width;
468 il->actual_height = height;
469 if (il->requested_width < 1 || il->requested_height < 1)
471 g_mutex_unlock(il->data_mutex);
472 image_loader_emit_size(il);
475 g_mutex_unlock(il->data_mutex);
477 mime_types = il->backend.get_format_mime_types(loader);
479 while (mime_types[n])
481 if (strstr(mime_types[n], "jpeg")) scale = TRUE;
484 g_strfreev(mime_types);
488 image_loader_emit_size(il);
492 g_mutex_lock(il->data_mutex);
495 if (width > il->requested_width || height > il->requested_height)
498 if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height))
500 nw = il->requested_width;
501 nh = (gdouble)nw / width * height;
506 nh = il->requested_height;
507 nw = (gdouble)nh / height * width;
511 il->actual_width = nw;
512 il->actual_height = nh;
513 il->backend.set_size(loader, nw, nh);
517 g_mutex_unlock(il->data_mutex);
518 image_loader_emit_size(il);
521 static void image_loader_stop_loader(ImageLoader *il)
527 /* some loaders do not have a pixbuf till close, order is important here */
528 il->backend.close(il->loader, il->error ? NULL : &il->error); /* we are interested in the first error only */
529 image_loader_sync_pixbuf(il);
530 il->backend.free(il->loader);
533 g_mutex_lock(il->data_mutex);
535 g_mutex_unlock(il->data_mutex);
538 static void image_loader_setup_loader(ImageLoader *il)
540 g_mutex_lock(il->data_mutex);
542 if (il->bytes_total >= 2 && il->mapped_file[0] == 0xff && il->mapped_file[1] == 0xd8)
544 DEBUG_1("Using custom jpeg loader");
545 image_loader_backend_set_jpeg(&il->backend);
550 if (il->bytes_total >= 10 &&
551 (memcmp(il->mapped_file, "MM\0*", 4) == 0 ||
552 memcmp(il->mapped_file, "II*\0", 4) == 0))
554 DEBUG_1("Using custom tiff loader");
555 image_loader_backend_set_tiff(&il->backend);
559 image_loader_backend_set_default(&il->backend);
561 il->loader = il->backend.loader_new(image_loader_area_updated_cb, image_loader_size_cb, image_loader_area_prepared_cb, il);
562 g_mutex_unlock(il->data_mutex);
566 static void image_loader_done(ImageLoader *il)
568 image_loader_stop_loader(il);
570 image_loader_emit_done(il);
573 static void image_loader_error(ImageLoader *il)
575 image_loader_stop_loader(il);
577 DEBUG_1("pixbuf_loader reported load error for: %s", il->fd->path);
579 image_loader_emit_error(il);
582 static gboolean image_loader_continue(ImageLoader *il)
587 if (!il) return FALSE;
589 c = il->idle_read_loop_count ? il->idle_read_loop_count : 1;
590 while (c > 0 && !image_loader_get_stopping(il))
592 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
596 image_loader_done(il);
600 if (b < 0 || (b > 0 && !il->backend.write(il->loader, il->mapped_file + il->bytes_read, b, &il->error)))
602 image_loader_error(il);
611 if (il->bytes_total > 0)
613 image_loader_emit_percent(il);
619 static gboolean image_loader_begin(ImageLoader *il)
623 if (il->pixbuf) return FALSE;
625 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
626 if (b < 1) return FALSE;
628 image_loader_setup_loader(il);
630 g_assert(il->bytes_read == 0);
631 if (il->backend.load) {
633 if (!il->backend.load(il->loader, il->mapped_file, b, &il->error))
635 image_loader_stop_loader(il);
639 else if (!il->backend.write(il->loader, il->mapped_file, b, &il->error))
641 image_loader_stop_loader(il);
647 /* read until size is known */
648 while (il->loader && !il->backend.get_pixbuf(il->loader) && b > 0 && !image_loader_get_stopping(il))
650 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
651 if (b < 0 || (b > 0 && !il->backend.write(il->loader, il->mapped_file + il->bytes_read, b, &il->error)))
653 image_loader_stop_loader(il);
658 if (!il->pixbuf) image_loader_sync_pixbuf(il);
660 if (il->bytes_read == il->bytes_total || b < 1)
662 /* done, handle (broken) loaders that do not have pixbuf till close */
663 image_loader_stop_loader(il);
665 if (!il->pixbuf) return FALSE;
667 image_loader_done(il);
673 image_loader_stop_loader(il);
680 /**************************************************************************************/
681 /* the following functions are always executed in the main thread */
684 static gboolean image_loader_setup_source(ImageLoader *il)
689 if (!il || il->loader || il->mapped_file) return FALSE;
691 il->mapped_file = NULL;
695 ExifData *exif = exif_read_fd(il->fd);
697 if (options->thumbnails.use_exif)
698 il->mapped_file = exif_get_preview(exif, (guint *)&il->bytes_total, il->requested_width, il->requested_height);
700 il->mapped_file = exif_get_preview(exif, (guint *)&il->bytes_total, 0, 0); /* get the largest available preview image or NULL for normal images*/
705 DEBUG_1("Usable reduced size (preview) image loaded from file %s", il->fd->path);
707 exif_free_fd(il->fd, exif);
711 if (!il->mapped_file)
716 pathl = path_from_utf8(il->fd->path);
717 load_fd = open(pathl, O_RDONLY | O_NONBLOCK);
719 if (load_fd == -1) return FALSE;
721 if (fstat(load_fd, &st) == 0)
723 il->bytes_total = st.st_size;
731 il->mapped_file = mmap(0, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0);
733 if (il->mapped_file == MAP_FAILED)
744 static void image_loader_stop_source(ImageLoader *il)
752 exif_free_preview(il->mapped_file);
756 munmap(il->mapped_file, il->bytes_total);
758 il->mapped_file = NULL;
762 static void image_loader_stop(ImageLoader *il)
768 g_source_remove(il->idle_id);
774 /* stop loader in the other thread */
775 g_mutex_lock(il->data_mutex);
777 while (!il->can_destroy) g_cond_wait(il->can_destroy_cond, il->data_mutex);
778 g_mutex_unlock(il->data_mutex);
781 image_loader_stop_loader(il);
782 image_loader_stop_source(il);
786 void image_loader_delay_area_ready(ImageLoader *il, gboolean enable)
788 g_mutex_lock(il->data_mutex);
789 il->delay_area_ready = enable;
794 list = g_list_reverse(il->area_param_delayed_list);
795 il->area_param_delayed_list = NULL;
796 g_mutex_unlock(il->data_mutex);
802 ImageLoaderAreaParam *par = work->data;
805 g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h);
813 g_mutex_unlock(il->data_mutex);
818 /**************************************************************************************/
819 /* execution via idle calls */
821 static gboolean image_loader_idle_cb(gpointer data)
823 gboolean ret = FALSE;
824 ImageLoader *il = data;
828 ret = image_loader_continue(il);
833 image_loader_stop_source(il);
840 static gboolean image_loader_start_idle(ImageLoader *il)
844 if (!il) return FALSE;
846 if (!il->fd) return FALSE;
848 if (!image_loader_setup_source(il)) return FALSE;
850 ret = image_loader_begin(il);
852 if (ret && !il->done) il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, NULL);
856 /**************************************************************************************/
857 /* execution via thread */
860 static GThreadPool *image_loader_thread_pool = NULL;
862 static GCond *image_loader_prio_cond = NULL;
863 static GMutex *image_loader_prio_mutex = NULL;
864 static gint image_loader_prio_num = 0;
867 static void image_loader_thread_enter_high(void)
869 g_mutex_lock(image_loader_prio_mutex);
870 image_loader_prio_num++;
871 g_mutex_unlock(image_loader_prio_mutex);
874 static void image_loader_thread_leave_high(void)
876 g_mutex_lock(image_loader_prio_mutex);
877 image_loader_prio_num--;
878 if (image_loader_prio_num == 0) g_cond_broadcast(image_loader_prio_cond); /* wake up all low prio threads */
879 g_mutex_unlock(image_loader_prio_mutex);
882 static void image_loader_thread_wait_high(void)
884 g_mutex_lock(image_loader_prio_mutex);
885 while (image_loader_prio_num)
887 g_cond_wait(image_loader_prio_cond, image_loader_prio_mutex);
890 g_mutex_unlock(image_loader_prio_mutex);
894 static void image_loader_thread_run(gpointer data, gpointer user_data)
896 ImageLoader *il = data;
900 if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE)
902 /* low prio, wait untill high prio tasks finishes */
903 image_loader_thread_wait_high();
908 image_loader_thread_enter_high();
911 err = !image_loader_begin(il);
916 loader failed, we have to send signal
917 (idle mode returns the image_loader_begin return value directly)
918 (success is always reported indirectly from image_loader_begin)
920 image_loader_emit_error(il);
925 while (cont && !image_loader_get_is_done(il) && !image_loader_get_stopping(il))
927 if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE)
929 /* low prio, wait untill high prio tasks finishes */
930 image_loader_thread_wait_high();
932 cont = image_loader_continue(il);
934 image_loader_stop_loader(il);
936 if (il->idle_priority <= G_PRIORITY_DEFAULT_IDLE)
939 image_loader_thread_leave_high();
942 g_mutex_lock(il->data_mutex);
943 il->can_destroy = TRUE;
944 g_cond_signal(il->can_destroy_cond);
945 g_mutex_unlock(il->data_mutex);
950 static gboolean image_loader_start_thread(ImageLoader *il)
952 if (!il) return FALSE;
954 if (!il->fd) return FALSE;
958 if (!image_loader_setup_source(il)) return FALSE;
960 if (!image_loader_thread_pool)
962 image_loader_thread_pool = g_thread_pool_new(image_loader_thread_run, NULL, -1, FALSE, NULL);
963 image_loader_prio_cond = g_cond_new();
964 image_loader_prio_mutex = g_mutex_new();
967 il->can_destroy = FALSE; /* ImageLoader can't be freed until image_loader_thread_run finishes */
969 g_thread_pool_push(image_loader_thread_pool, il, NULL);
970 DEBUG_1("Thread pool num threads: %d", g_thread_pool_get_num_threads(image_loader_thread_pool));
974 #endif /* HAVE_GTHREAD */
977 /**************************************************************************************/
978 /* public interface */
981 gboolean image_loader_start(ImageLoader *il)
983 if (!il) return FALSE;
985 if (!il->fd) return FALSE;
988 return image_loader_start_thread(il);
990 return image_loader_start_idle(il);
995 /* don't forget to gdk_pixbuf_ref() it if you want to use it after image_loader_free() */
996 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il)
999 if (!il) return NULL;
1001 g_mutex_lock(il->data_mutex);
1003 g_mutex_unlock(il->data_mutex);
1007 gchar *image_loader_get_format(ImageLoader *il)
1012 if (!il || !il->loader) return NULL;
1014 mimev = il->backend.get_format_mime_types(il->loader);
1015 if (!mimev) return NULL;
1017 /* return first member of mimev, as GdkPixbufLoader has no way to tell us which exact one ? */
1018 mime = g_strdup(mimev[0]);
1024 void image_loader_set_requested_size(ImageLoader *il, gint width, gint height)
1028 g_mutex_lock(il->data_mutex);
1029 il->requested_width = width;
1030 il->requested_height = height;
1031 g_mutex_unlock(il->data_mutex);
1034 void image_loader_set_buffer_size(ImageLoader *il, guint count)
1038 g_mutex_lock(il->data_mutex);
1039 il->idle_read_loop_count = count ? count : 1;
1040 g_mutex_unlock(il->data_mutex);
1043 void image_loader_set_priority(ImageLoader *il, gint priority)
1047 if (il->thread) return; /* can't change prio if the thread already runs */
1048 il->idle_priority = priority;
1052 gdouble image_loader_get_percent(ImageLoader *il)
1055 if (!il) return 0.0;
1057 g_mutex_lock(il->data_mutex);
1058 if (il->bytes_total == 0)
1064 ret = (gdouble)il->bytes_read / il->bytes_total;
1066 g_mutex_unlock(il->data_mutex);
1070 gboolean image_loader_get_is_done(ImageLoader *il)
1073 if (!il) return FALSE;
1075 g_mutex_lock(il->data_mutex);
1077 g_mutex_unlock(il->data_mutex);
1082 FileData *image_loader_get_fd(ImageLoader *il)
1085 if (!il) return NULL;
1087 g_mutex_lock(il->data_mutex);
1089 g_mutex_unlock(il->data_mutex);
1094 gboolean image_loader_get_shrunk(ImageLoader *il)
1097 if (!il) return FALSE;
1099 g_mutex_lock(il->data_mutex);
1101 g_mutex_unlock(il->data_mutex);
1105 const gchar *image_loader_get_error(ImageLoader *il)
1107 const gchar *ret = NULL;
1108 if (!il) return NULL;
1109 g_mutex_lock(il->data_mutex);
1110 if (il->error) ret = il->error->message;
1111 g_mutex_unlock(il->data_mutex);
1116 /* FIXME - this can be rather slow and blocks until the size is known */
1117 gboolean image_load_dimensions(FileData *fd, gint *width, gint *height)
1122 il = image_loader_new(fd);
1124 success = image_loader_start_idle(il);
1126 if (success && il->pixbuf)
1128 if (width) *width = gdk_pixbuf_get_width(il->pixbuf);
1129 if (height) *height = gdk_pixbuf_get_height(il->pixbuf);;
1133 if (width) *width = -1;
1134 if (height) *height = -1;
1137 image_loader_free(il);
1141 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */