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