Mercurial > geeqie
comparison src/thumb.c @ 864:f40509d56fe3
added pixbuf_fallback function
fixed thumb loader for non-image files
author | nadvornik |
---|---|
date | Fri, 27 Jun 2008 21:09:15 +0000 |
parents | 0c3f6ef17d18 |
children | 5169bd198d5a |
comparison
equal
deleted
inserted
replaced
863:8ddd00cc8b69 | 864:f40509d56fe3 |
---|---|
360 | 360 |
361 if (!tl->fd && !fd) return FALSE; | 361 if (!tl->fd && !fd) return FALSE; |
362 | 362 |
363 if (!tl->fd) tl->fd = file_data_ref(fd); | 363 if (!tl->fd) tl->fd = file_data_ref(fd); |
364 | 364 |
365 if (tl->fd->thumb_pixbuf) g_object_unref(tl->fd->thumb_pixbuf); | |
366 tl->fd->thumb_pixbuf = pixbuf_fallback(tl->fd, tl->max_w, tl->max_h); | |
367 | |
365 if (tl->cache_enable) | 368 if (tl->cache_enable) |
366 { | 369 { |
367 cache_path = cache_find_location(CACHE_TYPE_THUMB, tl->fd->path); | 370 cache_path = cache_find_location(CACHE_TYPE_THUMB, tl->fd->path); |
368 | 371 |
369 if (cache_path) | 372 if (cache_path) |
445 | 448 |
446 return thumb_loader_get_space(tl); | 449 return thumb_loader_get_space(tl); |
447 } | 450 } |
448 #endif | 451 #endif |
449 | 452 |
450 GdkPixbuf *thumb_loader_get_pixbuf(ThumbLoader *tl, gint with_fallback) | 453 GdkPixbuf *thumb_loader_get_pixbuf(ThumbLoader *tl) |
451 { | 454 { |
452 GdkPixbuf *pixbuf; | 455 GdkPixbuf *pixbuf; |
453 | 456 |
454 if (tl && tl->standard_loader) | 457 if (tl && tl->standard_loader) |
455 { | 458 { |
456 return thumb_loader_std_get_pixbuf((ThumbLoaderStd *)tl, with_fallback); | 459 return thumb_loader_std_get_pixbuf((ThumbLoaderStd *)tl); |
457 } | 460 } |
458 | 461 |
459 if (tl && tl->fd && tl->fd->thumb_pixbuf) | 462 if (tl && tl->fd && tl->fd->thumb_pixbuf) |
460 { | 463 { |
461 pixbuf = tl->fd->thumb_pixbuf; | 464 pixbuf = tl->fd->thumb_pixbuf; |
462 g_object_ref(pixbuf); | 465 g_object_ref(pixbuf); |
463 } | 466 } |
464 else if (with_fallback) | |
465 { | |
466 gint w, h; | |
467 | |
468 pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN); | |
469 w = gdk_pixbuf_get_width(pixbuf); | |
470 h = gdk_pixbuf_get_height(pixbuf); | |
471 if ((w > tl->max_w || h > tl->max_h) && | |
472 normalize_thumb(&w, &h, tl->max_w, tl->max_h)) | |
473 { | |
474 GdkPixbuf *tmp; | |
475 | |
476 tmp = pixbuf; | |
477 pixbuf = gdk_pixbuf_scale_simple(tmp, w, h, GDK_INTERP_NEAREST); | |
478 gdk_pixbuf_unref(tmp); | |
479 } | |
480 } | |
481 else | 467 else |
482 { | 468 { |
483 pixbuf = NULL; | 469 pixbuf = pixbuf_fallback(NULL, tl->max_w, tl->max_h); |
484 } | 470 } |
485 | 471 |
486 return pixbuf; | 472 return pixbuf; |
487 } | 473 } |
488 | 474 |
548 | 534 |
549 pixbuf = gdk_pixbuf_new_from_xpm_data(data); | 535 pixbuf = gdk_pixbuf_new_from_xpm_data(data); |
550 w = gdk_pixbuf_get_width(pixbuf); | 536 w = gdk_pixbuf_get_width(pixbuf); |
551 h = gdk_pixbuf_get_height(pixbuf); | 537 h = gdk_pixbuf_get_height(pixbuf); |
552 | 538 |
553 if ((w > max_w || h > max_h) && | 539 if (pixbuf_scale_aspect(w, h, max_w, max_h, &w, &h)) |
554 normalize_thumb(&w, &h, max_w, max_h)) | |
555 { | 540 { |
556 /* scale */ | 541 /* scale */ |
557 GdkPixbuf *tmp; | 542 GdkPixbuf *tmp; |
558 | 543 |
559 tmp = pixbuf; | 544 tmp = pixbuf; |
616 *widthp = width; | 601 *widthp = width; |
617 *heightp = height; | 602 *heightp = height; |
618 return data; | 603 return data; |
619 } | 604 } |
620 #undef XV_BUFFER | 605 #undef XV_BUFFER |
621 | |
622 static gint normalize_thumb(gint *width, gint *height, gint max_w, gint max_h) | |
623 { | |
624 gdouble scale; | |
625 gint new_w, new_h; | |
626 | |
627 scale = MIN((gdouble) max_w / *width, (gdouble) max_h / *height); | |
628 new_w = *width * scale; | |
629 new_h = *height * scale; | |
630 | |
631 if (new_w != *width || new_h != *height) | |
632 { | |
633 *width = new_w; | |
634 *height = new_h; | |
635 return TRUE; | |
636 } | |
637 | |
638 return FALSE; | |
639 } | |
640 | 606 |
641 static void free_rgb_buffer(guchar *pixels, gpointer data) | 607 static void free_rgb_buffer(guchar *pixels, gpointer data) |
642 { | 608 { |
643 g_free(pixels); | 609 g_free(pixels); |
644 } | 610 } |
681 g_free(packed_data); | 647 g_free(packed_data); |
682 | 648 |
683 pixbuf = gdk_pixbuf_new_from_data(rgb_data, GDK_COLORSPACE_RGB, FALSE, 8, | 649 pixbuf = gdk_pixbuf_new_from_data(rgb_data, GDK_COLORSPACE_RGB, FALSE, 8, |
684 width, height, 3 * width, free_rgb_buffer, NULL); | 650 width, height, 3 * width, free_rgb_buffer, NULL); |
685 | 651 |
686 if (normalize_thumb(&width, &height, max_w, max_h)) | 652 if (pixbuf_scale_aspect(width, height, max_w, max_h, &width, &height)) |
687 { | 653 { |
688 /* scale */ | 654 /* scale */ |
689 GdkPixbuf *tmp; | 655 GdkPixbuf *tmp; |
690 | 656 |
691 tmp = pixbuf; | 657 tmp = pixbuf; |