annotate src/image-load.c @ 1020:2bd19478ba29

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