comparison src/thumb_standard.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 06929cbcd796
children 2d8705f33da5
comparison
equal deleted inserted replaced
863:8ddd00cc8b69 864:f40509d56fe3
374 } 374 }
375 375
376 g_object_unref(G_OBJECT(pixbuf)); 376 g_object_unref(G_OBJECT(pixbuf));
377 } 377 }
378 378
379 static gint thumb_loader_std_scale_aspect(gint req_w, gint req_h, gint old_w, gint old_h,
380 gint *new_w, gint *new_h)
381 {
382 if (((gdouble)req_w / old_w) < ((gdouble)req_h / old_h))
383 {
384 *new_w = req_w;
385 *new_h = (gdouble)*new_w / old_w * old_h;
386 if (*new_h < 1) *new_h = 1;
387 }
388 else
389 {
390 *new_h = req_h;
391 *new_w = (gdouble)*new_h / old_h * old_w;
392 if (*new_w < 1) *new_w = 1;
393 }
394
395 return (*new_w != old_w || *new_h != old_h);
396 }
397
398 static GdkPixbuf *thumb_loader_std_finish(ThumbLoaderStd *tl, GdkPixbuf *pixbuf, gint shrunk) 379 static GdkPixbuf *thumb_loader_std_finish(ThumbLoaderStd *tl, GdkPixbuf *pixbuf, gint shrunk)
399 { 380 {
400 GdkPixbuf *pixbuf_thumb = NULL; 381 GdkPixbuf *pixbuf_thumb = NULL;
401 GdkPixbuf *result; 382 GdkPixbuf *result;
402 GdkPixbuf *rotated = NULL; 383 GdkPixbuf *rotated = NULL;
444 425
445 if (sw > cache_w || sh > cache_h || shrunk) 426 if (sw > cache_w || sh > cache_h || shrunk)
446 { 427 {
447 gint thumb_w, thumb_h; 428 gint thumb_w, thumb_h;
448 429
449 if (thumb_loader_std_scale_aspect(cache_w, cache_h, sw, sh, 430 if (pixbuf_scale_aspect(cache_w, cache_h, sw, sh,
450 &thumb_w, &thumb_h)) 431 &thumb_w, &thumb_h))
451 { 432 {
452 pixbuf_thumb = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h, 433 pixbuf_thumb = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h,
453 (GdkInterpType)options->thumbnails.quality); 434 (GdkInterpType)options->thumbnails.quality);
454 } 435 }
492 pixbuf = pixbuf_thumb; 473 pixbuf = pixbuf_thumb;
493 sw = gdk_pixbuf_get_width(pixbuf); 474 sw = gdk_pixbuf_get_width(pixbuf);
494 sh = gdk_pixbuf_get_height(pixbuf); 475 sh = gdk_pixbuf_get_height(pixbuf);
495 } 476 }
496 477
497 if (thumb_loader_std_scale_aspect(tl->requested_width, tl->requested_height, sw, sh, 478 if (pixbuf_scale_aspect(tl->requested_width, tl->requested_height, sw, sh,
498 &thumb_w, &thumb_h)) 479 &thumb_w, &thumb_h))
499 { 480 {
500 result = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h, 481 result = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h,
501 (GdkInterpType)options->thumbnails.quality); 482 (GdkInterpType)options->thumbnails.quality);
502 } 483 }
665 struct stat st; 646 struct stat st;
666 647
667 if (!tl || !fd) return FALSE; 648 if (!tl || !fd) return FALSE;
668 649
669 thumb_loader_std_reset(tl); 650 thumb_loader_std_reset(tl);
651
652 if (fd->thumb_pixbuf) g_object_unref(fd->thumb_pixbuf);
653 fd->thumb_pixbuf = pixbuf_fallback(fd, tl->requested_width, tl->requested_height);
654
670 655
671 if (!stat_utf8(fd->path, &st)) return FALSE; 656 if (!stat_utf8(fd->path, &st)) return FALSE;
672 657
673 tl->fd = file_data_ref(fd); 658 tl->fd = file_data_ref(fd);
674 tl->source_mtime = st.st_mtime; 659 tl->source_mtime = st.st_mtime;
716 701
717 thumb_loader_std_reset(tl); 702 thumb_loader_std_reset(tl);
718 g_free(tl); 703 g_free(tl);
719 } 704 }
720 705
721 GdkPixbuf *thumb_loader_std_get_pixbuf(ThumbLoaderStd *tl, gint with_fallback) 706 GdkPixbuf *thumb_loader_std_get_pixbuf(ThumbLoaderStd *tl)
722 { 707 {
723 GdkPixbuf *pixbuf; 708 GdkPixbuf *pixbuf;
724 709
725 if (tl && tl->fd && tl->fd->thumb_pixbuf) 710 if (tl && tl->fd && tl->fd->thumb_pixbuf)
726 { 711 {
727 pixbuf = tl->fd->thumb_pixbuf; 712 pixbuf = tl->fd->thumb_pixbuf;
728 g_object_ref(pixbuf); 713 g_object_ref(pixbuf);
729 } 714 }
730 else if (with_fallback)
731 {
732 gint w, h;
733
734 pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN);
735 w = gdk_pixbuf_get_width(pixbuf);
736 h = gdk_pixbuf_get_height(pixbuf);
737
738 if (w > tl->requested_width || h > tl->requested_height)
739 {
740 gint nw, nh;
741
742 if (thumb_loader_std_scale_aspect(tl->requested_width, tl->requested_height,
743 w, h, &nw, &nh))
744 {
745 GdkPixbuf *tmp;
746
747 tmp = pixbuf;
748 pixbuf = gdk_pixbuf_scale_simple(tmp, nw, nh, GDK_INTERP_TILES);
749 g_object_unref(G_OBJECT(tmp));
750 }
751 }
752 }
753 else 715 else
754 { 716 {
755 pixbuf = NULL; 717 pixbuf = pixbuf_fallback(NULL, tl->requested_width, tl->requested_height);
756 } 718 }
757 719
758 return pixbuf; 720 return pixbuf;
759 } 721 }
760 722
804 { 766 {
805 ThumbValidate *tv = data; 767 ThumbValidate *tv = data;
806 GdkPixbuf *pixbuf; 768 GdkPixbuf *pixbuf;
807 gint valid = FALSE; 769 gint valid = FALSE;
808 770
809 pixbuf = thumb_loader_std_get_pixbuf(tv->tl, FALSE); 771 /* this function is called on success, so the pixbuf should not be a fallback*/
772 pixbuf = thumb_loader_std_get_pixbuf(tv->tl);
810 if (pixbuf) 773 if (pixbuf)
811 { 774 {
812 const gchar *uri; 775 const gchar *uri;
813 const gchar *mtime_str; 776 const gchar *mtime_str;
814 777
965 static void thumb_std_maint_move_validate_cb(const gchar *path, gint valid, gpointer data) 928 static void thumb_std_maint_move_validate_cb(const gchar *path, gint valid, gpointer data)
966 { 929 {
967 TMaintMove *tm = data; 930 TMaintMove *tm = data;
968 GdkPixbuf *pixbuf; 931 GdkPixbuf *pixbuf;
969 932
970 pixbuf = thumb_loader_std_get_pixbuf(tm->tl, FALSE); 933 /* this function is called on success, so the pixbuf should not be a fallback*/
934 pixbuf = thumb_loader_std_get_pixbuf(tm->tl);
971 if (pixbuf) 935 if (pixbuf)
972 { 936 {
973 const gchar *uri; 937 const gchar *uri;
974 const gchar *mtime_str; 938 const gchar *mtime_str;
975 939
1008 thumb_loader_std_save(tm->tl, pixbuf); 972 thumb_loader_std_save(tm->tl, pixbuf);
1009 } 973 }
1010 974
1011 DEBUG_1("thumb move unlink: %s", tm->thumb_path); 975 DEBUG_1("thumb move unlink: %s", tm->thumb_path);
1012 unlink_file(tm->thumb_path); 976 unlink_file(tm->thumb_path);
977 g_object_unref(pixbuf);
1013 } 978 }
1014 979
1015 thumb_std_maint_move_step(tm); 980 thumb_std_maint_move_step(tm);
1016 } 981 }
1017 982