Krolyxon
Commit eb5feb4

Branches

Refs →

nsxiveb5feb4

Discard cached & EXIF thumbnails, which are smaller than the configured maximum size

Author
Bert Münnich
Date
2014-10-30 09:30 +0100
Committer
Bert Münnich · 2014-10-31 10:41 +0100
Parent
f5f49e7
Commit
eb5feb4585cff2818455fd83b546f8c639beee55

+21 −12

1 file changed

  1. M thumbs.c +21 −12
M thumbs.c View
@@ -240,6 +240,7 @@ Imlib_Image tns_scale_down(Imlib_Image im, int dim)
240240 bool tns_load(tns_t *tns, int n, bool force)
241241 {
242242 int w, h;
243+ int maxwh = thumb_sizes[ARRLEN(thumb_sizes)-1];
243244 bool cache_hit = false;
244245 float zw, zh;
245246 thumb_t *t;
@@ -261,11 +262,11 @@ bool tns_load(tns_t *tns, int n, bool force)
261262 imlib_free_image();
262263 }
263264
264− if (!force && (im = tns_cache_load(file->path, &force)) != NULL) {
265− cache_hit = true;
266− } else {
265+ if (!force) {
266+ if ((im = tns_cache_load(file->path, &force)) != NULL) {
267+ cache_hit = true;
267268 #if HAVE_LIBEXIF
268− if (!force) {
269+ } else {
269270 int pw = 0, ph = 0, x = 0, y = 0;
270271 bool err;
271272 ExifData *ed;
@@ -318,23 +319,31 @@ bool tns_load(tns_t *tns, int n, bool force)
318319 }
319320 exif_data_unref(ed);
320321 }
321− }
322322 #endif
323− if (im == NULL && (access(file->path, R_OK) < 0 ||
324− (im = imlib_load_image(file->path)) == NULL))
325− {
326− if (file->warn)
327− warn("could not open image: %s", file->name);
328− return false;
329323 }
330324 }
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+ }
333+ if (im == NULL && (access(file->path, R_OK) < 0 ||
334+ (im = imlib_load_image(file->path)) == NULL))
335+ {
336+ if (file->warn)
337+ warn("could not open image: %s", file->name);
338+ return false;
339+ }
331340
332341 if (!cache_hit) {
333342 #if HAVE_LIBEXIF
334343 imlib_context_set_image(im);
335344 exif_auto_orientate(file);
336345 #endif
337− im = tns_scale_down(im, thumb_sizes[ARRLEN(thumb_sizes)-1]);
346+ im = tns_scale_down(im, maxwh);
338347 tns_cache_write(im, file->path, true);
339348 }
340349