From 7b497406136dabcce280bae3886a88ee77ebc1e7 Mon Sep 17 00:00:00 2001 From: Bert Date: Wed, 16 Feb 2011 16:47:12 +0100 Subject: First things for thumbnail mode --- config.h | 2 ++ image.c | 21 +++++++++++++++++++++ image.h | 7 +++++++ main.c | 8 ++++++++ options.c | 8 ++++++-- options.h | 1 + window.c | 8 ++++++++ window.h | 2 ++ 8 files changed, 55 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index e140446..b53acb4 100644 --- a/config.h +++ b/config.h @@ -19,3 +19,5 @@ static const float zoom_levels[] = { 12.5, 25.0, 50.0, 75.0, 100.0, 150.0, 200.0, 400.0, 800.0 }; + +#define THUMB_SIZE 50 diff --git a/image.c b/image.c index 64225b1..cc664b6 100644 --- a/image.c +++ b/image.c @@ -149,6 +149,27 @@ int img_fit(img_t *img, win_t *win) { return oz != img->zoom; } +int img_load_thumb(thumb_t *tn, const char *filename) { + int w; + int h; + + if (!tn) + return 0; + + if (!_imlib_load_image(filename)) + return 0; + + w = imlib_image_get_width(); + h = imlib_image_get_height(); + + imlib_context_set_drawable(tn->pm); + imlib_render_image_part_on_drawable_at_size(0, 0, w, h, + 0, 0, THUMB_SIZE, THUMB_SIZE); + imlib_free_image(); + + return 1; +} + void img_render(img_t *img, win_t *win) { int sx, sy, sw, sh; int dx, dy, dw, dh; diff --git a/image.h b/image.h index fd5b0fe..d0ebbf1 100644 --- a/image.h +++ b/image.h @@ -49,11 +49,18 @@ typedef struct img_s { int h; } img_t; +typedef struct thumb_s { + int x; + int y; + Pixmap pm; +} thumb_t; + void img_init(img_t*, win_t*); void img_free(img_t*); int img_check(const char*); int img_load(img_t*, const char*); +int img_load_thumb(thumb_t*, const char*); void img_render(img_t*, win_t*); diff --git a/main.c b/main.c index 9e5965b..c680bef 100644 --- a/main.c +++ b/main.c @@ -46,6 +46,8 @@ const char **filenames; int filecnt, fileidx; size_t filesize; +thumb_t *thumbs; + #define TITLE_LEN 256 char win_title[TITLE_LEN]; @@ -119,6 +121,12 @@ int main(int argc, char **argv) { win_open(&win); img_init(&img, &win); + if (options->thumbnails) { + thumbs = (thumb_t*) s_malloc(filecnt * sizeof(thumb_t)); + for (i = 0; i < filecnt; ++i) + img_load_thumb(&thumbs[i], filenames[i]); + } + load_image(); img_render(&img, &win); update_title(); diff --git a/options.c b/options.c index 0a1aeda..2291ded 100644 --- a/options.c +++ b/options.c @@ -30,7 +30,7 @@ options_t _options; const options_t *options = (const options_t*) &_options; void print_usage() { - printf("usage: sxiv [-dFfhpqrsvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n"); + printf("usage: sxiv [-dFfhpqrstvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n"); } void print_version() { @@ -45,6 +45,7 @@ void parse_options(int argc, char **argv) { _options.scalemode = SCALE_MODE; _options.zoom = 1.0; _options.aa = 1; + _options.thumbnails = 0; _options.fixed = 0; _options.fullscreen = 0; @@ -53,7 +54,7 @@ void parse_options(int argc, char **argv) { _options.quiet = 0; _options.recursive = 0; - while ((opt = getopt(argc, argv, "dFfg:hpqrsvZz:")) != -1) { + while ((opt = getopt(argc, argv, "dFfg:hpqrstvZz:")) != -1) { switch (opt) { case '?': print_usage(); @@ -85,6 +86,9 @@ void parse_options(int argc, char **argv) { case 's': _options.scalemode = SCALE_FIT; break; + case 't': + _options.thumbnails = 1; + break; case 'v': print_version(); exit(0); diff --git a/options.h b/options.h index fd2e0bd..246ddb7 100644 --- a/options.h +++ b/options.h @@ -29,6 +29,7 @@ typedef struct options_s { scalemode_t scalemode; float zoom; unsigned char aa; + unsigned char thumbnails; unsigned char fixed; unsigned char fullscreen; diff --git a/window.c b/window.c index 76a8e87..1be14c1 100644 --- a/window.c +++ b/window.c @@ -211,6 +211,14 @@ void win_toggle_fullscreen(win_t *win) { SubstructureNotifyMask, &ev); } +Pixmap win_create_pixmap(win_t *win) { + if (!win) + return 0; + + return XCreatePixmap(win->env.dpy, win->xwin, THUMB_SIZE, THUMB_SIZE, + win->env.depth); +} + void win_clear(win_t *win) { win_env_t *e; XGCValues gcval; diff --git a/window.h b/window.h index 1ae431b..212272f 100644 --- a/window.h +++ b/window.h @@ -63,6 +63,8 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int); void win_toggle_fullscreen(win_t*); +Pixmap win_create_pixmap(win_t*); + void win_clear(win_t*); void win_draw(win_t*); -- cgit v1.2.3