summaryrefslogtreecommitdiffstats
path: root/thumbs.c
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2015-01-04 21:19:26 +0100
committerBert Münnich <ber.t@posteo.de>2015-01-04 21:24:43 +0100
commit47af0dd7b5e154fb64d8b4d6c5302ba905055799 (patch)
tree6d8d46f14e7330b0b18943b649f82c841da3fb5f /thumbs.c
parent9b9294bae67da4e0388e7c31d0063f4e114aa1f8 (diff)
downloadnsxiv-47af0dd7b5e154fb64d8b4d6c5302ba905055799.tar.zst
Cache out of view thumbnails in the background
Diffstat (limited to 'thumbs.c')
-rw-r--r--thumbs.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/thumbs.c b/thumbs.c
index 8ec7a30..209c94b 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -152,7 +152,7 @@ void tns_clean_cache(tns_t *tns)
}
-void tns_init(tns_t *tns, const fileinfo_t *files, const int *cnt, int *sel,
+void tns_init(tns_t *tns, fileinfo_t *files, const int *cnt, int *sel,
win_t *win)
{
int len;
@@ -169,7 +169,8 @@ void tns_init(tns_t *tns, const fileinfo_t *files, const int *cnt, int *sel,
}
tns->files = files;
tns->cnt = cnt;
- tns->loadnext = tns->first = tns->end = tns->r_first = tns->r_end = 0;
+ tns->initnext = tns->loadnext = 0;
+ tns->first = tns->end = tns->r_first = tns->r_end = 0;
tns->sel = sel;
tns->win = win;
tns->dirty = false;
@@ -237,7 +238,7 @@ Imlib_Image tns_scale_down(Imlib_Image im, int dim)
return im;
}
-bool tns_load(tns_t *tns, int n, bool force)
+bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
{
int w, h;
int maxwh = thumb_sizes[ARRLEN(thumb_sizes)-1];
@@ -245,8 +246,8 @@ bool tns_load(tns_t *tns, int n, bool force)
char *cfile;
float zw, zh;
thumb_t *t;
+ fileinfo_t *file;
Imlib_Image im = NULL;
- const fileinfo_t *file;
if (tns == NULL || tns->thumbs == NULL)
return false;
@@ -261,6 +262,7 @@ bool tns_load(tns_t *tns, int n, bool force)
if (t->im != NULL) {
imlib_context_set_image(t->im);
imlib_free_image();
+ t->im = NULL;
}
if (!force) {
@@ -345,10 +347,10 @@ bool tns_load(tns_t *tns, int n, bool force)
warn("could not open image: %s", file->name);
return false;
}
+ imlib_context_set_image(im);
if (!cache_hit) {
#if HAVE_LIBEXIF
- imlib_context_set_image(im);
exif_auto_orientate(file);
#endif
im = tns_scale_down(im, maxwh);
@@ -357,12 +359,22 @@ bool tns_load(tns_t *tns, int n, bool force)
tns_cache_write(im, file->path, true);
}
- t->im = tns_scale_down(im, thumb_sizes[tns->zl]);
- imlib_context_set_image(t->im);
- t->w = imlib_image_get_width();
- t->h = imlib_image_get_height();
+ if (cache_only) {
+ imlib_free_image_and_decache();
+ } else {
+ t->im = tns_scale_down(im, thumb_sizes[tns->zl]);
+ imlib_context_set_image(t->im);
+ t->w = imlib_image_get_width();
+ t->h = imlib_image_get_height();
+ tns->dirty = true;
+ }
+ file->flags |= FF_TN_INIT;
+
+ if (n == tns->initnext)
+ while (++tns->initnext < *tns->cnt && ((++file)->flags & FF_TN_INIT));
+ if (n == tns->loadnext && !cache_only)
+ while (++tns->loadnext < tns->end && (++t)->im != NULL);
- tns->dirty = true;
return true;
}