Use imlib-handles in thumbs.c instead of pixmaps

master
Bert 2011-03-15 13:55:52 +01:00
parent aadba6f7e5
commit 55659ffcc3
5 changed files with 32 additions and 46 deletions

View File

@ -1,6 +1,6 @@
all: sxiv
VERSION=git-20110310
VERSION=git-20110315
CC?=gcc
PREFIX?=/usr/local

View File

@ -19,8 +19,6 @@
#include <stdlib.h>
#include <string.h>
#include <Imlib2.h>
#include "config.h"
#include "thumbs.h"
#include "util.h"
@ -45,8 +43,12 @@ void tns_free(tns_t *tns, win_t *win) {
if (!tns || !tns->thumbs)
return;
for (i = 0; i < tns->cnt; ++i)
win_free_pixmap(win, tns->thumbs[i].pm);
for (i = 0; i < tns->cnt; ++i) {
if (tns->thumbs[i].im) {
imlib_context_set_image(tns->thumbs[i].im);
imlib_free_image();
}
}
free(tns->thumbs);
tns->thumbs = NULL;
@ -66,6 +68,13 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
else if (n >= tns->cnt)
tns->cnt = n + 1;
t = &tns->thumbs[n];
if (t->im) {
imlib_context_set_image(t->im);
imlib_free_image();
}
if ((im = imlib_load_image(filename)))
imlib_context_set_image(im);
else
@ -79,23 +88,16 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) {
if (!im && z > 1.0)
z = 1.0;
t = &tns->thumbs[n];
t->w = z * w;
t->h = z * h;
if (t->pm)
win_free_pixmap(win, t->pm);
t->pm = win_create_pixmap(win, t->w, t->h);
imlib_context_set_drawable(t->pm);
imlib_context_set_anti_alias(1);
if (imlib_image_has_alpha())
win_draw_rect(win, t->pm, 0, 0, t->w, t->h, True, 0, win->white);
imlib_render_image_part_on_drawable_at_size(0, 0, w, h,
0, 0, t->w, t->h);
tns->dirty = 1;
if (!(t->im = imlib_create_cropped_scaled_image(0, 0, w, h, t->w, t->h)))
die("could not allocate memory");
if (im)
imlib_free_image_and_decache();
tns->dirty = 1;
}
void tns_check_view(tns_t *tns, Bool scrolled) {
@ -133,6 +135,7 @@ void tns_render(tns_t *tns, win_t *win) {
return;
win_clear(win);
imlib_context_set_drawable(win->pm);
tns->cols = MAX(1, win->w / thumb_dim);
tns->rows = MAX(1, win->h / thumb_dim);
@ -157,7 +160,9 @@ void tns_render(tns_t *tns, win_t *win) {
t = &tns->thumbs[tns->first + i];
t->x = x + (THUMB_SIZE - t->w) / 2;
t->y = y + (THUMB_SIZE - t->h) / 2;
win_draw_pixmap(win, t->pm, t->x, t->y, t->w, t->h);
imlib_context_set_image(t->im);
imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h,
t->x, t->y, t->w, t->h);
if ((i + 1) % tns->cols == 0) {
x = tns->x;
y += thumb_dim;

View File

@ -19,6 +19,8 @@
#ifndef THUMBS_H
#define THUMBS_H
#include <Imlib2.h>
#include "window.h"
typedef enum {
@ -29,7 +31,7 @@ typedef enum {
} tnsdir_t;
typedef struct {
Pixmap pm;
Imlib_Image *im;
int x;
int y;
int w;

View File

@ -232,18 +232,6 @@ void win_toggle_fullscreen(win_t *win) {
SubstructureNotifyMask, &ev);
}
Pixmap win_create_pixmap(win_t *win, int w, int h) {
if (!win)
return 0;
return XCreatePixmap(win->env.dpy, win->xwin, w, h, win->env.depth);
}
void win_free_pixmap(win_t *win, Pixmap pm) {
if (win && pm)
XFreePixmap(win->env.dpy, pm);
}
void win_clear(win_t *win) {
win_env_t *e;
XGCValues gcval;
@ -262,9 +250,12 @@ void win_clear(win_t *win) {
XFillRectangle(e->dpy, win->pm, gc, 0, 0, e->scrw, e->scrh);
}
void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) {
if (win)
XCopyArea(win->env.dpy, pm, win->pm, gc, 0, 0, w, h, x, y);
void win_draw(win_t *win) {
if (!win)
return;
XSetWindowBackgroundPixmap(win->env.dpy, win->xwin, win->pm);
XClearWindow(win->env.dpy, win->xwin);
}
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,
XDrawRectangle(win->env.dpy, pm, gc, x, y, w, h);
}
void win_draw(win_t *win) {
if (!win)
return;
XSetWindowBackgroundPixmap(win->env.dpy, win->xwin, win->pm);
XClearWindow(win->env.dpy, win->xwin);
}
void win_set_title(win_t *win, const char *title) {
if (!win)
return;

View File

@ -68,14 +68,10 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int);
void win_toggle_fullscreen(win_t*);
Pixmap win_create_pixmap(win_t*, int, int);
void win_free_pixmap(win_t*, Pixmap);
void win_clear(win_t*);
void win_draw_pixmap(win_t*, Pixmap, int, int, int, int);
void win_draw(win_t*);
void win_draw_rect(win_t*, Pixmap, int, int, int, int, Bool, int,
unsigned long);
void win_draw(win_t*);
void win_set_title(win_t*, const char*);
void win_set_cursor(win_t*, win_cur_t);