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