Do not cache thumbnails, which are smaller than the maximum size

This commit is contained in:
Bert Münnich 2014-10-31 09:52:26 +01:00
parent eb5feb4585
commit d154b9826f

View File

@ -242,6 +242,7 @@ bool tns_load(tns_t *tns, int n, bool force)
int w, h; int w, h;
int maxwh = thumb_sizes[ARRLEN(thumb_sizes)-1]; int maxwh = thumb_sizes[ARRLEN(thumb_sizes)-1];
bool cache_hit = false; bool cache_hit = false;
char *cfile;
float zw, zh; float zw, zh;
thumb_t *t; thumb_t *t;
Imlib_Image im = NULL; Imlib_Image im = NULL;
@ -264,7 +265,19 @@ bool tns_load(tns_t *tns, int n, bool force)
if (!force) { if (!force) {
if ((im = tns_cache_load(file->path, &force)) != NULL) { if ((im = tns_cache_load(file->path, &force)) != NULL) {
imlib_context_set_image(im);
if (imlib_image_get_width() < maxwh &&
imlib_image_get_height() < maxwh)
{
if ((cfile = tns_cache_filepath(file->path)) != NULL) {
unlink(cfile);
free(cfile);
}
imlib_free_image_and_decache();
im = NULL;
} else {
cache_hit = true; cache_hit = true;
}
#if HAVE_LIBEXIF #if HAVE_LIBEXIF
} else { } else {
int pw = 0, ph = 0, x = 0, y = 0; int pw = 0, ph = 0, x = 0, y = 0;
@ -311,8 +324,10 @@ bool tns_load(tns_t *tns, int n, bool force)
h = ph; h = ph;
} }
} }
if (w >= maxwh || h >= maxwh) {
if ((im = imlib_create_cropped_image(x, y, w, h)) == NULL) if ((im = imlib_create_cropped_image(x, y, w, h)) == NULL)
die("could not allocate memory"); die("could not allocate memory");
}
imlib_free_image_and_decache(); imlib_free_image_and_decache();
} }
unlink(tmppath); unlink(tmppath);
@ -322,14 +337,7 @@ bool tns_load(tns_t *tns, int n, bool force)
#endif #endif
} }
} }
if (im != NULL) {
imlib_context_set_image(im);
if (imlib_image_get_width() < maxwh && imlib_image_get_height() < maxwh) {
imlib_free_image_and_decache();
im = NULL;
cache_hit = false;
}
}
if (im == NULL && (access(file->path, R_OK) < 0 || if (im == NULL && (access(file->path, R_OK) < 0 ||
(im = imlib_load_image(file->path)) == NULL)) (im = imlib_load_image(file->path)) == NULL))
{ {
@ -344,6 +352,8 @@ bool tns_load(tns_t *tns, int n, bool force)
exif_auto_orientate(file); exif_auto_orientate(file);
#endif #endif
im = tns_scale_down(im, maxwh); im = tns_scale_down(im, maxwh);
imlib_context_set_image(im);
if (imlib_image_get_width() == maxwh || imlib_image_get_height() == maxwh)
tns_cache_write(im, file->path, true); tns_cache_write(im, file->path, true);
} }