annotate src/image-load.c @ 1008:68b0cb6ca8f0

use mmaped files image loader implemented new interface for extracting raw previews experiments with previews support in SVN version of Exiv2
author nadvornik
date Thu, 28 Aug 2008 22:26:09 +0000
parents 4fe8f9656107
children dd311dae857a
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"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21 #include <fcntl.h>
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
22 #include <sys/mman.h>
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
25 static const gchar *image_loader_path(ImageLoader *il)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
26 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
27 if (il->fd)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
28 return il->fd->path;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
29 return il->path;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
30 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
31
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32 static void image_loader_sync_pixbuf(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34 GdkPixbuf *pb;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36 if (!il->loader) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38 pb = gdk_pixbuf_loader_get_pixbuf(il->loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40 if (pb == il->pixbuf) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 il->pixbuf = pb;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44 if (il->pixbuf) gdk_pixbuf_ref(il->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
47 static void image_loader_area_updated_cb(GdkPixbufLoader *loader,
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 guint x, guint y, guint w, guint h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 if (il->func_area_ready)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55 if (!il->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57 image_loader_sync_pixbuf(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 if (!il->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 {
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
60 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
61 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63 il->func_area_ready(il, x, y, w, h, il->data_area_ready);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
67 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
68 {
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
69 GdkPixbuf *pb;
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
70 guchar *pix;
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
71 size_t h, rs;
961
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
72
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
73 /* 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
74 gchar *format = gdk_pixbuf_format_get_name(gdk_pixbuf_loader_get_format(loader));
995
6ca2c5fd7b13 Whitespaces cleanup.
zas_
parents: 961
diff changeset
75 if (strcmp(format, "svg") == 0)
961
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
76 {
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
77 g_free(format);
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
78 return;
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
79 }
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
80
3f03282ec40e a workaround for http://bugzilla.gnome.org/show_bug.cgi?id=547669
nadvornik
parents: 890
diff changeset
81 g_free(format);
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
82
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
83 pb = gdk_pixbuf_loader_get_pixbuf(loader);
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
84
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
85 h = gdk_pixbuf_get_height(pb);
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
86 rs = gdk_pixbuf_get_rowstride(pb);
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
87 pix = gdk_pixbuf_get_pixels(pb);
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
88
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
89 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
90
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
91 }
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
92
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 static void image_loader_size_cb(GdkPixbufLoader *loader,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 gint width, gint height, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97 GdkPixbufFormat *format;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 gchar **mime_types;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99 gint scale = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100 gint n;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102 if (il->requested_width < 1 || il->requested_height < 1) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 format = gdk_pixbuf_loader_get_format(loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 if (!format) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107 mime_types = gdk_pixbuf_format_get_mime_types(format);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108 n = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 while (mime_types[n])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111 if (strstr(mime_types[n], "jpeg")) scale = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112 n++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114 g_strfreev(mime_types);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
115
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 if (!scale) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 if (width > il->requested_width || height > il->requested_height)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
119 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
120 gint nw, nh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122 if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 nw = il->requested_width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125 nh = (gdouble)nw / width * height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 if (nh < 1) nh = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
129 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130 nh = il->requested_height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131 nw = (gdouble)nh / height * width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132 if (nw < 1) nw = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
134
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 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
136 il->shrunk = TRUE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140 static void image_loader_stop(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
143
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
144 if (il->idle_id != -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 g_source_remove(il->idle_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147 il->idle_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150 if (il->loader)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
152 /* 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
153 gdk_pixbuf_loader_close(il->loader, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154 image_loader_sync_pixbuf(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 g_object_unref(G_OBJECT(il->loader));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156 il->loader = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
159 if (il->mapped_file)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160 {
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
161 if (il->preview)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
162 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
163 exif_free_preview(il->mapped_file);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
164 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
165 else
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
166 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
167 munmap(il->mapped_file, il->bytes_total);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
168 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
169 il->mapped_file = NULL;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172 il->done = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173 }
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 static void image_loader_done(ImageLoader *il)
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 image_loader_stop(il);
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 (il->func_done) il->func_done(il, il->data_done);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 static gint image_loader_done_delay_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 il->idle_done_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 image_loader_done(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 static void image_loader_done_delay(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 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
194 image_loader_done_delay_cb, il, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 static void image_loader_error(ImageLoader *il)
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 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 500
diff changeset
201 DEBUG_1("pixbuf_loader reported load error for: %s", image_loader_path(il));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
203 if (il->func_error) il->func_error(il, il->data_error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
206 static gint image_loader_idle_cb(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
207 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209 gint b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
210 gint c;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
211
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212 if (!il) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214 if (il->idle_id == -1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
216 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
217 while (c > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218 {
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
219 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
220
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 if (b == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223 image_loader_done(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
227 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
228 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 image_loader_error(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 il->bytes_read += b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 c--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236 }
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->func_percent && il->bytes_total > 0)
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 il->func_percent(il, (gdouble)il->bytes_read / il->bytes_total, il->data_percent);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241 }
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 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 static gint image_loader_begin(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 {
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 995
diff changeset
248 gint b;
9
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 if (!il->loader || il->pixbuf) return FALSE;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
251
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
252 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
253
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 if (b < 1)
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 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
260 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
261 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
266 il->bytes_read += b;
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
267
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
268 /* read until size is known */
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
269 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
270 {
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
271 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
272 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
273 {
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
274 image_loader_stop(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
275 return FALSE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
276 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
277 il->bytes_read += b;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
278 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
279 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
280
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
281 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
282 {
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
283 /* 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
284 image_loader_stop(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
285
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
286 if (!il->pixbuf) return FALSE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
287
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
288 image_loader_done_delay(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
289 return TRUE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
290 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
291
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
292 if (!il->pixbuf)
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
293 {
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
294 image_loader_stop(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
295 return FALSE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
296 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
297
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
298 /* finally, progressive loading :) */
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
299 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
300
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 static gint image_loader_setup(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
309 if (!il || il->loader || il->mapped_file) return FALSE;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
310
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
311 il->mapped_file = NULL;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
312
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
313 if (il->fd)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
314 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
315 ExifData *exif = exif_read_fd(il->fd);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
316
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
317 il->mapped_file = exif_get_preview(exif, &il->bytes_total);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
318
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
319 if (il->mapped_file)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
320 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
321 il->preview = TRUE;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
322 DEBUG_1("Raw file %s contains embedded image", image_loader_path(il));
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
323 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
324 exif_free_fd(il->fd, exif);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
325 }
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
327
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
328 if (!il->mapped_file)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
329 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
330 /* normal file */
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
331 gint load_fd;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
332
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
333 pathl = path_from_utf8(image_loader_path(il));
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
334 load_fd = open(pathl, O_RDONLY | O_NONBLOCK);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
335 g_free(pathl);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
336 if (load_fd == -1) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
338 if (fstat(load_fd, &st) == 0)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
339 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
340 il->bytes_total = st.st_size;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
341 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
342 else
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
343 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
344 close(load_fd);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
345 return FALSE;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
346 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
347
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
348 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
349 close(load_fd);
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
350 if (il->mapped_file == MAP_FAILED)
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
351 {
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
352 il->mapped_file = 0;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
353 return FALSE;
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
354 }
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
355 il->preview = FALSE;
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
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
358
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 il->loader = gdk_pixbuf_loader_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 g_signal_connect(G_OBJECT(il->loader), "area_updated",
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
361 G_CALLBACK(image_loader_area_updated_cb), il);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362 g_signal_connect(G_OBJECT(il->loader), "size_prepared",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 G_CALLBACK(image_loader_size_cb), il);
500
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
364 g_signal_connect(G_OBJECT(il->loader), "area_prepared",
01fe7ca55c69 clear the buffer before loading of an image
nadvornik
parents: 495
diff changeset
365 G_CALLBACK(image_loader_area_prepared_cb), il);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366
14
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
367 il->shrunk = FALSE;
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
368
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369 return image_loader_begin(il);
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
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
372 static ImageLoader *image_loader_new_real(FileData *fd, const gchar *path)
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 ImageLoader *il;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
376 if (!fd && !path) return NULL;
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 il = g_new0(ImageLoader, 1);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
379 if (fd) il->fd = file_data_ref(fd);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 if (path) il->path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381 il->pixbuf = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 il->idle_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383 il->idle_priority = G_PRIORITY_DEFAULT_IDLE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 il->done = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 il->loader = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 il->bytes_read = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388 il->bytes_total = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390 il->idle_done_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
392 il->idle_read_loop_count = options->image.idle_read_loop_count;
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
393 il->read_buffer_size = options->image.read_buffer_size;
1008
68b0cb6ca8f0 use mmaped files image loader
nadvornik
parents: 1000
diff changeset
394 il->mapped_file = NULL;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 il->requested_width = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 il->requested_height = 0;
14
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
398 il->shrunk = FALSE;
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 500
diff changeset
399 DEBUG_1("new image loader %p, bufsize=%u idle_loop=%u", il, il->read_buffer_size, il->idle_read_loop_count);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 return il;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
403 ImageLoader *image_loader_new(FileData *fd)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
404 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
405 return image_loader_new_real(fd, NULL);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
406 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
407
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
408 ImageLoader *image_loader_new_from_path(const gchar *path)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
409 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
410 return image_loader_new_real(NULL, path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
411 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
412
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 void image_loader_free(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 if (il->idle_done_id != -1) g_source_remove(il->idle_done_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
420 if (il->fd) file_data_unref(il->fd);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
421 if (il->path) g_free(il->path);
506
fc9c8a3e1a8b Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents: 500
diff changeset
422 DEBUG_1("freeing image loader %p bytes_read=%d", il, il->bytes_read);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 g_free(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 /* 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
427 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 if (!il) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 return il->pixbuf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432 }
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 gchar *image_loader_get_format(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 GdkPixbufFormat *format;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 gchar **mimev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 gchar *mime;
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 if (!il || !il->loader) return NULL;
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 format = gdk_pixbuf_loader_get_format(il->loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443 if (!format) return NULL;
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 mimev = gdk_pixbuf_format_get_mime_types(format);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 if (!mimev) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 /* 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
449 mime = g_strdup(mimev[0]);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450 g_strfreev(mimev);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452 return mime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 }
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 void image_loader_set_area_ready_func(ImageLoader *il,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 void (*func_area_ready)(ImageLoader *, guint, guint, guint, guint, gpointer),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 gpointer data_area_ready)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 il->func_area_ready = func_area_ready;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462 il->data_area_ready = data_area_ready;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 void image_loader_set_error_func(ImageLoader *il,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 void (*func_error)(ImageLoader *, gpointer),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 gpointer data_error)
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 il->func_error = func_error;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 il->data_error = data_error;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474
890
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
475 void image_loader_set_done_func(ImageLoader *il,
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
476 void (*func_done)(ImageLoader *, gpointer),
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
477 gpointer data_done)
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
478 {
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
479 if (!il) return;
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
480
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
481 il->func_done = func_done;
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
482 il->data_done = data_done;
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
483 }
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
484
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 void image_loader_set_percent_func(ImageLoader *il,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 void (*func_percent)(ImageLoader *, gdouble, gpointer),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487 gpointer data_percent)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491 il->func_percent = func_percent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 il->data_percent = data_percent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495 void image_loader_set_requested_size(ImageLoader *il, gint width, gint height)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 il->requested_width = width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500 il->requested_height = height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
502
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
503 void image_loader_set_buffer_size(ImageLoader *il, guint count)
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 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
507 il->idle_read_loop_count = count ? count : 1;
9
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510 void image_loader_set_priority(ImageLoader *il, gint priority)
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;
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 il->idle_priority = priority;
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 gint image_loader_start(ImageLoader *il, void (*func_done)(ImageLoader *, gpointer), gpointer data_done)
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 if (!il) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
521 if (!image_loader_path(il)) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522
890
bc9df0fecdc1 Introduce image_loader_set_done_func().
zas_
parents: 673
diff changeset
523 image_loader_set_done_func(il, func_done, data_done);
9
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 return image_loader_setup(il);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528 gdouble image_loader_get_percent(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 if (!il || il->bytes_total == 0) return 0.0;
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 return (gdouble)il->bytes_read / il->bytes_total;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533 }
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 gint image_loader_get_is_done(ImageLoader *il)
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 if (!il) return FALSE;
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 return il->done;
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
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
542 gint image_load_dimensions(FileData *fd, gint *width, gint *height)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544 ImageLoader *il;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
545 gint success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
547 il = image_loader_new(fd);
9
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 success = image_loader_start(il, NULL, NULL);
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 if (success && il->pixbuf)
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 if (width) *width = gdk_pixbuf_get_width(il->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 if (height) *height = gdk_pixbuf_get_height(il->pixbuf);;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
557 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558 if (width) *width = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559 if (height) *height = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560 }
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 image_loader_free(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564 return success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
565 }