Use a checkerboard background for alpha layer; fixes issue #138

This commit is contained in:
Bert Münnich 2014-04-06 22:47:42 +02:00
parent 6d7acac3d1
commit e685859a30
11 changed files with 46 additions and 47 deletions

View file

@ -1,4 +1,4 @@
VERSION = git-20140317 VERSION = git-20140406
PREFIX = /usr/local PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man MANPREFIX = $(PREFIX)/share/man

View file

@ -102,7 +102,6 @@ of small previews is displayed, making it easy to choose an image to open.
f Toggle fullscreen mode (requires an EWMH/NetWM compliant f Toggle fullscreen mode (requires an EWMH/NetWM compliant
window manager) window manager)
b Toggle visibility of info bar on bottom of window b Toggle visibility of info bar on bottom of window
A Toggle visibility of alpha-channel, i.e. transparency
r Reload image r Reload image
R Reload all thumbnails R Reload all thumbnails
@ -149,6 +148,7 @@ of small previews is displayed, making it easy to choose an image to open.
Ctrl-g Reset gamma Ctrl-g Reset gamma
a Toggle anti-aliasing a Toggle anti-aliasing
A Toggle visibility of alpha-channel, i.e. transparency
s Toggle slideshow or set delay to [count] seconds s Toggle slideshow or set delay to [count] seconds

View file

@ -75,10 +75,8 @@ cmdreturn_t it_quit(arg_t a)
cmdreturn_t it_switch_mode(arg_t a) cmdreturn_t it_switch_mode(arg_t a)
{ {
if (mode == MODE_IMAGE) { if (mode == MODE_IMAGE) {
if (tns.thumbs == NULL) { if (tns.thumbs == NULL)
tns_init(&tns, filecnt, &win); tns_init(&tns, filecnt, &win);
tns.alpha = img.alpha;
}
img_close(&img, false); img_close(&img, false);
reset_timeout(reset_cursor); reset_timeout(reset_cursor);
if (img.ss.on) { if (img.ss.on) {
@ -494,14 +492,15 @@ cmdreturn_t i_toggle_antialias(arg_t a)
} }
} }
cmdreturn_t it_toggle_alpha(arg_t a) cmdreturn_t i_toggle_alpha(arg_t a)
{ {
img.alpha = tns.alpha = !img.alpha; if (mode == MODE_IMAGE) {
if (mode == MODE_IMAGE) img.alpha = !img.alpha;
img.dirty = true; img.dirty = true;
else return CMD_DIRTY;
tns.dirty = true; } else {
return CMD_DIRTY; return CMD_INVALID;
}
} }
cmdreturn_t i_change_gamma(arg_t a) cmdreturn_t i_change_gamma(arg_t a)

View file

@ -74,7 +74,7 @@ cmdreturn_t i_rotate(arg_t);
cmdreturn_t i_flip(arg_t); cmdreturn_t i_flip(arg_t);
cmdreturn_t i_slideshow(arg_t); cmdreturn_t i_slideshow(arg_t);
cmdreturn_t i_toggle_antialias(arg_t); cmdreturn_t i_toggle_antialias(arg_t);
cmdreturn_t it_toggle_alpha(arg_t); cmdreturn_t i_toggle_alpha(arg_t);
cmdreturn_t i_change_gamma(arg_t); cmdreturn_t i_change_gamma(arg_t);
#endif /* COMMANDS_H */ #endif /* COMMANDS_H */

View file

@ -47,25 +47,22 @@ enum {
static const double GAMMA_MAX = 10.0; static const double GAMMA_MAX = 10.0;
static const int GAMMA_RANGE = 32; static const int GAMMA_RANGE = 32;
/* if false, pixelate images at zoom level != 100%,
* toggled with 'a' key binding
*/
static const bool ANTI_ALIAS = true;
/* if true, use a checkerboard background for alpha layer,
* toggled with 'A' key binding
*/
static const bool ALPHA_LAYER = false;
#endif #endif
#ifdef _THUMBS_CONFIG #ifdef _THUMBS_CONFIG
/* default dimension of thumbnails (width == height): */ /* default dimension of thumbnails (width == height): */
enum { THUMB_SIZE = 60 }; enum { THUMB_SIZE = 60 };
#endif
#ifdef _RENDER_CONFIG
/* if false, pixelate images at zoom level != 100%,
* toggled with 'a' key binding
*/
static const bool RENDER_ANTI_ALIAS = true;
/* if true, use white background for alpha layer,
* toggled with 'A' key binding
*/
static const bool RENDER_WHITE_ALPHA = false;
#endif #endif
#ifdef _MAPPINGS_CONFIG #ifdef _MAPPINGS_CONFIG
@ -145,7 +142,7 @@ static const keymap_t keys[] = {
{ 0, XK_s, i_slideshow, (arg_t) None }, { 0, XK_s, i_slideshow, (arg_t) None },
{ 0, XK_a, i_toggle_antialias, (arg_t) None }, { 0, XK_a, i_toggle_antialias, (arg_t) None },
{ 0, XK_A, it_toggle_alpha, (arg_t) None }, { 0, XK_A, i_toggle_alpha, (arg_t) None },
{ 0, XK_braceleft, i_change_gamma, (arg_t) -1 }, { 0, XK_braceleft, i_change_gamma, (arg_t) -1 },
{ 0, XK_braceright, i_change_gamma, (arg_t) +1 }, { 0, XK_braceright, i_change_gamma, (arg_t) +1 },

30
image.c
View file

@ -18,7 +18,6 @@
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#define _IMAGE_CONFIG #define _IMAGE_CONFIG
#define _RENDER_CONFIG
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -80,8 +79,8 @@ void img_init(img_t *img, win_t *win)
img->zoom = MIN(img->zoom, zoom_max); img->zoom = MIN(img->zoom, zoom_max);
img->checkpan = false; img->checkpan = false;
img->dirty = false; img->dirty = false;
img->aa = RENDER_ANTI_ALIAS; img->aa = ANTI_ALIAS;
img->alpha = !RENDER_WHITE_ALPHA; img->alpha = ALPHA_LAYER;
img->multi.cap = img->multi.cnt = 0; img->multi.cap = img->multi.cnt = 0;
img->multi.animate = false; img->multi.animate = false;
img->multi.length = img->multi.repeat = 0; img->multi.length = img->multi.repeat = 0;
@ -497,13 +496,26 @@ void img_render(img_t *img)
imlib_context_set_image(bg); imlib_context_set_image(bg);
imlib_image_set_has_alpha(0); imlib_image_set_has_alpha(0);
if (img->alpha) if (img->alpha) {
c = win->fullscreen ? win->fscol : win->bgcol; int i, c, r;
else DATA32 col[2] = { 0xFF666666, 0xFF999999 };
c = win->white; DATA32 * data = imlib_image_get_data();
imlib_context_set_color(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF, 0xFF);
imlib_image_fill_rectangle(0, 0, dw, dh);
for (r = 0; r < dh; r++) {
i = r * dw;
if (r == 0 || r == 8) {
for (c = 0; c < dw; c++)
data[i++] = col[!(c & 8) ^ !r];
} else {
memcpy(&data[i], &data[(r & 8) * dw], dw * sizeof(data[0]));
}
}
imlib_image_put_back_data(data);
} else {
c = win->fullscreen ? win->fscol : win->bgcol;
imlib_context_set_color(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF, 0xFF);
imlib_image_fill_rectangle(0, 0, dw, dh);
}
imlib_blend_image_onto_image(img->im, 0, sx, sy, sw, sh, 0, 0, dw, dh); imlib_blend_image_onto_image(img->im, 0, sx, sy, sw, sh, 0, 0, dw, dh);
imlib_context_set_color_modifier(NULL); imlib_context_set_color_modifier(NULL);
imlib_render_image_on_drawable(dx, dy); imlib_render_image_on_drawable(dx, dy);

6
sxiv.1
View file

@ -121,9 +121,6 @@ Toggle visibility of info bar on bottom of window.
.B Ctrl-x .B Ctrl-x
Send the next key to the external key-handler. Send the next key to the external key-handler.
.TP .TP
.B A
Toggle visibility of alpha-channel, i.e. image transparency.
.TP
.B r .B r
Reload image. Reload image.
.TP .TP
@ -309,6 +306,9 @@ Reset gamma.
.B a .B a
Toggle anti-aliasing. Toggle anti-aliasing.
.TP .TP
.B A
Toggle visibility of alpha-channel, i.e. image transparency.
.TP
.B s .B s
Toggle slideshow mode and/or set the delay between images to Toggle slideshow mode and/or set the delay between images to
.I count .I count

View file

@ -18,7 +18,6 @@
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#define _THUMBS_CONFIG #define _THUMBS_CONFIG
#define _RENDER_CONFIG
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -177,7 +176,6 @@ void tns_init(tns_t *tns, int cnt, win_t *win)
tns->cap = cnt; tns->cap = cnt;
tns->cnt = tns->first = tns->sel = 0; tns->cnt = tns->first = tns->sel = 0;
tns->win = win; tns->win = win;
tns->alpha = !RENDER_WHITE_ALPHA;
tns->dirty = false; tns->dirty = false;
if ((homedir = getenv("XDG_CACHE_HOME")) == NULL || homedir[0] == '\0') { if ((homedir = getenv("XDG_CACHE_HOME")) == NULL || homedir[0] == '\0') {
@ -360,10 +358,6 @@ void tns_render(tns_t *tns)
t->x = x + (THUMB_SIZE - t->w) / 2; t->x = x + (THUMB_SIZE - t->w) / 2;
t->y = y + (THUMB_SIZE - t->h) / 2; t->y = y + (THUMB_SIZE - t->h) / 2;
imlib_context_set_image(t->im); imlib_context_set_image(t->im);
if (!tns->alpha && imlib_image_has_alpha())
win_draw_rect(win, win->pm, t->x, t->y, t->w, t->h, true, 0, win->white);
imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h, imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h,
t->x, t->y, t->w, t->h); t->x, t->y, t->w, t->h);
if (t->file->marked) if (t->file->marked)

View file

@ -47,7 +47,6 @@ typedef struct {
int cols; int cols;
int rows; int rows;
bool alpha;
bool dirty; bool dirty;
} tns_t; } tns_t;

View file

@ -163,7 +163,6 @@ void win_init(win_t *win)
win_init_font(e->dpy, BAR_FONT); win_init_font(e->dpy, BAR_FONT);
win->white = WhitePixel(e->dpy, e->scr);
win->bgcol = win_alloc_color(win, WIN_BG_COLOR); win->bgcol = win_alloc_color(win, WIN_BG_COLOR);
win->fscol = win_alloc_color(win, WIN_FS_COLOR); win->fscol = win_alloc_color(win, WIN_FS_COLOR);
win->selcol = win_alloc_color(win, SEL_COLOR); win->selcol = win_alloc_color(win, SEL_COLOR);

View file

@ -53,7 +53,6 @@ typedef struct {
Window xwin; Window xwin;
win_env_t env; win_env_t env;
unsigned long white;
unsigned long bgcol; unsigned long bgcol;
unsigned long fscol; unsigned long fscol;
unsigned long selcol; unsigned long selcol;