Mercurial > geeqie
annotate src/image-load.c @ 1498:5f49f305a6b6
improved debug messages
author | nadvornik |
---|---|
date | Tue, 31 Mar 2009 20:05:16 +0000 |
parents | 2c54f3f71634 |
children | 0a1266bde95b |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
1284 | 4 * Copyright (C) 2008 - 2009 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" |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
20 #include "gq-marshal.h" |
9 | 21 |
22 #include <fcntl.h> | |
1008 | 23 #include <sys/mman.h> |
9 | 24 |
1014 | 25 |
26 /**************************************************************************************/ | |
1346
c9949c19a6d0
No space between function name and first parenthesis, it eases greping (see CODING).
zas_
parents:
1284
diff
changeset
|
27 /* image loader class */ |
1014 | 28 |
29 | |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
30 enum { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
31 SIGNAL_AREA_READY = 0, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
32 SIGNAL_ERROR, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
33 SIGNAL_DONE, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
34 SIGNAL_PERCENT, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
35 SIGNAL_COUNT |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
36 }; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
37 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
38 static guint signals[SIGNAL_COUNT] = { 0 }; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
39 |
1346
c9949c19a6d0
No space between function name and first parenthesis, it eases greping (see CODING).
zas_
parents:
1284
diff
changeset
|
40 static void image_loader_init(GTypeInstance *instance, gpointer g_class); |
c9949c19a6d0
No space between function name and first parenthesis, it eases greping (see CODING).
zas_
parents:
1284
diff
changeset
|
41 static void image_loader_class_init(ImageLoaderClass *class); |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
42 static void image_loader_finalize(GObject *object); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
43 static void image_loader_stop(ImageLoader *il); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
44 |
1346
c9949c19a6d0
No space between function name and first parenthesis, it eases greping (see CODING).
zas_
parents:
1284
diff
changeset
|
45 GType image_loader_get_type(void) |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
46 { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
47 static GType type = 0; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
48 if (type == 0) |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
49 { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
50 static const GTypeInfo info = { |
1346
c9949c19a6d0
No space between function name and first parenthesis, it eases greping (see CODING).
zas_
parents:
1284
diff
changeset
|
51 sizeof(ImageLoaderClass), |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
52 NULL, /* base_init */ |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
53 NULL, /* base_finalize */ |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
54 (GClassInitFunc)image_loader_class_init, /* class_init */ |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
55 NULL, /* class_finalize */ |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
56 NULL, /* class_data */ |
1346
c9949c19a6d0
No space between function name and first parenthesis, it eases greping (see CODING).
zas_
parents:
1284
diff
changeset
|
57 sizeof(ImageLoader), |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
58 0, /* n_preallocs */ |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
59 (GInstanceInitFunc)image_loader_init, /* instance_init */ |
1016 | 60 NULL /* value_table */ |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
61 }; |
1346
c9949c19a6d0
No space between function name and first parenthesis, it eases greping (see CODING).
zas_
parents:
1284
diff
changeset
|
62 type = g_type_register_static(G_TYPE_OBJECT, "ImageLoaderType", &info, 0); |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
63 } |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
64 return type; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
65 } |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
66 |
1346
c9949c19a6d0
No space between function name and first parenthesis, it eases greping (see CODING).
zas_
parents:
1284
diff
changeset
|
67 static void image_loader_init(GTypeInstance *instance, gpointer g_class) |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
68 { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
69 ImageLoader *il = (ImageLoader *)instance; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
70 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
71 il->pixbuf = NULL; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
72 il->idle_id = -1; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
73 il->idle_priority = G_PRIORITY_DEFAULT_IDLE; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
74 il->done = FALSE; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
75 il->loader = NULL; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
76 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
77 il->bytes_read = 0; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
78 il->bytes_total = 0; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
79 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
80 il->idle_done_id = -1; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
81 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
82 il->idle_read_loop_count = options->image.idle_read_loop_count; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
83 il->read_buffer_size = options->image.read_buffer_size; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
84 il->mapped_file = NULL; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
85 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
86 il->requested_width = 0; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
87 il->requested_height = 0; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
88 il->shrunk = FALSE; |
1015 | 89 |
1026 | 90 il->can_destroy = TRUE; |
91 | |
1015 | 92 #ifdef HAVE_GTHREAD |
93 il->data_mutex = g_mutex_new(); | |
1021 | 94 il->can_destroy_cond = g_cond_new(); |
1015 | 95 #endif |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
96 DEBUG_1("new image loader %p, bufsize=%u idle_loop=%u", il, il->read_buffer_size, il->idle_read_loop_count); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
97 } |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
98 |
1346
c9949c19a6d0
No space between function name and first parenthesis, it eases greping (see CODING).
zas_
parents:
1284
diff
changeset
|
99 static void image_loader_class_init(ImageLoaderClass *class) |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
100 { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
101 GObjectClass *gobject_class = G_OBJECT_CLASS (class); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
102 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
103 // gobject_class->set_property = image_loader_set_property; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
104 // gobject_class->get_property = image_loader_get_property; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
105 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
106 gobject_class->finalize = image_loader_finalize; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
107 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
108 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
109 signals[SIGNAL_AREA_READY] = |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
110 g_signal_new("area_ready", |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
111 G_OBJECT_CLASS_TYPE(gobject_class), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
112 G_SIGNAL_RUN_LAST, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
113 G_STRUCT_OFFSET(ImageLoaderClass, area_ready), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
114 NULL, NULL, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
115 gq_marshal_VOID__INT_INT_INT_INT, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
116 G_TYPE_NONE, 4, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
117 G_TYPE_INT, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
118 G_TYPE_INT, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
119 G_TYPE_INT, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
120 G_TYPE_INT); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
121 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
122 signals[SIGNAL_ERROR] = |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
123 g_signal_new("error", |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
124 G_OBJECT_CLASS_TYPE(gobject_class), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
125 G_SIGNAL_RUN_LAST, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
126 G_STRUCT_OFFSET(ImageLoaderClass, error), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
127 NULL, NULL, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
128 g_cclosure_marshal_VOID__VOID, |
1026 | 129 G_TYPE_NONE, 0); |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
130 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
131 signals[SIGNAL_DONE] = |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
132 g_signal_new("done", |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
133 G_OBJECT_CLASS_TYPE(gobject_class), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
134 G_SIGNAL_RUN_LAST, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
135 G_STRUCT_OFFSET(ImageLoaderClass, done), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
136 NULL, NULL, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
137 g_cclosure_marshal_VOID__VOID, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
138 G_TYPE_NONE, 0); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
139 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
140 signals[SIGNAL_PERCENT] = |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
141 g_signal_new("percent", |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
142 G_OBJECT_CLASS_TYPE(gobject_class), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
143 G_SIGNAL_RUN_LAST, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
144 G_STRUCT_OFFSET(ImageLoaderClass, percent), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
145 NULL, NULL, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
146 g_cclosure_marshal_VOID__DOUBLE, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
147 G_TYPE_NONE, 1, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
148 G_TYPE_DOUBLE); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
149 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
150 } |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
151 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
152 static void image_loader_finalize(GObject *object) |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
153 { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
154 ImageLoader *il = (ImageLoader *)object; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
155 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
156 image_loader_stop(il); |
1014 | 157 |
1497 | 158 if (il->error) DEBUG_1("%s", image_loader_get_error(il)); |
159 | |
1014 | 160 DEBUG_1("freeing image loader %p bytes_read=%d", il, il->bytes_read); |
161 | |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
162 if (il->idle_done_id != -1) g_source_remove(il->idle_done_id); |
1014 | 163 |
164 while (g_source_remove_by_user_data(il)) | |
165 { | |
1498 | 166 DEBUG_2("pending signals detected"); |
1014 | 167 } |
168 | |
169 while (il->area_param_list) | |
170 { | |
171 DEBUG_1("pending area_ready signals detected"); | |
172 while (g_source_remove_by_user_data(il->area_param_list->data)) {} | |
173 g_free(il->area_param_list->data); | |
174 il->area_param_list = g_list_delete_link(il->area_param_list, il->area_param_list); | |
175 } | |
176 | |
1045
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
177 while (il->area_param_delayed_list) |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
178 { |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
179 g_free(il->area_param_delayed_list->data); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
180 il->area_param_delayed_list = g_list_delete_link(il->area_param_delayed_list, il->area_param_delayed_list); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
181 } |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
182 |
1043 | 183 if (il->pixbuf) g_object_unref(il->pixbuf); |
1497 | 184 |
185 if (il->error) g_error_free(il->error); | |
1043 | 186 |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
187 file_data_unref(il->fd); |
1015 | 188 #ifdef HAVE_GTHREAD |
189 g_mutex_free(il->data_mutex); | |
1021 | 190 g_cond_free(il->can_destroy_cond); |
1015 | 191 #endif |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
192 } |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
193 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
194 void image_loader_free(ImageLoader *il) |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
195 { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
196 if (!il) return; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
197 g_object_unref(G_OBJECT(il)); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
198 } |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
199 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
200 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
201 ImageLoader *image_loader_new(FileData *fd) |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
202 { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
203 ImageLoader *il; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
204 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
205 if (!fd) return NULL; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
206 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
207 il = (ImageLoader *) g_object_new(TYPE_IMAGE_LOADER, NULL); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
208 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
209 il->fd = file_data_ref(fd); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
210 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
211 return il; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
212 } |
9 | 213 |
1014 | 214 /**************************************************************************************/ |
215 /* send signals via idle calbacks - the callback are executed in the main thread */ | |
216 | |
217 typedef struct _ImageLoaderAreaParam ImageLoaderAreaParam; | |
218 struct _ImageLoaderAreaParam { | |
219 ImageLoader *il; | |
220 guint x; | |
221 guint y; | |
222 guint w; | |
223 guint h; | |
224 }; | |
225 | |
226 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
227 static gboolean image_loader_emit_area_ready_cb(gpointer data) |
1014 | 228 { |
229 ImageLoaderAreaParam *par = data; | |
230 ImageLoader *il = par->il; | |
231 g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h); | |
1015 | 232 g_mutex_lock(il->data_mutex); |
1014 | 233 il->area_param_list = g_list_remove(il->area_param_list, par); |
234 g_free(par); | |
1015 | 235 g_mutex_unlock(il->data_mutex); |
1014 | 236 |
237 return FALSE; | |
238 } | |
239 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
240 static gboolean image_loader_emit_done_cb(gpointer data) |
1014 | 241 { |
242 ImageLoader *il = data; | |
243 g_signal_emit(il, signals[SIGNAL_DONE], 0); | |
244 return FALSE; | |
245 } | |
246 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
247 static gboolean image_loader_emit_error_cb(gpointer data) |
1014 | 248 { |
249 ImageLoader *il = data; | |
250 g_signal_emit(il, signals[SIGNAL_ERROR], 0); | |
251 return FALSE; | |
252 } | |
253 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
254 static gboolean image_loader_emit_percent_cb(gpointer data) |
1014 | 255 { |
256 ImageLoader *il = data; | |
1015 | 257 g_signal_emit(il, signals[SIGNAL_PERCENT], 0, image_loader_get_percent(il)); |
1014 | 258 return FALSE; |
259 } | |
260 | |
261 /* DONE and ERROR are emited only once, thus they can have normal priority | |
262 PERCENT and AREA_READY should be processed ASAP | |
263 */ | |
264 | |
265 static void image_loader_emit_done(ImageLoader *il) | |
266 { | |
267 g_idle_add_full(il->idle_priority, image_loader_emit_done_cb, il, NULL); | |
268 } | |
269 | |
270 static void image_loader_emit_error(ImageLoader *il) | |
271 { | |
272 g_idle_add_full(il->idle_priority, image_loader_emit_error_cb, il, NULL); | |
273 } | |
274 | |
275 static void image_loader_emit_percent(ImageLoader *il) | |
276 { | |
277 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_percent_cb, il, NULL); | |
278 } | |
279 | |
1045
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
280 /* this function expects that il->data_mutex is locked by caller */ |
1014 | 281 static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h) |
282 { | |
283 ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1); | |
284 par->il = il; | |
285 par->x = x; | |
286 par->y = y; | |
287 par->w = w; | |
288 par->h = h; | |
289 | |
290 il->area_param_list = g_list_prepend(il->area_param_list, par); | |
1015 | 291 |
1014 | 292 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL); |
293 } | |
294 | |
295 /**************************************************************************************/ | |
296 /* the following functions may be executed in separate thread */ | |
297 | |
1045
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
298 /* this function expects that il->data_mutex is locked by caller */ |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
299 static void image_loader_queue_delayed_erea_ready(ImageLoader *il, guint x, guint y, guint w, guint h) |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
300 { |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
301 ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
302 par->il = il; |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
303 par->x = x; |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
304 par->y = y; |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
305 par->w = w; |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
306 par->h = h; |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
307 |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
308 il->area_param_delayed_list = g_list_prepend(il->area_param_delayed_list, par); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
309 } |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
310 |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
311 |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
312 |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
313 static gboolean image_loader_get_stopping(ImageLoader *il) |
1020 | 314 { |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
315 gboolean ret; |
1020 | 316 if (!il) return FALSE; |
317 | |
318 g_mutex_lock(il->data_mutex); | |
319 ret = il->stopping; | |
320 g_mutex_unlock(il->data_mutex); | |
321 | |
322 return ret; | |
323 } | |
324 | |
1045
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
325 |
9 | 326 static void image_loader_sync_pixbuf(ImageLoader *il) |
327 { | |
328 GdkPixbuf *pb; | |
1015 | 329 |
330 g_mutex_lock(il->data_mutex); | |
331 | |
332 if (!il->loader) | |
333 { | |
334 g_mutex_unlock(il->data_mutex); | |
335 return; | |
336 } | |
9 | 337 |
338 pb = gdk_pixbuf_loader_get_pixbuf(il->loader); | |
339 | |
1015 | 340 if (pb == il->pixbuf) |
341 { | |
342 g_mutex_unlock(il->data_mutex); | |
343 return; | |
344 } | |
9 | 345 |
1043 | 346 if (il->pixbuf) g_object_unref(il->pixbuf); |
347 | |
9 | 348 il->pixbuf = pb; |
1043 | 349 if (il->pixbuf) g_object_ref(il->pixbuf); |
350 | |
1015 | 351 g_mutex_unlock(il->data_mutex); |
9 | 352 } |
353 | |
500 | 354 static void image_loader_area_updated_cb(GdkPixbufLoader *loader, |
9 | 355 guint x, guint y, guint w, guint h, |
356 gpointer data) | |
357 { | |
358 ImageLoader *il = data; | |
359 | |
1015 | 360 if (!image_loader_get_pixbuf(il)) |
9 | 361 { |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
362 image_loader_sync_pixbuf(il); |
1015 | 363 if (!image_loader_get_pixbuf(il)) |
9 | 364 { |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
365 log_printf("critical: area_ready signal with NULL pixbuf (out of mem?)\n"); |
9 | 366 } |
367 } | |
1045
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
368 |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
369 g_mutex_lock(il->data_mutex); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
370 if (il->delay_area_ready) |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
371 image_loader_queue_delayed_erea_ready(il, x, y, w, h); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
372 else |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
373 image_loader_emit_area_ready(il, x, y, w, h); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
374 g_mutex_unlock(il->data_mutex); |
9 | 375 } |
376 | |
500 | 377 static void image_loader_area_prepared_cb(GdkPixbufLoader *loader, gpointer data) |
378 { | |
379 GdkPixbuf *pb; | |
380 guchar *pix; | |
381 size_t h, rs; | |
961
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
382 |
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
383 /* 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
|
384 gchar *format = gdk_pixbuf_format_get_name(gdk_pixbuf_loader_get_format(loader)); |
995 | 385 if (strcmp(format, "svg") == 0) |
961
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
386 { |
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
387 g_free(format); |
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
388 return; |
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
389 } |
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
390 |
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
391 g_free(format); |
500 | 392 |
393 pb = gdk_pixbuf_loader_get_pixbuf(loader); | |
394 | |
395 h = gdk_pixbuf_get_height(pb); | |
396 rs = gdk_pixbuf_get_rowstride(pb); | |
397 pix = gdk_pixbuf_get_pixels(pb); | |
398 | |
399 memset(pix, 0, rs * h); /*this should be faster than pixbuf_fill */ | |
400 | |
401 } | |
402 | |
9 | 403 static void image_loader_size_cb(GdkPixbufLoader *loader, |
404 gint width, gint height, gpointer data) | |
405 { | |
406 ImageLoader *il = data; | |
407 GdkPixbufFormat *format; | |
408 gchar **mime_types; | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
409 gboolean scale = FALSE; |
9 | 410 gint n; |
411 | |
1015 | 412 g_mutex_lock(il->data_mutex); |
413 if (il->requested_width < 1 || il->requested_height < 1) | |
414 { | |
415 g_mutex_unlock(il->data_mutex); | |
416 return; | |
417 } | |
418 g_mutex_unlock(il->data_mutex); | |
9 | 419 |
420 format = gdk_pixbuf_loader_get_format(loader); | |
421 if (!format) return; | |
422 | |
423 mime_types = gdk_pixbuf_format_get_mime_types(format); | |
424 n = 0; | |
425 while (mime_types[n]) | |
426 { | |
427 if (strstr(mime_types[n], "jpeg")) scale = TRUE; | |
428 n++; | |
429 } | |
430 g_strfreev(mime_types); | |
442 | 431 |
9 | 432 if (!scale) return; |
433 | |
1015 | 434 g_mutex_lock(il->data_mutex); |
435 | |
9 | 436 if (width > il->requested_width || height > il->requested_height) |
437 { | |
438 gint nw, nh; | |
439 | |
440 if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height)) | |
441 { | |
442 nw = il->requested_width; | |
443 nh = (gdouble)nw / width * height; | |
444 if (nh < 1) nh = 1; | |
445 } | |
446 else | |
447 { | |
448 nh = il->requested_height; | |
449 nw = (gdouble)nh / height * width; | |
450 if (nw < 1) nw = 1; | |
451 } | |
442 | 452 |
9 | 453 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
|
454 il->shrunk = TRUE; |
9 | 455 } |
1015 | 456 g_mutex_unlock(il->data_mutex); |
457 | |
9 | 458 } |
459 | |
1014 | 460 static void image_loader_stop_loader(ImageLoader *il) |
9 | 461 { |
462 if (!il) return; | |
463 | |
464 if (il->loader) | |
465 { | |
466 /* some loaders do not have a pixbuf till close, order is important here */ | |
1497 | 467 gdk_pixbuf_loader_close(il->loader, il->error ? NULL : &il->error); /* we are interested in the first error only */ |
9 | 468 image_loader_sync_pixbuf(il); |
469 g_object_unref(G_OBJECT(il->loader)); | |
470 il->loader = NULL; | |
471 } | |
1020 | 472 g_mutex_lock(il->data_mutex); |
9 | 473 il->done = TRUE; |
1020 | 474 g_mutex_unlock(il->data_mutex); |
9 | 475 } |
476 | |
1014 | 477 static void image_loader_setup_loader(ImageLoader *il) |
478 { | |
1015 | 479 g_mutex_lock(il->data_mutex); |
1014 | 480 il->loader = gdk_pixbuf_loader_new(); |
1015 | 481 |
1014 | 482 g_signal_connect(G_OBJECT(il->loader), "area_updated", |
483 G_CALLBACK(image_loader_area_updated_cb), il); | |
484 g_signal_connect(G_OBJECT(il->loader), "size_prepared", | |
485 G_CALLBACK(image_loader_size_cb), il); | |
486 g_signal_connect(G_OBJECT(il->loader), "area_prepared", | |
487 G_CALLBACK(image_loader_area_prepared_cb), il); | |
1020 | 488 g_mutex_unlock(il->data_mutex); |
1014 | 489 } |
490 | |
491 | |
9 | 492 static void image_loader_done(ImageLoader *il) |
493 { | |
1014 | 494 image_loader_stop_loader(il); |
9 | 495 |
1014 | 496 image_loader_emit_done(il); |
9 | 497 } |
498 | |
499 static void image_loader_error(ImageLoader *il) | |
500 { | |
1014 | 501 image_loader_stop_loader(il); |
9 | 502 |
1009
dd311dae857a
fixed thumbnail loader for the new raw preview interface
nadvornik
parents:
1008
diff
changeset
|
503 DEBUG_1("pixbuf_loader reported load error for: %s", il->fd->path); |
9 | 504 |
1014 | 505 image_loader_emit_error(il); |
9 | 506 } |
507 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
508 static gboolean image_loader_continue(ImageLoader *il) |
9 | 509 { |
510 gint b; | |
511 gint c; | |
512 | |
513 if (!il) return FALSE; | |
514 | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
515 c = il->idle_read_loop_count ? il->idle_read_loop_count : 1; |
1020 | 516 while (c > 0 && !image_loader_get_stopping(il)) |
9 | 517 { |
1008 | 518 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read); |
9 | 519 |
520 if (b == 0) | |
521 { | |
522 image_loader_done(il); | |
523 return FALSE; | |
524 } | |
525 | |
1497 | 526 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, &il->error))) |
9 | 527 { |
528 image_loader_error(il); | |
529 return FALSE; | |
530 } | |
531 | |
532 il->bytes_read += b; | |
533 | |
534 c--; | |
535 } | |
536 | |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
537 if (il->bytes_total > 0) |
9 | 538 { |
1014 | 539 image_loader_emit_percent(il); |
9 | 540 } |
541 | |
542 return TRUE; | |
543 } | |
544 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
545 static gboolean image_loader_begin(ImageLoader *il) |
9 | 546 { |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
547 gssize b; |
1014 | 548 |
549 if (il->pixbuf) return FALSE; | |
442 | 550 |
1008 | 551 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read); |
1014 | 552 if (b < 1) return FALSE; |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
553 |
1014 | 554 image_loader_setup_loader(il); |
9 | 555 |
1497 | 556 if (!gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, &il->error)) |
9 | 557 { |
1014 | 558 image_loader_stop_loader(il); |
9 | 559 return FALSE; |
560 } | |
561 | |
1008 | 562 il->bytes_read += b; |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
563 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
564 /* read until size is known */ |
1020 | 565 while (il->loader && !gdk_pixbuf_loader_get_pixbuf(il->loader) && b > 0 && !image_loader_get_stopping(il)) |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
566 { |
1008 | 567 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read); |
1497 | 568 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, &il->error))) |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
569 { |
1014 | 570 image_loader_stop_loader(il); |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
571 return FALSE; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
572 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
573 il->bytes_read += b; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
574 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
575 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
|
576 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
577 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
|
578 { |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
579 /* done, handle (broken) loaders that do not have pixbuf till close */ |
1014 | 580 image_loader_stop_loader(il); |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
581 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
582 if (!il->pixbuf) return FALSE; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
583 |
1014 | 584 image_loader_done(il); |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
585 return TRUE; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
586 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
587 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
588 if (!il->pixbuf) |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
589 { |
1014 | 590 image_loader_stop_loader(il); |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
591 return FALSE; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
592 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
593 |
9 | 594 return TRUE; |
595 } | |
596 | |
1014 | 597 /**************************************************************************************/ |
598 /* the following functions are always executed in the main thread */ | |
599 | |
600 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
601 static gboolean image_loader_setup_source(ImageLoader *il) |
9 | 602 { |
603 struct stat st; | |
604 gchar *pathl; | |
605 | |
1008 | 606 if (!il || il->loader || il->mapped_file) return FALSE; |
607 | |
608 il->mapped_file = NULL; | |
609 | |
610 if (il->fd) | |
611 { | |
612 ExifData *exif = exif_read_fd(il->fd); | |
613 | |
1060 | 614 if (options->thumbnails.use_exif) |
615 il->mapped_file = exif_get_preview(exif, &il->bytes_total, il->requested_width, il->requested_height); | |
616 else | |
617 il->mapped_file = exif_get_preview(exif, &il->bytes_total, 0, 0); /* get the largest available preview image or NULL for normal images*/ | |
618 | |
1008 | 619 if (il->mapped_file) |
620 { | |
621 il->preview = TRUE; | |
1060 | 622 DEBUG_1("Usable reduced size (preview) image loaded from file %s", il->fd->path); |
1008 | 623 } |
624 exif_free_fd(il->fd, exif); | |
625 } | |
9 | 626 |
1008 | 627 |
628 if (!il->mapped_file) | |
629 { | |
630 /* normal file */ | |
631 gint load_fd; | |
632 | |
1009
dd311dae857a
fixed thumbnail loader for the new raw preview interface
nadvornik
parents:
1008
diff
changeset
|
633 pathl = path_from_utf8(il->fd->path); |
1008 | 634 load_fd = open(pathl, O_RDONLY | O_NONBLOCK); |
635 g_free(pathl); | |
636 if (load_fd == -1) return FALSE; | |
9 | 637 |
1008 | 638 if (fstat(load_fd, &st) == 0) |
639 { | |
640 il->bytes_total = st.st_size; | |
641 } | |
642 else | |
643 { | |
644 close(load_fd); | |
645 return FALSE; | |
646 } | |
647 | |
648 il->mapped_file = mmap(0, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0); | |
649 close(load_fd); | |
650 if (il->mapped_file == MAP_FAILED) | |
651 { | |
652 il->mapped_file = 0; | |
653 return FALSE; | |
654 } | |
655 il->preview = FALSE; | |
9 | 656 } |
1014 | 657 |
658 return TRUE; | |
659 } | |
660 | |
661 static void image_loader_stop_source(ImageLoader *il) | |
662 { | |
663 if (!il) return; | |
664 | |
665 if (il->mapped_file) | |
666 { | |
667 if (il->preview) | |
668 { | |
669 exif_free_preview(il->mapped_file); | |
670 } | |
671 else | |
672 { | |
673 munmap(il->mapped_file, il->bytes_total); | |
674 } | |
675 il->mapped_file = NULL; | |
676 } | |
677 } | |
9 | 678 |
1014 | 679 static void image_loader_stop(ImageLoader *il) |
680 { | |
681 if (!il) return; | |
682 | |
683 if (il->idle_id != -1) | |
684 { | |
685 g_source_remove(il->idle_id); | |
686 il->idle_id = -1; | |
687 } | |
688 | |
1015 | 689 if (il->thread) |
690 { | |
1021 | 691 /* stop loader in the other thread */ |
1020 | 692 g_mutex_lock(il->data_mutex); |
1015 | 693 il->stopping = TRUE; |
1021 | 694 while (!il->can_destroy) g_cond_wait(il->can_destroy_cond, il->data_mutex); |
1020 | 695 g_mutex_unlock(il->data_mutex); |
1015 | 696 } |
1014 | 697 |
698 image_loader_stop_loader(il); | |
699 image_loader_stop_source(il); | |
700 | |
701 } | |
702 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
703 void image_loader_delay_area_ready(ImageLoader *il, gboolean enable) |
1045
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
704 { |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
705 g_mutex_lock(il->data_mutex); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
706 il->delay_area_ready = enable; |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
707 if (!enable) |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
708 { |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
709 /* send delayed */ |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
710 GList *list, *work; |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
711 list = g_list_reverse(il->area_param_delayed_list); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
712 il->area_param_delayed_list = NULL; |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
713 g_mutex_unlock(il->data_mutex); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
714 |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
715 work = list; |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
716 |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
717 while (work) |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
718 { |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
719 ImageLoaderAreaParam *par = work->data; |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
720 work = work->next; |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
721 |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
722 g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
723 g_free(par); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
724 } |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
725 g_list_free(list); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
726 } |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
727 else |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
728 { |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
729 /* just unlock */ |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
730 g_mutex_unlock(il->data_mutex); |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
731 } |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
732 } |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
733 |
0ab0deb0cfcc
added possibility to redraw only the parts of image that are already
nadvornik
parents:
1043
diff
changeset
|
734 |
1014 | 735 /**************************************************************************************/ |
736 /* execution via idle calls */ | |
9 | 737 |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
738 static gboolean image_loader_idle_cb(gpointer data) |
1014 | 739 { |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
740 gboolean ret = FALSE; |
1014 | 741 ImageLoader *il = data; |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
742 |
1014 | 743 if (il->idle_id != -1) |
744 { | |
745 ret = image_loader_continue(il); | |
746 } | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
747 |
1014 | 748 if (!ret) |
749 { | |
750 image_loader_stop_source(il); | |
751 } | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
752 |
1014 | 753 return ret; |
754 } | |
755 | |
756 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
757 static gboolean image_loader_start_idle(ImageLoader *il) |
1014 | 758 { |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
759 gboolean ret; |
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
760 |
1014 | 761 if (!il) return FALSE; |
14
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
762 |
1014 | 763 if (!il->fd) return FALSE; |
764 | |
765 if (!image_loader_setup_source(il)) return FALSE; | |
766 | |
767 ret = image_loader_begin(il); | |
768 | |
769 if (ret && !il->done) il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, NULL); | |
770 return ret; | |
771 } | |
772 | |
773 /**************************************************************************************/ | |
1015 | 774 /* execution via thread */ |
1021 | 775 static GThreadPool *image_loader_thread_pool = NULL; |
1015 | 776 |
1036 | 777 static GCond *image_loader_prio_cond = NULL; |
778 static GMutex *image_loader_prio_mutex = NULL; | |
779 static gint image_loader_prio_num = 0; | |
780 | |
781 | |
1184 | 782 static void image_loader_thread_enter_high(void) |
1036 | 783 { |
784 g_mutex_lock(image_loader_prio_mutex); | |
785 image_loader_prio_num++; | |
786 g_mutex_unlock(image_loader_prio_mutex); | |
787 } | |
788 | |
1184 | 789 static void image_loader_thread_leave_high(void) |
1036 | 790 { |
791 g_mutex_lock(image_loader_prio_mutex); | |
792 image_loader_prio_num--; | |
1438
9141908e0609
fixed possible deadlock with multiple thumb loaders in parallel
nadvornik
parents:
1433
diff
changeset
|
793 if (image_loader_prio_num == 0) g_cond_broadcast(image_loader_prio_cond); /* wake up all low prio threads */ |
1036 | 794 g_mutex_unlock(image_loader_prio_mutex); |
795 } | |
796 | |
1184 | 797 static void image_loader_thread_wait_high(void) |
1036 | 798 { |
799 g_mutex_lock(image_loader_prio_mutex); | |
800 while (image_loader_prio_num) | |
801 { | |
802 g_cond_wait(image_loader_prio_cond, image_loader_prio_mutex); | |
803 } | |
804 | |
805 g_mutex_unlock(image_loader_prio_mutex); | |
806 } | |
807 | |
808 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
809 static void image_loader_thread_run(gpointer data, gpointer user_data) |
1015 | 810 { |
811 ImageLoader *il = data; | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
812 gboolean cont; |
1036 | 813 |
814 if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE) | |
815 { | |
816 /* low prio, wait untill high prio tasks finishes */ | |
817 image_loader_thread_wait_high(); | |
818 } | |
819 else | |
820 { | |
821 /* high prio */ | |
822 image_loader_thread_enter_high(); | |
823 } | |
824 | |
825 cont = image_loader_begin(il); | |
1015 | 826 |
1026 | 827 if (!cont && !image_loader_get_pixbuf(il)) |
828 { | |
829 /* | |
830 loader failed, we have to send signal | |
831 (idle mode returns the image_loader_begin return value directly) | |
832 (success is always reported indirectly from image_loader_begin) | |
833 */ | |
834 image_loader_emit_error(il); | |
835 } | |
836 | |
1020 | 837 while (cont && !image_loader_get_is_done(il) && !image_loader_get_stopping(il)) |
1015 | 838 { |
1036 | 839 if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE) |
840 { | |
841 /* low prio, wait untill high prio tasks finishes */ | |
842 image_loader_thread_wait_high(); | |
843 } | |
1015 | 844 cont = image_loader_continue(il); |
845 } | |
1020 | 846 image_loader_stop_loader(il); |
1021 | 847 |
1036 | 848 if (il->idle_priority <= G_PRIORITY_DEFAULT_IDLE) |
849 { | |
850 /* high prio */ | |
851 image_loader_thread_leave_high(); | |
852 } | |
853 | |
1021 | 854 g_mutex_lock(il->data_mutex); |
855 il->can_destroy = TRUE; | |
856 g_cond_signal(il->can_destroy_cond); | |
857 g_mutex_unlock(il->data_mutex); | |
858 | |
1015 | 859 } |
860 | |
1021 | 861 |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
862 static gboolean image_loader_start_thread(ImageLoader *il) |
1015 | 863 { |
864 if (!il) return FALSE; | |
865 | |
866 if (!il->fd) return FALSE; | |
867 | |
1021 | 868 il->thread = TRUE; |
869 | |
1015 | 870 if (!image_loader_setup_source(il)) return FALSE; |
871 | |
1021 | 872 if (!image_loader_thread_pool) |
873 { | |
874 image_loader_thread_pool = g_thread_pool_new(image_loader_thread_run, NULL, -1, FALSE, NULL); | |
1036 | 875 image_loader_prio_cond = g_cond_new(); |
876 image_loader_prio_mutex = g_mutex_new(); | |
1021 | 877 } |
878 | |
1026 | 879 il->can_destroy = FALSE; /* ImageLoader can't be freed until image_loader_thread_run finishes */ |
880 | |
1021 | 881 g_thread_pool_push(image_loader_thread_pool, il, NULL); |
882 DEBUG_1("Thread pool num threads: %d", g_thread_pool_get_num_threads(image_loader_thread_pool)); | |
1015 | 883 |
884 return TRUE; | |
885 } | |
886 | |
887 | |
888 /**************************************************************************************/ | |
1014 | 889 /* public interface */ |
890 | |
891 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
892 gboolean image_loader_start(ImageLoader *il) |
1014 | 893 { |
894 if (!il) return FALSE; | |
895 | |
896 if (!il->fd) return FALSE; | |
897 | |
1015 | 898 #ifdef HAVE_GTHREAD |
899 return image_loader_start_thread(il); | |
900 #else | |
1014 | 901 return image_loader_start_idle(il); |
1015 | 902 #endif |
9 | 903 } |
904 | |
905 | |
906 /* don't forget to gdk_pixbuf_ref() it if you want to use it after image_loader_free() */ | |
907 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il) | |
908 { | |
1015 | 909 GdkPixbuf *ret; |
9 | 910 if (!il) return NULL; |
1015 | 911 |
912 g_mutex_lock(il->data_mutex); | |
913 ret = il->pixbuf; | |
914 g_mutex_unlock(il->data_mutex); | |
915 return ret; | |
9 | 916 } |
917 | |
918 gchar *image_loader_get_format(ImageLoader *il) | |
919 { | |
920 GdkPixbufFormat *format; | |
921 gchar **mimev; | |
922 gchar *mime; | |
923 | |
924 if (!il || !il->loader) return NULL; | |
925 | |
926 format = gdk_pixbuf_loader_get_format(il->loader); | |
927 if (!format) return NULL; | |
928 | |
929 mimev = gdk_pixbuf_format_get_mime_types(format); | |
930 if (!mimev) return NULL; | |
931 | |
932 /* return first member of mimev, as GdkPixbufLoader has no way to tell us which exact one ? */ | |
933 mime = g_strdup(mimev[0]); | |
934 g_strfreev(mimev); | |
935 | |
936 return mime; | |
937 } | |
938 | |
939 void image_loader_set_requested_size(ImageLoader *il, gint width, gint height) | |
940 { | |
941 if (!il) return; | |
942 | |
1015 | 943 g_mutex_lock(il->data_mutex); |
9 | 944 il->requested_width = width; |
945 il->requested_height = height; | |
1015 | 946 g_mutex_unlock(il->data_mutex); |
9 | 947 } |
948 | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
949 void image_loader_set_buffer_size(ImageLoader *il, guint count) |
9 | 950 { |
951 if (!il) return; | |
952 | |
1015 | 953 g_mutex_lock(il->data_mutex); |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
954 il->idle_read_loop_count = count ? count : 1; |
1015 | 955 g_mutex_unlock(il->data_mutex); |
9 | 956 } |
957 | |
958 void image_loader_set_priority(ImageLoader *il, gint priority) | |
959 { | |
960 if (!il) return; | |
961 | |
1036 | 962 if (il->thread) return; /* can't change prio if the thread already runs */ |
9 | 963 il->idle_priority = priority; |
964 } | |
965 | |
966 | |
967 gdouble image_loader_get_percent(ImageLoader *il) | |
968 { | |
1015 | 969 gdouble ret; |
970 if (!il) return 0.0; | |
971 | |
972 g_mutex_lock(il->data_mutex); | |
973 if (il->bytes_total == 0) | |
974 { | |
975 ret = 0.0; | |
976 } | |
977 else | |
978 { | |
979 ret = (gdouble)il->bytes_read / il->bytes_total; | |
980 } | |
981 g_mutex_unlock(il->data_mutex); | |
982 return ret; | |
9 | 983 } |
984 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
985 gboolean image_loader_get_is_done(ImageLoader *il) |
9 | 986 { |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
987 gboolean ret; |
9 | 988 if (!il) return FALSE; |
989 | |
1015 | 990 g_mutex_lock(il->data_mutex); |
991 ret = il->done; | |
992 g_mutex_unlock(il->data_mutex); | |
993 | |
994 return ret; | |
9 | 995 } |
996 | |
1011 | 997 FileData *image_loader_get_fd(ImageLoader *il) |
998 { | |
1015 | 999 FileData *ret; |
1011 | 1000 if (!il) return NULL; |
1001 | |
1015 | 1002 g_mutex_lock(il->data_mutex); |
1003 ret = il->fd; | |
1004 g_mutex_unlock(il->data_mutex); | |
1005 | |
1006 return ret; | |
1011 | 1007 } |
1008 | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
1009 gboolean image_loader_get_shrunk(ImageLoader *il) |
1011 | 1010 { |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
1011 gboolean ret; |
1011 | 1012 if (!il) return FALSE; |
1013 | |
1015 | 1014 g_mutex_lock(il->data_mutex); |
1015 ret = il->shrunk; | |
1016 g_mutex_unlock(il->data_mutex); | |
1017 return ret; | |
1011 | 1018 } |
1019 | |
1497 | 1020 const gchar *image_loader_get_error(ImageLoader *il) |
1021 { | |
1022 const gchar *ret = NULL; | |
1023 if (!il) return NULL; | |
1024 g_mutex_lock(il->data_mutex); | |
1025 if (il->error) ret = il->error->message; | |
1026 g_mutex_unlock(il->data_mutex); | |
1027 return ret; | |
1028 } | |
1029 | |
1011 | 1030 |
1014 | 1031 /* FIXME - this can be rather slow and blocks until the size is known */ |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
1032 gboolean image_load_dimensions(FileData *fd, gint *width, gint *height) |
9 | 1033 { |
1034 ImageLoader *il; | |
1433
b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
zas_
parents:
1346
diff
changeset
|
1035 gboolean success; |
9 | 1036 |
138 | 1037 il = image_loader_new(fd); |
9 | 1038 |
1014 | 1039 success = image_loader_start_idle(il); |
9 | 1040 |
1041 if (success && il->pixbuf) | |
1042 { | |
1043 if (width) *width = gdk_pixbuf_get_width(il->pixbuf); | |
1044 if (height) *height = gdk_pixbuf_get_height(il->pixbuf);; | |
1045 } | |
1046 else | |
1047 { | |
1048 if (width) *width = -1; | |
1049 if (height) *height = -1; | |
1050 } | |
1051 | |
1052 image_loader_free(il); | |
1053 | |
1054 return success; | |
1055 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1045
diff
changeset
|
1056 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |