Krolyxon
Commit 55659ff

Branches

Refs →

nsxiv55659ff

Use imlib-handles in thumbs.c instead of pixmaps

Author
Bert
Date
2011-03-15 13:55 +0100
Parent
aadba6f
Commit
55659ffcc38d547b2a1525b9e444ae9ec8394643

+32 −46

5 files changed

  1. M Makefile +1 −1
  2. M thumbs.c +21 −16
  3. M thumbs.h +3 −1
  4. M window.c +6 −23
  5. M window.h +1 −5
M Makefile View
@@ -1,6 +1,6 @@
11 all: sxiv
22
3−VERSION=git-20110310
3+VERSION=git-20110315
44
55 CC?=gcc
66 PREFIX?=/usr/local
M thumbs.c View
@@ -19,8 +19,6 @@
1919 #include <stdlib.h>
2020 #include <string.h>
2121
22−#include <Imlib2.h>
23−
2422 #include "config.h"
2523 #include "thumbs.h"
2624 #include "util.h"
@@ -45,8 +43,12 @@ void tns_free(tns_t *tns, win_t *win) {
4543 if (!tns || !tns->thumbs)
4644 return;
4745
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+ }
5052
5153 free(tns->thumbs);
5254 tns->thumbs = NULL;
@@ -66,6 +68,13 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
6668 else if (n >= tns->cnt)
6769 tns->cnt = n + 1;
6870
71+ t = &tns->thumbs[n];
72+
73+ if (t->im) {
74+ imlib_context_set_image(t->im);
75+ imlib_free_image();
76+ }
77+
6978 if ((im = imlib_load_image(filename)))
7079 imlib_context_set_image(im);
7180 else
@@ -79,23 +88,16 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
7988 if (!im && z > 1.0)
8089 z = 1.0;
8190
82− t = &tns->thumbs[n];
8391 t->w = z * w;
8492 t->h = z * h;
8593
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);
9094 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");
9797 if (im)
9898 imlib_free_image_and_decache();
99+
100+ tns->dirty = 1;
99101 }
100102
101103 void tns_check_view(tns_t *tns, Bool scrolled) {
@@ -133,6 +135,7 @@ void tns_render(tns_t *tns, win_t *win) {
133135 return;
134136
135137 win_clear(win);
138+ imlib_context_set_drawable(win->pm);
136139
137140 tns->cols = MAX(1, win->w / thumb_dim);
138141 tns->rows = MAX(1, win->h / thumb_dim);
@@ -157,7 +160,9 @@ void tns_render(tns_t *tns, win_t *win) {
157160 t = &tns->thumbs[tns->first + i];
158161 t->x = x + (THUMB_SIZE - t->w) / 2;
159162 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);
161166 if ((i + 1) % tns->cols == 0) {
162167 x = tns->x;
163168 y += thumb_dim;
M thumbs.h View
@@ -19,6 +19,8 @@
1919 #ifndef THUMBS_H
2020 #define THUMBS_H
2121
22+#include <Imlib2.h>
23+
2224 #include "window.h"
2325
2426 typedef enum {
@@ -29,7 +31,7 @@ typedef enum {
2931 } tnsdir_t;
3032
3133 typedef struct {
32− Pixmap pm;
34+ Imlib_Image *im;
3335 int x;
3436 int y;
3537 int w;
M window.c View
@@ -232,18 +232,6 @@ void win_toggle_fullscreen(win_t *win) {
232232 SubstructureNotifyMask, &ev);
233233 }
234234
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−
247235 void win_clear(win_t *win) {
248236 win_env_t *e;
249237 XGCValues gcval;
@@ -262,9 +250,12 @@ void win_clear(win_t *win) {
262250 XFillRectangle(e->dpy, win->pm, gc, 0, 0, e->scrw, e->scrh);
263251 }
264252
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);
268259 }
269260
270261 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,
284275 XDrawRectangle(win->env.dpy, pm, gc, x, y, w, h);
285276 }
286277
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−
295278 void win_set_title(win_t *win, const char *title) {
296279 if (!win)
297280 return;
M window.h View
@@ -68,14 +68,10 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int);
6868
6969 void win_toggle_fullscreen(win_t*);
7070
71−Pixmap win_create_pixmap(win_t*, int, int);
72−void win_free_pixmap(win_t*, Pixmap);
73−
7471 void win_clear(win_t*);
75−void win_draw_pixmap(win_t*, Pixmap, int, int, int, int);
72+void win_draw(win_t*);
7673 void win_draw_rect(win_t*, Pixmap, int, int, int, int, Bool, int,
7774 unsigned long);
78−void win_draw(win_t*);
7975
8076 void win_set_title(win_t*, const char*);
8177 void win_set_cursor(win_t*, win_cur_t);