First things for thumbnail mode

master
Bert 2011-02-16 16:47:12 +01:00
parent e8ed491ba9
commit 7b49740613
8 changed files with 55 additions and 2 deletions

View File

@ -19,3 +19,5 @@ static const float zoom_levels[] = {
12.5, 25.0, 50.0, 75.0,
100.0, 150.0, 200.0, 400.0, 800.0
};
#define THUMB_SIZE 50

21
image.c
View File

@ -149,6 +149,27 @@ int img_fit(img_t *img, win_t *win) {
return oz != img->zoom;
}
int img_load_thumb(thumb_t *tn, const char *filename) {
int w;
int h;
if (!tn)
return 0;
if (!_imlib_load_image(filename))
return 0;
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_drawable(tn->pm);
imlib_render_image_part_on_drawable_at_size(0, 0, w, h,
0, 0, THUMB_SIZE, THUMB_SIZE);
imlib_free_image();
return 1;
}
void img_render(img_t *img, win_t *win) {
int sx, sy, sw, sh;
int dx, dy, dw, dh;

View File

@ -49,11 +49,18 @@ typedef struct img_s {
int h;
} img_t;
typedef struct thumb_s {
int x;
int y;
Pixmap pm;
} thumb_t;
void img_init(img_t*, win_t*);
void img_free(img_t*);
int img_check(const char*);
int img_load(img_t*, const char*);
int img_load_thumb(thumb_t*, const char*);
void img_render(img_t*, win_t*);

8
main.c
View File

@ -46,6 +46,8 @@ const char **filenames;
int filecnt, fileidx;
size_t filesize;
thumb_t *thumbs;
#define TITLE_LEN 256
char win_title[TITLE_LEN];
@ -119,6 +121,12 @@ int main(int argc, char **argv) {
win_open(&win);
img_init(&img, &win);
if (options->thumbnails) {
thumbs = (thumb_t*) s_malloc(filecnt * sizeof(thumb_t));
for (i = 0; i < filecnt; ++i)
img_load_thumb(&thumbs[i], filenames[i]);
}
load_image();
img_render(&img, &win);
update_title();

View File

@ -30,7 +30,7 @@ options_t _options;
const options_t *options = (const options_t*) &_options;
void print_usage() {
printf("usage: sxiv [-dFfhpqrsvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
printf("usage: sxiv [-dFfhpqrstvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
}
void print_version() {
@ -45,6 +45,7 @@ void parse_options(int argc, char **argv) {
_options.scalemode = SCALE_MODE;
_options.zoom = 1.0;
_options.aa = 1;
_options.thumbnails = 0;
_options.fixed = 0;
_options.fullscreen = 0;
@ -53,7 +54,7 @@ void parse_options(int argc, char **argv) {
_options.quiet = 0;
_options.recursive = 0;
while ((opt = getopt(argc, argv, "dFfg:hpqrsvZz:")) != -1) {
while ((opt = getopt(argc, argv, "dFfg:hpqrstvZz:")) != -1) {
switch (opt) {
case '?':
print_usage();
@ -85,6 +86,9 @@ void parse_options(int argc, char **argv) {
case 's':
_options.scalemode = SCALE_FIT;
break;
case 't':
_options.thumbnails = 1;
break;
case 'v':
print_version();
exit(0);

View File

@ -29,6 +29,7 @@ typedef struct options_s {
scalemode_t scalemode;
float zoom;
unsigned char aa;
unsigned char thumbnails;
unsigned char fixed;
unsigned char fullscreen;

View File

@ -211,6 +211,14 @@ void win_toggle_fullscreen(win_t *win) {
SubstructureNotifyMask, &ev);
}
Pixmap win_create_pixmap(win_t *win) {
if (!win)
return 0;
return XCreatePixmap(win->env.dpy, win->xwin, THUMB_SIZE, THUMB_SIZE,
win->env.depth);
}
void win_clear(win_t *win) {
win_env_t *e;
XGCValues gcval;

View File

@ -63,6 +63,8 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int);
void win_toggle_fullscreen(win_t*);
Pixmap win_create_pixmap(win_t*);
void win_clear(win_t*);
void win_draw(win_t*);