Mercurial > geeqie
comparison src/image-load.c @ 138:71e1ebee420e
replaced gchar* path with FileData *fd
author | nadvornik |
---|---|
date | Tue, 11 Sep 2007 20:06:29 +0000 |
parents | 9c0c402b0ef3 |
children | 695e1ad3b169 |
comparison
equal
deleted
inserted
replaced
137:be3328a58875 | 138:71e1ebee420e |
---|---|
10 */ | 10 */ |
11 | 11 |
12 | 12 |
13 #include "gqview.h" | 13 #include "gqview.h" |
14 #include "image-load.h" | 14 #include "image-load.h" |
15 #include "filelist.h" | |
15 | 16 |
16 #include "format_raw.h" | 17 #include "format_raw.h" |
17 #include "ui_fileops.h" | 18 #include "ui_fileops.h" |
18 | 19 |
19 #include <fcntl.h> | 20 #include <fcntl.h> |
22 /* bytes to read from file per read() */ | 23 /* bytes to read from file per read() */ |
23 #define IMAGE_LOADER_BUFFER_SIZE 512 | 24 #define IMAGE_LOADER_BUFFER_SIZE 512 |
24 | 25 |
25 /* the number of bytes to read per idle call (define x IMAGE_LOADER_BUFFER_SIZE) */ | 26 /* the number of bytes to read per idle call (define x IMAGE_LOADER_BUFFER_SIZE) */ |
26 #define IMAGE_LOADER_BUFFER_DEFAULT_COUNT 1 | 27 #define IMAGE_LOADER_BUFFER_DEFAULT_COUNT 1 |
28 | |
29 static const gchar *image_loader_path(ImageLoader *il) | |
30 { | |
31 if (il->fd) | |
32 return il->fd->path; | |
33 return il->path; | |
34 } | |
27 | 35 |
28 static void image_loader_sync_pixbuf(ImageLoader *il) | 36 static void image_loader_sync_pixbuf(ImageLoader *il) |
29 { | 37 { |
30 GdkPixbuf *pb; | 38 GdkPixbuf *pb; |
31 | 39 |
159 | 167 |
160 static void image_loader_error(ImageLoader *il) | 168 static void image_loader_error(ImageLoader *il) |
161 { | 169 { |
162 image_loader_stop(il); | 170 image_loader_stop(il); |
163 | 171 |
164 if (debug) printf("pixbuf_loader reported load error for: %s\n", il->path); | 172 if (debug) printf("pixbuf_loader reported load error for: %s\n", image_loader_path(il)); |
165 | 173 |
166 if (il->func_error) il->func_error(il, il->data_error); | 174 if (il->func_error) il->func_error(il, il->data_error); |
167 } | 175 } |
168 | 176 |
169 static gint image_loader_idle_cb(gpointer data) | 177 static gint image_loader_idle_cb(gpointer data) |
216 if (!il->loader || il->pixbuf) return FALSE; | 224 if (!il->loader || il->pixbuf) return FALSE; |
217 | 225 |
218 b = read(il->load_fd, &buf, sizeof(buf)); | 226 b = read(il->load_fd, &buf, sizeof(buf)); |
219 | 227 |
220 if (b > 0 && | 228 if (b > 0 && |
221 format_raw_img_exif_offsets_fd(il->load_fd, il->path, buf, b, &offset, NULL)) | 229 format_raw_img_exif_offsets_fd(il->load_fd, image_loader_path(il), buf, b, &offset, NULL)) |
222 { | 230 { |
223 if (debug) printf("Raw file %s contains embedded image\n", il->path); | 231 if (debug) printf("Raw file %s contains embedded image\n", image_loader_path(il)); |
224 | 232 |
225 b = read(il->load_fd, &buf, sizeof(buf)); | 233 b = read(il->load_fd, &buf, sizeof(buf)); |
226 } | 234 } |
227 | 235 |
228 if (b < 1) | 236 if (b < 1) |
280 struct stat st; | 288 struct stat st; |
281 gchar *pathl; | 289 gchar *pathl; |
282 | 290 |
283 if (!il || il->load_fd != -1 || il->loader) return FALSE; | 291 if (!il || il->load_fd != -1 || il->loader) return FALSE; |
284 | 292 |
285 pathl = path_from_utf8(il->path); | 293 pathl = path_from_utf8(image_loader_path(il)); |
286 il->load_fd = open(pathl, O_RDONLY | O_NONBLOCK); | 294 il->load_fd = open(pathl, O_RDONLY | O_NONBLOCK); |
287 g_free(pathl); | 295 g_free(pathl); |
288 if (il->load_fd == -1) return FALSE; | 296 if (il->load_fd == -1) return FALSE; |
289 | 297 |
290 if (fstat(il->load_fd, &st) == 0) | 298 if (fstat(il->load_fd, &st) == 0) |
301 il->shrunk = FALSE; | 309 il->shrunk = FALSE; |
302 | 310 |
303 return image_loader_begin(il); | 311 return image_loader_begin(il); |
304 } | 312 } |
305 | 313 |
306 ImageLoader *image_loader_new(const gchar *path) | 314 static ImageLoader *image_loader_new_real(FileData *fd, const gchar *path) |
307 { | 315 { |
308 ImageLoader *il; | 316 ImageLoader *il; |
309 | 317 |
310 if (!path) return NULL; | 318 if (!fd && !path) return NULL; |
311 | 319 |
312 il = g_new0(ImageLoader, 1); | 320 il = g_new0(ImageLoader, 1); |
321 if (fd) il->fd = file_data_ref(fd); | |
313 if (path) il->path = g_strdup(path); | 322 if (path) il->path = g_strdup(path); |
314 il->pixbuf = NULL; | 323 il->pixbuf = NULL; |
315 il->idle_id = -1; | 324 il->idle_id = -1; |
316 il->idle_priority = G_PRIORITY_DEFAULT_IDLE; | 325 il->idle_priority = G_PRIORITY_DEFAULT_IDLE; |
317 il->done = FALSE; | 326 il->done = FALSE; |
330 il->shrunk = FALSE; | 339 il->shrunk = FALSE; |
331 | 340 |
332 return il; | 341 return il; |
333 } | 342 } |
334 | 343 |
344 ImageLoader *image_loader_new(FileData *fd) | |
345 { | |
346 return image_loader_new_real(fd, NULL); | |
347 } | |
348 | |
349 ImageLoader *image_loader_new_from_path(const gchar *path) | |
350 { | |
351 return image_loader_new_real(NULL, path); | |
352 } | |
353 | |
335 void image_loader_free(ImageLoader *il) | 354 void image_loader_free(ImageLoader *il) |
336 { | 355 { |
337 if (!il) return; | 356 if (!il) return; |
338 | 357 |
339 image_loader_stop(il); | 358 image_loader_stop(il); |
340 if (il->idle_done_id != -1) g_source_remove(il->idle_done_id); | 359 if (il->idle_done_id != -1) g_source_remove(il->idle_done_id); |
341 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf); | 360 if (il->pixbuf) gdk_pixbuf_unref(il->pixbuf); |
342 g_free(il->path); | 361 if (il->fd) file_data_unref(il->fd); |
362 if (il->path) g_free(il->path); | |
343 g_free(il); | 363 g_free(il); |
344 } | 364 } |
345 | 365 |
346 /* don't forget to gdk_pixbuf_ref() it if you want to use it after image_loader_free() */ | 366 /* don't forget to gdk_pixbuf_ref() it if you want to use it after image_loader_free() */ |
347 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il) | 367 GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il) |
426 | 446 |
427 gint image_loader_start(ImageLoader *il, void (*func_done)(ImageLoader *, gpointer), gpointer data_done) | 447 gint image_loader_start(ImageLoader *il, void (*func_done)(ImageLoader *, gpointer), gpointer data_done) |
428 { | 448 { |
429 if (!il) return FALSE; | 449 if (!il) return FALSE; |
430 | 450 |
431 if (!il->path) return FALSE; | 451 if (!image_loader_path(il)) return FALSE; |
432 | 452 |
433 il->func_done = func_done; | 453 il->func_done = func_done; |
434 il->data_done = data_done; | 454 il->data_done = data_done; |
435 | 455 |
436 return image_loader_setup(il); | 456 return image_loader_setup(il); |
448 if (!il) return FALSE; | 468 if (!il) return FALSE; |
449 | 469 |
450 return il->done; | 470 return il->done; |
451 } | 471 } |
452 | 472 |
453 gint image_load_dimensions(const gchar *path, gint *width, gint *height) | 473 gint image_load_dimensions(FileData *fd, gint *width, gint *height) |
454 { | 474 { |
455 ImageLoader *il; | 475 ImageLoader *il; |
456 gint success; | 476 gint success; |
457 | 477 |
458 il = image_loader_new(path); | 478 il = image_loader_new(fd); |
459 | 479 |
460 success = image_loader_start(il, NULL, NULL); | 480 success = image_loader_start(il, NULL, NULL); |
461 | 481 |
462 if (success && il->pixbuf) | 482 if (success && il->pixbuf) |
463 { | 483 { |