nsxiv55659ff
Use imlib-handles in thumbs.c instead of pixmaps
+32 −46
5 files changed
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | all: sxiv | |
| 2 | 2 | ||
| 3 | − | VERSION=git-20110310 | |
| 3 | + | VERSION=git-20110315 | |
| 4 | 4 | ||
| 5 | 5 | CC?=gcc | |
| 6 | 6 | PREFIX?=/usr/local | |
| @@ -19,8 +19,6 @@ | |||
| 19 | 19 | #include <stdlib.h> | |
| 20 | 20 | #include <string.h> | |
| 21 | 21 | ||
| 22 | − | #include <Imlib2.h> | |
| 23 | − | ||
| 24 | 22 | #include "config.h" | |
| 25 | 23 | #include "thumbs.h" | |
| 26 | 24 | #include "util.h" | |
| @@ -45,8 +43,12 @@ void tns_free(tns_t *tns, win_t *win) { | |||
| 45 | 43 | if (!tns || !tns->thumbs) | |
| 46 | 44 | return; | |
| 47 | 45 | ||
| 48 | − | for (i = 0; i < tns->cnt; ++i) | |
| 49 | − | win_free_pixmap(win, tns->thumbs[i].pm); | |
| 46 | + | for (i = 0; i < tns->cnt; ++i) { | |
| 47 | + | if (tns->thumbs[i].im) { | |
| 48 | + | imlib_context_set_image(tns->thumbs[i].im); | |
| 49 | + | imlib_free_image(); | |
| 50 | + | } | |
| 51 | + | } | |
| 50 | 52 | ||
| 51 | 53 | free(tns->thumbs); | |
| 52 | 54 | tns->thumbs = NULL; | |
| @@ -66,6 +68,13 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |||
| 66 | 68 | else if (n >= tns->cnt) | |
| 67 | 69 | tns->cnt = n + 1; | |
| 68 | 70 | ||
| 71 | + | t = &tns->thumbs[n]; | |
| 72 | + | ||
| 73 | + | if (t->im) { | |
| 74 | + | imlib_context_set_image(t->im); | |
| 75 | + | imlib_free_image(); | |
| 76 | + | } | |
| 77 | + | ||
| 69 | 78 | if ((im = imlib_load_image(filename))) | |
| 70 | 79 | imlib_context_set_image(im); | |
| 71 | 80 | else | |
| @@ -79,23 +88,16 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |||
| 79 | 88 | if (!im && z > 1.0) | |
| 80 | 89 | z = 1.0; | |
| 81 | 90 | ||
| 82 | − | t = &tns->thumbs[n]; | |
| 83 | 91 | t->w = z * w; | |
| 84 | 92 | t->h = z * h; | |
| 85 | 93 | ||
| 86 | − | if (t->pm) | |
| 87 | − | win_free_pixmap(win, t->pm); | |
| 88 | − | t->pm = win_create_pixmap(win, t->w, t->h); | |
| 89 | − | imlib_context_set_drawable(t->pm); | |
| 90 | 94 | imlib_context_set_anti_alias(1); | |
| 91 | − | if (imlib_image_has_alpha()) | |
| 92 | − | win_draw_rect(win, t->pm, 0, 0, t->w, t->h, True, 0, win->white); | |
| 93 | − | imlib_render_image_part_on_drawable_at_size(0, 0, w, h, | |
| 94 | − | 0, 0, t->w, t->h); | |
| 95 | − | tns->dirty = 1; | |
| 96 | − | ||
| 95 | + | if (!(t->im = imlib_create_cropped_scaled_image(0, 0, w, h, t->w, t->h))) | |
| 96 | + | die("could not allocate memory"); | |
| 97 | 97 | if (im) | |
| 98 | 98 | imlib_free_image_and_decache(); | |
| 99 | + | ||
| 100 | + | tns->dirty = 1; | |
| 99 | 101 | } | |
| 100 | 102 | ||
| 101 | 103 | void tns_check_view(tns_t *tns, Bool scrolled) { | |
| @@ -133,6 +135,7 @@ void tns_render(tns_t *tns, win_t *win) { | |||
| 133 | 135 | return; | |
| 134 | 136 | ||
| 135 | 137 | win_clear(win); | |
| 138 | + | imlib_context_set_drawable(win->pm); | |
| 136 | 139 | ||
| 137 | 140 | tns->cols = MAX(1, win->w / thumb_dim); | |
| 138 | 141 | tns->rows = MAX(1, win->h / thumb_dim); | |
| @@ -157,7 +160,9 @@ void tns_render(tns_t *tns, win_t *win) { | |||
| 157 | 160 | t = &tns->thumbs[tns->first + i]; | |
| 158 | 161 | t->x = x + (THUMB_SIZE - t->w) / 2; | |
| 159 | 162 | t->y = y + (THUMB_SIZE - t->h) / 2; | |
| 160 | − | win_draw_pixmap(win, t->pm, t->x, t->y, t->w, t->h); | |
| 163 | + | imlib_context_set_image(t->im); | |
| 164 | + | imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h, | |
| 165 | + | t->x, t->y, t->w, t->h); | |
| 161 | 166 | if ((i + 1) % tns->cols == 0) { | |
| 162 | 167 | x = tns->x; | |
| 163 | 168 | y += thumb_dim; | |
| @@ -19,6 +19,8 @@ | |||
| 19 | 19 | #ifndef THUMBS_H | |
| 20 | 20 | #define THUMBS_H | |
| 21 | 21 | ||
| 22 | + | #include <Imlib2.h> | |
| 23 | + | ||
| 22 | 24 | #include "window.h" | |
| 23 | 25 | ||
| 24 | 26 | typedef enum { | |
| @@ -29,7 +31,7 @@ typedef enum { | |||
| 29 | 31 | } tnsdir_t; | |
| 30 | 32 | ||
| 31 | 33 | typedef struct { | |
| 32 | − | Pixmap pm; | |
| 34 | + | Imlib_Image *im; | |
| 33 | 35 | int x; | |
| 34 | 36 | int y; | |
| 35 | 37 | int w; | |
| @@ -232,18 +232,6 @@ void win_toggle_fullscreen(win_t *win) { | |||
| 232 | 232 | SubstructureNotifyMask, &ev); | |
| 233 | 233 | } | |
| 234 | 234 | ||
| 235 | − | Pixmap win_create_pixmap(win_t *win, int w, int h) { | |
| 236 | − | if (!win) | |
| 237 | − | return 0; | |
| 238 | − | ||
| 239 | − | return XCreatePixmap(win->env.dpy, win->xwin, w, h, win->env.depth); | |
| 240 | − | } | |
| 241 | − | ||
| 242 | − | void win_free_pixmap(win_t *win, Pixmap pm) { | |
| 243 | − | if (win && pm) | |
| 244 | − | XFreePixmap(win->env.dpy, pm); | |
| 245 | − | } | |
| 246 | − | ||
| 247 | 235 | void win_clear(win_t *win) { | |
| 248 | 236 | win_env_t *e; | |
| 249 | 237 | XGCValues gcval; | |
| @@ -262,9 +250,12 @@ void win_clear(win_t *win) { | |||
| 262 | 250 | XFillRectangle(e->dpy, win->pm, gc, 0, 0, e->scrw, e->scrh); | |
| 263 | 251 | } | |
| 264 | 252 | ||
| 265 | − | void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) { | |
| 266 | − | if (win) | |
| 267 | − | XCopyArea(win->env.dpy, pm, win->pm, gc, 0, 0, w, h, x, y); | |
| 253 | + | void win_draw(win_t *win) { | |
| 254 | + | if (!win) | |
| 255 | + | return; | |
| 256 | + | ||
| 257 | + | XSetWindowBackgroundPixmap(win->env.dpy, win->xwin, win->pm); | |
| 258 | + | XClearWindow(win->env.dpy, win->xwin); | |
| 268 | 259 | } | |
| 269 | 260 | ||
| 270 | 261 | void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h, | |
| @@ -284,14 +275,6 @@ void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h, | |||
| 284 | 275 | XDrawRectangle(win->env.dpy, pm, gc, x, y, w, h); | |
| 285 | 276 | } | |
| 286 | 277 | ||
| 287 | − | void win_draw(win_t *win) { | |
| 288 | − | if (!win) | |
| 289 | − | return; | |
| 290 | − | ||
| 291 | − | XSetWindowBackgroundPixmap(win->env.dpy, win->xwin, win->pm); | |
| 292 | − | XClearWindow(win->env.dpy, win->xwin); | |
| 293 | − | } | |
| 294 | − | ||
| 295 | 278 | void win_set_title(win_t *win, const char *title) { | |
| 296 | 279 | if (!win) | |
| 297 | 280 | return; | |
| @@ -68,14 +68,10 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int); | |||
| 68 | 68 | ||
| 69 | 69 | void win_toggle_fullscreen(win_t*); | |
| 70 | 70 | ||
| 71 | − | Pixmap win_create_pixmap(win_t*, int, int); | |
| 72 | − | void win_free_pixmap(win_t*, Pixmap); | |
| 73 | − | ||
| 74 | 71 | void win_clear(win_t*); | |
| 75 | − | void win_draw_pixmap(win_t*, Pixmap, int, int, int, int); | |
| 72 | + | void win_draw(win_t*); | |
| 76 | 73 | void win_draw_rect(win_t*, Pixmap, int, int, int, int, Bool, int, | |
| 77 | 74 | unsigned long); | |
| 78 | − | void win_draw(win_t*); | |
| 79 | 75 | ||
| 80 | 76 | void win_set_title(win_t*, const char*); | |
| 81 | 77 | void win_set_cursor(win_t*, win_cur_t); | |