Render thumbnails
This commit is contained in:
parent
89ec18385b
commit
8919204a2e
47
image.c
47
image.c
|
@ -110,6 +110,32 @@ int img_load(img_t *img, const char *filename) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int img_load_thumb(thumb_t *tn, const char *filename) {
|
||||||
|
int w, h;
|
||||||
|
float z, zw, zh;
|
||||||
|
|
||||||
|
if (!tn)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!_imlib_load_image(filename))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
w = imlib_image_get_width();
|
||||||
|
h = imlib_image_get_height();
|
||||||
|
zw = (float) THUMB_SIZE / (float) w;
|
||||||
|
zh = (float) THUMB_SIZE / (float) h;
|
||||||
|
z = MIN(zw, zh);
|
||||||
|
tn->w = z * w;
|
||||||
|
tn->h = z * h;
|
||||||
|
|
||||||
|
imlib_context_set_drawable(tn->pm);
|
||||||
|
imlib_render_image_part_on_drawable_at_size(0, 0, w, h,
|
||||||
|
0, 0, tn->w, tn->h);
|
||||||
|
imlib_free_image();
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void img_check_pan(img_t *img, win_t *win) {
|
void img_check_pan(img_t *img, win_t *win) {
|
||||||
if (!img || !win)
|
if (!img || !win)
|
||||||
return;
|
return;
|
||||||
|
@ -149,27 +175,6 @@ int img_fit(img_t *img, win_t *win) {
|
||||||
return oz != img->zoom;
|
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) {
|
void img_render(img_t *img, win_t *win) {
|
||||||
int sx, sy, sw, sh;
|
int sx, sy, sw, sh;
|
||||||
int dx, dy, dw, dh;
|
int dx, dy, dw, dh;
|
||||||
|
|
2
image.h
2
image.h
|
@ -52,6 +52,8 @@ typedef struct img_s {
|
||||||
typedef struct thumb_s {
|
typedef struct thumb_s {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
Pixmap pm;
|
Pixmap pm;
|
||||||
} thumb_t;
|
} thumb_t;
|
||||||
|
|
||||||
|
|
33
main.c
33
main.c
|
@ -27,6 +27,7 @@
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -38,6 +39,7 @@ typedef enum appmode_e {
|
||||||
} appmode_t;
|
} appmode_t;
|
||||||
|
|
||||||
void update_title();
|
void update_title();
|
||||||
|
void render_thumbs();
|
||||||
int check_append(const char*);
|
int check_append(const char*);
|
||||||
void read_dir_rec(const char*);
|
void read_dir_rec(const char*);
|
||||||
void run();
|
void run();
|
||||||
|
@ -53,6 +55,7 @@ int filecnt, fileidx;
|
||||||
size_t filesize;
|
size_t filesize;
|
||||||
|
|
||||||
thumb_t *thumbs;
|
thumb_t *thumbs;
|
||||||
|
int tvis, tcols, trows;
|
||||||
|
|
||||||
#define TITLE_LEN 256
|
#define TITLE_LEN 256
|
||||||
char win_title[TITLE_LEN];
|
char win_title[TITLE_LEN];
|
||||||
|
@ -137,6 +140,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
if (options->thumbnails == 2) {
|
if (options->thumbnails == 2) {
|
||||||
mode = MODE_THUMBS;
|
mode = MODE_THUMBS;
|
||||||
|
render_thumbs();
|
||||||
} else {
|
} else {
|
||||||
mode = MODE_NORMAL;
|
mode = MODE_NORMAL;
|
||||||
load_image();
|
load_image();
|
||||||
|
@ -175,6 +179,35 @@ void update_title() {
|
||||||
win_set_title(&win, win_title);
|
win_set_title(&win, win_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void render_thumbs() {
|
||||||
|
int i, cnt, x, y;
|
||||||
|
|
||||||
|
tcols = win.w / (THUMB_SIZE + 10);
|
||||||
|
trows = win.h / (THUMB_SIZE + 10);
|
||||||
|
|
||||||
|
x = win.w - tcols * (THUMB_SIZE + 10) + 5;
|
||||||
|
y = win.h - trows * (THUMB_SIZE + 10) + 5;
|
||||||
|
cnt = MIN(tcols * trows, filecnt);
|
||||||
|
|
||||||
|
win_clear(&win);
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < cnt) {
|
||||||
|
thumbs[i].x = x + (THUMB_SIZE - thumbs[i].w) / 2;
|
||||||
|
thumbs[i].y = y + (THUMB_SIZE - thumbs[i].h) / 2;
|
||||||
|
win_draw_pixmap(&win, thumbs[i].pm, thumbs[i].x, thumbs[i].y, thumbs[i].w,
|
||||||
|
thumbs[i].h);
|
||||||
|
if (++i % tcols == 0) {
|
||||||
|
x = win.w - tcols * (THUMB_SIZE + 10) + 5;
|
||||||
|
y += THUMB_SIZE + 10;
|
||||||
|
} else {
|
||||||
|
x += THUMB_SIZE + 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
win_draw(&win);
|
||||||
|
}
|
||||||
|
|
||||||
int check_append(const char *filename) {
|
int check_append(const char *filename) {
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
10
options.c
10
options.c
|
@ -25,12 +25,13 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
options_t _options;
|
options_t _options;
|
||||||
const options_t *options = (const options_t*) &_options;
|
const options_t *options = (const options_t*) &_options;
|
||||||
|
|
||||||
void print_usage() {
|
void print_usage() {
|
||||||
printf("usage: sxiv [-dFfhpqrstvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
|
printf("usage: sxiv [-dFfhpqrsTtvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_version() {
|
void print_version() {
|
||||||
|
@ -54,7 +55,7 @@ void parse_options(int argc, char **argv) {
|
||||||
_options.quiet = 0;
|
_options.quiet = 0;
|
||||||
_options.recursive = 0;
|
_options.recursive = 0;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "dFfg:hpqrstvZz:")) != -1) {
|
while ((opt = getopt(argc, argv, "dFfg:hpqrsTtvZz:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case '?':
|
case '?':
|
||||||
print_usage();
|
print_usage();
|
||||||
|
@ -86,8 +87,11 @@ void parse_options(int argc, char **argv) {
|
||||||
case 's':
|
case 's':
|
||||||
_options.scalemode = SCALE_FIT;
|
_options.scalemode = SCALE_FIT;
|
||||||
break;
|
break;
|
||||||
|
case 'T':
|
||||||
|
_options.thumbnails = 2;
|
||||||
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
_options.thumbnails = 1;
|
_options.thumbnails = MAX(_options.thumbnails, 1);
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
print_version();
|
print_version();
|
||||||
|
|
7
window.c
7
window.c
|
@ -219,6 +219,13 @@ Pixmap win_create_pixmap(win_t *win) {
|
||||||
win->env.depth);
|
win->env.depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) {
|
||||||
|
if (!win)
|
||||||
|
return;
|
||||||
|
|
||||||
|
XCopyArea(win->env.dpy, pm, win->pm, bgc, 0, 0, w, h, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
void win_clear(win_t *win) {
|
void win_clear(win_t *win) {
|
||||||
win_env_t *e;
|
win_env_t *e;
|
||||||
XGCValues gcval;
|
XGCValues gcval;
|
||||||
|
|
1
window.h
1
window.h
|
@ -64,6 +64,7 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int);
|
||||||
void win_toggle_fullscreen(win_t*);
|
void win_toggle_fullscreen(win_t*);
|
||||||
|
|
||||||
Pixmap win_create_pixmap(win_t*);
|
Pixmap win_create_pixmap(win_t*);
|
||||||
|
void win_draw_pixmap(win_t*, Pixmap, int, int, int, int);
|
||||||
|
|
||||||
void win_clear(win_t*);
|
void win_clear(win_t*);
|
||||||
void win_draw(win_t*);
|
void win_draw(win_t*);
|
||||||
|
|
Loading…
Reference in a new issue