Krolyxon
Commit 7b49740

Branches

Refs →

nsxiv7b49740

First things for thumbnail mode

Author
Bert
Date
2011-02-16 16:47 +0100
Parent
e8ed491
Commit
7b497406136dabcce280bae3886a88ee77ebc1e7

+55 −2

8 files changed

  1. M config.h +2 −0
  2. M image.c +21 −0
  3. M image.h +7 −0
  4. M main.c +8 −0
  5. M options.c +6 −2
  6. M options.h +1 −0
  7. M window.c +8 −0
  8. M window.h +2 −0
M config.h View
@@ -19,3 +19,5 @@ static const float zoom_levels[] = {
1919 12.5, 25.0, 50.0, 75.0,
2020 100.0, 150.0, 200.0, 400.0, 800.0
2121 };
22+
23+#define THUMB_SIZE 50
M image.c View
@@ -149,6 +149,27 @@ int img_fit(img_t *img, win_t *win) {
149149 return oz != img->zoom;
150150 }
151151
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+
152173 void img_render(img_t *img, win_t *win) {
153174 int sx, sy, sw, sh;
154175 int dx, dy, dw, dh;
M image.h View
@@ -49,11 +49,18 @@ typedef struct img_s {
4949 int h;
5050 } img_t;
5151
52+typedef struct thumb_s {
53+ int x;
54+ int y;
55+ Pixmap pm;
56+} thumb_t;
57+
5258 void img_init(img_t*, win_t*);
5359 void img_free(img_t*);
5460
5561 int img_check(const char*);
5662 int img_load(img_t*, const char*);
63+int img_load_thumb(thumb_t*, const char*);
5764
5865 void img_render(img_t*, win_t*);
5966
M main.c View
@@ -46,6 +46,8 @@ const char **filenames;
4646 int filecnt, fileidx;
4747 size_t filesize;
4848
49+thumb_t *thumbs;
50+
4951 #define TITLE_LEN 256
5052 char win_title[TITLE_LEN];
5153
@@ -119,6 +121,12 @@ int main(int argc, char **argv) {
119121 win_open(&win);
120122 img_init(&img, &win);
121123
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+
122130 load_image();
123131 img_render(&img, &win);
124132 update_title();
M options.c View
@@ -30,7 +30,7 @@ options_t _options;
3030 const options_t *options = (const options_t*) &_options;
3131
3232 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");
3434 }
3535
3636 void print_version() {
@@ -45,6 +45,7 @@ void parse_options(int argc, char **argv) {
4545 _options.scalemode = SCALE_MODE;
4646 _options.zoom = 1.0;
4747 _options.aa = 1;
48+ _options.thumbnails = 0;
4849
4950 _options.fixed = 0;
5051 _options.fullscreen = 0;
@@ -53,7 +54,7 @@ void parse_options(int argc, char **argv) {
5354 _options.quiet = 0;
5455 _options.recursive = 0;
5556
56− while ((opt = getopt(argc, argv, "dFfg:hpqrsvZz:")) != -1) {
57+ while ((opt = getopt(argc, argv, "dFfg:hpqrstvZz:")) != -1) {
5758 switch (opt) {
5859 case '?':
5960 print_usage();
@@ -85,6 +86,9 @@ void parse_options(int argc, char **argv) {
8586 case 's':
8687 _options.scalemode = SCALE_FIT;
8788 break;
89+ case 't':
90+ _options.thumbnails = 1;
91+ break;
8892 case 'v':
8993 print_version();
9094 exit(0);
M options.h View
@@ -29,6 +29,7 @@ typedef struct options_s {
2929 scalemode_t scalemode;
3030 float zoom;
3131 unsigned char aa;
32+ unsigned char thumbnails;
3233
3334 unsigned char fixed;
3435 unsigned char fullscreen;
M window.c View
@@ -211,6 +211,14 @@ void win_toggle_fullscreen(win_t *win) {
211211 SubstructureNotifyMask, &ev);
212212 }
213213
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+
214222 void win_clear(win_t *win) {
215223 win_env_t *e;
216224 XGCValues gcval;
M window.h View
@@ -63,6 +63,8 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int);
6363
6464 void win_toggle_fullscreen(win_t*);
6565
66+Pixmap win_create_pixmap(win_t*);
67+
6668 void win_clear(win_t*);
6769 void win_draw(win_t*);
6870