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