Mercurial > geeqie
annotate src/image-load.c @ 1014:4d3c98219246
prepared image loader code for threads
author | nadvornik |
---|---|
date | Sat, 30 Aug 2008 13:04:06 +0000 |
parents | fe82830ab8fd |
children | 2cdcf67e9300 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
281 | 14 #include "main.h" |
9 | 15 #include "image-load.h" |
507 | 16 |
17 #include "exif.h" | |
586 | 18 #include "filedata.h" |
9 | 19 #include "ui_fileops.h" |
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 /**************************************************************************************/ | |
27 /* image looader class */ | |
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 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
40 static void image_loader_init (GTypeInstance *instance, gpointer g_class); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
41 static void image_loader_class_init (ImageLoaderClass *class); |
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 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
45 GType image_loader_get_type (void) |
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 = { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
51 sizeof (ImageLoaderClass), |
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 */ |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
57 sizeof (ImageLoader), |
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 */ |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
60 }; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
61 type = g_type_register_static (G_TYPE_OBJECT, "ImageLoaderType", &info, 0); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
62 } |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
63 return type; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
64 } |
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 static void image_loader_init (GTypeInstance *instance, gpointer g_class) |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
67 { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
68 ImageLoader *il = (ImageLoader *)instance; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
69 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
70 il->pixbuf = NULL; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
71 il->idle_id = -1; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
72 il->idle_priority = G_PRIORITY_DEFAULT_IDLE; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
73 il->done = FALSE; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
74 il->loader = NULL; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
75 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
76 il->bytes_read = 0; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
77 il->bytes_total = 0; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
78 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
79 il->idle_done_id = -1; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
80 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
81 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
|
82 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
|
83 il->mapped_file = NULL; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
84 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
85 il->requested_width = 0; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
86 il->requested_height = 0; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
87 il->shrunk = FALSE; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
88 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
|
89 } |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
90 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
91 static void image_loader_class_init (ImageLoaderClass *class) |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
92 { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
93 GObjectClass *gobject_class = G_OBJECT_CLASS (class); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
94 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
95 // 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
|
96 // 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
|
97 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
98 gobject_class->finalize = image_loader_finalize; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
99 |
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 signals[SIGNAL_AREA_READY] = |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
102 g_signal_new("area_ready", |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
103 G_OBJECT_CLASS_TYPE(gobject_class), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
104 G_SIGNAL_RUN_LAST, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
105 G_STRUCT_OFFSET(ImageLoaderClass, area_ready), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
106 NULL, NULL, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
107 gq_marshal_VOID__INT_INT_INT_INT, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
108 G_TYPE_NONE, 4, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
109 G_TYPE_INT, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
110 G_TYPE_INT, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
111 G_TYPE_INT, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
112 G_TYPE_INT); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
113 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
114 signals[SIGNAL_ERROR] = |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
115 g_signal_new("error", |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
116 G_OBJECT_CLASS_TYPE(gobject_class), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
117 G_SIGNAL_RUN_LAST, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
118 G_STRUCT_OFFSET(ImageLoaderClass, error), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
119 NULL, NULL, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
120 g_cclosure_marshal_VOID__VOID, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
121 G_TYPE_NONE, 1, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
122 GDK_TYPE_EVENT); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
123 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
124 signals[SIGNAL_DONE] = |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
125 g_signal_new("done", |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
126 G_OBJECT_CLASS_TYPE(gobject_class), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
127 G_SIGNAL_RUN_LAST, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
128 G_STRUCT_OFFSET(ImageLoaderClass, done), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
129 NULL, NULL, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
130 g_cclosure_marshal_VOID__VOID, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
131 G_TYPE_NONE, 0); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
132 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
133 signals[SIGNAL_PERCENT] = |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
134 g_signal_new("percent", |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
135 G_OBJECT_CLASS_TYPE(gobject_class), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
136 G_SIGNAL_RUN_LAST, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
137 G_STRUCT_OFFSET(ImageLoaderClass, percent), |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
138 NULL, NULL, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
139 g_cclosure_marshal_VOID__DOUBLE, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
140 G_TYPE_NONE, 1, |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
141 G_TYPE_DOUBLE); |
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 } |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
144 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
145 static void image_loader_finalize(GObject *object) |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
146 { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
147 ImageLoader *il = (ImageLoader *)object; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
148 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
149 image_loader_stop(il); |
1014 | 150 |
151 DEBUG_1("freeing image loader %p bytes_read=%d", il, il->bytes_read); | |
152 | |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
153 if (il->idle_done_id != -1) g_source_remove(il->idle_done_id); |
1014 | 154 |
155 while (g_source_remove_by_user_data(il)) | |
156 { | |
157 DEBUG_1("pending signals detected"); | |
158 } | |
159 | |
160 while (il->area_param_list) | |
161 { | |
162 DEBUG_1("pending area_ready signals detected"); | |
163 while (g_source_remove_by_user_data(il->area_param_list->data)) {} | |
164 g_free(il->area_param_list->data); | |
165 il->area_param_list = g_list_delete_link(il->area_param_list, il->area_param_list); | |
166 } | |
167 | |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
168 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
169 file_data_unref(il->fd); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
170 } |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
171 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
172 void image_loader_free(ImageLoader *il) |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
173 { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
174 if (!il) return; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
175 g_object_unref(G_OBJECT(il)); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
176 } |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
177 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
178 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
179 ImageLoader *image_loader_new(FileData *fd) |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
180 { |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
181 ImageLoader *il; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
182 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
183 if (!fd) return NULL; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
184 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
185 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
|
186 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
187 il->fd = file_data_ref(fd); |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
188 |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
189 return il; |
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
190 } |
9 | 191 |
1014 | 192 /**************************************************************************************/ |
193 /* send signals via idle calbacks - the callback are executed in the main thread */ | |
194 | |
195 typedef struct _ImageLoaderAreaParam ImageLoaderAreaParam; | |
196 struct _ImageLoaderAreaParam { | |
197 ImageLoader *il; | |
198 guint x; | |
199 guint y; | |
200 guint w; | |
201 guint h; | |
202 }; | |
203 | |
204 | |
205 static gint image_loader_emit_area_ready_cb(gpointer data) | |
206 { | |
207 ImageLoaderAreaParam *par = data; | |
208 ImageLoader *il = par->il; | |
209 g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h); | |
210 il->area_param_list = g_list_remove(il->area_param_list, par); | |
211 g_free(par); | |
212 | |
213 return FALSE; | |
214 } | |
215 | |
216 static gint image_loader_emit_done_cb(gpointer data) | |
217 { | |
218 ImageLoader *il = data; | |
219 g_signal_emit(il, signals[SIGNAL_DONE], 0); | |
220 return FALSE; | |
221 } | |
222 | |
223 static gint image_loader_emit_error_cb(gpointer data) | |
224 { | |
225 ImageLoader *il = data; | |
226 g_signal_emit(il, signals[SIGNAL_ERROR], 0); | |
227 return FALSE; | |
228 } | |
229 | |
230 static gint image_loader_emit_percent_cb(gpointer data) | |
231 { | |
232 ImageLoader *il = data; | |
233 g_signal_emit(il, signals[SIGNAL_PERCENT], 0, (gdouble)il->bytes_read / il->bytes_total); | |
234 return FALSE; | |
235 } | |
236 | |
237 /* DONE and ERROR are emited only once, thus they can have normal priority | |
238 PERCENT and AREA_READY should be processed ASAP | |
239 */ | |
240 | |
241 static void image_loader_emit_done(ImageLoader *il) | |
242 { | |
243 g_idle_add_full(il->idle_priority, image_loader_emit_done_cb, il, NULL); | |
244 } | |
245 | |
246 static void image_loader_emit_error(ImageLoader *il) | |
247 { | |
248 g_idle_add_full(il->idle_priority, image_loader_emit_error_cb, il, NULL); | |
249 } | |
250 | |
251 static void image_loader_emit_percent(ImageLoader *il) | |
252 { | |
253 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_percent_cb, il, NULL); | |
254 } | |
255 | |
256 static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h) | |
257 { | |
258 ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1); | |
259 par->il = il; | |
260 par->x = x; | |
261 par->y = y; | |
262 par->w = w; | |
263 par->h = h; | |
264 | |
265 il->area_param_list = g_list_prepend(il->area_param_list, par); | |
266 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL); | |
267 } | |
268 | |
269 /**************************************************************************************/ | |
270 /* the following functions may be executed in separate thread */ | |
271 | |
9 | 272 static void image_loader_sync_pixbuf(ImageLoader *il) |
273 { | |
274 GdkPixbuf *pb; | |
275 | |
276 if (!il->loader) return; | |
277 | |
278 pb = gdk_pixbuf_loader_get_pixbuf(il->loader); | |
279 | |
280 if (pb == il->pixbuf) return; | |
281 | |
282 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf); | |
283 il->pixbuf = pb; | |
284 if (il->pixbuf) gdk_pixbuf_ref(il->pixbuf); | |
285 } | |
286 | |
500 | 287 static void image_loader_area_updated_cb(GdkPixbufLoader *loader, |
9 | 288 guint x, guint y, guint w, guint h, |
289 gpointer data) | |
290 { | |
291 ImageLoader *il = data; | |
292 | |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
293 if (!il->pixbuf) |
9 | 294 { |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
295 image_loader_sync_pixbuf(il); |
9 | 296 if (!il->pixbuf) |
297 { | |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
298 log_printf("critical: area_ready signal with NULL pixbuf (out of mem?)\n"); |
9 | 299 } |
300 } | |
1014 | 301 image_loader_emit_area_ready(il, x, y, w, h); |
9 | 302 } |
303 | |
500 | 304 static void image_loader_area_prepared_cb(GdkPixbufLoader *loader, gpointer data) |
305 { | |
306 GdkPixbuf *pb; | |
307 guchar *pix; | |
308 size_t h, rs; | |
961
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
309 |
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
310 /* 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
|
311 gchar *format = gdk_pixbuf_format_get_name(gdk_pixbuf_loader_get_format(loader)); |
995 | 312 if (strcmp(format, "svg") == 0) |
961
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
313 { |
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
314 g_free(format); |
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
315 return; |
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
316 } |
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
317 |
3f03282ec40e
a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents:
890
diff
changeset
|
318 g_free(format); |
500 | 319 |
320 pb = gdk_pixbuf_loader_get_pixbuf(loader); | |
321 | |
322 h = gdk_pixbuf_get_height(pb); | |
323 rs = gdk_pixbuf_get_rowstride(pb); | |
324 pix = gdk_pixbuf_get_pixels(pb); | |
325 | |
326 memset(pix, 0, rs * h); /*this should be faster than pixbuf_fill */ | |
327 | |
328 } | |
329 | |
9 | 330 static void image_loader_size_cb(GdkPixbufLoader *loader, |
331 gint width, gint height, gpointer data) | |
332 { | |
333 ImageLoader *il = data; | |
334 GdkPixbufFormat *format; | |
335 gchar **mime_types; | |
336 gint scale = FALSE; | |
337 gint n; | |
338 | |
339 if (il->requested_width < 1 || il->requested_height < 1) return; | |
340 | |
341 format = gdk_pixbuf_loader_get_format(loader); | |
342 if (!format) return; | |
343 | |
344 mime_types = gdk_pixbuf_format_get_mime_types(format); | |
345 n = 0; | |
346 while (mime_types[n]) | |
347 { | |
348 if (strstr(mime_types[n], "jpeg")) scale = TRUE; | |
349 n++; | |
350 } | |
351 g_strfreev(mime_types); | |
442 | 352 |
9 | 353 if (!scale) return; |
354 | |
355 if (width > il->requested_width || height > il->requested_height) | |
356 { | |
357 gint nw, nh; | |
358 | |
359 if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height)) | |
360 { | |
361 nw = il->requested_width; | |
362 nh = (gdouble)nw / width * height; | |
363 if (nh < 1) nh = 1; | |
364 } | |
365 else | |
366 { | |
367 nh = il->requested_height; | |
368 nw = (gdouble)nh / height * width; | |
369 if (nw < 1) nw = 1; | |
370 } | |
442 | 371 |
9 | 372 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
|
373 il->shrunk = TRUE; |
9 | 374 } |
375 } | |
376 | |
1014 | 377 static void image_loader_stop_loader(ImageLoader *il) |
9 | 378 { |
379 if (!il) return; | |
380 | |
381 if (il->loader) | |
382 { | |
383 /* some loaders do not have a pixbuf till close, order is important here */ | |
384 gdk_pixbuf_loader_close(il->loader, NULL); | |
385 image_loader_sync_pixbuf(il); | |
386 g_object_unref(G_OBJECT(il->loader)); | |
387 il->loader = NULL; | |
388 } | |
389 | |
390 il->done = TRUE; | |
391 } | |
392 | |
1014 | 393 static void image_loader_setup_loader(ImageLoader *il) |
394 { | |
395 il->loader = gdk_pixbuf_loader_new(); | |
396 g_signal_connect(G_OBJECT(il->loader), "area_updated", | |
397 G_CALLBACK(image_loader_area_updated_cb), il); | |
398 g_signal_connect(G_OBJECT(il->loader), "size_prepared", | |
399 G_CALLBACK(image_loader_size_cb), il); | |
400 g_signal_connect(G_OBJECT(il->loader), "area_prepared", | |
401 G_CALLBACK(image_loader_area_prepared_cb), il); | |
402 } | |
403 | |
404 | |
9 | 405 static void image_loader_done(ImageLoader *il) |
406 { | |
1014 | 407 image_loader_stop_loader(il); |
9 | 408 |
1014 | 409 image_loader_emit_done(il); |
9 | 410 } |
411 | |
412 static void image_loader_error(ImageLoader *il) | |
413 { | |
1014 | 414 image_loader_stop_loader(il); |
9 | 415 |
1009
dd311dae857a
fixed thumbnail loader for the new raw preview interface
nadvornik
parents:
1008
diff
changeset
|
416 DEBUG_1("pixbuf_loader reported load error for: %s", il->fd->path); |
9 | 417 |
1014 | 418 image_loader_emit_error(il); |
9 | 419 } |
420 | |
1014 | 421 static gint image_loader_continue(ImageLoader *il) |
9 | 422 { |
423 gint b; | |
424 gint c; | |
425 | |
426 if (!il) return FALSE; | |
427 | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
428 c = il->idle_read_loop_count ? il->idle_read_loop_count : 1; |
9 | 429 while (c > 0) |
430 { | |
1008 | 431 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read); |
9 | 432 |
433 if (b == 0) | |
434 { | |
435 image_loader_done(il); | |
436 return FALSE; | |
437 } | |
438 | |
1008 | 439 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL))) |
9 | 440 { |
441 image_loader_error(il); | |
442 return FALSE; | |
443 } | |
444 | |
445 il->bytes_read += b; | |
446 | |
447 c--; | |
448 } | |
449 | |
1012
fe82830ab8fd
converted image loader to a GObject and use signals for notification
nadvornik
parents:
1011
diff
changeset
|
450 if (il->bytes_total > 0) |
9 | 451 { |
1014 | 452 image_loader_emit_percent(il); |
9 | 453 } |
454 | |
455 return TRUE; | |
456 } | |
457 | |
458 static gint image_loader_begin(ImageLoader *il) | |
459 { | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
460 gint b; |
1014 | 461 |
462 if (il->pixbuf) return FALSE; | |
442 | 463 |
1008 | 464 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read); |
1014 | 465 if (b < 1) return FALSE; |
45
7cfa60beda76
Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents:
43
diff
changeset
|
466 |
1014 | 467 image_loader_setup_loader(il); |
9 | 468 |
1008 | 469 if (!gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL)) |
9 | 470 { |
1014 | 471 image_loader_stop_loader(il); |
9 | 472 return FALSE; |
473 } | |
474 | |
1008 | 475 il->bytes_read += b; |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
476 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
477 /* read until size is known */ |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
478 while (il->loader && !gdk_pixbuf_loader_get_pixbuf(il->loader) && b > 0) |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
479 { |
1008 | 480 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read); |
481 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL))) | |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
482 { |
1014 | 483 image_loader_stop_loader(il); |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
484 return FALSE; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
485 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
486 il->bytes_read += b; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
487 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
488 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
|
489 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
490 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
|
491 { |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
492 /* done, handle (broken) loaders that do not have pixbuf till close */ |
1014 | 493 image_loader_stop_loader(il); |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
494 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
495 if (!il->pixbuf) return FALSE; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
496 |
1014 | 497 image_loader_done(il); |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
498 return TRUE; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
499 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
500 |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
501 if (!il->pixbuf) |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
502 { |
1014 | 503 image_loader_stop_loader(il); |
60
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
504 return FALSE; |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
505 } |
9c0c402b0ef3
Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents:
54
diff
changeset
|
506 |
9 | 507 return TRUE; |
508 } | |
509 | |
1014 | 510 /**************************************************************************************/ |
511 /* the following functions are always executed in the main thread */ | |
512 | |
513 | |
514 static gint image_loader_setup_source(ImageLoader *il) | |
9 | 515 { |
516 struct stat st; | |
517 gchar *pathl; | |
518 | |
1008 | 519 if (!il || il->loader || il->mapped_file) return FALSE; |
520 | |
521 il->mapped_file = NULL; | |
522 | |
523 if (il->fd) | |
524 { | |
525 ExifData *exif = exif_read_fd(il->fd); | |
526 | |
527 il->mapped_file = exif_get_preview(exif, &il->bytes_total); | |
528 | |
529 if (il->mapped_file) | |
530 { | |
531 il->preview = TRUE; | |
1009
dd311dae857a
fixed thumbnail loader for the new raw preview interface
nadvornik
parents:
1008
diff
changeset
|
532 DEBUG_1("Raw file %s contains embedded image", il->fd->path); |
1008 | 533 } |
534 exif_free_fd(il->fd, exif); | |
535 } | |
9 | 536 |
1008 | 537 |
538 if (!il->mapped_file) | |
539 { | |
540 /* normal file */ | |
541 gint load_fd; | |
542 | |
1009
dd311dae857a
fixed thumbnail loader for the new raw preview interface
nadvornik
parents:
1008
diff
changeset
|
543 pathl = path_from_utf8(il->fd->path); |
1008 | 544 load_fd = open(pathl, O_RDONLY | O_NONBLOCK); |
545 g_free(pathl); | |
546 if (load_fd == -1) return FALSE; | |
9 | 547 |
1008 | 548 if (fstat(load_fd, &st) == 0) |
549 { | |
550 il->bytes_total = st.st_size; | |
551 } | |
552 else | |
553 { | |
554 close(load_fd); | |
555 return FALSE; | |
556 } | |
557 | |
558 il->mapped_file = mmap(0, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0); | |
559 close(load_fd); | |
560 if (il->mapped_file == MAP_FAILED) | |
561 { | |
562 il->mapped_file = 0; | |
563 return FALSE; | |
564 } | |
565 il->preview = FALSE; | |
9 | 566 } |
1014 | 567 |
568 return TRUE; | |
569 } | |
570 | |
571 static void image_loader_stop_source(ImageLoader *il) | |
572 { | |
573 if (!il) return; | |
574 | |
575 if (il->mapped_file) | |
576 { | |
577 if (il->preview) | |
578 { | |
579 exif_free_preview(il->mapped_file); | |
580 } | |
581 else | |
582 { | |
583 munmap(il->mapped_file, il->bytes_total); | |
584 } | |
585 il->mapped_file = NULL; | |
586 } | |
587 } | |
9 | 588 |
1008 | 589 |
1014 | 590 /* |
591 static gint image_loader_setup(ImageLoader *il) | |
592 { | |
593 if (!image_loader_setup_source(il)) return FALSE; | |
594 | |
595 return image_loader_begin(il); | |
596 } | |
597 */ | |
598 | |
599 static void image_loader_stop(ImageLoader *il) | |
600 { | |
601 if (!il) return; | |
602 | |
603 if (il->idle_id != -1) | |
604 { | |
605 g_source_remove(il->idle_id); | |
606 il->idle_id = -1; | |
607 } | |
608 | |
609 | |
610 image_loader_stop_loader(il); | |
611 image_loader_stop_source(il); | |
612 | |
613 } | |
614 | |
615 /**************************************************************************************/ | |
616 /* execution via idle calls */ | |
9 | 617 |
1014 | 618 static gint image_loader_idle_cb(gpointer data) |
619 { | |
620 gint ret = FALSE; | |
621 ImageLoader *il = data; | |
622 if (il->idle_id != -1) | |
623 { | |
624 ret = image_loader_continue(il); | |
625 } | |
626 if (!ret) | |
627 { | |
628 image_loader_stop_source(il); | |
629 } | |
630 return ret; | |
631 } | |
632 | |
633 | |
634 gint image_loader_start_idle(ImageLoader *il) | |
635 { | |
636 gint ret; | |
637 if (!il) return FALSE; | |
14
25335c62cd9b
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
638 |
1014 | 639 if (!il->fd) return FALSE; |
640 | |
641 if (!image_loader_setup_source(il)) return FALSE; | |
642 | |
643 ret = image_loader_begin(il); | |
644 | |
645 if (ret && !il->done) il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, NULL); | |
646 return ret; | |
647 } | |
648 | |
649 /**************************************************************************************/ | |
650 /* public interface */ | |
651 | |
652 | |
653 gint image_loader_start(ImageLoader *il) | |
654 { | |
655 if (!il) return FALSE; | |
656 | |
657 if (!il->fd) return FALSE; | |
658 | |
659 return image_loader_start_idle(il); | |
9 | 660 } |
661 | |
662 | |
663 /* don't forget to gdk_pixbuf_ref() it if you want to use it after image_loader_free() */ | |
664 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il) | |
665 { | |
666 if (!il) return NULL; | |
667 | |
668 return il->pixbuf; | |
669 } | |
670 | |
671 gchar *image_loader_get_format(ImageLoader *il) | |
672 { | |
673 GdkPixbufFormat *format; | |
674 gchar **mimev; | |
675 gchar *mime; | |
676 | |
677 if (!il || !il->loader) return NULL; | |
678 | |
679 format = gdk_pixbuf_loader_get_format(il->loader); | |
680 if (!format) return NULL; | |
681 | |
682 mimev = gdk_pixbuf_format_get_mime_types(format); | |
683 if (!mimev) return NULL; | |
684 | |
685 /* return first member of mimev, as GdkPixbufLoader has no way to tell us which exact one ? */ | |
686 mime = g_strdup(mimev[0]); | |
687 g_strfreev(mimev); | |
688 | |
689 return mime; | |
690 } | |
691 | |
692 void image_loader_set_requested_size(ImageLoader *il, gint width, gint height) | |
693 { | |
694 if (!il) return; | |
695 | |
696 il->requested_width = width; | |
697 il->requested_height = height; | |
698 } | |
699 | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
700 void image_loader_set_buffer_size(ImageLoader *il, guint count) |
9 | 701 { |
702 if (!il) return; | |
703 | |
413
9e521adbf312
Add two new options to control image read buffer at runtime.
zas_
parents:
281
diff
changeset
|
704 il->idle_read_loop_count = count ? count : 1; |
9 | 705 } |
706 | |
707 void image_loader_set_priority(ImageLoader *il, gint priority) | |
708 { | |
709 if (!il) return; | |
710 | |
711 il->idle_priority = priority; | |
712 } | |
713 | |
714 | |
715 gdouble image_loader_get_percent(ImageLoader *il) | |
716 { | |
717 if (!il || il->bytes_total == 0) return 0.0; | |
718 | |
719 return (gdouble)il->bytes_read / il->bytes_total; | |
720 } | |
721 | |
722 gint image_loader_get_is_done(ImageLoader *il) | |
723 { | |
724 if (!il) return FALSE; | |
725 | |
726 return il->done; | |
727 } | |
728 | |
1011 | 729 FileData *image_loader_get_fd(ImageLoader *il) |
730 { | |
731 if (!il) return NULL; | |
732 | |
733 return il->fd; | |
734 | |
735 } | |
736 | |
737 gint image_loader_get_shrunk(ImageLoader *il) | |
738 { | |
739 if (!il) return FALSE; | |
740 | |
741 return il->shrunk; | |
742 | |
743 } | |
744 | |
745 | |
1014 | 746 /* FIXME - this can be rather slow and blocks until the size is known */ |
138 | 747 gint image_load_dimensions(FileData *fd, gint *width, gint *height) |
9 | 748 { |
749 ImageLoader *il; | |
750 gint success; | |
751 | |
138 | 752 il = image_loader_new(fd); |
9 | 753 |
1014 | 754 success = image_loader_start_idle(il); |
9 | 755 |
756 if (success && il->pixbuf) | |
757 { | |
758 if (width) *width = gdk_pixbuf_get_width(il->pixbuf); | |
759 if (height) *height = gdk_pixbuf_get_height(il->pixbuf);; | |
760 } | |
761 else | |
762 { | |
763 if (width) *width = -1; | |
764 if (height) *height = -1; | |
765 } | |
766 | |
767 image_loader_free(il); | |
768 | |
769 return success; | |
770 } |