nsxiveb5feb4
Discard cached & EXIF thumbnails, which are smaller than the configured maximum size
+21 −12
1 file changed
- M thumbs.c +21 −12
| @@ -240,6 +240,7 @@ Imlib_Image tns_scale_down(Imlib_Image im, int dim) | |||
| 240 | 240 | bool tns_load(tns_t *tns, int n, bool force) | |
| 241 | 241 | { | |
| 242 | 242 | int w, h; | |
| 243 | + | int maxwh = thumb_sizes[ARRLEN(thumb_sizes)-1]; | |
| 243 | 244 | bool cache_hit = false; | |
| 244 | 245 | float zw, zh; | |
| 245 | 246 | thumb_t *t; | |
| @@ -261,11 +262,11 @@ bool tns_load(tns_t *tns, int n, bool force) | |||
| 261 | 262 | imlib_free_image(); | |
| 262 | 263 | } | |
| 263 | 264 | ||
| 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; | |
| 267 | 268 | #if HAVE_LIBEXIF | |
| 268 | − | if (!force) { | |
| 269 | + | } else { | |
| 269 | 270 | int pw = 0, ph = 0, x = 0, y = 0; | |
| 270 | 271 | bool err; | |
| 271 | 272 | ExifData *ed; | |
| @@ -318,23 +319,31 @@ bool tns_load(tns_t *tns, int n, bool force) | |||
| 318 | 319 | } | |
| 319 | 320 | exif_data_unref(ed); | |
| 320 | 321 | } | |
| 321 | − | } | |
| 322 | 322 | #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; | |
| 329 | 323 | } | |
| 330 | 324 | } | |
| 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 | + | } | |
| 331 | 340 | ||
| 332 | 341 | if (!cache_hit) { | |
| 333 | 342 | #if HAVE_LIBEXIF | |
| 334 | 343 | imlib_context_set_image(im); | |
| 335 | 344 | exif_auto_orientate(file); | |
| 336 | 345 | #endif | |
| 337 | − | im = tns_scale_down(im, thumb_sizes[ARRLEN(thumb_sizes)-1]); | |
| 346 | + | im = tns_scale_down(im, maxwh); | |
| 338 | 347 | tns_cache_write(im, file->path, true); | |
| 339 | 348 | } | |
| 340 | 349 | ||