nsxiv7b49740
First things for thumbnail mode
+55 −2
8 files changed
- M config.h +2 −0
- M image.c +21 −0
- M image.h +7 −0
- M main.c +8 −0
- M options.c +6 −2
- M options.h +1 −0
- M window.c +8 −0
- M window.h +2 −0
| @@ -19,3 +19,5 @@ static const float zoom_levels[] = { | |||
| 19 | 19 | 12.5, 25.0, 50.0, 75.0, | |
| 20 | 20 | 100.0, 150.0, 200.0, 400.0, 800.0 | |
| 21 | 21 | }; | |
| 22 | + | ||
| 23 | + | #define THUMB_SIZE 50 | |
| @@ -149,6 +149,27 @@ int img_fit(img_t *img, win_t *win) { | |||
| 149 | 149 | return oz != img->zoom; | |
| 150 | 150 | } | |
| 151 | 151 | ||
| 152 | + | int img_load_thumb(thumb_t *tn, const char *filename) { | |
| 153 | + | int w; | |
| 154 | + | int h; | |
| 155 | + | ||
| 156 | + | if (!tn) | |
| 157 | + | return 0; | |
| 158 | + | ||
| 159 | + | if (!_imlib_load_image(filename)) | |
| 160 | + | return 0; | |
| 161 | + | ||
| 162 | + | w = imlib_image_get_width(); | |
| 163 | + | h = imlib_image_get_height(); | |
| 164 | + | ||
| 165 | + | imlib_context_set_drawable(tn->pm); | |
| 166 | + | imlib_render_image_part_on_drawable_at_size(0, 0, w, h, | |
| 167 | + | 0, 0, THUMB_SIZE, THUMB_SIZE); | |
| 168 | + | imlib_free_image(); | |
| 169 | + | ||
| 170 | + | return 1; | |
| 171 | + | } | |
| 172 | + | ||
| 152 | 173 | void img_render(img_t *img, win_t *win) { | |
| 153 | 174 | int sx, sy, sw, sh; | |
| 154 | 175 | int dx, dy, dw, dh; | |
| @@ -49,11 +49,18 @@ typedef struct img_s { | |||
| 49 | 49 | int h; | |
| 50 | 50 | } img_t; | |
| 51 | 51 | ||
| 52 | + | typedef struct thumb_s { | |
| 53 | + | int x; | |
| 54 | + | int y; | |
| 55 | + | Pixmap pm; | |
| 56 | + | } thumb_t; | |
| 57 | + | ||
| 52 | 58 | void img_init(img_t*, win_t*); | |
| 53 | 59 | void img_free(img_t*); | |
| 54 | 60 | ||
| 55 | 61 | int img_check(const char*); | |
| 56 | 62 | int img_load(img_t*, const char*); | |
| 63 | + | int img_load_thumb(thumb_t*, const char*); | |
| 57 | 64 | ||
| 58 | 65 | void img_render(img_t*, win_t*); | |
| 59 | 66 | ||
| @@ -46,6 +46,8 @@ const char **filenames; | |||
| 46 | 46 | int filecnt, fileidx; | |
| 47 | 47 | size_t filesize; | |
| 48 | 48 | ||
| 49 | + | thumb_t *thumbs; | |
| 50 | + | ||
| 49 | 51 | #define TITLE_LEN 256 | |
| 50 | 52 | char win_title[TITLE_LEN]; | |
| 51 | 53 | ||
| @@ -119,6 +121,12 @@ int main(int argc, char **argv) { | |||
| 119 | 121 | win_open(&win); | |
| 120 | 122 | img_init(&img, &win); | |
| 121 | 123 | ||
| 124 | + | if (options->thumbnails) { | |
| 125 | + | thumbs = (thumb_t*) s_malloc(filecnt * sizeof(thumb_t)); | |
| 126 | + | for (i = 0; i < filecnt; ++i) | |
| 127 | + | img_load_thumb(&thumbs[i], filenames[i]); | |
| 128 | + | } | |
| 129 | + | ||
| 122 | 130 | load_image(); | |
| 123 | 131 | img_render(&img, &win); | |
| 124 | 132 | update_title(); | |
| @@ -30,7 +30,7 @@ options_t _options; | |||
| 30 | 30 | const options_t *options = (const options_t*) &_options; | |
| 31 | 31 | ||
| 32 | 32 | void print_usage() { | |
| 33 | − | printf("usage: sxiv [-dFfhpqrsvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n"); | |
| 33 | + | printf("usage: sxiv [-dFfhpqrstvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n"); | |
| 34 | 34 | } | |
| 35 | 35 | ||
| 36 | 36 | void print_version() { | |
| @@ -45,6 +45,7 @@ void parse_options(int argc, char **argv) { | |||
| 45 | 45 | _options.scalemode = SCALE_MODE; | |
| 46 | 46 | _options.zoom = 1.0; | |
| 47 | 47 | _options.aa = 1; | |
| 48 | + | _options.thumbnails = 0; | |
| 48 | 49 | ||
| 49 | 50 | _options.fixed = 0; | |
| 50 | 51 | _options.fullscreen = 0; | |
| @@ -53,7 +54,7 @@ void parse_options(int argc, char **argv) { | |||
| 53 | 54 | _options.quiet = 0; | |
| 54 | 55 | _options.recursive = 0; | |
| 55 | 56 | ||
| 56 | − | while ((opt = getopt(argc, argv, "dFfg:hpqrsvZz:")) != -1) { | |
| 57 | + | while ((opt = getopt(argc, argv, "dFfg:hpqrstvZz:")) != -1) { | |
| 57 | 58 | switch (opt) { | |
| 58 | 59 | case '?': | |
| 59 | 60 | print_usage(); | |
| @@ -85,6 +86,9 @@ void parse_options(int argc, char **argv) { | |||
| 85 | 86 | case 's': | |
| 86 | 87 | _options.scalemode = SCALE_FIT; | |
| 87 | 88 | break; | |
| 89 | + | case 't': | |
| 90 | + | _options.thumbnails = 1; | |
| 91 | + | break; | |
| 88 | 92 | case 'v': | |
| 89 | 93 | print_version(); | |
| 90 | 94 | exit(0); | |
| @@ -29,6 +29,7 @@ typedef struct options_s { | |||
| 29 | 29 | scalemode_t scalemode; | |
| 30 | 30 | float zoom; | |
| 31 | 31 | unsigned char aa; | |
| 32 | + | unsigned char thumbnails; | |
| 32 | 33 | ||
| 33 | 34 | unsigned char fixed; | |
| 34 | 35 | unsigned char fullscreen; | |
| @@ -211,6 +211,14 @@ void win_toggle_fullscreen(win_t *win) { | |||
| 211 | 211 | SubstructureNotifyMask, &ev); | |
| 212 | 212 | } | |
| 213 | 213 | ||
| 214 | + | Pixmap win_create_pixmap(win_t *win) { | |
| 215 | + | if (!win) | |
| 216 | + | return 0; | |
| 217 | + | ||
| 218 | + | return XCreatePixmap(win->env.dpy, win->xwin, THUMB_SIZE, THUMB_SIZE, | |
| 219 | + | win->env.depth); | |
| 220 | + | } | |
| 221 | + | ||
| 214 | 222 | void win_clear(win_t *win) { | |
| 215 | 223 | win_env_t *e; | |
| 216 | 224 | XGCValues gcval; | |
| @@ -63,6 +63,8 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int); | |||
| 63 | 63 | ||
| 64 | 64 | void win_toggle_fullscreen(win_t*); | |
| 65 | 65 | ||
| 66 | + | Pixmap win_create_pixmap(win_t*); | |
| 67 | + | ||
| 66 | 68 | void win_clear(win_t*); | |
| 67 | 69 | void win_draw(win_t*); | |
| 68 | 70 | ||