Commit 62ad1f1e authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

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.
parent cf36be97
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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>

+1 −1
Original line number Diff line number Diff line
@@ -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
+1 −9
Original line number Diff line number Diff line
@@ -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"
+27 −9
Original line number Diff line number Diff line
@@ -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))
+14 −10
Original line number Diff line number Diff line
@@ -58,7 +58,11 @@ typedef struct thumbmode_data {

	int max_column_w;        /* FIXME: description */
	int vertical;            /* FIXME: vertical in what way? */
	int cache_thumbnails;	/* use cached thumbnails from ~/.thumbnails/normal */

	int cache_thumbnails;    /* use cached thumbnails from ~/.thumbnails */
	int cache_dim;           /* 128 = 128x128 ("normal"), 256 = 256x256 ("large") */
	char *cache_dir;         /* "normal"/"large" (.thumbnails/...) */

} thumbmode_data;

feh_thumbnail *feh_thumbnail_new(feh_file * fil, int x, int y, int w, int h);