Krolyxon
Commit e685859

Branches

Refs →

nsxive685859

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

Author
Bert Münnich
Date
2014-04-06 22:47 +0200
Parent
6d7acac
Commit
e685859a30560e076db4de003fba4e4500ade2c7

+45 −46

11 files changed

  1. M Makefile +1 −1
  2. M README.md +1 −1
  3. M commands.c +8 −9
  4. M commands.h +1 −1
  5. M config.def.h +10 −13
  6. M image.c +21 −9
  7. M sxiv.1 +3 −3
  8. M thumbs.c +0 −6
  9. M thumbs.h +0 −1
  10. M window.c +0 −1
  11. M window.h +0 −1
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20140317
1+VERSION = git-20140406
22
33 PREFIX = /usr/local
44 MANPREFIX = $(PREFIX)/share/man
M README.md View
@@ -102,7 +102,6 @@ of small previews is displayed, making it easy to choose an image to open.
102102 f Toggle fullscreen mode (requires an EWMH/NetWM compliant
103103 window manager)
104104 b Toggle visibility of info bar on bottom of window
105− A Toggle visibility of alpha-channel, i.e. transparency
106105
107106 r Reload image
108107 R Reload all thumbnails
@@ -149,6 +148,7 @@ of small previews is displayed, making it easy to choose an image to open.
149148 Ctrl-g Reset gamma
150149
151150 a Toggle anti-aliasing
151+ A Toggle visibility of alpha-channel, i.e. transparency
152152
153153 s Toggle slideshow or set delay to [count] seconds
154154
M commands.c View
@@ -75,10 +75,8 @@ cmdreturn_t it_quit(arg_t a)
7575 cmdreturn_t it_switch_mode(arg_t a)
7676 {
7777 if (mode == MODE_IMAGE) {
78− if (tns.thumbs == NULL) {
78+ if (tns.thumbs == NULL)
7979 tns_init(&tns, filecnt, &win);
80− tns.alpha = img.alpha;
81− }
8280 img_close(&img, false);
8381 reset_timeout(reset_cursor);
8482 if (img.ss.on) {
@@ -494,14 +492,15 @@ cmdreturn_t i_toggle_antialias(arg_t a)
494492 }
495493 }
496494
497−cmdreturn_t it_toggle_alpha(arg_t a)
495+cmdreturn_t i_toggle_alpha(arg_t a)
498496 {
499− img.alpha = tns.alpha = !img.alpha;
500− if (mode == MODE_IMAGE)
497+ if (mode == MODE_IMAGE) {
498+ img.alpha = !img.alpha;
501499 img.dirty = true;
502− else
503− tns.dirty = true;
504− return CMD_DIRTY;
500+ return CMD_DIRTY;
501+ } else {
502+ return CMD_INVALID;
503+ }
505504 }
506505
507506 cmdreturn_t i_change_gamma(arg_t a)
M commands.h View
@@ -74,7 +74,7 @@ cmdreturn_t i_rotate(arg_t);
7474 cmdreturn_t i_flip(arg_t);
7575 cmdreturn_t i_slideshow(arg_t);
7676 cmdreturn_t i_toggle_antialias(arg_t);
77−cmdreturn_t it_toggle_alpha(arg_t);
77+cmdreturn_t i_toggle_alpha(arg_t);
7878 cmdreturn_t i_change_gamma(arg_t);
7979
8080 #endif /* COMMANDS_H */
M config.def.h View
@@ -47,24 +47,21 @@ enum {
4747 static const double GAMMA_MAX = 10.0;
4848 static const int GAMMA_RANGE = 32;
4949
50−#endif
51−#ifdef _THUMBS_CONFIG
52−
53−/* default dimension of thumbnails (width == height): */
54−enum { THUMB_SIZE = 60 };
55−
56−#endif
57−#ifdef _RENDER_CONFIG
58−
5950 /* if false, pixelate images at zoom level != 100%,
6051 * toggled with 'a' key binding
6152 */
62−static const bool RENDER_ANTI_ALIAS = true;
53+static const bool ANTI_ALIAS = true;
6354
64−/* if true, use white background for alpha layer,
55+/* if true, use a checkerboard background for alpha layer,
6556 * toggled with 'A' key binding
6657 */
67−static const bool RENDER_WHITE_ALPHA = false;
58+static const bool ALPHA_LAYER = false;
59+
60+#endif
61+#ifdef _THUMBS_CONFIG
62+
63+/* default dimension of thumbnails (width == height): */
64+enum { THUMB_SIZE = 60 };
6865
6966 #endif
7067 #ifdef _MAPPINGS_CONFIG
@@ -145,7 +142,7 @@ static const keymap_t keys[] = {
145142 { 0, XK_s, i_slideshow, (arg_t) None },
146143
147144 { 0, XK_a, i_toggle_antialias, (arg_t) None },
148− { 0, XK_A, it_toggle_alpha, (arg_t) None },
145+ { 0, XK_A, i_toggle_alpha, (arg_t) None },
149146
150147 { 0, XK_braceleft, i_change_gamma, (arg_t) -1 },
151148 { 0, XK_braceright, i_change_gamma, (arg_t) +1 },
M image.c View
@@ -18,7 +18,6 @@
1818
1919 #define _POSIX_C_SOURCE 200112L
2020 #define _IMAGE_CONFIG
21−#define _RENDER_CONFIG
2221
2322 #include <stdlib.h>
2423 #include <string.h>
@@ -80,8 +79,8 @@ void img_init(img_t *img, win_t *win)
8079 img->zoom = MIN(img->zoom, zoom_max);
8180 img->checkpan = false;
8281 img->dirty = false;
83− img->aa = RENDER_ANTI_ALIAS;
84− img->alpha = !RENDER_WHITE_ALPHA;
82+ img->aa = ANTI_ALIAS;
83+ img->alpha = ALPHA_LAYER;
8584 img->multi.cap = img->multi.cnt = 0;
8685 img->multi.animate = false;
8786 img->multi.length = img->multi.repeat = 0;
@@ -497,13 +496,26 @@ void img_render(img_t *img)
497496 imlib_context_set_image(bg);
498497 imlib_image_set_has_alpha(0);
499498
500− if (img->alpha)
499+ if (img->alpha) {
500+ int i, c, r;
501+ DATA32 col[2] = { 0xFF666666, 0xFF999999 };
502+ DATA32 * data = imlib_image_get_data();
503+
504+ for (r = 0; r < dh; r++) {
505+ i = r * dw;
506+ if (r == 0 || r == 8) {
507+ for (c = 0; c < dw; c++)
508+ data[i++] = col[!(c & 8) ^ !r];
509+ } else {
510+ memcpy(&data[i], &data[(r & 8) * dw], dw * sizeof(data[0]));
511+ }
512+ }
513+ imlib_image_put_back_data(data);
514+ } else {
501515 c = win->fullscreen ? win->fscol : win->bgcol;
502− else
503− c = win->white;
504− imlib_context_set_color(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF, 0xFF);
505− imlib_image_fill_rectangle(0, 0, dw, dh);
506−
516+ imlib_context_set_color(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF, 0xFF);
517+ imlib_image_fill_rectangle(0, 0, dw, dh);
518+ }
507519 imlib_blend_image_onto_image(img->im, 0, sx, sy, sw, sh, 0, 0, dw, dh);
508520 imlib_context_set_color_modifier(NULL);
509521 imlib_render_image_on_drawable(dx, dy);
M sxiv.1 View
@@ -121,9 +121,6 @@ Toggle visibility of info bar on bottom of window.
121121 .B Ctrl-x
122122 Send the next key to the external key-handler.
123123 .TP
124−.B A
125−Toggle visibility of alpha-channel, i.e. image transparency.
126−.TP
127124 .B r
128125 Reload image.
129126 .TP
@@ -309,6 +306,9 @@ Reset gamma.
309306 .B a
310307 Toggle anti-aliasing.
311308 .TP
309+.B A
310+Toggle visibility of alpha-channel, i.e. image transparency.
311+.TP
312312 .B s
313313 Toggle slideshow mode and/or set the delay between images to
314314 .I count
M thumbs.c View
@@ -18,7 +18,6 @@
1818
1919 #define _POSIX_C_SOURCE 200112L
2020 #define _THUMBS_CONFIG
21−#define _RENDER_CONFIG
2221
2322 #include <stdlib.h>
2423 #include <string.h>
@@ -177,7 +176,6 @@ void tns_init(tns_t *tns, int cnt, win_t *win)
177176 tns->cap = cnt;
178177 tns->cnt = tns->first = tns->sel = 0;
179178 tns->win = win;
180− tns->alpha = !RENDER_WHITE_ALPHA;
181179 tns->dirty = false;
182180
183181 if ((homedir = getenv("XDG_CACHE_HOME")) == NULL || homedir[0] == '\0') {
@@ -360,10 +358,6 @@ void tns_render(tns_t *tns)
360358 t->x = x + (THUMB_SIZE - t->w) / 2;
361359 t->y = y + (THUMB_SIZE - t->h) / 2;
362360 imlib_context_set_image(t->im);
363−
364− if (!tns->alpha && imlib_image_has_alpha())
365− win_draw_rect(win, win->pm, t->x, t->y, t->w, t->h, true, 0, win->white);
366−
367361 imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h,
368362 t->x, t->y, t->w, t->h);
369363 if (t->file->marked)
M thumbs.h View
@@ -47,7 +47,6 @@ typedef struct {
4747 int cols;
4848 int rows;
4949
50− bool alpha;
5150 bool dirty;
5251 } tns_t;
5352
M window.c View
@@ -163,7 +163,6 @@ void win_init(win_t *win)
163163
164164 win_init_font(e->dpy, BAR_FONT);
165165
166− win->white = WhitePixel(e->dpy, e->scr);
167166 win->bgcol = win_alloc_color(win, WIN_BG_COLOR);
168167 win->fscol = win_alloc_color(win, WIN_FS_COLOR);
169168 win->selcol = win_alloc_color(win, SEL_COLOR);
M window.h View
@@ -53,7 +53,6 @@ typedef struct {
5353 Window xwin;
5454 win_env_t env;
5555
56− unsigned long white;
5756 unsigned long bgcol;
5857 unsigned long fscol;
5958 unsigned long selcol;