2011-02-16 21:40:20 +01:00
|
|
|
/* sxiv: thumbs.c
|
|
|
|
* Copyright (c) 2011 Bert Muennich <muennich at informatik.hu-berlin.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2011-02-16 23:03:42 +01:00
|
|
|
#include <string.h>
|
2011-04-07 14:33:57 +02:00
|
|
|
#include <sys/time.h>
|
2011-04-07 01:26:08 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2011-02-16 21:40:20 +01:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "thumbs.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2011-04-04 20:35:10 +02:00
|
|
|
extern Imlib_Image *im_invalid;
|
2011-04-07 17:23:47 +02:00
|
|
|
|
2011-02-16 21:40:20 +01:00
|
|
|
const int thumb_dim = THUMB_SIZE + 10;
|
2011-04-07 17:23:47 +02:00
|
|
|
char *cache_dir = NULL;
|
2011-02-16 21:40:20 +01:00
|
|
|
|
2011-04-07 01:26:08 +02:00
|
|
|
int tns_cache_enabled();
|
2011-04-07 15:05:17 +02:00
|
|
|
Imlib_Image* tns_cache_load(const char*);
|
2011-04-07 01:26:08 +02:00
|
|
|
void tns_cache_write(thumb_t*, Bool);
|
|
|
|
|
2011-02-17 11:04:58 +01:00
|
|
|
void tns_init(tns_t *tns, int cnt) {
|
2011-04-07 17:23:47 +02:00
|
|
|
int len;
|
|
|
|
char *homedir;
|
|
|
|
|
2011-02-17 11:04:58 +01:00
|
|
|
if (!tns)
|
2011-02-16 23:03:42 +01:00
|
|
|
return;
|
|
|
|
|
2011-02-21 14:59:29 +01:00
|
|
|
tns->cnt = tns->first = tns->sel = 0;
|
2011-02-17 11:04:58 +01:00
|
|
|
tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t));
|
2011-02-18 15:33:52 +01:00
|
|
|
memset(tns->thumbs, 0, cnt * sizeof(thumb_t));
|
2011-02-27 13:29:24 +01:00
|
|
|
tns->cap = cnt;
|
2011-02-19 09:47:53 +01:00
|
|
|
tns->dirty = 0;
|
2011-04-07 17:23:47 +02:00
|
|
|
|
|
|
|
if ((homedir = getenv("HOME"))) {
|
|
|
|
if (cache_dir)
|
|
|
|
free(cache_dir);
|
|
|
|
len = strlen(homedir) + 10;
|
|
|
|
cache_dir = (char*) s_malloc(len * sizeof(char));
|
|
|
|
snprintf(cache_dir, len, "%s/.sxiv", homedir);
|
|
|
|
}
|
2011-02-16 21:40:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void tns_free(tns_t *tns, win_t *win) {
|
|
|
|
int i;
|
|
|
|
|
2011-02-21 14:59:29 +01:00
|
|
|
if (!tns || !tns->thumbs)
|
2011-02-16 21:40:20 +01:00
|
|
|
return;
|
|
|
|
|
2011-03-15 13:55:52 +01:00
|
|
|
for (i = 0; i < tns->cnt; ++i) {
|
|
|
|
if (tns->thumbs[i].im) {
|
|
|
|
imlib_context_set_image(tns->thumbs[i].im);
|
|
|
|
imlib_free_image();
|
|
|
|
}
|
|
|
|
}
|
2011-02-16 21:40:20 +01:00
|
|
|
|
|
|
|
free(tns->thumbs);
|
|
|
|
tns->thumbs = NULL;
|
2011-04-07 17:23:47 +02:00
|
|
|
|
|
|
|
if (cache_dir) {
|
|
|
|
free(cache_dir);
|
|
|
|
cache_dir = NULL;
|
|
|
|
}
|
2011-02-16 21:40:20 +01:00
|
|
|
}
|
|
|
|
|
2011-02-27 13:29:24 +01:00
|
|
|
void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
|
2011-02-17 11:04:58 +01:00
|
|
|
int w, h;
|
2011-04-07 16:17:10 +02:00
|
|
|
int use_cache, cached = 0;
|
2011-02-17 11:04:58 +01:00
|
|
|
float z, zw, zh;
|
|
|
|
thumb_t *t;
|
|
|
|
Imlib_Image *im;
|
|
|
|
|
|
|
|
if (!tns || !win || !filename)
|
|
|
|
return;
|
|
|
|
|
2011-02-27 13:29:24 +01:00
|
|
|
if (n >= tns->cap)
|
|
|
|
return;
|
|
|
|
else if (n >= tns->cnt)
|
|
|
|
tns->cnt = n + 1;
|
|
|
|
|
2011-03-15 13:55:52 +01:00
|
|
|
t = &tns->thumbs[n];
|
|
|
|
|
|
|
|
if (t->im) {
|
|
|
|
imlib_context_set_image(t->im);
|
|
|
|
imlib_free_image();
|
|
|
|
}
|
|
|
|
|
2011-04-07 16:17:10 +02:00
|
|
|
if ((use_cache = tns_cache_enabled())) {
|
|
|
|
if ((im = tns_cache_load(filename)))
|
|
|
|
cached = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cached || (im = imlib_load_image(filename)))
|
2011-02-17 15:58:11 +01:00
|
|
|
imlib_context_set_image(im);
|
2011-03-01 18:49:02 +01:00
|
|
|
else
|
2011-04-04 20:35:10 +02:00
|
|
|
imlib_context_set_image(im_invalid);
|
2011-02-17 11:04:58 +01:00
|
|
|
|
|
|
|
w = imlib_image_get_width();
|
|
|
|
h = imlib_image_get_height();
|
2011-04-07 00:26:45 +02:00
|
|
|
|
|
|
|
if (im) {
|
2011-04-07 01:26:08 +02:00
|
|
|
t->filename = filename;
|
2011-04-07 00:26:45 +02:00
|
|
|
zw = (float) THUMB_SIZE / (float) w;
|
|
|
|
zh = (float) THUMB_SIZE / (float) h;
|
|
|
|
z = MIN(zw, zh);
|
|
|
|
} else {
|
2011-04-07 01:26:08 +02:00
|
|
|
t->filename = NULL;
|
2011-02-17 15:58:11 +01:00
|
|
|
z = 1.0;
|
2011-04-07 00:26:45 +02:00
|
|
|
}
|
2011-02-17 11:04:58 +01:00
|
|
|
|
|
|
|
t->w = z * w;
|
|
|
|
t->h = z * h;
|
|
|
|
|
2011-02-25 12:08:12 +01:00
|
|
|
imlib_context_set_anti_alias(1);
|
2011-03-15 13:55:52 +01:00
|
|
|
if (!(t->im = imlib_create_cropped_scaled_image(0, 0, w, h, t->w, t->h)))
|
|
|
|
die("could not allocate memory");
|
2011-02-25 12:08:12 +01:00
|
|
|
if (im)
|
2011-03-01 18:49:02 +01:00
|
|
|
imlib_free_image_and_decache();
|
2011-04-07 16:17:10 +02:00
|
|
|
if (use_cache && !cached)
|
|
|
|
tns_cache_write(t, False);
|
2011-03-15 13:55:52 +01:00
|
|
|
|
|
|
|
tns->dirty = 1;
|
2011-02-17 11:04:58 +01:00
|
|
|
}
|
|
|
|
|
2011-02-19 22:12:08 +01:00
|
|
|
void tns_check_view(tns_t *tns, Bool scrolled) {
|
2011-02-20 00:08:17 +01:00
|
|
|
int r;
|
|
|
|
|
2011-02-19 22:12:08 +01:00
|
|
|
if (!tns)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tns->first -= tns->first % tns->cols;
|
2011-02-21 14:59:29 +01:00
|
|
|
r = tns->sel % tns->cols;
|
2011-02-19 22:12:08 +01:00
|
|
|
|
|
|
|
if (scrolled) {
|
|
|
|
/* move selection into visible area */
|
2011-02-21 14:59:29 +01:00
|
|
|
if (tns->sel >= tns->first + tns->cols * tns->rows)
|
|
|
|
tns->sel = tns->first + r + tns->cols * (tns->rows - 1);
|
|
|
|
else if (tns->sel < tns->first)
|
|
|
|
tns->sel = tns->first + r;
|
2011-02-19 22:12:08 +01:00
|
|
|
} else {
|
|
|
|
/* scroll to selection */
|
2011-02-21 14:59:29 +01:00
|
|
|
if (tns->first + tns->cols * tns->rows <= tns->sel) {
|
|
|
|
tns->first = tns->sel - r - tns->cols * (tns->rows - 1);
|
2011-02-19 22:12:08 +01:00
|
|
|
tns->dirty = 1;
|
2011-02-21 14:59:29 +01:00
|
|
|
} else if (tns->first > tns->sel) {
|
|
|
|
tns->first = tns->sel - r;
|
2011-02-19 22:12:08 +01:00
|
|
|
tns->dirty = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-16 21:40:20 +01:00
|
|
|
void tns_render(tns_t *tns, win_t *win) {
|
2011-02-19 22:12:08 +01:00
|
|
|
int i, cnt, r, x, y;
|
|
|
|
thumb_t *t;
|
2011-02-16 21:40:20 +01:00
|
|
|
|
2011-02-19 09:47:53 +01:00
|
|
|
if (!tns || !tns->dirty || !win)
|
2011-02-16 21:40:20 +01:00
|
|
|
return;
|
|
|
|
|
2011-02-19 22:12:08 +01:00
|
|
|
win_clear(win);
|
2011-03-15 13:55:52 +01:00
|
|
|
imlib_context_set_drawable(win->pm);
|
2011-02-19 22:12:08 +01:00
|
|
|
|
2011-02-17 16:22:54 +01:00
|
|
|
tns->cols = MAX(1, win->w / thumb_dim);
|
|
|
|
tns->rows = MAX(1, win->h / thumb_dim);
|
2011-02-16 21:40:20 +01:00
|
|
|
|
2011-02-19 22:12:08 +01:00
|
|
|
if (tns->cnt < tns->cols * tns->rows) {
|
|
|
|
tns->first = 0;
|
|
|
|
cnt = tns->cnt;
|
|
|
|
} else {
|
|
|
|
tns_check_view(tns, False);
|
|
|
|
cnt = tns->cols * tns->rows;
|
|
|
|
if ((r = tns->first + cnt - tns->cnt) >= tns->cols)
|
|
|
|
tns->first -= r - r % tns->cols;
|
|
|
|
if (r > 0)
|
|
|
|
cnt -= r % tns->cols;
|
|
|
|
}
|
2011-02-16 21:40:20 +01:00
|
|
|
|
2011-02-19 22:12:08 +01:00
|
|
|
r = cnt % tns->cols ? 1 : 0;
|
2011-02-18 14:57:24 +01:00
|
|
|
tns->x = x = (win->w - MIN(cnt, tns->cols) * thumb_dim) / 2 + 5;
|
2011-02-19 22:12:08 +01:00
|
|
|
tns->y = y = (win->h - (cnt / tns->cols + r) * thumb_dim) / 2 + 5;
|
|
|
|
|
|
|
|
for (i = 0; i < cnt; ++i) {
|
|
|
|
t = &tns->thumbs[tns->first + i];
|
|
|
|
t->x = x + (THUMB_SIZE - t->w) / 2;
|
|
|
|
t->y = y + (THUMB_SIZE - t->h) / 2;
|
2011-03-15 13:55:52 +01:00
|
|
|
imlib_context_set_image(t->im);
|
|
|
|
imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h,
|
|
|
|
t->x, t->y, t->w, t->h);
|
2011-02-19 22:12:08 +01:00
|
|
|
if ((i + 1) % tns->cols == 0) {
|
2011-02-18 14:57:24 +01:00
|
|
|
x = tns->x;
|
2011-02-16 21:40:20 +01:00
|
|
|
y += thumb_dim;
|
|
|
|
} else {
|
|
|
|
x += thumb_dim;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-19 09:47:53 +01:00
|
|
|
tns->dirty = 0;
|
2011-02-21 14:59:29 +01:00
|
|
|
tns_highlight(tns, win, tns->sel, True);
|
2011-02-16 21:40:20 +01:00
|
|
|
}
|
|
|
|
|
2011-02-19 22:12:08 +01:00
|
|
|
void tns_highlight(tns_t *tns, win_t *win, int n, Bool hl) {
|
2011-02-17 16:22:54 +01:00
|
|
|
thumb_t *t;
|
2011-03-09 11:37:49 +01:00
|
|
|
unsigned long col;
|
2011-02-17 16:22:54 +01:00
|
|
|
|
|
|
|
if (!tns || !win)
|
|
|
|
return;
|
|
|
|
|
2011-02-19 22:12:08 +01:00
|
|
|
if (n >= 0 && n < tns->cnt) {
|
|
|
|
t = &tns->thumbs[n];
|
2011-03-09 11:37:49 +01:00
|
|
|
|
|
|
|
if (hl)
|
|
|
|
col = win->selcol;
|
|
|
|
else if (win->fullscreen)
|
|
|
|
col = win->black;
|
|
|
|
else
|
|
|
|
col = win->bgcol;
|
|
|
|
|
|
|
|
win_draw_rect(win, win->pm, t->x - 2, t->y - 2, t->w + 4, t->h + 4,
|
|
|
|
False, 2, col);
|
2011-02-17 16:22:54 +01:00
|
|
|
}
|
2011-02-17 16:57:55 +01:00
|
|
|
|
|
|
|
win_draw(win);
|
|
|
|
}
|
|
|
|
|
2011-02-20 00:08:17 +01:00
|
|
|
int tns_move_selection(tns_t *tns, win_t *win, tnsdir_t dir) {
|
2011-02-19 22:12:08 +01:00
|
|
|
int old;
|
2011-02-17 16:57:55 +01:00
|
|
|
|
|
|
|
if (!tns || !win)
|
2011-02-19 09:47:53 +01:00
|
|
|
return 0;
|
2011-02-17 16:57:55 +01:00
|
|
|
|
2011-02-21 14:59:29 +01:00
|
|
|
old = tns->sel;
|
2011-02-17 16:57:55 +01:00
|
|
|
|
|
|
|
switch (dir) {
|
2011-02-20 00:08:17 +01:00
|
|
|
case TNS_LEFT:
|
2011-02-21 14:59:29 +01:00
|
|
|
if (tns->sel > 0)
|
|
|
|
--tns->sel;
|
2011-02-17 16:57:55 +01:00
|
|
|
break;
|
2011-02-20 00:08:17 +01:00
|
|
|
case TNS_RIGHT:
|
2011-02-21 14:59:29 +01:00
|
|
|
if (tns->sel < tns->cnt - 1)
|
|
|
|
++tns->sel;
|
2011-02-17 16:57:55 +01:00
|
|
|
break;
|
2011-02-20 00:08:17 +01:00
|
|
|
case TNS_UP:
|
2011-02-21 14:59:29 +01:00
|
|
|
if (tns->sel >= tns->cols)
|
|
|
|
tns->sel -= tns->cols;
|
2011-02-17 16:57:55 +01:00
|
|
|
break;
|
2011-02-20 00:08:17 +01:00
|
|
|
case TNS_DOWN:
|
2011-02-21 14:59:29 +01:00
|
|
|
if (tns->sel + tns->cols < tns->cnt)
|
|
|
|
tns->sel += tns->cols;
|
2011-02-17 16:57:55 +01:00
|
|
|
break;
|
|
|
|
}
|
2011-02-18 15:33:52 +01:00
|
|
|
|
2011-02-21 14:59:29 +01:00
|
|
|
if (tns->sel != old) {
|
2011-02-19 22:12:08 +01:00
|
|
|
tns_highlight(tns, win, old, False);
|
|
|
|
tns_check_view(tns, False);
|
|
|
|
if (!tns->dirty)
|
2011-02-21 14:59:29 +01:00
|
|
|
tns_highlight(tns, win, tns->sel, True);
|
2011-02-18 15:33:52 +01:00
|
|
|
}
|
2011-02-19 09:47:53 +01:00
|
|
|
|
2011-02-21 14:59:29 +01:00
|
|
|
return tns->sel != old;
|
2011-02-17 16:22:54 +01:00
|
|
|
}
|
2011-02-17 17:28:13 +01:00
|
|
|
|
2011-02-20 00:08:17 +01:00
|
|
|
int tns_scroll(tns_t *tns, tnsdir_t dir) {
|
|
|
|
int old;
|
|
|
|
|
|
|
|
if (!tns)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
old = tns->first;
|
|
|
|
|
2011-02-20 00:28:28 +01:00
|
|
|
if (dir == TNS_DOWN && tns->first + tns->cols * tns->rows < tns->cnt) {
|
2011-02-20 00:08:17 +01:00
|
|
|
tns->first += tns->cols;
|
2011-02-20 00:28:28 +01:00
|
|
|
tns_check_view(tns, True);
|
|
|
|
tns->dirty = 1;
|
|
|
|
} else if (dir == TNS_UP && tns->first >= tns->cols) {
|
2011-02-20 00:08:17 +01:00
|
|
|
tns->first -= tns->cols;
|
|
|
|
tns_check_view(tns, True);
|
|
|
|
tns->dirty = 1;
|
|
|
|
}
|
2011-02-20 00:28:28 +01:00
|
|
|
|
|
|
|
return tns->first != old;
|
2011-02-20 00:08:17 +01:00
|
|
|
}
|
|
|
|
|
2011-02-17 17:28:13 +01:00
|
|
|
int tns_translate(tns_t *tns, int x, int y) {
|
|
|
|
int n;
|
|
|
|
thumb_t *t;
|
|
|
|
|
2011-02-18 14:57:24 +01:00
|
|
|
if (!tns || x < tns->x || y < tns->y)
|
2011-02-17 17:28:13 +01:00
|
|
|
return -1;
|
|
|
|
|
2011-02-19 22:12:08 +01:00
|
|
|
n = tns->first + (y - tns->y) / thumb_dim * tns->cols +
|
|
|
|
(x - tns->x) / thumb_dim;
|
2011-02-18 15:02:49 +01:00
|
|
|
|
|
|
|
if (n < tns->cnt) {
|
2011-02-17 17:28:13 +01:00
|
|
|
t = &tns->thumbs[n];
|
2011-02-18 15:02:49 +01:00
|
|
|
if (x >= t->x && x <= t->x + t->w && y >= t->y && y <= t->y + t->h)
|
2011-02-17 17:28:13 +01:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2011-04-07 01:26:08 +02:00
|
|
|
|
2011-04-07 14:33:57 +02:00
|
|
|
|
|
|
|
/* thumbnail caching */
|
|
|
|
|
2011-04-07 01:26:08 +02:00
|
|
|
int tns_cache_enabled() {
|
|
|
|
struct stat stats;
|
|
|
|
|
2011-04-07 17:23:47 +02:00
|
|
|
return cache_dir && !stat(cache_dir, &stats) && S_ISDIR(stats.st_mode) &&
|
|
|
|
!access(cache_dir, W_OK);
|
2011-04-07 01:26:08 +02:00
|
|
|
}
|
|
|
|
|
2011-04-07 14:33:57 +02:00
|
|
|
char* tns_cache_filename(const char *filename) {
|
|
|
|
size_t len;
|
2011-04-07 17:23:47 +02:00
|
|
|
char *cfile, *abspath;
|
2011-04-07 14:33:57 +02:00
|
|
|
|
2011-04-07 17:23:47 +02:00
|
|
|
if (!cache_dir || !filename)
|
2011-04-07 14:33:57 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (*filename != '/') {
|
|
|
|
if (!(abspath = absolute_path(filename)))
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
abspath = (char*) s_malloc(strlen(filename) + 1);
|
|
|
|
strcpy(abspath, filename);
|
|
|
|
}
|
|
|
|
|
2011-04-07 17:29:59 +02:00
|
|
|
len = strlen(cache_dir) + strlen(abspath) + 6;
|
2011-04-07 14:33:57 +02:00
|
|
|
cfile = (char*) s_malloc(len);
|
2011-04-07 17:23:47 +02:00
|
|
|
snprintf(cfile, len, "%s/%s.png", cache_dir, abspath + 1);
|
2011-04-07 14:33:57 +02:00
|
|
|
|
|
|
|
free(abspath);
|
|
|
|
|
|
|
|
return cfile;
|
|
|
|
}
|
|
|
|
|
2011-04-07 15:05:17 +02:00
|
|
|
Imlib_Image* tns_cache_load(const char *filename) {
|
|
|
|
char *cfile;
|
|
|
|
struct stat cstats, fstats;
|
|
|
|
Imlib_Image *im = NULL;
|
|
|
|
|
|
|
|
if (!filename || stat(filename, &fstats))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((cfile = tns_cache_filename(filename))) {
|
|
|
|
if (!stat(cfile, &cstats) &&
|
|
|
|
cstats.st_mtim.tv_sec == fstats.st_mtim.tv_sec &&
|
|
|
|
cstats.st_mtim.tv_nsec == fstats.st_mtim.tv_nsec)
|
|
|
|
{
|
|
|
|
printf("cache hit: %s\n", filename);
|
|
|
|
im = imlib_load_image(cfile);
|
|
|
|
} else
|
|
|
|
printf("cache MISS: %s\n", filename);
|
|
|
|
free(cfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
return im;
|
|
|
|
}
|
|
|
|
|
2011-04-07 01:26:08 +02:00
|
|
|
void tns_cache_write(thumb_t *t, Bool force) {
|
2011-04-07 17:29:59 +02:00
|
|
|
char *cfile, *dirend;
|
2011-04-07 14:33:57 +02:00
|
|
|
struct stat cstats, fstats;
|
|
|
|
struct timeval times[2];
|
2011-04-07 17:29:59 +02:00
|
|
|
Imlib_Load_Error err = 0;
|
2011-04-07 14:33:57 +02:00
|
|
|
|
|
|
|
if (!t || !t->im || !t->filename)
|
|
|
|
return;
|
2011-04-07 15:05:17 +02:00
|
|
|
if (stat(t->filename, &fstats))
|
|
|
|
return;
|
2011-04-07 14:33:57 +02:00
|
|
|
|
|
|
|
if ((cfile = tns_cache_filename(t->filename))) {
|
|
|
|
if (force || stat(cfile, &cstats) ||
|
|
|
|
cstats.st_mtim.tv_sec != fstats.st_mtim.tv_sec ||
|
|
|
|
cstats.st_mtim.tv_nsec != fstats.st_mtim.tv_nsec)
|
|
|
|
{
|
2011-04-07 17:29:59 +02:00
|
|
|
if ((dirend = strrchr(cfile, '/'))) {
|
|
|
|
*dirend = '\0';
|
|
|
|
err = create_dir_rec(cfile);
|
|
|
|
*dirend = '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!err) {
|
|
|
|
imlib_context_set_image(t->im);
|
|
|
|
imlib_image_set_format("png");
|
|
|
|
imlib_save_image_with_error_return(cfile, &err);
|
|
|
|
}
|
2011-04-07 14:33:57 +02:00
|
|
|
|
|
|
|
if (err) {
|
2011-04-07 16:17:10 +02:00
|
|
|
warn("could not cache thumbnail: %s", t->filename);
|
2011-04-07 14:33:57 +02:00
|
|
|
} else {
|
|
|
|
TIMESPEC_TO_TIMEVAL(×[0], &fstats.st_atim);
|
|
|
|
TIMESPEC_TO_TIMEVAL(×[1], &fstats.st_mtim);
|
|
|
|
utimes(cfile, times);
|
2011-04-07 15:05:17 +02:00
|
|
|
printf("thumbnail cache file written: %s\n", t->filename);
|
2011-04-07 14:33:57 +02:00
|
|
|
}
|
|
|
|
}
|
2011-04-07 15:05:17 +02:00
|
|
|
free(cfile);
|
2011-04-07 14:33:57 +02:00
|
|
|
}
|
2011-04-07 01:26:08 +02:00
|
|
|
}
|