# HG changeset patch # User nadvornik # Date 1214600955 0 # Node ID f40509d56fe3dcaf2172c49e74f6e54c289d8455 # Parent 8ddd00cc8b69c9e01e18f97eddd92e352d8fda54 added pixbuf_fallback function fixed thumb loader for non-image files diff -r 8ddd00cc8b69 -r f40509d56fe3 src/collect-io.c --- a/src/collect-io.c Fri Jun 27 18:43:05 2008 +0000 +++ b/src/collect-io.c Fri Jun 27 21:09:15 2008 +0000 @@ -223,7 +223,7 @@ if (!cd->thumb_loader || !g_list_find(cd->list, cd->thumb_info)) return; - pixbuf = thumb_loader_get_pixbuf(cd->thumb_loader, TRUE); + pixbuf = thumb_loader_get_pixbuf(cd->thumb_loader); collection_info_set_thumb(cd->thumb_info, pixbuf); g_object_unref(pixbuf); diff -r 8ddd00cc8b69 -r f40509d56fe3 src/dupe.c --- a/src/dupe.c Fri Jun 27 18:43:05 2008 +0000 +++ b/src/dupe.c Fri Jun 27 21:09:15 2008 +0000 @@ -1264,7 +1264,7 @@ di = dw->thumb_item; if (di->pixbuf) g_object_unref(di->pixbuf); - di->pixbuf = thumb_loader_get_pixbuf(dw->thumb_loader, TRUE); + di->pixbuf = thumb_loader_get_pixbuf(dw->thumb_loader); dupe_listview_set_thumb(dw, di, NULL); } diff -r 8ddd00cc8b69 -r f40509d56fe3 src/pan-view.c --- a/src/pan-view.c Fri Jun 27 18:43:05 2008 +0000 +++ b/src/pan-view.c Fri Jun 27 21:09:15 2008 +0000 @@ -94,7 +94,7 @@ pi->queued = FALSE; if (pi->pixbuf) g_object_unref(pi->pixbuf); - pi->pixbuf = thumb_loader_get_pixbuf(tl, TRUE); + pi->pixbuf = thumb_loader_get_pixbuf(tl); rc = pi->refcount; image_area_changed(pw->imd, pi->x, pi->y, pi->width, pi->height); diff -r 8ddd00cc8b69 -r f40509d56fe3 src/pixbuf_util.c --- a/src/pixbuf_util.c Fri Jun 27 18:43:05 2008 +0000 +++ b/src/pixbuf_util.c Fri Jun 27 21:09:15 2008 +0000 @@ -131,6 +131,53 @@ return NULL; } +gint pixbuf_scale_aspect(gint req_w, gint req_h, gint old_w, gint old_h, + gint *new_w, gint *new_h) +{ + if (((gdouble)req_w / old_w) < ((gdouble)req_h / old_h)) + { + *new_w = req_w; + *new_h = (gdouble)*new_w / old_w * old_h; + if (*new_h < 1) *new_h = 1; + } + else + { + *new_h = req_h; + *new_w = (gdouble)*new_h / old_h * old_w; + if (*new_w < 1) *new_w = 1; + } + + return (*new_w != old_w || *new_h != old_h); +} + +GdkPixbuf *pixbuf_fallback(FileData *fd, gint requested_width, gint requested_height) +{ + GdkPixbuf *pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN); /* FIXME use different images according to FORMAT_CLASS */ + + if (requested_width && requested_height) + { + gint w = gdk_pixbuf_get_width(pixbuf); + gint h = gdk_pixbuf_get_height(pixbuf); + + if (w > requested_width || h > requested_height) + { + gint nw, nh; + + if (pixbuf_scale_aspect(requested_width, requested_height, + w, h, &nw, &nh)) + { + GdkPixbuf *tmp; + + tmp = pixbuf; + pixbuf = gdk_pixbuf_scale_simple(tmp, nw, nh, GDK_INTERP_TILES); + g_object_unref(G_OBJECT(tmp)); + } + } + } + return pixbuf; +} + + /* *----------------------------------------------------------------------------- * misc utils diff -r 8ddd00cc8b69 -r f40509d56fe3 src/pixbuf_util.h --- a/src/pixbuf_util.h Fri Jun 27 18:43:05 2008 +0000 +++ b/src/pixbuf_util.h Fri Jun 27 21:09:15 2008 +0000 @@ -20,6 +20,9 @@ GdkPixbuf *pixbuf_inline(const gchar *key); +GdkPixbuf *pixbuf_fallback(FileData *fd, gint requested_width, gint requested_height); + +gint pixbuf_scale_aspect(gint req_w, gint req_h, gint old_w, gint old_h, gint *new_w, gint *new_h); #define PIXBUF_INLINE_FOLDER_CLOSED "folder_closed" #define PIXBUF_INLINE_FOLDER_LOCKED "folder_locked" diff -r 8ddd00cc8b69 -r f40509d56fe3 src/thumb.c --- a/src/thumb.c Fri Jun 27 18:43:05 2008 +0000 +++ b/src/thumb.c Fri Jun 27 21:09:15 2008 +0000 @@ -362,6 +362,9 @@ if (!tl->fd) tl->fd = file_data_ref(fd); + if (tl->fd->thumb_pixbuf) g_object_unref(tl->fd->thumb_pixbuf); + tl->fd->thumb_pixbuf = pixbuf_fallback(tl->fd, tl->max_w, tl->max_h); + if (tl->cache_enable) { cache_path = cache_find_location(CACHE_TYPE_THUMB, tl->fd->path); @@ -447,13 +450,13 @@ } #endif -GdkPixbuf *thumb_loader_get_pixbuf(ThumbLoader *tl, gint with_fallback) +GdkPixbuf *thumb_loader_get_pixbuf(ThumbLoader *tl) { GdkPixbuf *pixbuf; if (tl && tl->standard_loader) { - return thumb_loader_std_get_pixbuf((ThumbLoaderStd *)tl, with_fallback); + return thumb_loader_std_get_pixbuf((ThumbLoaderStd *)tl); } if (tl && tl->fd && tl->fd->thumb_pixbuf) @@ -461,26 +464,9 @@ pixbuf = tl->fd->thumb_pixbuf; g_object_ref(pixbuf); } - else if (with_fallback) - { - gint w, h; - - pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN); - w = gdk_pixbuf_get_width(pixbuf); - h = gdk_pixbuf_get_height(pixbuf); - if ((w > tl->max_w || h > tl->max_h) && - normalize_thumb(&w, &h, tl->max_w, tl->max_h)) - { - GdkPixbuf *tmp; - - tmp = pixbuf; - pixbuf = gdk_pixbuf_scale_simple(tmp, w, h, GDK_INTERP_NEAREST); - gdk_pixbuf_unref(tmp); - } - } else { - pixbuf = NULL; + pixbuf = pixbuf_fallback(NULL, tl->max_w, tl->max_h); } return pixbuf; @@ -550,8 +536,7 @@ w = gdk_pixbuf_get_width(pixbuf); h = gdk_pixbuf_get_height(pixbuf); - if ((w > max_w || h > max_h) && - normalize_thumb(&w, &h, max_w, max_h)) + if (pixbuf_scale_aspect(w, h, max_w, max_h, &w, &h)) { /* scale */ GdkPixbuf *tmp; @@ -619,25 +604,6 @@ } #undef XV_BUFFER -static gint normalize_thumb(gint *width, gint *height, gint max_w, gint max_h) -{ - gdouble scale; - gint new_w, new_h; - - scale = MIN((gdouble) max_w / *width, (gdouble) max_h / *height); - new_w = *width * scale; - new_h = *height * scale; - - if (new_w != *width || new_h != *height) - { - *width = new_w; - *height = new_h; - return TRUE; - } - - return FALSE; -} - static void free_rgb_buffer(guchar *pixels, gpointer data) { g_free(pixels); @@ -683,7 +649,7 @@ pixbuf = gdk_pixbuf_new_from_data(rgb_data, GDK_COLORSPACE_RGB, FALSE, 8, width, height, 3 * width, free_rgb_buffer, NULL); - if (normalize_thumb(&width, &height, max_w, max_h)) + if (pixbuf_scale_aspect(width, height, max_w, max_h, &width, &height)) { /* scale */ GdkPixbuf *tmp; diff -r 8ddd00cc8b69 -r f40509d56fe3 src/thumb.h --- a/src/thumb.h Fri Jun 27 18:43:05 2008 +0000 +++ b/src/thumb.h Fri Jun 27 21:09:15 2008 +0000 @@ -26,7 +26,7 @@ gint thumb_loader_start(ThumbLoader *tl, FileData *fd); void thumb_loader_free(ThumbLoader *tl); -GdkPixbuf *thumb_loader_get_pixbuf(ThumbLoader *tl, gint with_fallback); +GdkPixbuf *thumb_loader_get_pixbuf(ThumbLoader *tl); #endif diff -r 8ddd00cc8b69 -r f40509d56fe3 src/thumb_standard.c --- a/src/thumb_standard.c Fri Jun 27 18:43:05 2008 +0000 +++ b/src/thumb_standard.c Fri Jun 27 21:09:15 2008 +0000 @@ -376,25 +376,6 @@ g_object_unref(G_OBJECT(pixbuf)); } -static gint thumb_loader_std_scale_aspect(gint req_w, gint req_h, gint old_w, gint old_h, - gint *new_w, gint *new_h) -{ - if (((gdouble)req_w / old_w) < ((gdouble)req_h / old_h)) - { - *new_w = req_w; - *new_h = (gdouble)*new_w / old_w * old_h; - if (*new_h < 1) *new_h = 1; - } - else - { - *new_h = req_h; - *new_w = (gdouble)*new_h / old_h * old_w; - if (*new_w < 1) *new_w = 1; - } - - return (*new_w != old_w || *new_h != old_h); -} - static GdkPixbuf *thumb_loader_std_finish(ThumbLoaderStd *tl, GdkPixbuf *pixbuf, gint shrunk) { GdkPixbuf *pixbuf_thumb = NULL; @@ -446,7 +427,7 @@ { gint thumb_w, thumb_h; - if (thumb_loader_std_scale_aspect(cache_w, cache_h, sw, sh, + if (pixbuf_scale_aspect(cache_w, cache_h, sw, sh, &thumb_w, &thumb_h)) { pixbuf_thumb = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h, @@ -494,7 +475,7 @@ sh = gdk_pixbuf_get_height(pixbuf); } - if (thumb_loader_std_scale_aspect(tl->requested_width, tl->requested_height, sw, sh, + if (pixbuf_scale_aspect(tl->requested_width, tl->requested_height, sw, sh, &thumb_w, &thumb_h)) { result = gdk_pixbuf_scale_simple(pixbuf, thumb_w, thumb_h, @@ -667,6 +648,10 @@ if (!tl || !fd) return FALSE; thumb_loader_std_reset(tl); + + if (fd->thumb_pixbuf) g_object_unref(fd->thumb_pixbuf); + fd->thumb_pixbuf = pixbuf_fallback(fd, tl->requested_width, tl->requested_height); + if (!stat_utf8(fd->path, &st)) return FALSE; @@ -718,7 +703,7 @@ g_free(tl); } -GdkPixbuf *thumb_loader_std_get_pixbuf(ThumbLoaderStd *tl, gint with_fallback) +GdkPixbuf *thumb_loader_std_get_pixbuf(ThumbLoaderStd *tl) { GdkPixbuf *pixbuf; @@ -727,32 +712,9 @@ pixbuf = tl->fd->thumb_pixbuf; g_object_ref(pixbuf); } - else if (with_fallback) - { - gint w, h; - - pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN); - w = gdk_pixbuf_get_width(pixbuf); - h = gdk_pixbuf_get_height(pixbuf); - - if (w > tl->requested_width || h > tl->requested_height) - { - gint nw, nh; - - if (thumb_loader_std_scale_aspect(tl->requested_width, tl->requested_height, - w, h, &nw, &nh)) - { - GdkPixbuf *tmp; - - tmp = pixbuf; - pixbuf = gdk_pixbuf_scale_simple(tmp, nw, nh, GDK_INTERP_TILES); - g_object_unref(G_OBJECT(tmp)); - } - } - } else { - pixbuf = NULL; + pixbuf = pixbuf_fallback(NULL, tl->requested_width, tl->requested_height); } return pixbuf; @@ -806,7 +768,8 @@ GdkPixbuf *pixbuf; gint valid = FALSE; - pixbuf = thumb_loader_std_get_pixbuf(tv->tl, FALSE); + /* this function is called on success, so the pixbuf should not be a fallback*/ + pixbuf = thumb_loader_std_get_pixbuf(tv->tl); if (pixbuf) { const gchar *uri; @@ -967,7 +930,8 @@ TMaintMove *tm = data; GdkPixbuf *pixbuf; - pixbuf = thumb_loader_std_get_pixbuf(tm->tl, FALSE); + /* this function is called on success, so the pixbuf should not be a fallback*/ + pixbuf = thumb_loader_std_get_pixbuf(tm->tl); if (pixbuf) { const gchar *uri; @@ -1010,6 +974,7 @@ DEBUG_1("thumb move unlink: %s", tm->thumb_path); unlink_file(tm->thumb_path); + g_object_unref(pixbuf); } thumb_std_maint_move_step(tm); diff -r 8ddd00cc8b69 -r f40509d56fe3 src/thumb_standard.h --- a/src/thumb_standard.h Fri Jun 27 18:43:05 2008 +0000 +++ b/src/thumb_standard.h Fri Jun 27 21:09:15 2008 +0000 @@ -71,7 +71,7 @@ gint thumb_loader_std_start(ThumbLoaderStd *tl, FileData *fd); void thumb_loader_std_free(ThumbLoaderStd *tl); -GdkPixbuf *thumb_loader_std_get_pixbuf(ThumbLoaderStd *tl, gint with_fallback); +GdkPixbuf *thumb_loader_std_get_pixbuf(ThumbLoaderStd *tl); /* validates a non local thumbnail file,