aboutsummaryrefslogtreecommitdiff
path: root/thumbs.c
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2014-10-30 09:30:00 +0100
committerBert Münnich <ber.t@posteo.de>2014-10-31 10:41:30 +0100
commiteb5feb4585cff2818455fd83b546f8c639beee55 (patch)
treef13daa47f842f8ffcac9a5815d01f6de3b98cfd0 /thumbs.c
parentf5f49e7a9deabd83303a7490cf606fb200c8af81 (diff)
Discard cached & EXIF thumbnails, which are smaller than the configured maximum size
Diffstat (limited to 'thumbs.c')
-rw-r--r--thumbs.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/thumbs.c b/thumbs.c
index 3e6cc88..98b4f6d 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -240,6 +240,7 @@ Imlib_Image tns_scale_down(Imlib_Image im, int dim)
bool tns_load(tns_t *tns, int n, bool force)
{
int w, h;
+ int maxwh = thumb_sizes[ARRLEN(thumb_sizes)-1];
bool cache_hit = false;
float zw, zh;
thumb_t *t;
@@ -261,11 +262,11 @@ bool tns_load(tns_t *tns, int n, bool force)
imlib_free_image();
}
- if (!force && (im = tns_cache_load(file->path, &force)) != NULL) {
- cache_hit = true;
- } else {
+ if (!force) {
+ if ((im = tns_cache_load(file->path, &force)) != NULL) {
+ cache_hit = true;
#if HAVE_LIBEXIF
- if (!force) {
+ } else {
int pw = 0, ph = 0, x = 0, y = 0;
bool err;
ExifData *ed;
@@ -318,23 +319,31 @@ bool tns_load(tns_t *tns, int n, bool force)
}
exif_data_unref(ed);
}
- }
#endif
- if (im == NULL && (access(file->path, R_OK) < 0 ||
- (im = imlib_load_image(file->path)) == NULL))
- {
- if (file->warn)
- warn("could not open image: %s", file->name);
- return false;
}
}
+ 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 ||
+ (im = imlib_load_image(file->path)) == NULL))
+ {
+ if (file->warn)
+ warn("could not open image: %s", file->name);
+ return false;
+ }
if (!cache_hit) {
#if HAVE_LIBEXIF
imlib_context_set_image(im);
exif_auto_orientate(file);
#endif
- im = tns_scale_down(im, thumb_sizes[ARRLEN(thumb_sizes)-1]);
+ im = tns_scale_down(im, maxwh);
tns_cache_write(im, file->path, true);
}