nsxivd154b98
Do not cache thumbnails, which are smaller than the maximum size
+22 −12
1 file changed
- M thumbs.c +22 −12
| @@ -242,6 +242,7 @@ bool tns_load(tns_t *tns, int n, bool force) | |||
| 242 | 242 | int w, h; | |
| 243 | 243 | int maxwh = thumb_sizes[ARRLEN(thumb_sizes)-1]; | |
| 244 | 244 | bool cache_hit = false; | |
| 245 | + | char *cfile; | |
| 245 | 246 | float zw, zh; | |
| 246 | 247 | thumb_t *t; | |
| 247 | 248 | Imlib_Image im = NULL; | |
| @@ -264,7 +265,19 @@ bool tns_load(tns_t *tns, int n, bool force) | |||
| 264 | 265 | ||
| 265 | 266 | if (!force) { | |
| 266 | 267 | 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 | + | } | |
| 268 | 281 | #if HAVE_LIBEXIF | |
| 269 | 282 | } else { | |
| 270 | 283 | int pw = 0, ph = 0, x = 0, y = 0; | |
| @@ -311,8 +324,10 @@ bool tns_load(tns_t *tns, int n, bool force) | |||
| 311 | 324 | h = ph; | |
| 312 | 325 | } | |
| 313 | 326 | } | |
| 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 | + | } | |
| 316 | 331 | imlib_free_image_and_decache(); | |
| 317 | 332 | } | |
| 318 | 333 | unlink(tmppath); | |
| @@ -322,14 +337,7 @@ bool tns_load(tns_t *tns, int n, bool force) | |||
| 322 | 337 | #endif | |
| 323 | 338 | } | |
| 324 | 339 | } | |
| 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 | + | ||
| 333 | 341 | if (im == NULL && (access(file->path, R_OK) < 0 || | |
| 334 | 342 | (im = imlib_load_image(file->path)) == NULL)) | |
| 335 | 343 | { | |
| @@ -344,7 +352,9 @@ bool tns_load(tns_t *tns, int n, bool force) | |||
| 344 | 352 | exif_auto_orientate(file); | |
| 345 | 353 | #endif | |
| 346 | 354 | 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); | |
| 348 | 358 | } | |
| 349 | 359 | ||
| 350 | 360 | t->im = tns_scale_down(im, thumb_sizes[tns->zl]); | |