Krolyxon
Commit 8919204

Branches

Refs →

nsxiv8919204

Render thumbnails

Author
Bert
Date
2011-02-16 18:16 +0100
Parent
89ec183
Commit
8919204a2e666e12216240a792bfff7a391d4d43

+76 −24

6 files changed

  1. M image.c +26 −21
  2. M image.h +2 −0
  3. M main.c +33 −0
  4. M options.c +7 −3
  5. M window.c +7 −0
  6. M window.h +1 −0
M image.c View
@@ -110,6 +110,32 @@ int img_load(img_t *img, const char *filename) {
110110 return 1;
111111 }
112112
113+int img_load_thumb(thumb_t *tn, const char *filename) {
114+ int w, h;
115+ float z, zw, zh;
116+
117+ if (!tn)
118+ return 0;
119+
120+ if (!_imlib_load_image(filename))
121+ return 0;
122+
123+ w = imlib_image_get_width();
124+ h = imlib_image_get_height();
125+ zw = (float) THUMB_SIZE / (float) w;
126+ zh = (float) THUMB_SIZE / (float) h;
127+ z = MIN(zw, zh);
128+ tn->w = z * w;
129+ tn->h = z * h;
130+
131+ imlib_context_set_drawable(tn->pm);
132+ imlib_render_image_part_on_drawable_at_size(0, 0, w, h,
133+ 0, 0, tn->w, tn->h);
134+ imlib_free_image();
135+
136+ return 1;
137+}
138+
113139 void img_check_pan(img_t *img, win_t *win) {
114140 if (!img || !win)
115141 return;
@@ -149,27 +175,6 @@ int img_fit(img_t *img, win_t *win) {
149175 return oz != img->zoom;
150176 }
151177
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−
173178 void img_render(img_t *img, win_t *win) {
174179 int sx, sy, sw, sh;
175180 int dx, dy, dw, dh;
M image.h View
@@ -52,6 +52,8 @@ typedef struct img_s {
5252 typedef struct thumb_s {
5353 int x;
5454 int y;
55+ int w;
56+ int h;
5557 Pixmap pm;
5658 } thumb_t;
5759
M main.c View
@@ -27,6 +27,7 @@
2727 #include <X11/Xutil.h>
2828 #include <X11/keysym.h>
2929
30+#include "config.h"
3031 #include "image.h"
3132 #include "options.h"
3233 #include "util.h"
@@ -38,6 +39,7 @@ typedef enum appmode_e {
3839 } appmode_t;
3940
4041 void update_title();
42+void render_thumbs();
4143 int check_append(const char*);
4244 void read_dir_rec(const char*);
4345 void run();
@@ -53,6 +55,7 @@ int filecnt, fileidx;
5355 size_t filesize;
5456
5557 thumb_t *thumbs;
58+int tvis, tcols, trows;
5659
5760 #define TITLE_LEN 256
5861 char win_title[TITLE_LEN];
@@ -137,6 +140,7 @@ int main(int argc, char **argv) {
137140
138141 if (options->thumbnails == 2) {
139142 mode = MODE_THUMBS;
143+ render_thumbs();
140144 } else {
141145 mode = MODE_NORMAL;
142146 load_image();
@@ -175,6 +179,35 @@ void update_title() {
175179 win_set_title(&win, win_title);
176180 }
177181
182+void render_thumbs() {
183+ int i, cnt, x, y;
184+
185+ tcols = win.w / (THUMB_SIZE + 10);
186+ trows = win.h / (THUMB_SIZE + 10);
187+
188+ x = win.w - tcols * (THUMB_SIZE + 10) + 5;
189+ y = win.h - trows * (THUMB_SIZE + 10) + 5;
190+ cnt = MIN(tcols * trows, filecnt);
191+
192+ win_clear(&win);
193+
194+ i = 0;
195+ while (i < cnt) {
196+ thumbs[i].x = x + (THUMB_SIZE - thumbs[i].w) / 2;
197+ thumbs[i].y = y + (THUMB_SIZE - thumbs[i].h) / 2;
198+ win_draw_pixmap(&win, thumbs[i].pm, thumbs[i].x, thumbs[i].y, thumbs[i].w,
199+ thumbs[i].h);
200+ if (++i % tcols == 0) {
201+ x = win.w - tcols * (THUMB_SIZE + 10) + 5;
202+ y += THUMB_SIZE + 10;
203+ } else {
204+ x += THUMB_SIZE + 10;
205+ }
206+ }
207+
208+ win_draw(&win);
209+}
210+
178211 int check_append(const char *filename) {
179212 if (!filename)
180213 return 0;
M options.c View
@@ -25,12 +25,13 @@
2525
2626 #include "config.h"
2727 #include "options.h"
28+#include "util.h"
2829
2930 options_t _options;
3031 const options_t *options = (const options_t*) &_options;
3132
3233 void print_usage() {
33− printf("usage: sxiv [-dFfhpqrstvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
34+ printf("usage: sxiv [-dFfhpqrsTtvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
3435 }
3536
3637 void print_version() {
@@ -54,7 +55,7 @@ void parse_options(int argc, char **argv) {
5455 _options.quiet = 0;
5556 _options.recursive = 0;
5657
57− while ((opt = getopt(argc, argv, "dFfg:hpqrstvZz:")) != -1) {
58+ while ((opt = getopt(argc, argv, "dFfg:hpqrsTtvZz:")) != -1) {
5859 switch (opt) {
5960 case '?':
6061 print_usage();
@@ -86,8 +87,11 @@ void parse_options(int argc, char **argv) {
8687 case 's':
8788 _options.scalemode = SCALE_FIT;
8889 break;
90+ case 'T':
91+ _options.thumbnails = 2;
92+ break;
8993 case 't':
90− _options.thumbnails = 1;
94+ _options.thumbnails = MAX(_options.thumbnails, 1);
9195 break;
9296 case 'v':
9397 print_version();
M window.c View
@@ -219,6 +219,13 @@ Pixmap win_create_pixmap(win_t *win) {
219219 win->env.depth);
220220 }
221221
222+void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) {
223+ if (!win)
224+ return;
225+
226+ XCopyArea(win->env.dpy, pm, win->pm, bgc, 0, 0, w, h, x, y);
227+}
228+
222229 void win_clear(win_t *win) {
223230 win_env_t *e;
224231 XGCValues gcval;
M window.h View
@@ -64,6 +64,7 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int);
6464 void win_toggle_fullscreen(win_t*);
6565
6666 Pixmap win_create_pixmap(win_t*);
67+void win_draw_pixmap(win_t*, Pixmap, int, int, int, int);
6768
6869 void win_clear(win_t*);
6970 void win_draw(win_t*);