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