summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2010-05-31 00:38:45 +0200
committerDaniel Friesel <derf@derf.homelinux.org>2010-05-31 00:38:45 +0200
commit62ad1f1e5c7164eab0e19af65f6384a13ad701ee (patch)
tree8e7542e463486e8604aa89637bae362d09d9102f
parentcf36be979939c93315b77f24575dc4028916776d (diff)
Support caching of thumbnails up to 256x256 pixels (.thumbnails/large)
Depending on --thumb-width/--thumb-height, either .thumbnails/normal or .thumbnails/large is used. For higher dimensions, thumbnail caching is still silently disabled, this should also be what the standard indicates.
-rw-r--r--ChangeLog2
-rw-r--r--man/feh.12
-rw-r--r--src/options.c10
-rw-r--r--src/thumbnail.c36
-rw-r--r--src/thumbnail.h24
5 files changed, 44 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index 4935b5f..78416e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,7 +3,7 @@ git HEAD
* Patch by aaptel: Support numpad keys for actions
* Fix blur mode (Ctrl + left mouse key)
* Center images in index/thumbnail mode relative to the text below them
- * Various thumbnail caching improvements, better standard implementation
+ * Support caching of "large" (up to 256x256 pixels) thumbnails
Thu May 6 08:34:39 CEST 2010 Daniel Friesel <derf@chaosdorf.de>
diff --git a/man/feh.1 b/man/feh.1
index 9dd2933..ea122a9 100644
--- a/man/feh.1
+++ b/man/feh.1
@@ -136,7 +136,7 @@ Use builtin HTTP client to grab remote files instead of
.It Cm --cache-thumbnails
Enable (experimental) thumbnail caching in
.Pa ~/.thumbnails .
-Only works with thumbnails <= 128x128 pixels.
+Only works with thumbnails <= 256x256 pixels.
.It Cm --caption-path Ar path
Path to directory containing image captions. This turns on caption viewing,
and if captions are found in
diff --git a/src/options.c b/src/options.c
index 52c90d6..f967456 100644
--- a/src/options.c
+++ b/src/options.c
@@ -798,14 +798,6 @@ static void check_options(void)
opt.thumb_title = NULL;
}
- if (opt.cache_thumbnails && ((opt.thumb_w > 128) || (opt.thumb_h > 128))) {
- /* No warning needed, the documentation should be clear enough.
- * Plus, we don't want to annoy users who use --cache-thumbnails by
- * default but frequently change their thumbnail size.
- */
- opt.cache_thumbnails = 0;
- }
-
D_RETURN_(4);
}
@@ -970,7 +962,7 @@ void show_usage(void)
" -t, --thumbnails As --index, but clicking an image will open it in\n"
" a new viewing window\n"
" --cache-thumbnails Enable thumbnail caching for thumbnail mode.\n"
-" Only works with thumbnails <= 128x128 pixels\n"
+" Only works with thumbnails <= 256x256 pixels\n"
" -~, --thumb-title STRING Set window title for images opened from thumbnail mode.\n"
" Supports format specifiers, see there.\n"
" -I, --fullindex Same as index mode, but below each thumbnail you\n"
diff --git a/src/thumbnail.c b/src/thumbnail.c
index ece4853..fe36213 100644
--- a/src/thumbnail.c
+++ b/src/thumbnail.c
@@ -172,9 +172,27 @@ void init_thumbnail_mode(void)
/* make sure we have an ~/.thumbnails/normal directory for storing
permanent thumbnails */
- td.cache_thumbnails = feh_thumbnail_setup_thumbnail_dir();
td.cache_thumbnails = opt.cache_thumbnails;
+ if (td.cache_thumbnails) {
+ if (opt.thumb_w > opt.thumb_h)
+ td.cache_dim = opt.thumb_w;
+ else
+ td.cache_dim = opt.thumb_h;
+
+ if (td.cache_dim > 256) {
+ /* No caching as specified by standard. Sort of. */
+ td.cache_thumbnails = 0;
+ } else if (td.cache_dim > 128) {
+ td.cache_dim = 256;
+ td.cache_dir = estrdup("large");
+ } else {
+ td.cache_dim = 128;
+ td.cache_dir = estrdup("normal");
+ }
+ feh_thumbnail_setup_thumbnail_dir();
+ }
+
for (l = filelist; l; l = l->next) {
file = FEH_FILE(l->data);
if (last) {
@@ -736,7 +754,7 @@ char *feh_thumbnail_get_name(char *uri)
home = getenv("HOME");
if (home) {
- thumb_file = estrjoin("/", home, ".thumbnails/normal", md5_name, NULL);
+ thumb_file = estrjoin("/", home, ".thumbnails", td.cache_dir, md5_name, NULL);
}
free(md5_name);
@@ -748,7 +766,7 @@ char *feh_thumbnail_get_name_uri(char *name)
{
char *cwd, *uri = NULL;
- /* FIXME: what happends with http, https, and ftp? MTime etc */
+ /* FIXME: what happens with http, https, and ftp? MTime etc */
if ((strncmp(name, "http://", 7) != 0) &&
(strncmp(name, "https://", 8) != 0) && (strncmp(name, "ftp://", 6) != 0)
&& (strncmp(name, "file://", 7) != 0)) {
@@ -801,15 +819,15 @@ int feh_thumbnail_generate(Imlib_Image * image, feh_file * file,
if (feh_load_image(&im_temp, file) != 0) {
w = gib_imlib_image_get_width(im_temp);
h = gib_imlib_image_get_height(im_temp);
- thumb_w = 128;
- thumb_h = 128;
+ thumb_w = td.cache_dim;
+ thumb_h = td.cache_dim;
- if ((w > 128) || (h > 128)) {
+ if ((w > td.cache_dim) || (h > td.cache_dim)) {
double ratio = (double) w / h;
if (ratio > 1.0)
- thumb_h = 128 / ratio;
+ thumb_h = td.cache_dim / ratio;
else if (ratio != 1.0)
- thumb_w = 128 * ratio;
+ thumb_w = td.cache_dim * ratio;
}
*image = gib_imlib_create_cropped_scaled_image(im_temp, 0, 0, w, h,
@@ -865,7 +883,7 @@ int feh_thumbnail_setup_thumbnail_dir(void)
home = getenv("HOME");
if (home != NULL) {
- dir = estrjoin("/", home, ".thumbnails/normal", NULL);
+ dir = estrjoin("/", home, ".thumbnails", td.cache_dir, NULL);
if (!stat(dir, &sb)) {
if (S_ISDIR(sb.st_mode))
diff --git a/src/thumbnail.h b/src/thumbnail.h
index d015994..a384d11 100644
--- a/src/thumbnail.h
+++ b/src/thumbnail.h
@@ -45,20 +45,24 @@ typedef struct thumbnail {
typedef struct thumbmode_data {
/* FIXME: text_area_h not really needed, remove? */
- Imlib_Image im_main; /* base image which all thumbnails are rendered on */
- Imlib_Image im_bg; /* background for the thumbnails */
+ Imlib_Image im_main; /* base image which all thumbnails are rendered on */
+ Imlib_Image im_bg; /* background for the thumbnails */
- Imlib_Font font_main; /* font used for file info */
- Imlib_Font font_title; /* font used for title */
+ Imlib_Font font_main; /* font used for file info */
+ Imlib_Font font_title; /* font used for title */
- int w, h, bg_w, bg_h; /* dimensions of the window and bg image */
+ int w, h, bg_w, bg_h; /* dimensions of the window and bg image */
- int thumb_tot_h; /* total space needed for a thumbnail including description */
- int text_area_w, text_area_h; /* space needed for thumbnail description */
+ int thumb_tot_h; /* total space needed for a thumbnail including description */
+ int text_area_w, text_area_h; /* space needed for thumbnail description */
+
+ int max_column_w; /* FIXME: description */
+ int vertical; /* FIXME: vertical in what way? */
+
+ int cache_thumbnails; /* use cached thumbnails from ~/.thumbnails */
+ int cache_dim; /* 128 = 128x128 ("normal"), 256 = 256x256 ("large") */
+ char *cache_dir; /* "normal"/"large" (.thumbnails/...) */
- int max_column_w; /* FIXME: description */
- int vertical; /* FIXME: vertical in what way? */
- int cache_thumbnails; /* use cached thumbnails from ~/.thumbnails/normal */
} thumbmode_data;
feh_thumbnail *feh_thumbnail_new(feh_file * fil, int x, int y, int w, int h);