Mercurial > geeqie.yaz
annotate src/image.c @ 61:0c912a2d94f1
Mon Jun 13 20:22:58 2005 John Ellis <johne@verizon.net>
* image.c (image_zoom_cb): If needed, update window title when
zoom changes.
* pixbuf-renderer.c (pr_size_sync): Send zoom signal when new window
size results in a new scale value.
* README: Updates.
* configure.in: Release 2.1.1
author | gqview |
---|---|
date | Tue, 14 Jun 2005 00:49:25 +0000 |
parents | 606fcf461a68 |
children | a4c1b7014e6e |
rev | line source |
---|---|
1 | 1 /* |
9 | 2 * GQview |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
3 * (C) 2005 John Ellis |
1 | 4 * |
5 * Author: John Ellis | |
6 * | |
9 | 7 * This software is released under the GNU General Public License (GNU GPL). |
8 * Please read the included file COPYING for more information. | |
9 * This software comes with no warranty of any kind, use at your own risk! | |
1 | 10 */ |
11 | |
9 | 12 |
1 | 13 #include "gqview.h" |
14 #include "image.h" | |
9 | 15 |
16 | |
17 #include "image-load.h" | |
18 #include "collect.h" | |
19 #include "exif.h" | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
20 #include "pixbuf-renderer.h" |
9 | 21 #include "pixbuf_util.h" |
22 #include "ui_fileops.h" | |
23 | |
24 #include <math.h> | |
25 | |
26 | |
27 /* size of the image loader buffer (512 bytes x defined number) */ | |
28 #define IMAGE_LOAD_BUFFER_COUNT 8 | |
29 | |
30 /* define this so that more bytes are read per idle loop on larger images (> 1MB) */ | |
31 #define IMAGE_THROTTLE_LARGER_IMAGES 1 | |
32 | |
33 /* throttle factor to increase read bytes by (2 is double, 3 is triple, etc.) */ | |
34 #define IMAGE_THROTTLE_FACTOR 4 | |
35 | |
36 /* the file size at which throttling take place */ | |
37 #define IMAGE_THROTTLE_THRESHOLD 1048576 | |
38 | |
39 #define IMAGE_AUTO_REFRESH_TIME 3000 | |
40 | |
1 | 41 |
26
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
42 static GList *image_list = NULL; |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
43 |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
44 |
61
0c912a2d94f1
Mon Jun 13 20:22:58 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
45 static void image_update_title(ImageWindow *imd); |
0c912a2d94f1
Mon Jun 13 20:22:58 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
46 |
1 | 47 /* |
9 | 48 *------------------------------------------------------------------- |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
49 * 'signals' |
9 | 50 *------------------------------------------------------------------- |
51 */ | |
52 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
53 static void image_click_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer data) |
9 | 54 { |
55 ImageWindow *imd = data; | |
56 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
57 if (imd->func_button) |
9 | 58 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
59 imd->func_button(imd, event->button, event->time, |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
60 event->x, event->y, event->state, imd->data_button); |
9 | 61 } |
62 } | |
63 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
64 static void image_scroll_notify_cb(PixbufRenderer *pr, gpointer data) |
9 | 65 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
66 ImageWindow *imd = data; |
9 | 67 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
68 if (imd->func_scroll_notify && pr->scale) |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
69 { |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
70 imd->func_scroll_notify(imd, |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
71 (gint)((gdouble)pr->x_scroll / pr->scale), |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
72 (gint)((gdouble)pr->y_scroll / pr->scale), |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
73 (gint)((gdouble)pr->image_width - pr->vis_width / pr->scale), |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
74 (gint)((gdouble)pr->image_height - pr->vis_height / pr->scale), |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
75 imd->data_scroll_notify); |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
76 } |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
77 } |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
78 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
79 static void image_update_util(ImageWindow *imd) |
1 | 80 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
81 if (imd->func_update) imd->func_update(imd, imd->data_update); |
9 | 82 } |
83 | |
25
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
84 static void image_zoom_cb(PixbufRenderer *pr, gdouble zoom, gpointer data) |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
85 { |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
86 ImageWindow *imd = data; |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
87 |
61
0c912a2d94f1
Mon Jun 13 20:22:58 2005 John Ellis <johne@verizon.net>
gqview
parents:
42
diff
changeset
|
88 if (imd->title_show_zoom) image_update_title(imd); |
25
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
89 image_update_util(imd); |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
90 } |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
91 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
92 static void image_complete_util(ImageWindow *imd, gint preload) |
9 | 93 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
94 if (imd->il && image_get_pixbuf(imd) != image_loader_get_pixbuf(imd->il)) return; |
9 | 95 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
96 if (debug) printf("image load completed \"%s\" (%s)\n", |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
97 (preload) ? imd->read_ahead_path : imd->image_path, |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
98 (preload) ? "preload" : "current"); |
9 | 99 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
100 if (!preload) imd->completed = TRUE; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
101 if (imd->func_complete) imd->func_complete(imd, preload, imd->data_complete); |
1 | 102 } |
103 | |
25
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
104 static void image_render_complete_cb(PixbufRenderer *pr, gpointer data) |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
105 { |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
106 ImageWindow *imd = data; |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
107 |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
108 image_complete_util(imd, FALSE); |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
109 } |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
110 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
111 static void image_new_util(ImageWindow *imd) |
9 | 112 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
113 if (imd->func_new) imd->func_new(imd, imd->data_new); |
1 | 114 } |
115 | |
116 /* | |
9 | 117 *------------------------------------------------------------------- |
118 * misc | |
119 *------------------------------------------------------------------- | |
120 */ | |
121 | |
122 static void image_update_title(ImageWindow *imd) | |
1 | 123 { |
9 | 124 gchar *title = NULL; |
125 gchar *zoom = NULL; | |
126 gchar *collection = NULL; | |
127 | |
128 if (!imd->top_window) return; | |
129 | |
130 if (imd->collection && collection_to_number(imd->collection) >= 0) | |
131 { | |
132 const gchar *name; | |
133 name = imd->collection->name; | |
134 if (!name) name = _("Untitled"); | |
135 collection = g_strdup_printf(" (Collection %s)", name); | |
136 } | |
137 | |
138 if (imd->title_show_zoom) | |
1 | 139 { |
9 | 140 gchar *buf = image_zoom_get_as_text(imd); |
141 zoom = g_strconcat(" [", buf, "]", NULL); | |
142 g_free(buf); | |
1 | 143 } |
144 | |
9 | 145 title = g_strdup_printf("%s%s%s%s%s%s", |
146 imd->title ? imd->title : "", | |
147 imd->image_name ? imd->image_name : "", | |
148 zoom ? zoom : "", | |
149 collection ? collection : "", | |
150 imd->image_name ? " - " : "", | |
151 imd->title_right ? imd->title_right : ""); | |
152 | |
153 gtk_window_set_title(GTK_WINDOW(imd->top_window), title); | |
154 | |
155 g_free(title); | |
156 g_free(zoom); | |
157 g_free(collection); | |
158 } | |
159 | |
160 /* | |
161 *------------------------------------------------------------------- | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
162 * rotation, flip, etc. |
9 | 163 *------------------------------------------------------------------- |
164 */ | |
165 | |
166 static void image_alter_real(ImageWindow *imd, AlterType type, gint clamp) | |
167 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
168 PixbufRenderer *pr; |
9 | 169 GdkPixbuf *new = NULL; |
170 gint x, y; | |
171 gint t; | |
172 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
173 pr = (PixbufRenderer *)imd->pr; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
174 |
9 | 175 imd->delay_alter_type = ALTER_NONE; |
176 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
177 if (!pr->pixbuf) return; |
9 | 178 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
179 x = pr->x_scroll + (pr->vis_width / 2); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
180 y = pr->y_scroll + (pr->vis_height / 2); |
9 | 181 |
182 switch (type) | |
183 { | |
184 case ALTER_ROTATE_90: | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
185 new = pixbuf_copy_rotate_90(pr->pixbuf, FALSE); |
9 | 186 t = x; |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
187 x = pr->height - y; |
9 | 188 y = t; |
189 break; | |
190 case ALTER_ROTATE_90_CC: | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
191 new = pixbuf_copy_rotate_90(pr->pixbuf, TRUE); |
9 | 192 t = x; |
193 x = y; | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
194 y = pr->width - t; |
9 | 195 break; |
196 case ALTER_ROTATE_180: | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
197 new = pixbuf_copy_mirror(pr->pixbuf, TRUE, TRUE); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
198 x = pr->width - x; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
199 y = pr->height - y; |
9 | 200 break; |
201 case ALTER_MIRROR: | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
202 new = pixbuf_copy_mirror(pr->pixbuf, TRUE, FALSE); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
203 x = pr->width - x; |
9 | 204 break; |
205 case ALTER_FLIP: | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
206 new = pixbuf_copy_mirror(pr->pixbuf, FALSE, TRUE); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
207 y = pr->height - y; |
9 | 208 break; |
209 case ALTER_NONE: | |
210 default: | |
211 return; | |
212 break; | |
213 } | |
214 | |
215 if (!new) return; | |
216 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
217 pixbuf_renderer_set_pixbuf(pr, new, pr->zoom); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
218 g_object_unref(new); |
9 | 219 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
220 if (clamp && pr->zoom != 0.0) |
9 | 221 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
222 pixbuf_renderer_scroll(pr, x - (pr->vis_width / 2), y - (pr->vis_height / 2)); |
9 | 223 } |
1 | 224 } |
225 | |
9 | 226 static void image_post_process(ImageWindow *imd, gint clamp) |
227 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
228 if (exif_rotate_enable && image_get_pixbuf(imd)) |
9 | 229 { |
230 ExifData *ed; | |
231 gint orientation; | |
232 | |
233 ed = exif_read(imd->image_path); | |
234 if (ed && exif_get_integer(ed, "Orientation", &orientation)) | |
235 { | |
236 /* see http://jpegclub.org/exif_orientation.html | |
237 1 2 3 4 5 6 7 8 | |
238 | |
239 888888 888888 88 88 8888888888 88 88 8888888888 | |
240 88 88 88 88 88 88 88 88 88 88 88 88 | |
241 8888 8888 8888 8888 88 8888888888 8888888888 88 | |
242 88 88 88 88 | |
243 88 88 888888 888888 | |
244 */ | |
245 | |
246 switch (orientation) | |
247 { | |
248 case EXIF_ORIENTATION_TOP_LEFT: | |
249 /* normal -- nothing to do */ | |
250 break; | |
251 case EXIF_ORIENTATION_TOP_RIGHT: | |
252 /* mirrored */ | |
253 imd->delay_alter_type = ALTER_MIRROR; | |
254 break; | |
255 case EXIF_ORIENTATION_BOTTOM_RIGHT: | |
256 /* upside down */ | |
257 imd->delay_alter_type = ALTER_ROTATE_180; | |
258 break; | |
259 case EXIF_ORIENTATION_BOTTOM_LEFT: | |
260 /* flipped */ | |
261 imd->delay_alter_type = ALTER_FLIP; | |
262 break; | |
263 case EXIF_ORIENTATION_LEFT_TOP: | |
264 /* not implemented -- too wacky to fix in one step */ | |
265 break; | |
266 case EXIF_ORIENTATION_RIGHT_TOP: | |
267 /* rotated -90 (270) */ | |
268 imd->delay_alter_type = ALTER_ROTATE_90; | |
269 break; | |
270 case EXIF_ORIENTATION_RIGHT_BOTTOM: | |
271 /* not implemented -- too wacky to fix in one step */ | |
272 break; | |
273 case EXIF_ORIENTATION_LEFT_BOTTOM: | |
274 /* rotated 90 */ | |
275 imd->delay_alter_type = ALTER_ROTATE_90_CC; | |
276 break; | |
277 default: | |
278 /* The other values are out of range */ | |
279 break; | |
280 } | |
281 } | |
282 exif_free(ed); | |
283 } | |
284 | |
285 if (imd->delay_alter_type != ALTER_NONE) | |
286 { | |
287 image_alter_real(imd, imd->delay_alter_type, clamp); | |
288 } | |
289 } | |
290 | |
291 /* | |
292 *------------------------------------------------------------------- | |
293 * read ahead (prebuffer) | |
294 *------------------------------------------------------------------- | |
295 */ | |
296 | |
297 static void image_read_ahead_cancel(ImageWindow *imd) | |
298 { | |
299 if (debug) printf("read ahead cancelled for :%s\n", imd->read_ahead_path); | |
300 | |
301 image_loader_free(imd->read_ahead_il); | |
302 imd->read_ahead_il = NULL; | |
303 | |
304 if (imd->read_ahead_pixbuf) g_object_unref(imd->read_ahead_pixbuf); | |
305 imd->read_ahead_pixbuf = NULL; | |
306 | |
307 g_free(imd->read_ahead_path); | |
308 imd->read_ahead_path = NULL; | |
309 } | |
310 | |
311 static void image_read_ahead_done_cb(ImageLoader *il, gpointer data) | |
312 { | |
313 ImageWindow *imd = data; | |
314 | |
315 if (debug) printf("read ahead done for :%s\n", imd->read_ahead_path); | |
316 | |
317 imd->read_ahead_pixbuf = image_loader_get_pixbuf(imd->read_ahead_il); | |
318 if (imd->read_ahead_pixbuf) | |
319 { | |
320 g_object_ref(imd->read_ahead_pixbuf); | |
321 } | |
322 else | |
323 { | |
324 imd->read_ahead_pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN); | |
325 } | |
326 image_loader_free(imd->read_ahead_il); | |
327 imd->read_ahead_il = NULL; | |
328 | |
329 image_complete_util(imd, TRUE); | |
330 } | |
331 | |
332 static void image_read_ahead_error_cb(ImageLoader *il, gpointer data) | |
333 { | |
334 /* we even treat errors as success, maybe at least some of the file was ok */ | |
335 image_read_ahead_done_cb(il, data); | |
336 } | |
337 | |
338 static void image_read_ahead_start(ImageWindow *imd) | |
339 { | |
340 /* already started ? */ | |
341 if (!imd->read_ahead_path || imd->read_ahead_il || imd->read_ahead_pixbuf) return; | |
342 | |
343 /* still loading ?, do later */ | |
344 if (imd->il) return; | |
345 | |
346 if (debug) printf("read ahead started for :%s\n", imd->read_ahead_path); | |
347 | |
348 imd->read_ahead_il = image_loader_new(imd->read_ahead_path); | |
349 | |
350 image_loader_set_error_func(imd->read_ahead_il, image_read_ahead_error_cb, imd); | |
351 if (!image_loader_start(imd->read_ahead_il, image_read_ahead_done_cb, imd)) | |
352 { | |
353 image_read_ahead_cancel(imd); | |
354 image_complete_util(imd, TRUE); | |
355 } | |
356 } | |
357 | |
358 static void image_read_ahead_set(ImageWindow *imd, const gchar *path) | |
359 { | |
360 if (imd->read_ahead_path && path && strcmp(imd->read_ahead_path, path) == 0) return; | |
361 | |
362 image_read_ahead_cancel(imd); | |
363 | |
364 imd->read_ahead_path = g_strdup(path); | |
365 | |
366 if (debug) printf("read ahead set to :%s\n", imd->read_ahead_path); | |
367 | |
368 image_read_ahead_start(imd); | |
369 } | |
370 | |
371 /* | |
372 *------------------------------------------------------------------- | |
373 * post buffering | |
374 *------------------------------------------------------------------- | |
375 */ | |
376 | |
377 static void image_post_buffer_set(ImageWindow *imd, const gchar *path, GdkPixbuf *pixbuf) | |
378 { | |
379 g_free(imd->prev_path); | |
380 if (imd->prev_pixbuf) g_object_unref(imd->prev_pixbuf); | |
381 | |
382 if (path && pixbuf) | |
383 { | |
384 imd->prev_path = g_strdup(path); | |
385 | |
386 g_object_ref(pixbuf); | |
387 imd->prev_pixbuf = pixbuf; | |
388 } | |
389 else | |
390 { | |
391 imd->prev_path = NULL; | |
392 imd->prev_pixbuf = NULL; | |
393 } | |
394 | |
395 if (debug) printf("post buffer set: %s\n", path); | |
396 } | |
397 | |
398 static gint image_post_buffer_get(ImageWindow *imd) | |
399 { | |
400 gint success; | |
401 | |
402 if (imd->prev_pixbuf && | |
403 imd->image_path && imd->prev_path && strcmp(imd->image_path, imd->prev_path) == 0) | |
404 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
405 image_change_pixbuf(imd, imd->prev_pixbuf, image_zoom_get(imd)); |
9 | 406 success = TRUE; |
407 } | |
408 else | |
409 { | |
410 success = FALSE; | |
411 } | |
412 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
413 if (imd->prev_pixbuf) g_object_unref(imd->prev_pixbuf); |
9 | 414 imd->prev_pixbuf = NULL; |
415 | |
416 g_free(imd->prev_path); | |
417 imd->prev_path = NULL; | |
418 | |
419 return success; | |
420 } | |
421 | |
422 /* | |
423 *------------------------------------------------------------------- | |
424 * loading | |
425 *------------------------------------------------------------------- | |
426 */ | |
427 | |
428 static void image_load_pixbuf_ready(ImageWindow *imd) | |
429 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
430 if (image_get_pixbuf(imd) || !imd->il) return; |
9 | 431 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
432 image_change_pixbuf(imd, image_loader_get_pixbuf(imd->il), image_zoom_get(imd)); |
9 | 433 } |
434 | |
435 static void image_load_area_cb(ImageLoader *il, guint x, guint y, guint w, guint h, gpointer data) | |
436 { | |
437 ImageWindow *imd = data; | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
438 PixbufRenderer *pr; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
439 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
440 pr = (PixbufRenderer *)imd->pr; |
9 | 441 |
442 if (imd->delay_flip && | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
443 pr->pixbuf != image_loader_get_pixbuf(il)) |
9 | 444 { |
445 return; | |
446 } | |
447 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
448 if (!pr->pixbuf) image_load_pixbuf_ready(imd); |
9 | 449 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
450 pixbuf_renderer_area_changed(pr, x, y, w, h); |
9 | 451 } |
452 | |
453 static void image_load_done_cb(ImageLoader *il, gpointer data) | |
1 | 454 { |
455 ImageWindow *imd = data; | |
9 | 456 |
457 if (debug) printf ("image done\n"); | |
458 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
459 g_object_set(G_OBJECT(imd->pr), "loading", FALSE, NULL); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
460 |
9 | 461 if (imd->delay_flip && |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
462 image_get_pixbuf(imd) != image_loader_get_pixbuf(imd->il)) |
9 | 463 { |
42
606fcf461a68
Sat May 14 13:04:23 2005 John Ellis <johne@verizon.net>
gqview
parents:
29
diff
changeset
|
464 g_object_set(G_OBJECT(imd->pr), "complete", FALSE, NULL); |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
465 image_change_pixbuf(imd, image_loader_get_pixbuf(imd->il), image_zoom_get(imd)); |
9 | 466 } |
467 | |
468 image_loader_free(imd->il); | |
469 imd->il = NULL; | |
470 | |
471 image_post_process(imd, TRUE); | |
472 | |
473 image_read_ahead_start(imd); | |
474 } | |
475 | |
476 static void image_load_error_cb(ImageLoader *il, gpointer data) | |
477 { | |
478 if (debug) printf ("image error\n"); | |
479 | |
480 /* even on error handle it like it was done, | |
481 * since we have a pixbuf with _something_ */ | |
482 | |
483 image_load_done_cb(il, data); | |
484 } | |
485 | |
486 #ifdef IMAGE_THROTTLE_LARGER_IMAGES | |
487 static void image_load_buffer_throttle(ImageLoader *il) | |
488 { | |
489 if (!il || il->bytes_total < IMAGE_THROTTLE_THRESHOLD) return; | |
490 | |
491 /* Larger image files usually have larger chunks of data per pixel... | |
492 * So increase the buffer read size so that the rendering chunks called | |
493 * are also larger. | |
494 */ | |
495 | |
496 image_loader_set_buffer_size(il, IMAGE_LOAD_BUFFER_COUNT * IMAGE_THROTTLE_FACTOR); | |
497 } | |
498 #endif | |
499 | |
500 /* this read ahead is located here merely for the callbacks, above */ | |
501 | |
502 static gint image_read_ahead_check(ImageWindow *imd) | |
503 { | |
504 if (!imd->read_ahead_path) return FALSE; | |
505 if (imd->il) return FALSE; | |
506 | |
507 if (!imd->image_path || strcmp(imd->read_ahead_path, imd->image_path) != 0) | |
508 { | |
509 image_read_ahead_cancel(imd); | |
510 return FALSE; | |
511 } | |
512 | |
513 if (imd->read_ahead_il) | |
514 { | |
515 imd->il = imd->read_ahead_il; | |
516 imd->read_ahead_il = NULL; | |
517 | |
518 /* override the old signals */ | |
519 image_loader_set_area_ready_func(imd->il, image_load_area_cb, imd); | |
520 image_loader_set_error_func(imd->il, image_load_error_cb, imd); | |
521 image_loader_set_buffer_size(imd->il, IMAGE_LOAD_BUFFER_COUNT); | |
522 | |
523 #ifdef IMAGE_THROTTLE_LARGER_IMAGES | |
524 image_load_buffer_throttle(imd->il); | |
525 #endif | |
526 | |
527 /* do this one directly (probably should add a set func) */ | |
528 imd->il->func_done = image_load_done_cb; | |
529 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
530 g_object_set(G_OBJECT(imd->pr), "loading", TRUE, NULL); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
531 |
9 | 532 if (!imd->delay_flip) |
533 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
534 image_change_pixbuf(imd, image_loader_get_pixbuf(imd->il), image_zoom_get(imd)); |
9 | 535 } |
536 | |
537 image_read_ahead_cancel(imd); | |
538 return TRUE; | |
539 } | |
540 else if (imd->read_ahead_pixbuf) | |
541 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
542 image_change_pixbuf(imd, imd->read_ahead_pixbuf, image_zoom_get(imd)); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
543 g_object_unref(imd->read_ahead_pixbuf); |
9 | 544 imd->read_ahead_pixbuf = NULL; |
545 | |
546 image_read_ahead_cancel(imd); | |
547 | |
548 image_post_process(imd, FALSE); | |
549 return TRUE; | |
550 } | |
551 | |
552 image_read_ahead_cancel(imd); | |
553 return FALSE; | |
554 } | |
555 | |
556 static gint image_load_begin(ImageWindow *imd, const gchar *path) | |
557 { | |
558 if (debug) printf ("image begin \n"); | |
559 | |
560 if (imd->il) return FALSE; | |
561 | |
562 imd->completed = FALSE; | |
25
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
563 g_object_set(G_OBJECT(imd->pr), "complete", FALSE, NULL); |
9 | 564 |
565 if (image_post_buffer_get(imd)) | |
566 { | |
567 if (debug) printf("from post buffer: %s\n", imd->image_path); | |
568 return TRUE; | |
569 } | |
570 | |
571 if (image_read_ahead_check(imd)) | |
572 { | |
573 if (debug) printf("from read ahead buffer: %s\n", imd->image_path); | |
574 return TRUE; | |
575 } | |
576 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
577 if (!imd->delay_flip && image_get_pixbuf(imd)) |
9 | 578 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
579 PixbufRenderer *pr; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
580 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
581 pr = PIXBUF_RENDERER(imd->pr); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
582 if (pr->pixbuf) g_object_unref(pr->pixbuf); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
583 pr->pixbuf = NULL; |
9 | 584 } |
585 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
586 g_object_set(G_OBJECT(imd->pr), "loading", TRUE, NULL); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
587 |
9 | 588 imd->il = image_loader_new(path); |
589 | |
590 image_loader_set_area_ready_func(imd->il, image_load_area_cb, imd); | |
591 image_loader_set_error_func(imd->il, image_load_error_cb, imd); | |
592 image_loader_set_buffer_size(imd->il, IMAGE_LOAD_BUFFER_COUNT); | |
593 | |
594 if (!image_loader_start(imd->il, image_load_done_cb, imd)) | |
595 { | |
596 if (debug) printf("image start error\n"); | |
597 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
598 g_object_set(G_OBJECT(imd->pr), "loading", FALSE, NULL); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
599 |
9 | 600 image_loader_free(imd->il); |
601 imd->il = NULL; | |
602 | |
603 image_complete_util(imd, FALSE); | |
604 | |
605 return FALSE; | |
606 } | |
607 | |
608 #ifdef IMAGE_THROTTLE_LARGER_IMAGES | |
609 image_load_buffer_throttle(imd->il); | |
610 #endif | |
611 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
612 if (!imd->delay_flip && !image_get_pixbuf(imd)) image_load_pixbuf_ready(imd); |
9 | 613 |
614 return TRUE; | |
615 } | |
616 | |
617 static void image_reset(ImageWindow *imd) | |
618 { | |
619 /* stops anything currently being done */ | |
620 | |
621 if (debug) printf("image reset\n"); | |
622 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
623 g_object_set(G_OBJECT(imd->pr), "loading", FALSE, NULL); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
624 |
9 | 625 image_loader_free(imd->il); |
626 imd->il = NULL; | |
627 | |
628 imd->delay_alter_type = ALTER_NONE; | |
629 } | |
630 | |
631 /* | |
632 *------------------------------------------------------------------- | |
633 * image changer | |
634 *------------------------------------------------------------------- | |
635 */ | |
636 | |
637 static void image_change_complete(ImageWindow *imd, gdouble zoom, gint new) | |
638 { | |
639 image_reset(imd); | |
640 | |
641 if (imd->image_path && isfile(imd->image_path)) | |
642 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
643 PixbufRenderer *pr; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
644 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
645 pr = PIXBUF_RENDERER(imd->pr); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
646 pr->zoom = zoom; /* store the zoom, needed by the loader */ |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
647 |
9 | 648 if (image_load_begin(imd, imd->image_path)) |
649 { | |
650 imd->unknown = FALSE; | |
651 } | |
652 else | |
653 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
654 GdkPixbuf *pixbuf; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
655 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
656 pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
657 image_change_pixbuf(imd, pixbuf, zoom); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
658 g_object_unref(pixbuf); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
659 |
9 | 660 imd->unknown = TRUE; |
661 } | |
662 imd->size = filesize(imd->image_path); | |
663 imd->mtime = filetime(imd->image_path); | |
664 } | |
665 else | |
666 { | |
667 if (imd->image_path) | |
668 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
669 GdkPixbuf *pixbuf; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
670 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
671 pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
672 image_change_pixbuf(imd, pixbuf, zoom); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
673 g_object_unref(pixbuf); |
9 | 674 imd->mtime = filetime(imd->image_path); |
675 } | |
676 else | |
677 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
678 image_change_pixbuf(imd, NULL, zoom); |
9 | 679 imd->mtime = 0; |
680 } | |
681 imd->unknown = TRUE; | |
682 imd->size = 0; | |
683 } | |
684 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
685 image_update_util(imd); |
9 | 686 } |
687 | |
688 static void image_change_real(ImageWindow *imd, const gchar *path, | |
689 CollectionData *cd, CollectInfo *info, gdouble zoom) | |
690 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
691 GdkPixbuf *pixbuf; |
9 | 692 GdkPixbuf *prev_pixbuf = NULL; |
693 gchar *prev_path = NULL; | |
694 gint prev_clear = FALSE; | |
695 | |
696 imd->collection = cd; | |
697 imd->collection_info = info; | |
698 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
699 pixbuf = image_get_pixbuf(imd); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
700 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
701 if (enable_read_ahead && imd->image_path && pixbuf) |
9 | 702 { |
703 if (imd->il) | |
704 { | |
705 /* current image is not finished */ | |
706 prev_clear = TRUE; | |
707 } | |
708 else | |
709 { | |
710 prev_path = g_strdup(imd->image_path); | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
711 prev_pixbuf = pixbuf; |
9 | 712 g_object_ref(prev_pixbuf); |
713 } | |
714 } | |
715 | |
716 g_free(imd->image_path); | |
717 imd->image_path = g_strdup(path); | |
718 imd->image_name = filename_from_path(imd->image_path); | |
719 | |
720 image_change_complete(imd, zoom, TRUE); | |
721 | |
722 if (prev_pixbuf) | |
723 { | |
724 image_post_buffer_set(imd, prev_path, prev_pixbuf); | |
725 g_free(prev_path); | |
726 g_object_unref(prev_pixbuf); | |
727 } | |
728 else if (prev_clear) | |
729 { | |
730 image_post_buffer_set(imd, NULL, NULL); | |
731 } | |
732 | |
733 image_update_title(imd); | |
734 image_new_util(imd); | |
735 } | |
736 | |
737 /* | |
738 *------------------------------------------------------------------- | |
739 * focus stuff | |
740 *------------------------------------------------------------------- | |
741 */ | |
742 | |
743 static void image_focus_paint(ImageWindow *imd, gint has_focus, GdkRectangle *area) | |
744 { | |
745 GtkWidget *widget; | |
746 | |
747 widget = imd->widget; | |
748 if (!widget->window) return; | |
749 | |
750 if (has_focus) | |
751 { | |
752 gtk_paint_focus (widget->style, widget->window, GTK_STATE_ACTIVE, | |
753 area, widget, "image_window", | |
754 widget->allocation.x, widget->allocation.y, | |
755 widget->allocation.width - 1, widget->allocation.height - 1); | |
756 } | |
757 else | |
758 { | |
759 gtk_paint_shadow (widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_IN, | |
760 area, widget, "image_window", | |
761 widget->allocation.x, widget->allocation.y, | |
762 widget->allocation.width - 1, widget->allocation.height - 1); | |
763 } | |
764 } | |
765 | |
766 static gint image_focus_expose(GtkWidget *widget, GdkEventExpose *event, gpointer data) | |
767 { | |
768 ImageWindow *imd = data; | |
769 | |
770 image_focus_paint(imd, GTK_WIDGET_HAS_FOCUS(widget), &event->area); | |
771 return TRUE; | |
772 } | |
773 | |
774 static gint image_focus_in_cb(GtkWidget *widget, GdkEventFocus *event, gpointer data) | |
775 { | |
776 ImageWindow *imd = data; | |
777 | |
778 GTK_WIDGET_SET_FLAGS(imd->widget, GTK_HAS_FOCUS); | |
779 image_focus_paint(imd, TRUE, NULL); | |
780 | |
781 return TRUE; | |
782 } | |
783 | |
784 static gint image_focus_out_cb(GtkWidget *widget, GdkEventFocus *event, gpointer data) | |
785 { | |
786 ImageWindow *imd = data; | |
787 | |
788 GTK_WIDGET_UNSET_FLAGS(imd->widget, GTK_HAS_FOCUS); | |
789 image_focus_paint(imd, FALSE, NULL); | |
790 | |
791 return TRUE; | |
792 } | |
793 | |
794 gint image_overlay_add(ImageWindow *imd, GdkPixbuf *pixbuf, gint x, gint y, | |
795 gint relative, gint always) | |
796 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
797 return pixbuf_renderer_overlay_add((PixbufRenderer *)imd->pr, pixbuf, x, y, relative, always); |
9 | 798 } |
799 | |
800 void image_overlay_set(ImageWindow *imd, gint id, GdkPixbuf *pixbuf, gint x, gint y) | |
801 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
802 pixbuf_renderer_overlay_set((PixbufRenderer *)imd->pr, id, pixbuf, x, y); |
9 | 803 } |
804 | |
805 gint image_overlay_get(ImageWindow *imd, gint id, GdkPixbuf **pixbuf, gint *x, gint *y) | |
806 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
807 return pixbuf_renderer_overlay_get((PixbufRenderer *)imd->pr, id, pixbuf, x, y); |
9 | 808 } |
809 | |
810 void image_overlay_remove(ImageWindow *imd, gint id) | |
811 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
812 pixbuf_renderer_overlay_remove((PixbufRenderer *)imd->pr, id); |
9 | 813 } |
814 | |
815 static gint image_scroll_cb(GtkWidget *widget, GdkEventScroll *event, gpointer data) | |
816 { | |
817 ImageWindow *imd = data; | |
818 | |
819 if (imd->func_scroll && | |
820 event && event->type == GDK_SCROLL) | |
821 { | |
822 imd->func_scroll(imd, event->direction, event->time, | |
823 event->x, event->y, event->state, imd->data_scroll); | |
824 return TRUE; | |
825 } | |
826 | |
827 return FALSE; | |
828 } | |
829 | |
830 /* | |
831 *------------------------------------------------------------------- | |
832 * public interface | |
833 *------------------------------------------------------------------- | |
834 */ | |
835 | |
836 void image_attach_window(ImageWindow *imd, GtkWidget *window, | |
837 const gchar *title, const gchar *title_right, gint show_zoom) | |
1 | 838 { |
839 imd->top_window = window; | |
840 g_free(imd->title); | |
9 | 841 imd->title = g_strdup(title); |
842 g_free(imd->title_right); | |
843 imd->title_right = g_strdup(title_right); | |
844 imd->title_show_zoom = show_zoom; | |
845 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
846 if (!fit_window) window = NULL; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
847 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
848 pixbuf_renderer_set_parent((PixbufRenderer *)imd->pr, (GtkWindow *)window); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
849 |
9 | 850 image_update_title(imd); |
851 } | |
852 | |
853 void image_set_update_func(ImageWindow *imd, | |
854 void (*func)(ImageWindow *imd, gpointer data), | |
855 gpointer data) | |
856 { | |
857 imd->func_update = func; | |
858 imd->data_update = data; | |
1 | 859 } |
860 | |
9 | 861 void image_set_complete_func(ImageWindow *imd, |
862 void (*func)(ImageWindow *, gint preload, gpointer), | |
863 gpointer data) | |
1 | 864 { |
9 | 865 imd->func_complete = func; |
866 imd->data_complete = data; | |
1 | 867 } |
868 | |
9 | 869 void image_set_new_func(ImageWindow *imd, |
870 void (*func)(ImageWindow *, gpointer), | |
871 gpointer data) | |
1 | 872 { |
9 | 873 imd->func_new = func; |
874 imd->data_new = data; | |
875 } | |
876 | |
877 | |
878 void image_set_button_func(ImageWindow *imd, | |
879 void (*func)(ImageWindow *, gint button, guint32 time, gdouble x, gdouble y, guint state, gpointer), | |
880 gpointer data) | |
881 { | |
882 imd->func_button = func; | |
883 imd->data_button = data; | |
884 } | |
885 | |
886 void image_set_scroll_func(ImageWindow *imd, | |
887 void (*func)(ImageWindow *, GdkScrollDirection direction, guint32 time, gdouble x, gdouble y, guint state, gpointer), | |
888 gpointer data) | |
1 | 889 { |
9 | 890 imd->func_scroll = func; |
891 imd->data_scroll = data; | |
1 | 892 } |
893 | |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
894 void image_set_scroll_notify_func(ImageWindow *imd, |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
895 void (*func)(ImageWindow *imd, gint x, gint y, gint width, gint height, gpointer data), |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
896 gpointer data) |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
897 { |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
898 imd->func_scroll_notify = func; |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
899 imd->data_scroll_notify = data; |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
900 } |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
901 |
9 | 902 /* path, name */ |
903 | |
904 const gchar *image_get_path(ImageWindow *imd) | |
905 { | |
906 return imd->image_path; | |
907 } | |
908 | |
909 const gchar *image_get_name(ImageWindow *imd) | |
910 { | |
911 return imd->image_name; | |
912 } | |
913 | |
914 /* merely changes path string, does not change the image! */ | |
915 void image_set_path(ImageWindow *imd, const gchar *newpath) | |
1 | 916 { |
917 g_free(imd->image_path); | |
9 | 918 imd->image_path = g_strdup(newpath); |
919 imd->image_name = filename_from_path(imd->image_path); | |
920 | |
921 image_update_title(imd); | |
922 image_new_util(imd); | |
923 } | |
924 | |
925 /* load a new image */ | |
926 | |
927 void image_change_path(ImageWindow *imd, const gchar *path, gdouble zoom) | |
928 { | |
929 if (imd->image_path == path || | |
930 (path && imd->image_path && !strcmp(path, imd->image_path)) ) return; | |
931 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
932 image_change_real(imd, path, NULL, NULL, zoom); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
933 } |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
934 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
935 GdkPixbuf *image_get_pixbuf(ImageWindow *imd) |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
936 { |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
937 return pixbuf_renderer_get_pixbuf((PixbufRenderer *)imd->pr); |
9 | 938 } |
939 | |
940 void image_change_pixbuf(ImageWindow *imd, GdkPixbuf *pixbuf, gdouble zoom) | |
941 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
942 pixbuf_renderer_set_pixbuf((PixbufRenderer *)imd->pr, pixbuf, zoom); |
9 | 943 image_new_util(imd); |
944 } | |
945 | |
946 void image_change_from_collection(ImageWindow *imd, CollectionData *cd, CollectInfo *info, gdouble zoom) | |
947 { | |
948 if (!cd || !info || !g_list_find(cd->list, info)) return; | |
949 | |
950 image_change_real(imd, info->path, cd, info, zoom); | |
951 } | |
952 | |
953 CollectionData *image_get_collection(ImageWindow *imd, CollectInfo **info) | |
954 { | |
955 if (collection_to_number(imd->collection) >= 0) | |
956 { | |
957 if (g_list_find(imd->collection->list, imd->collection_info) != NULL) | |
958 { | |
959 if (info) *info = imd->collection_info; | |
960 } | |
961 else | |
962 { | |
963 if (info) *info = NULL; | |
964 } | |
965 return imd->collection; | |
966 } | |
967 | |
968 if (info) *info = NULL; | |
969 return NULL; | |
970 } | |
971 | |
972 static void image_loader_sync_data(ImageLoader *il, gpointer data) | |
973 { | |
974 /* change data for the callbacks directly */ | |
975 | |
976 il->data_area_ready = data; | |
977 il->data_error = data; | |
978 il->data_done = data; | |
979 il->data_percent = data; | |
1 | 980 } |
981 | |
9 | 982 /* this is more like a move function |
24
104e34f9ab1f
Wed Mar 23 00:22:28 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
983 * it moves most data from source to imd |
9 | 984 */ |
985 void image_change_from_image(ImageWindow *imd, ImageWindow *source) | |
986 { | |
987 if (imd == source) return; | |
988 | |
989 imd->unknown = source->unknown; | |
990 | |
991 imd->collection = source->collection; | |
992 imd->collection_info = source->collection_info; | |
993 imd->size = source->size; | |
994 imd->mtime = source->mtime; | |
995 | |
996 image_set_path(imd, image_get_path(source)); | |
997 | |
998 image_loader_free(imd->il); | |
999 imd->il = NULL; | |
1000 | |
24
104e34f9ab1f
Wed Mar 23 00:22:28 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
1001 if (source->il) |
9 | 1002 { |
1003 imd->il = source->il; | |
1004 source->il = NULL; | |
1005 | |
1006 image_loader_sync_data(imd->il, imd); | |
1007 | |
1008 imd->delay_alter_type = source->delay_alter_type; | |
1009 source->delay_alter_type = ALTER_NONE; | |
1010 } | |
1011 | |
1012 image_loader_free(imd->read_ahead_il); | |
1013 imd->read_ahead_il = source->read_ahead_il; | |
1014 source->read_ahead_il = NULL; | |
1015 if (imd->read_ahead_il) image_loader_sync_data(imd->read_ahead_il, imd); | |
1016 | |
1017 if (imd->read_ahead_pixbuf) g_object_unref(imd->read_ahead_pixbuf); | |
1018 imd->read_ahead_pixbuf = source->read_ahead_pixbuf; | |
1019 source->read_ahead_pixbuf = NULL; | |
1020 | |
1021 g_free(imd->read_ahead_path); | |
1022 imd->read_ahead_path = source->read_ahead_path; | |
1023 source->read_ahead_path = NULL; | |
1024 | |
1025 if (imd->prev_pixbuf) g_object_unref(imd->prev_pixbuf); | |
1026 imd->prev_pixbuf = source->prev_pixbuf; | |
1027 source->prev_pixbuf = NULL; | |
1028 | |
1029 g_free(imd->prev_path); | |
1030 imd->prev_path = source->prev_path; | |
1031 source->prev_path = NULL; | |
1032 | |
1033 imd->completed = source->completed; | |
1034 | |
24
104e34f9ab1f
Wed Mar 23 00:22:28 2005 John Ellis <johne@verizon.net>
gqview
parents:
23
diff
changeset
|
1035 pixbuf_renderer_move(PIXBUF_RENDERER(imd->pr), PIXBUF_RENDERER(source->pr)); |
9 | 1036 } |
1037 | |
1038 /* manipulation */ | |
1039 | |
1040 void image_area_changed(ImageWindow *imd, gint x, gint y, gint width, gint height) | |
1041 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1042 pixbuf_renderer_area_changed((PixbufRenderer *)imd->pr, x, y, width, height); |
9 | 1043 } |
1044 | |
1045 void image_reload(ImageWindow *imd) | |
1046 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1047 if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return; |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1048 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1049 image_change_complete(imd, image_zoom_get(imd), FALSE); |
9 | 1050 } |
1051 | |
1052 void image_scroll(ImageWindow *imd, gint x, gint y) | |
1053 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1054 pixbuf_renderer_scroll((PixbufRenderer *)imd->pr, x, y); |
9 | 1055 } |
1056 | |
13
ef790149ae21
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
12
diff
changeset
|
1057 void image_scroll_to_point(ImageWindow *imd, gint x, gint y, |
ef790149ae21
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
12
diff
changeset
|
1058 gdouble x_align, gdouble y_align) |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1059 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1060 pixbuf_renderer_scroll_to_point((PixbufRenderer *)imd->pr, x, y, x_align, y_align); |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1061 } |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1062 |
9 | 1063 void image_alter(ImageWindow *imd, AlterType type) |
1 | 1064 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1065 if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return; |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1066 |
9 | 1067 if (imd->il) |
1068 { | |
1069 /* still loading, wait till done */ | |
1070 imd->delay_alter_type = type; | |
1071 return; | |
1072 } | |
1073 | |
1074 image_alter_real(imd, type, TRUE); | |
1075 } | |
1076 | |
1077 void image_zoom_adjust(ImageWindow *imd, gdouble increment) | |
1078 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1079 pixbuf_renderer_zoom_adjust((PixbufRenderer *)imd->pr, increment); |
9 | 1080 } |
1081 | |
1082 void image_zoom_adjust_at_point(ImageWindow *imd, gdouble increment, gint x, gint y) | |
1083 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1084 pixbuf_renderer_zoom_adjust_at_point((PixbufRenderer *)imd->pr, increment, x, y); |
9 | 1085 } |
1086 | |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1087 void image_zoom_set_limits(ImageWindow *imd, gdouble min, gdouble max) |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1088 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1089 pixbuf_renderer_zoom_set_limits((PixbufRenderer *)imd->pr, min, max); |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1090 } |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1091 |
9 | 1092 void image_zoom_set(ImageWindow *imd, gdouble zoom) |
1093 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1094 pixbuf_renderer_zoom_set((PixbufRenderer *)imd->pr, zoom); |
9 | 1095 } |
1096 | |
1097 void image_zoom_set_fill_geometry(ImageWindow *imd, gint vertical) | |
1098 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1099 PixbufRenderer *pr; |
9 | 1100 gdouble zoom; |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1101 gint width, height; |
9 | 1102 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1103 pr = (PixbufRenderer *)imd->pr; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1104 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1105 if (!pixbuf_renderer_get_pixbuf(pr) || |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1106 !pixbuf_renderer_get_image_size(pr, &width, &height)) return; |
9 | 1107 |
1108 if (vertical) | |
1109 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1110 zoom = (gdouble)pr->window_height / height; |
9 | 1111 } |
1112 else | |
1113 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1114 zoom = (gdouble)pr->window_width / width; |
9 | 1115 } |
1116 | |
1117 if (zoom < 1.0) | |
1118 { | |
1119 zoom = 0.0 - 1.0 / zoom; | |
1 | 1120 } |
9 | 1121 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1122 pixbuf_renderer_zoom_set(pr, zoom); |
9 | 1123 } |
1124 | |
1125 gdouble image_zoom_get(ImageWindow *imd) | |
1126 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1127 return pixbuf_renderer_zoom_get((PixbufRenderer *)imd->pr); |
9 | 1128 } |
1129 | |
1130 gdouble image_zoom_get_real(ImageWindow *imd) | |
1131 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1132 return pixbuf_renderer_zoom_get_scale((PixbufRenderer *)imd->pr); |
9 | 1133 } |
1134 | |
1135 gchar *image_zoom_get_as_text(ImageWindow *imd) | |
1136 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1137 gdouble zoom; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1138 gdouble scale; |
9 | 1139 gdouble l = 1.0; |
1140 gdouble r = 1.0; | |
1141 gint pl = 0; | |
1142 gint pr = 0; | |
1143 gchar *approx = " "; | |
1144 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1145 zoom = image_zoom_get(imd); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1146 scale = image_zoom_get_real(imd); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1147 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1148 if (zoom > 0.0) |
1 | 1149 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1150 l = zoom; |
9 | 1151 } |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1152 else if (zoom < 0.0) |
9 | 1153 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1154 r = 0.0 - zoom; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1155 } |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1156 else if (zoom == 0.0 && scale != 0.0) |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1157 { |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1158 if (scale >= 1.0) |
9 | 1159 { |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1160 l = scale; |
9 | 1161 } |
1162 else | |
1163 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1164 r = 1.0 / scale; |
9 | 1165 } |
1166 approx = " ~"; | |
1167 } | |
1168 | |
1169 if (rint(l) != l) pl = 1; | |
1170 if (rint(r) != r) pr = 1; | |
1171 | |
1172 return g_strdup_printf("%.*f :%s%.*f", pl, l, approx, pr, r); | |
1173 } | |
1174 | |
1175 gdouble image_zoom_get_default(ImageWindow *imd, gint mode) | |
1176 { | |
1177 gdouble zoom; | |
1178 | |
1179 if (mode == ZOOM_RESET_ORIGINAL) | |
1180 { | |
1181 zoom = 1.0; | |
1182 } | |
1183 else if (mode == ZOOM_RESET_FIT_WINDOW) | |
1184 { | |
1185 zoom = 0.0; | |
1 | 1186 } |
1187 else | |
1188 { | |
1189 if (imd) | |
1190 { | |
9 | 1191 zoom = image_zoom_get(imd); |
1 | 1192 } |
1193 else | |
1194 { | |
9 | 1195 zoom = 1.0; |
1 | 1196 } |
1197 } | |
1198 | |
1199 return zoom; | |
1200 } | |
1201 | |
9 | 1202 /* read ahead */ |
1203 | |
1204 void image_prebuffer_set(ImageWindow *imd, const gchar *path) | |
1205 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1206 if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return; |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1207 |
9 | 1208 if (path) |
1209 { | |
1210 image_read_ahead_set(imd, path); | |
1211 } | |
1212 else | |
1213 { | |
1214 image_read_ahead_cancel(imd); | |
1215 } | |
1216 } | |
1217 | |
1218 static gint image_auto_refresh_cb(gpointer data) | |
1219 { | |
1220 ImageWindow *imd = data; | |
1221 time_t newtime; | |
1222 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1223 if (!imd || !image_get_pixbuf(imd) || |
9 | 1224 imd->il || !imd->image_path || |
1225 !update_on_time_change) return TRUE; | |
1226 | |
1227 newtime = filetime(imd->image_path); | |
1228 if (newtime > 0 && newtime != imd->mtime) | |
1229 { | |
1230 imd->mtime = newtime; | |
1231 image_reload(imd); | |
1232 } | |
1233 | |
1234 return TRUE; | |
1235 } | |
1236 | |
1237 /* image auto refresh on time stamp change, in 1/1000's second, -1 disables */ | |
1238 | |
1239 void image_auto_refresh(ImageWindow *imd, gint interval) | |
1240 { | |
1241 if (!imd) return; | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1242 if (pixbuf_renderer_get_tiles((PixbufRenderer *)imd->pr)) return; |
9 | 1243 |
1244 if (imd->auto_refresh_id > -1) | |
1245 { | |
1246 g_source_remove(imd->auto_refresh_id); | |
1247 imd->auto_refresh_id = -1; | |
1248 imd->auto_refresh_interval = -1; | |
1249 } | |
1250 | |
1251 if (interval < 0) return; | |
1252 | |
1253 if (interval == 0) interval = IMAGE_AUTO_REFRESH_TIME; | |
1254 | |
1255 imd->auto_refresh_id = g_timeout_add((guint32)interval, image_auto_refresh_cb, imd); | |
1256 imd->auto_refresh_interval = interval; | |
1257 } | |
1258 | |
1259 void image_top_window_set_sync(ImageWindow *imd, gint allow_sync) | |
1260 { | |
1261 imd->top_window_sync = allow_sync; | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1262 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1263 g_object_set(G_OBJECT(imd->pr), "window_fit", allow_sync, NULL); |
9 | 1264 } |
1265 | |
1266 void image_background_set_black(ImageWindow *imd, gint black) | |
1267 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1268 pixbuf_renderer_set_black((PixbufRenderer *)imd->pr, black); |
9 | 1269 } |
1270 | |
1271 void image_background_set_color(ImageWindow *imd, GdkColor *color) | |
1272 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1273 pixbuf_renderer_set_color((PixbufRenderer *)imd->pr, color); |
9 | 1274 } |
1275 | |
1276 void image_set_delay_flip(ImageWindow *imd, gint delay) | |
1277 { | |
1278 if (!imd || | |
1279 imd->delay_flip == delay) return; | |
1280 | |
1281 imd->delay_flip = delay; | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1282 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1283 g_object_set(G_OBJECT(imd->pr), "delay_flip", delay, NULL); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1284 |
9 | 1285 if (!imd->delay_flip && imd->il) |
1286 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1287 PixbufRenderer *pr; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1288 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1289 pr = PIXBUF_RENDERER(imd->pr); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1290 if (pr->pixbuf) g_object_unref(pr->pixbuf); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1291 pr->pixbuf = NULL; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1292 |
9 | 1293 image_load_pixbuf_ready(imd); |
1294 } | |
1295 } | |
1296 | |
1297 void image_to_root_window(ImageWindow *imd, gint scaled) | |
1298 { | |
1299 GdkScreen *screen; | |
3 | 1300 GdkWindow *rootwindow; |
1301 GdkPixmap *pixmap; | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1302 GdkPixbuf *pixbuf; |
9 | 1303 GdkPixbuf *pb; |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1304 gint width, height; |
9 | 1305 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1306 if (!imd) return; |
9 | 1307 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1308 pixbuf = image_get_pixbuf(imd); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1309 if (!pixbuf) return; |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1310 |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1311 screen = gtk_widget_get_screen(imd->widget); |
9 | 1312 rootwindow = gdk_screen_get_root_window(screen); |
1313 if (gdk_drawable_get_visual(rootwindow) != gdk_visual_get_system()) return; | |
3 | 1314 |
1315 if (scaled) | |
1316 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1317 width = gdk_screen_width(); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1318 height = gdk_screen_height(); |
3 | 1319 } |
1320 else | |
1321 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1322 pixbuf_renderer_get_scaled_size((PixbufRenderer *)imd->pr, &width, &height); |
3 | 1323 } |
1324 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1325 pb = gdk_pixbuf_scale_simple(pixbuf, width, height, (GdkInterpType)zoom_quality); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1326 |
9 | 1327 gdk_pixbuf_render_pixmap_and_mask (pb, &pixmap, NULL, 128); |
3 | 1328 gdk_window_set_back_pixmap(rootwindow, pixmap, FALSE); |
1329 gdk_window_clear(rootwindow); | |
9 | 1330 g_object_unref(pb); |
1331 g_object_unref(pixmap); | |
3 | 1332 |
1333 gdk_flush(); | |
1334 } | |
1335 | |
9 | 1336 /* |
1337 *------------------------------------------------------------------- | |
26
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1338 * prefs sync |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1339 *------------------------------------------------------------------- |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1340 */ |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1341 |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1342 static void image_options_set(ImageWindow *imd) |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1343 { |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1344 g_object_set(G_OBJECT(imd->pr), "zoom_quality", zoom_quality, |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1345 "zoom_2pass", two_pass_zoom, |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1346 "zoom_expand", zoom_to_fit_expands, |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1347 "dither_quality", dither_quality, |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1348 "scroll_reset", scroll_reset_method, |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1349 "cache_display", tile_cache_max, |
29
8a8ec4b3e769
Sun Apr 3 00:36:22 2005 John Ellis <johne@verizon.net>
gqview
parents:
27
diff
changeset
|
1350 "window_fit", (imd->top_window_sync && fit_window), |
26
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1351 "window_limit", limit_window_size, |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1352 "window_limit_value", max_window_size, |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1353 NULL); |
27
9c24765c2d3a
Sat Apr 2 17:28:16 2005 John Ellis <johne@verizon.net>
gqview
parents:
26
diff
changeset
|
1354 |
9c24765c2d3a
Sat Apr 2 17:28:16 2005 John Ellis <johne@verizon.net>
gqview
parents:
26
diff
changeset
|
1355 pixbuf_renderer_set_parent((PixbufRenderer *)imd->pr, (GtkWindow *)imd->top_window); |
26
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1356 } |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1357 |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1358 void image_options_sync(void) |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1359 { |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1360 GList *work; |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1361 |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1362 work = image_list; |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1363 while (work) |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1364 { |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1365 ImageWindow *imd; |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1366 |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1367 imd = work->data; |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1368 work = work->next; |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1369 |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1370 image_options_set(imd); |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1371 } |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1372 } |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1373 |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1374 /* |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1375 *------------------------------------------------------------------- |
9 | 1376 * init / destroy |
1377 *------------------------------------------------------------------- | |
1378 */ | |
1379 | |
1380 static void image_free(ImageWindow *imd) | |
1381 { | |
26
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1382 image_list = g_list_remove(image_list, imd); |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1383 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1384 image_reset(imd); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1385 |
9 | 1386 image_read_ahead_cancel(imd); |
1387 image_post_buffer_set(imd, NULL, NULL); | |
1388 image_auto_refresh(imd, -1); | |
1389 | |
1390 g_free(imd->image_path); | |
1391 g_free(imd->title); | |
1392 g_free(imd->title_right); | |
1393 | |
1394 g_free(imd); | |
1395 } | |
1396 | |
1397 static void image_destroy_cb(GtkObject *widget, gpointer data) | |
1398 { | |
1399 ImageWindow *imd = data; | |
1400 image_free(imd); | |
1401 } | |
1402 | |
1403 ImageWindow *image_new(gint frame) | |
1404 { | |
1405 ImageWindow *imd; | |
1406 | |
1407 imd = g_new0(ImageWindow, 1); | |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1408 |
9 | 1409 imd->top_window = NULL; |
1410 imd->title = NULL; | |
1411 imd->title_right = NULL; | |
1412 imd->title_show_zoom = FALSE; | |
1413 | |
1414 imd->unknown = TRUE; | |
1415 | |
1416 imd->has_frame = frame; | |
1417 imd->top_window_sync = FALSE; | |
1418 | |
1419 imd->delay_alter_type = ALTER_NONE; | |
1420 | |
1421 imd->read_ahead_il = NULL; | |
1422 imd->read_ahead_pixbuf = NULL; | |
1423 imd->read_ahead_path = NULL; | |
1424 | |
1425 imd->completed = FALSE; | |
1426 | |
1427 imd->auto_refresh_id = -1; | |
1428 imd->auto_refresh_interval = -1; | |
1429 | |
1430 imd->delay_flip = FALSE; | |
1431 | |
1432 imd->func_update = NULL; | |
1433 imd->func_complete = NULL; | |
12
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1434 imd->func_tile_request = NULL; |
147f4c4b9025
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
1435 imd->func_tile_dispose = NULL; |
9 | 1436 |
1437 imd->func_button = NULL; | |
1438 imd->func_scroll = NULL; | |
1439 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1440 imd->pr = GTK_WIDGET(pixbuf_renderer_new()); |
9 | 1441 |
26
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1442 image_options_set(imd); |
9 | 1443 |
1444 if (imd->has_frame) | |
1445 { | |
1446 imd->widget = gtk_frame_new(NULL); | |
1447 gtk_frame_set_shadow_type(GTK_FRAME(imd->widget), GTK_SHADOW_IN); | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1448 gtk_container_add(GTK_CONTAINER(imd->widget), imd->pr); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1449 gtk_widget_show(imd->pr); |
9 | 1450 |
1451 GTK_WIDGET_SET_FLAGS(imd->widget, GTK_CAN_FOCUS); | |
1452 g_signal_connect(G_OBJECT(imd->widget), "focus_in_event", | |
1453 G_CALLBACK(image_focus_in_cb), imd); | |
1454 g_signal_connect(G_OBJECT(imd->widget), "focus_out_event", | |
1455 G_CALLBACK(image_focus_out_cb), imd); | |
1456 | |
1457 g_signal_connect_after(G_OBJECT(imd->widget), "expose_event", | |
1458 G_CALLBACK(image_focus_expose), imd); | |
1459 } | |
1460 else | |
1461 { | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1462 imd->widget = imd->pr; |
9 | 1463 } |
1464 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1465 g_signal_connect(G_OBJECT(imd->pr), "clicked", |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1466 G_CALLBACK(image_click_cb), imd); |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1467 g_signal_connect(G_OBJECT(imd->pr), "scroll_notify", |
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1468 G_CALLBACK(image_scroll_notify_cb), imd); |
9 | 1469 |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1470 g_signal_connect(G_OBJECT(imd->pr), "scroll_event", |
9 | 1471 G_CALLBACK(image_scroll_cb), imd); |
1472 | |
23
17acca639a86
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
14
diff
changeset
|
1473 g_signal_connect(G_OBJECT(imd->pr), "destroy", |
9 | 1474 G_CALLBACK(image_destroy_cb), imd); |
1475 | |
25
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
1476 g_signal_connect(G_OBJECT(imd->pr), "zoom", |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
1477 G_CALLBACK(image_zoom_cb), imd); |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
1478 g_signal_connect(G_OBJECT(imd->pr), "render_complete", |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
1479 G_CALLBACK(image_render_complete_cb), imd); |
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
24
diff
changeset
|
1480 |
26
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1481 image_list = g_list_append(image_list, imd); |
acd9885ebd78
Mon Mar 28 20:23:34 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
1482 |
9 | 1483 return imd; |
1484 } | |
1485 |