Krolyxon
Commit d154b98

Branches

Refs →

nsxivd154b98

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

Author
Bert Münnich
Date
2014-10-31 09:52 +0100
Committer
Bert Münnich · 2014-10-31 10:41 +0100
Parent
eb5feb4
Commit
d154b9826fba9342f517223efc3926ea081752ba

+22 −12

1 file changed

  1. M thumbs.c +22 −12
M thumbs.c View
@@ -242,6 +242,7 @@ bool tns_load(tns_t *tns, int n, bool force)
242242 int w, h;
243243 int maxwh = thumb_sizes[ARRLEN(thumb_sizes)-1];
244244 bool cache_hit = false;
245+ char *cfile;
245246 float zw, zh;
246247 thumb_t *t;
247248 Imlib_Image im = NULL;
@@ -264,7 +265,19 @@ bool tns_load(tns_t *tns, int n, bool force)
264265
265266 if (!force) {
266267 if ((im = tns_cache_load(file->path, &force)) != NULL) {
267− cache_hit = true;
268+ imlib_context_set_image(im);
269+ if (imlib_image_get_width() < maxwh &&
270+ imlib_image_get_height() < maxwh)
271+ {
272+ if ((cfile = tns_cache_filepath(file->path)) != NULL) {
273+ unlink(cfile);
274+ free(cfile);
275+ }
276+ imlib_free_image_and_decache();
277+ im = NULL;
278+ } else {
279+ cache_hit = true;
280+ }
268281 #if HAVE_LIBEXIF
269282 } else {
270283 int pw = 0, ph = 0, x = 0, y = 0;
@@ -311,8 +324,10 @@ bool tns_load(tns_t *tns, int n, bool force)
311324 h = ph;
312325 }
313326 }
314− if ((im = imlib_create_cropped_image(x, y, w, h)) == NULL)
315− die("could not allocate memory");
327+ if (w >= maxwh || h >= maxwh) {
328+ if ((im = imlib_create_cropped_image(x, y, w, h)) == NULL)
329+ die("could not allocate memory");
330+ }
316331 imlib_free_image_and_decache();
317332 }
318333 unlink(tmppath);
@@ -322,14 +337,7 @@ bool tns_load(tns_t *tns, int n, bool force)
322337 #endif
323338 }
324339 }
325− if (im != NULL) {
326− imlib_context_set_image(im);
327− if (imlib_image_get_width() < maxwh && imlib_image_get_height() < maxwh) {
328− imlib_free_image_and_decache();
329− im = NULL;
330− cache_hit = false;
331− }
332− }
340+
333341 if (im == NULL && (access(file->path, R_OK) < 0 ||
334342 (im = imlib_load_image(file->path)) == NULL))
335343 {
@@ -344,7 +352,9 @@ bool tns_load(tns_t *tns, int n, bool force)
344352 exif_auto_orientate(file);
345353 #endif
346354 im = tns_scale_down(im, maxwh);
347− tns_cache_write(im, file->path, true);
355+ imlib_context_set_image(im);
356+ if (imlib_image_get_width() == maxwh || imlib_image_get_height() == maxwh)
357+ tns_cache_write(im, file->path, true);
348358 }
349359
350360 t->im = tns_scale_down(im, thumb_sizes[tns->zl]);