annotate src/image-load.c @ 1580:2002c865f120

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