annotate src/image-load.c @ 1012:fe82830ab8fd

converted image loader to a GObject and use signals for notification
author nadvornik
date Fri, 29 Aug 2008 20:53:53 +0000
parents 616b14da08c2
children 4d3c98219246
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
196
f6e307c7bad6 rename GQview -> Geeqie over the code
nadvornik
parents: 176
diff changeset
2 * Geeqie
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
3 * (C) 2004 John Ellis
475
48c8e49b571c updated copyright in source files
nadvornik
parents: 446
diff changeset
4 * Copyright (C) 2008 The Geeqie Team
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 196
diff changeset
14 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15 #include "image-load.h"
507
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents: 506
diff changeset
16
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents: 506
diff changeset
17 #include "exif.h"
586
905688aa2317 split filelist.c to filefilter.c and filedata.c
nadvornik
parents: 507
diff changeset
18 #include "filedata.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include "ui_fileops.h"
1012
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
20 #include "gq-marshal.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22 #include <fcntl.h>
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
23 #include <sys/mman.h>
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24
1012
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
25 enum {
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
26 SIGNAL_AREA_READY = 0,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
27 SIGNAL_ERROR,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
28 SIGNAL_DONE,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
29 SIGNAL_PERCENT,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
30 SIGNAL_COUNT
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
31 };
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
32
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
33 static guint signals[SIGNAL_COUNT] = { 0 };
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
34
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
35 static void image_loader_init (GTypeInstance *instance, gpointer g_class);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
36 static void image_loader_class_init (ImageLoaderClass *class);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
37 static void image_loader_finalize(GObject *object);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
38 static void image_loader_stop(ImageLoader *il);
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 GType image_loader_get_type (void)
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
41 {
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
42 static GType type = 0;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
43 if (type == 0)
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
44 {
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
45 static const GTypeInfo info = {
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
46 sizeof (ImageLoaderClass),
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
47 NULL, /* base_init */
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
48 NULL, /* base_finalize */
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
49 (GClassInitFunc)image_loader_class_init, /* class_init */
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
50 NULL, /* class_finalize */
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
51 NULL, /* class_data */
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
52 sizeof (ImageLoader),
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
53 0, /* n_preallocs */
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
54 (GInstanceInitFunc)image_loader_init, /* instance_init */
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
55 };
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
56 type = g_type_register_static (G_TYPE_OBJECT, "ImageLoaderType", &info, 0);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
57 }
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
58 return type;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
59 }
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
60
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
61 static void image_loader_init (GTypeInstance *instance, gpointer g_class)
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
62 {
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
63 ImageLoader *il = (ImageLoader *)instance;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
64
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
65 il->pixbuf = NULL;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
66 il->idle_id = -1;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
67 il->idle_priority = G_PRIORITY_DEFAULT_IDLE;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
68 il->done = FALSE;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
69 il->loader = NULL;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
70
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
71 il->bytes_read = 0;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
72 il->bytes_total = 0;
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->idle_done_id = -1;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
75
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
76 il->idle_read_loop_count = options->image.idle_read_loop_count;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
77 il->read_buffer_size = options->image.read_buffer_size;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
78 il->mapped_file = 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->requested_width = 0;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
81 il->requested_height = 0;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
82 il->shrunk = FALSE;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
83 DEBUG_1("new image loader %p, bufsize=%u idle_loop=%u", il, il->read_buffer_size, il->idle_read_loop_count);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
84 }
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
85
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
86 static void image_loader_class_init (ImageLoaderClass *class)
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
87 {
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
88 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
89
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
90 // 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
91 // 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
92
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
93 gobject_class->finalize = image_loader_finalize;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
94
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
95
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
96 signals[SIGNAL_AREA_READY] =
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
97 g_signal_new("area_ready",
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
98 G_OBJECT_CLASS_TYPE(gobject_class),
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
99 G_SIGNAL_RUN_LAST,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
100 G_STRUCT_OFFSET(ImageLoaderClass, area_ready),
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
101 NULL, NULL,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
102 gq_marshal_VOID__INT_INT_INT_INT,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
103 G_TYPE_NONE, 4,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
104 G_TYPE_INT,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
105 G_TYPE_INT,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
106 G_TYPE_INT,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
107 G_TYPE_INT);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
108
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
109 signals[SIGNAL_ERROR] =
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
110 g_signal_new("error",
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
111 G_OBJECT_CLASS_TYPE(gobject_class),
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
112 G_SIGNAL_RUN_LAST,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
113 G_STRUCT_OFFSET(ImageLoaderClass, error),
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
114 NULL, NULL,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
115 g_cclosure_marshal_VOID__VOID,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
116 G_TYPE_NONE, 1,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
117 GDK_TYPE_EVENT);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
118
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
119 signals[SIGNAL_DONE] =
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
120 g_signal_new("done",
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
121 G_OBJECT_CLASS_TYPE(gobject_class),
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
122 G_SIGNAL_RUN_LAST,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
123 G_STRUCT_OFFSET(ImageLoaderClass, done),
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
124 NULL, NULL,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
125 g_cclosure_marshal_VOID__VOID,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
126 G_TYPE_NONE, 0);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
127
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
128 signals[SIGNAL_PERCENT] =
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
129 g_signal_new("percent",
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
130 G_OBJECT_CLASS_TYPE(gobject_class),
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
131 G_SIGNAL_RUN_LAST,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
132 G_STRUCT_OFFSET(ImageLoaderClass, percent),
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
133 NULL, NULL,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
134 g_cclosure_marshal_VOID__DOUBLE,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
135 G_TYPE_NONE, 1,
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
136 G_TYPE_DOUBLE);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
137
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
138 }
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
139
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
140 static void image_loader_finalize(GObject *object)
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
141 {
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
142 ImageLoader *il = (ImageLoader *)object;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
143
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
144 image_loader_stop(il);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
145 if (il->idle_done_id != -1) g_source_remove(il->idle_done_id);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
146 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
147 file_data_unref(il->fd);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
148 DEBUG_1("freeing image loader %p bytes_read=%d", il, il->bytes_read);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
149 }
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
150
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
151 void image_loader_free(ImageLoader *il)
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 if (!il) return;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
154 g_object_unref(G_OBJECT(il));
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
155 }
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
156
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
157
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
158 ImageLoader *image_loader_new(FileData *fd)
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
159 {
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
160 ImageLoader *il;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
161
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
162 if (!fd) return NULL;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
163
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
164 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
165
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
166 il->fd = file_data_ref(fd);
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
167
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
168 return il;
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
169 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171 static void image_loader_sync_pixbuf(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173 GdkPixbuf *pb;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 if (!il->loader) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177 pb = gdk_pixbuf_loader_get_pixbuf(il->loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179 if (pb == il->pixbuf) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 il->pixbuf = pb;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 if (il->pixbuf) gdk_pixbuf_ref(il->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
186 static void image_loader_area_updated_cb(GdkPixbufLoader *loader,
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 guint x, guint y, guint w, guint h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188 gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191
1012
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
192 if (!il->pixbuf)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 {
1012
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
194 image_loader_sync_pixbuf(il);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 if (!il->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 {
1012
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
197 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
198 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 }
1012
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
200 g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, x, y, w, h);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
203 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
204 {
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
205 GdkPixbuf *pb;
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
206 guchar *pix;
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
207 size_t h, rs;
961
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
208
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
209 /* 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
210 gchar *format = gdk_pixbuf_format_get_name(gdk_pixbuf_loader_get_format(loader));
995
6ca2c5fd7b13 Whitespaces cleanup.
zas_
parents: 961
diff changeset
211 if (strcmp(format, "svg") == 0)
961
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
212 {
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
213 g_free(format);
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
214 return;
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
215 }
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
216
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
217 g_free(format);
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
218
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
219 pb = gdk_pixbuf_loader_get_pixbuf(loader);
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
220
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
221 h = gdk_pixbuf_get_height(pb);
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
222 rs = gdk_pixbuf_get_rowstride(pb);
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
223 pix = gdk_pixbuf_get_pixels(pb);
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
224
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
225 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
226
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
227 }
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
228
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 static void image_loader_size_cb(GdkPixbufLoader *loader,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 gint width, gint height, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 GdkPixbufFormat *format;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 gchar **mime_types;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 gint scale = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 gint n;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 if (il->requested_width < 1 || il->requested_height < 1) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 format = gdk_pixbuf_loader_get_format(loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241 if (!format) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243 mime_types = gdk_pixbuf_format_get_mime_types(format);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244 n = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245 while (mime_types[n])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 if (strstr(mime_types[n], "jpeg")) scale = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248 n++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250 g_strfreev(mime_types);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
251
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252 if (!scale) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 if (width > il->requested_width || height > il->requested_height)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256 gint nw, nh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
260 nw = il->requested_width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
261 nh = (gdouble)nw / width * height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262 if (nh < 1) nh = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
266 nh = il->requested_height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
267 nw = (gdouble)nh / height * width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
268 if (nw < 1) nw = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
269 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
270
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
271 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
272 il->shrunk = TRUE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
273 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
274 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
275
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276 static void image_loader_stop(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
279
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280 if (il->idle_id != -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
281 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
282 g_source_remove(il->idle_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
283 il->idle_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
286 if (il->loader)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288 /* some loaders do not have a pixbuf till close, order is important here */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289 gdk_pixbuf_loader_close(il->loader, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290 image_loader_sync_pixbuf(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 g_object_unref(G_OBJECT(il->loader));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292 il->loader = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
295 if (il->mapped_file)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296 {
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
297 if (il->preview)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
298 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
299 exif_free_preview(il->mapped_file);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
300 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
301 else
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
302 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
303 munmap(il->mapped_file, il->bytes_total);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
304 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
305 il->mapped_file = NULL;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 il->done = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 static void image_loader_done(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314
1012
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
315 g_signal_emit(il, signals[SIGNAL_DONE], 0);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 static gint image_loader_done_delay_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322 il->idle_done_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 image_loader_done(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 static void image_loader_done_delay(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329 if (il->idle_done_id == -1) il->idle_done_id = g_idle_add_full(il->idle_priority,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 image_loader_done_delay_cb, il, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 static void image_loader_error(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 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336
1009
dd311dae857a fixed thumbnail loader for the new raw preview interface
nadvornik
parents: 1008
diff changeset
337 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
338
1012
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
339 g_signal_emit(il, signals[SIGNAL_ERROR], 0);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 static gint image_loader_idle_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345 gint b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 gint c;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348 if (!il) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 if (il->idle_id == -1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
352 c = il->idle_read_loop_count ? il->idle_read_loop_count : 1;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 while (c > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354 {
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
355 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
356
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357 if (b == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 image_loader_done(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
361 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
363 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL)))
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
365 image_loader_error(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
367 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369 il->bytes_read += b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 c--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373
1012
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
374 if (il->bytes_total > 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 {
1012
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
376 g_signal_emit(il, signals[SIGNAL_PERCENT], 0, (gdouble)il->bytes_read / il->bytes_total);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 static gint image_loader_begin(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383 {
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 995
diff changeset
384 gint b;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 if (!il->loader || il->pixbuf) return FALSE;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
387
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
388 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
389
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390 if (b < 1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
396 if (!gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL))
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
402 il->bytes_read += b;
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
403
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
404 /* read until size is known */
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
405 while (il->loader && !gdk_pixbuf_loader_get_pixbuf(il->loader) && b > 0)
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
406 {
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
407 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
408 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL)))
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
409 {
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
410 image_loader_stop(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
411 return FALSE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
412 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
413 il->bytes_read += b;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
414 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
415 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
416
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
417 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
418 {
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
419 /* done, handle (broken) loaders that do not have pixbuf till close */
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
420 image_loader_stop(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
421
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
422 if (!il->pixbuf) return FALSE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
423
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
424 image_loader_done_delay(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
425 return TRUE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
426 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
427
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
428 if (!il->pixbuf)
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
429 {
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
430 image_loader_stop(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
431 return FALSE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
432 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
433
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
434 /* finally, progressive loading :) */
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
435 il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, NULL);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
436
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440 static gint image_loader_setup(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
445 if (!il || il->loader || il->mapped_file) return FALSE;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
446
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
447 il->mapped_file = NULL;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
448
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
449 if (il->fd)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
450 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
451 ExifData *exif = exif_read_fd(il->fd);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
452
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
453 il->mapped_file = exif_get_preview(exif, &il->bytes_total);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
454
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
455 if (il->mapped_file)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
456 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
457 il->preview = TRUE;
1009
dd311dae857a fixed thumbnail loader for the new raw preview interface
nadvornik
parents: 1008
diff changeset
458 DEBUG_1("Raw file %s contains embedded image", il->fd->path);
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
459 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
460 exif_free_fd(il->fd, exif);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
461 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
463
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
464 if (!il->mapped_file)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
465 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
466 /* normal file */
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
467 gint load_fd;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
468
1009
dd311dae857a fixed thumbnail loader for the new raw preview interface
nadvornik
parents: 1008
diff changeset
469 pathl = path_from_utf8(il->fd->path);
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
470 load_fd = open(pathl, O_RDONLY | O_NONBLOCK);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
471 g_free(pathl);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
472 if (load_fd == -1) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
474 if (fstat(load_fd, &st) == 0)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
475 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
476 il->bytes_total = st.st_size;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
477 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
478 else
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
479 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
480 close(load_fd);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
481 return FALSE;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
482 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
483
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
484 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
485 close(load_fd);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
486 if (il->mapped_file == MAP_FAILED)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
487 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
488 il->mapped_file = 0;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
489 return FALSE;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
490 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
491 il->preview = FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
494
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495 il->loader = gdk_pixbuf_loader_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 g_signal_connect(G_OBJECT(il->loader), "area_updated",
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
497 G_CALLBACK(image_loader_area_updated_cb), il);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498 g_signal_connect(G_OBJECT(il->loader), "size_prepared",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 G_CALLBACK(image_loader_size_cb), il);
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
500 g_signal_connect(G_OBJECT(il->loader), "area_prepared",
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
501 G_CALLBACK(image_loader_area_prepared_cb), il);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
502
14
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
503 il->shrunk = FALSE;
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
504
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505 return image_loader_begin(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 /* 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
510 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512 if (!il) return NULL;
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 return il->pixbuf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515 }
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 gchar *image_loader_get_format(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519 GdkPixbufFormat *format;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520 gchar **mimev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521 gchar *mime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523 if (!il || !il->loader) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 format = gdk_pixbuf_loader_get_format(il->loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526 if (!format) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
527
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528 mimev = gdk_pixbuf_format_get_mime_types(format);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 if (!mimev) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 /* 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
532 mime = g_strdup(mimev[0]);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533 g_strfreev(mimev);
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 return mime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536 }
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 void image_loader_set_requested_size(ImageLoader *il, gint width, gint height)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542 il->requested_width = width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 il->requested_height = height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
545
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
546 void image_loader_set_buffer_size(ImageLoader *il, guint count)
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 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
549
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
550 il->idle_read_loop_count = count ? count : 1;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 void image_loader_set_priority(ImageLoader *il, gint priority)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
557 il->idle_priority = priority;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559
1012
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
560 gint image_loader_start(ImageLoader *il)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562 if (!il) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563
1009
dd311dae857a fixed thumbnail loader for the new raw preview interface
nadvornik
parents: 1008
diff changeset
564 if (!il->fd) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
565
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566 return image_loader_setup(il);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
569 gdouble image_loader_get_percent(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
570 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 if (!il || il->bytes_total == 0) return 0.0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
573 return (gdouble)il->bytes_read / il->bytes_total;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 gint image_loader_get_is_done(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
578 if (!il) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580 return il->done;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
581 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
582
1011
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
583 FileData *image_loader_get_fd(ImageLoader *il)
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
584 {
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
585 if (!il) return NULL;
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
586
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
587 return il->fd;
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
588
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
589 }
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
590
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
591 gint image_loader_get_shrunk(ImageLoader *il)
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
592 {
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
593 if (!il) return FALSE;
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
594
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
595 return il->shrunk;
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
596
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
597 }
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
598
616b14da08c2 do not access image_loader directly
nadvornik
parents: 1009
diff changeset
599
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
600 gint image_load_dimensions(FileData *fd, gint *width, gint *height)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602 ImageLoader *il;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
603 gint success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
604
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
605 il = image_loader_new(fd);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
606
1012
fe82830ab8fd converted image loader to a GObject and use signals for notification
nadvornik
parents: 1011
diff changeset
607 success = image_loader_start(il);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
608
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
609 if (success && il->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
611 if (width) *width = gdk_pixbuf_get_width(il->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
612 if (height) *height = gdk_pixbuf_get_height(il->pixbuf);;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
614 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
615 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
616 if (width) *width = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
617 if (height) *height = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
619
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620 image_loader_free(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622 return success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623 }