annotate src/image-load.c @ 495:c7a2471e5c4e

Introduce macros to display debug messages. if (debug) printf(...) is now replaced by variadic macros: DEBUG_1() And for higher debugging levels: DEBUG_2() DEBUG_3() DEBUG_4()
author zas_
date Wed, 23 Apr 2008 20:47:19 +0000
parents 48c8e49b571c
children 01fe7ca55c69
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"
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
16 #include "filelist.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17
176
695e1ad3b169 simplified exif.h, moved implementation-specific stuff to exif-int.h
nadvornik
parents: 138
diff changeset
18 #include "exif.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>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
24 static const gchar *image_loader_path(ImageLoader *il)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
25 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
26 if (il->fd)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
27 return il->fd->path;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
28 return il->path;
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
29 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
30
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31 static void image_loader_sync_pixbuf(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 GdkPixbuf *pb;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 if (!il->loader) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37 pb = gdk_pixbuf_loader_get_pixbuf(il->loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39 if (pb == il->pixbuf) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 il->pixbuf = pb;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 if (il->pixbuf) gdk_pixbuf_ref(il->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44 }
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 static void image_loader_area_cb(GdkPixbufLoader *loader,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 guint x, guint y, guint w, guint h,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 if (il->func_area_ready)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 if (!il->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56 image_loader_sync_pixbuf(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57 if (!il->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 printf("critical: area_ready signal with NULL pixbuf (out of mem?)\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 }
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 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
63 }
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 static void image_loader_size_cb(GdkPixbufLoader *loader,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67 gint width, gint height, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
70 GdkPixbufFormat *format;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71 gchar **mime_types;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 gint scale = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73 gint n;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75 if (il->requested_width < 1 || il->requested_height < 1) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77 format = gdk_pixbuf_loader_get_format(loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78 if (!format) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80 mime_types = gdk_pixbuf_format_get_mime_types(format);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81 n = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82 while (mime_types[n])
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84 if (strstr(mime_types[n], "jpeg")) scale = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85 n++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87 g_strfreev(mime_types);
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
88
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89 if (!scale) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91 if (width > il->requested_width || height > il->requested_height)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 gint nw, nh;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97 nw = il->requested_width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 nh = (gdouble)nw / width * height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99 if (nh < 1) nh = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 nh = il->requested_height;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 nw = (gdouble)nh / height * width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 if (nw < 1) nw = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
107
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108 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
109 il->shrunk = TRUE;
9
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 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 static void image_loader_stop(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117 if (il->idle_id != -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
119 g_source_remove(il->idle_id);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
120 il->idle_id = -1;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123 if (il->loader)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125 /* 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
126 gdk_pixbuf_loader_close(il->loader, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 image_loader_sync_pixbuf(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128 g_object_unref(G_OBJECT(il->loader));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
129 il->loader = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132 if (il->load_fd != -1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134 close(il->load_fd);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 il->load_fd = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
136 }
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 il->done = TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 static void image_loader_done(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
143 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
144
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 if (il->func_done) il->func_done(il, il->data_done);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 static gint image_loader_done_delay_cb(gpointer data)
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 ImageLoader *il = data;
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 il->idle_done_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 image_loader_done(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157 static void image_loader_done_delay(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159 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
160 image_loader_done_delay_cb, il, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
161 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163 static void image_loader_error(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166
495
c7a2471e5c4e Introduce macros to display debug messages.
zas_
parents: 475
diff changeset
167 DEBUG_1("pixbuf_loader reported load error for: %s\n", image_loader_path(il));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169 if (il->func_error) il->func_error(il, il->data_error);
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 static gint image_loader_idle_cb(gpointer data)
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 ImageLoader *il = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 gint b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176 gint c;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178 if (!il) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 if (il->idle_id == -1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
182 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
183 while (c > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 {
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
185 b = read(il->load_fd, il->read_buffer, il->read_buffer_size);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 if (b == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 image_loader_done(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
193 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->read_buffer, b, NULL)))
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 image_loader_error(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 }
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 il->bytes_read += b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 c--;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204 if (il->func_percent && il->bytes_total > 0)
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 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
207 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
210 }
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 static gint image_loader_begin(ImageLoader *il)
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 int b;
43
ee03f36e9e4b Sun May 15 21:40:26 2005 John Ellis <johne@verizon.net>
gqview
parents: 14
diff changeset
215 unsigned int offset = 0;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 if (!il->loader || il->pixbuf) return FALSE;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
218
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
219 b = read(il->load_fd, il->read_buffer, il->read_buffer_size);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
221 if (b > 0 &&
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
222 format_raw_img_exif_offsets_fd(il->load_fd, image_loader_path(il), il->read_buffer, b, &offset, NULL))
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
223 {
495
c7a2471e5c4e Introduce macros to display debug messages.
zas_
parents: 475
diff changeset
224 DEBUG_1("Raw file %s contains embedded image\n", image_loader_path(il));
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
225
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
226 b = read(il->load_fd, il->read_buffer, il->read_buffer_size);
45
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
227 }
7cfa60beda76 Thu May 26 13:57:19 2005 John Ellis <johne@verizon.net>
gqview
parents: 43
diff changeset
228
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 if (b < 1)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
235 if (!gdk_pixbuf_loader_write(il->loader, il->read_buffer, b, NULL))
9
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 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 return FALSE;
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
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
241 il->bytes_read += b + offset;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
242
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
243 /* read until size is known */
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
244 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
245 {
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
246 b = read(il->load_fd, il->read_buffer, il->read_buffer_size);
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
247 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->read_buffer, b, NULL)))
60
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
248 {
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
249 image_loader_stop(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
250 return FALSE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
251 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
252 il->bytes_read += b;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
253 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
254 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
255
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
256 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
257 {
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
258 /* 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
259 image_loader_stop(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
260
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
261 if (!il->pixbuf) return FALSE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
262
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
263 image_loader_done_delay(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
264 return TRUE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
265 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
266
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
267 if (!il->pixbuf)
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
268 {
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
269 image_loader_stop(il);
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
270 return FALSE;
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
271 }
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
272
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
273 /* finally, progressive loading :) */
9c0c402b0ef3 Mon Jun 13 17:31:46 2005 John Ellis <johne@verizon.net>
gqview
parents: 54
diff changeset
274 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
275
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276 return TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
279 static gint image_loader_setup(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
281 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
282 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
283
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 if (!il || il->load_fd != -1 || il->loader) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
286 pathl = path_from_utf8(image_loader_path(il));
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287 il->load_fd = open(pathl, O_RDONLY | O_NONBLOCK);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289 if (il->load_fd == -1) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 if (fstat(il->load_fd, &st) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293 il->bytes_total = st.st_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296 il->loader = gdk_pixbuf_loader_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297 g_signal_connect(G_OBJECT(il->loader), "area_updated",
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 413
diff changeset
298 G_CALLBACK(image_loader_area_cb), il);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 g_signal_connect(G_OBJECT(il->loader), "size_prepared",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 G_CALLBACK(image_loader_size_cb), il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301
14
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
302 il->shrunk = FALSE;
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
303
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 return image_loader_begin(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
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
307 static ImageLoader *image_loader_new_real(FileData *fd, const gchar *path)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 ImageLoader *il;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
311 if (!fd && !path) return NULL;
9
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 il = g_new0(ImageLoader, 1);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
314 if (fd) il->fd = file_data_ref(fd);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315 if (path) il->path = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 il->pixbuf = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317 il->idle_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 il->idle_priority = G_PRIORITY_DEFAULT_IDLE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 il->done = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320 il->loader = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321 il->load_fd = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 il->bytes_read = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 il->bytes_total = 0;
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 il->idle_done_id = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
328 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
329 il->read_buffer_size = options->image.read_buffer_size;
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
330 il->read_buffer = g_new(guchar, il->read_buffer_size);
9
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 il->requested_width = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 il->requested_height = 0;
14
25335c62cd9b ##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents: 9
diff changeset
334 il->shrunk = FALSE;
495
c7a2471e5c4e Introduce macros to display debug messages.
zas_
parents: 475
diff changeset
335 DEBUG_1("new image loader %p, bufsize=%u idle_loop=%u\n", il, il->read_buffer_size, il->idle_read_loop_count);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336 return il;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
339 ImageLoader *image_loader_new(FileData *fd)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
340 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
341 return image_loader_new_real(fd, NULL);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
342 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
343
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
344 ImageLoader *image_loader_new_from_path(const gchar *path)
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
345 {
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
346 return image_loader_new_real(NULL, path);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
347 }
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
348
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349 void image_loader_free(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 image_loader_stop(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354 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
355 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf);
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
356 if (il->fd) file_data_unref(il->fd);
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
357 if (il->path) g_free(il->path);
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
358 if (il->read_buffer) g_free(il->read_buffer);
495
c7a2471e5c4e Introduce macros to display debug messages.
zas_
parents: 475
diff changeset
359 DEBUG_1("freeing image loader %p bytes_read=%d\n", il, il->bytes_read);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 g_free(il);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363 /* 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
364 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
365 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 if (!il) return NULL;
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 return il->pixbuf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369 }
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 gchar *image_loader_get_format(ImageLoader *il)
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 GdkPixbufFormat *format;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 gchar **mimev;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 gchar *mime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377 if (!il || !il->loader) return NULL;
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 format = gdk_pixbuf_loader_get_format(il->loader);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 if (!format) return NULL;
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 mimev = gdk_pixbuf_format_get_mime_types(format);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383 if (!mimev) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 /* 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
386 mime = g_strdup(mimev[0]);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 g_strfreev(mimev);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389 return mime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390 }
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 void image_loader_set_area_ready_func(ImageLoader *il,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 void (*func_area_ready)(ImageLoader *, guint, guint, guint, guint, gpointer),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 gpointer data_area_ready)
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 if (!il) return;
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 il->func_area_ready = func_area_ready;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 il->data_area_ready = data_area_ready;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 void image_loader_set_error_func(ImageLoader *il,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 void (*func_error)(ImageLoader *, gpointer),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 gpointer data_error)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408 il->func_error = func_error;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 il->data_error = data_error;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 void image_loader_set_percent_func(ImageLoader *il,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 void (*func_percent)(ImageLoader *, gdouble, gpointer),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414 gpointer data_percent)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 il->func_percent = func_percent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 il->data_percent = data_percent;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422 void image_loader_set_requested_size(ImageLoader *il, gint width, gint height)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 if (!il) return;
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 il->requested_width = width;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427 il->requested_height = height;
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
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
430 void image_loader_set_buffer_size(ImageLoader *il, guint count)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433
413
9e521adbf312 Add two new options to control image read buffer at runtime.
zas_
parents: 281
diff changeset
434 il->idle_read_loop_count = count ? count : 1;
9
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437 void image_loader_set_priority(ImageLoader *il, gint priority)
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 if (!il) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 il->idle_priority = priority;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444 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
445 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 if (!il) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
448 if (!image_loader_path(il)) return FALSE;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450 il->func_done = func_done;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 il->data_done = data_done;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 return image_loader_setup(il);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 gdouble image_loader_get_percent(ImageLoader *il)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 if (!il || il->bytes_total == 0) return 0.0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460 return (gdouble)il->bytes_read / il->bytes_total;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463 gint image_loader_get_is_done(ImageLoader *il)
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 if (!il) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 return il->done;
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
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
470 gint image_load_dimensions(FileData *fd, gint *width, gint *height)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 ImageLoader *il;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 gint success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474
138
71e1ebee420e replaced gchar* path with FileData *fd
nadvornik
parents: 60
diff changeset
475 il = image_loader_new(fd);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477 success = image_loader_start(il, NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479 if (success && il->pixbuf)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 if (width) *width = gdk_pixbuf_get_width(il->pixbuf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 if (height) *height = gdk_pixbuf_get_height(il->pixbuf);;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
484 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 if (width) *width = -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487 if (height) *height = -1;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490 image_loader_free(il);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 return success;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493 }