diff options
author | Bert <ber.t@gmx.com> | 2011-02-16 16:47:12 +0100 |
---|---|---|
committer | Bert <ber.t@gmx.com> | 2011-02-16 16:47:12 +0100 |
commit | 7b497406136dabcce280bae3886a88ee77ebc1e7 (patch) | |
tree | ec183d7ff703de99d5f3e9eb1b65c0d11a046774 | |
parent | e8ed491ba9f2fe6df8f071e7c59e0174bb307a1b (diff) |
First things for thumbnail mode
-rw-r--r-- | config.h | 2 | ||||
-rw-r--r-- | image.c | 21 | ||||
-rw-r--r-- | image.h | 7 | ||||
-rw-r--r-- | main.c | 8 | ||||
-rw-r--r-- | options.c | 8 | ||||
-rw-r--r-- | options.h | 1 | ||||
-rw-r--r-- | window.c | 8 | ||||
-rw-r--r-- | window.h | 2 |
8 files changed, 55 insertions, 2 deletions
@@ -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 @@ -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; @@ -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*); @@ -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(); @@ -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); @@ -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; @@ -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; @@ -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*); |