nsxive685859
Use a checkerboard background for alpha layer; fixes issue #138
+45 −46
11 files changed
- M Makefile +1 −1
- M README.md +1 −1
- M commands.c +8 −9
- M commands.h +1 −1
- M config.def.h +10 −13
- M image.c +21 −9
- M sxiv.1 +3 −3
- M thumbs.c +0 −6
- M thumbs.h +0 −1
- M window.c +0 −1
- M window.h +0 −1
| @@ -1,4 +1,4 @@ | |||
| 1 | − | VERSION = git-20140317 | |
| 1 | + | VERSION = git-20140406 | |
| 2 | 2 | ||
| 3 | 3 | PREFIX = /usr/local | |
| 4 | 4 | MANPREFIX = $(PREFIX)/share/man | |
| @@ -102,7 +102,6 @@ of small previews is displayed, making it easy to choose an image to open. | |||
| 102 | 102 | f Toggle fullscreen mode (requires an EWMH/NetWM compliant | |
| 103 | 103 | window manager) | |
| 104 | 104 | b Toggle visibility of info bar on bottom of window | |
| 105 | − | A Toggle visibility of alpha-channel, i.e. transparency | |
| 106 | 105 | ||
| 107 | 106 | r Reload image | |
| 108 | 107 | R Reload all thumbnails | |
| @@ -149,6 +148,7 @@ of small previews is displayed, making it easy to choose an image to open. | |||
| 149 | 148 | Ctrl-g Reset gamma | |
| 150 | 149 | ||
| 151 | 150 | a Toggle anti-aliasing | |
| 151 | + | A Toggle visibility of alpha-channel, i.e. transparency | |
| 152 | 152 | ||
| 153 | 153 | s Toggle slideshow or set delay to [count] seconds | |
| 154 | 154 | ||
| @@ -75,10 +75,8 @@ cmdreturn_t it_quit(arg_t a) | |||
| 75 | 75 | cmdreturn_t it_switch_mode(arg_t a) | |
| 76 | 76 | { | |
| 77 | 77 | if (mode == MODE_IMAGE) { | |
| 78 | − | if (tns.thumbs == NULL) { | |
| 78 | + | if (tns.thumbs == NULL) | |
| 79 | 79 | tns_init(&tns, filecnt, &win); | |
| 80 | − | tns.alpha = img.alpha; | |
| 81 | − | } | |
| 82 | 80 | img_close(&img, false); | |
| 83 | 81 | reset_timeout(reset_cursor); | |
| 84 | 82 | if (img.ss.on) { | |
| @@ -494,14 +492,15 @@ cmdreturn_t i_toggle_antialias(arg_t a) | |||
| 494 | 492 | } | |
| 495 | 493 | } | |
| 496 | 494 | ||
| 497 | − | cmdreturn_t it_toggle_alpha(arg_t a) | |
| 495 | + | cmdreturn_t i_toggle_alpha(arg_t a) | |
| 498 | 496 | { | |
| 499 | − | img.alpha = tns.alpha = !img.alpha; | |
| 500 | − | if (mode == MODE_IMAGE) | |
| 497 | + | if (mode == MODE_IMAGE) { | |
| 498 | + | img.alpha = !img.alpha; | |
| 501 | 499 | img.dirty = true; | |
| 502 | − | else | |
| 503 | − | tns.dirty = true; | |
| 504 | − | return CMD_DIRTY; | |
| 500 | + | return CMD_DIRTY; | |
| 501 | + | } else { | |
| 502 | + | return CMD_INVALID; | |
| 503 | + | } | |
| 505 | 504 | } | |
| 506 | 505 | ||
| 507 | 506 | cmdreturn_t i_change_gamma(arg_t a) | |
| @@ -74,7 +74,7 @@ cmdreturn_t i_rotate(arg_t); | |||
| 74 | 74 | cmdreturn_t i_flip(arg_t); | |
| 75 | 75 | cmdreturn_t i_slideshow(arg_t); | |
| 76 | 76 | cmdreturn_t i_toggle_antialias(arg_t); | |
| 77 | − | cmdreturn_t it_toggle_alpha(arg_t); | |
| 77 | + | cmdreturn_t i_toggle_alpha(arg_t); | |
| 78 | 78 | cmdreturn_t i_change_gamma(arg_t); | |
| 79 | 79 | ||
| 80 | 80 | #endif /* COMMANDS_H */ | |
| @@ -47,24 +47,21 @@ enum { | |||
| 47 | 47 | static const double GAMMA_MAX = 10.0; | |
| 48 | 48 | static const int GAMMA_RANGE = 32; | |
| 49 | 49 | ||
| 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 | − | ||
| 59 | 50 | /* if false, pixelate images at zoom level != 100%, | |
| 60 | 51 | * toggled with 'a' key binding | |
| 61 | 52 | */ | |
| 62 | − | static const bool RENDER_ANTI_ALIAS = true; | |
| 53 | + | static const bool ANTI_ALIAS = true; | |
| 63 | 54 | ||
| 64 | − | /* if true, use white background for alpha layer, | |
| 55 | + | /* if true, use a checkerboard background for alpha layer, | |
| 65 | 56 | * toggled with 'A' key binding | |
| 66 | 57 | */ | |
| 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 }; | |
| 68 | 65 | ||
| 69 | 66 | #endif | |
| 70 | 67 | #ifdef _MAPPINGS_CONFIG | |
| @@ -145,7 +142,7 @@ static const keymap_t keys[] = { | |||
| 145 | 142 | { 0, XK_s, i_slideshow, (arg_t) None }, | |
| 146 | 143 | ||
| 147 | 144 | { 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 }, | |
| 149 | 146 | ||
| 150 | 147 | { 0, XK_braceleft, i_change_gamma, (arg_t) -1 }, | |
| 151 | 148 | { 0, XK_braceright, i_change_gamma, (arg_t) +1 }, | |
| @@ -18,7 +18,6 @@ | |||
| 18 | 18 | ||
| 19 | 19 | #define _POSIX_C_SOURCE 200112L | |
| 20 | 20 | #define _IMAGE_CONFIG | |
| 21 | − | #define _RENDER_CONFIG | |
| 22 | 21 | ||
| 23 | 22 | #include <stdlib.h> | |
| 24 | 23 | #include <string.h> | |
| @@ -80,8 +79,8 @@ void img_init(img_t *img, win_t *win) | |||
| 80 | 79 | img->zoom = MIN(img->zoom, zoom_max); | |
| 81 | 80 | img->checkpan = false; | |
| 82 | 81 | 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; | |
| 85 | 84 | img->multi.cap = img->multi.cnt = 0; | |
| 86 | 85 | img->multi.animate = false; | |
| 87 | 86 | img->multi.length = img->multi.repeat = 0; | |
| @@ -497,13 +496,26 @@ void img_render(img_t *img) | |||
| 497 | 496 | imlib_context_set_image(bg); | |
| 498 | 497 | imlib_image_set_has_alpha(0); | |
| 499 | 498 | ||
| 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 { | |
| 501 | 515 | 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 | + | } | |
| 507 | 519 | imlib_blend_image_onto_image(img->im, 0, sx, sy, sw, sh, 0, 0, dw, dh); | |
| 508 | 520 | imlib_context_set_color_modifier(NULL); | |
| 509 | 521 | imlib_render_image_on_drawable(dx, dy); | |
| @@ -121,9 +121,6 @@ Toggle visibility of info bar on bottom of window. | |||
| 121 | 121 | .B Ctrl-x | |
| 122 | 122 | Send the next key to the external key-handler. | |
| 123 | 123 | .TP | |
| 124 | − | .B A | |
| 125 | − | Toggle visibility of alpha-channel, i.e. image transparency. | |
| 126 | − | .TP | |
| 127 | 124 | .B r | |
| 128 | 125 | Reload image. | |
| 129 | 126 | .TP | |
| @@ -309,6 +306,9 @@ Reset gamma. | |||
| 309 | 306 | .B a | |
| 310 | 307 | Toggle anti-aliasing. | |
| 311 | 308 | .TP | |
| 309 | + | .B A | |
| 310 | + | Toggle visibility of alpha-channel, i.e. image transparency. | |
| 311 | + | .TP | |
| 312 | 312 | .B s | |
| 313 | 313 | Toggle slideshow mode and/or set the delay between images to | |
| 314 | 314 | .I count | |
| @@ -18,7 +18,6 @@ | |||
| 18 | 18 | ||
| 19 | 19 | #define _POSIX_C_SOURCE 200112L | |
| 20 | 20 | #define _THUMBS_CONFIG | |
| 21 | − | #define _RENDER_CONFIG | |
| 22 | 21 | ||
| 23 | 22 | #include <stdlib.h> | |
| 24 | 23 | #include <string.h> | |
| @@ -177,7 +176,6 @@ void tns_init(tns_t *tns, int cnt, win_t *win) | |||
| 177 | 176 | tns->cap = cnt; | |
| 178 | 177 | tns->cnt = tns->first = tns->sel = 0; | |
| 179 | 178 | tns->win = win; | |
| 180 | − | tns->alpha = !RENDER_WHITE_ALPHA; | |
| 181 | 179 | tns->dirty = false; | |
| 182 | 180 | ||
| 183 | 181 | if ((homedir = getenv("XDG_CACHE_HOME")) == NULL || homedir[0] == '\0') { | |
| @@ -360,10 +358,6 @@ void tns_render(tns_t *tns) | |||
| 360 | 358 | t->x = x + (THUMB_SIZE - t->w) / 2; | |
| 361 | 359 | t->y = y + (THUMB_SIZE - t->h) / 2; | |
| 362 | 360 | 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 | − | ||
| 367 | 361 | imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h, | |
| 368 | 362 | t->x, t->y, t->w, t->h); | |
| 369 | 363 | if (t->file->marked) | |
| @@ -47,7 +47,6 @@ typedef struct { | |||
| 47 | 47 | int cols; | |
| 48 | 48 | int rows; | |
| 49 | 49 | ||
| 50 | − | bool alpha; | |
| 51 | 50 | bool dirty; | |
| 52 | 51 | } tns_t; | |
| 53 | 52 | ||
| @@ -163,7 +163,6 @@ void win_init(win_t *win) | |||
| 163 | 163 | ||
| 164 | 164 | win_init_font(e->dpy, BAR_FONT); | |
| 165 | 165 | ||
| 166 | − | win->white = WhitePixel(e->dpy, e->scr); | |
| 167 | 166 | win->bgcol = win_alloc_color(win, WIN_BG_COLOR); | |
| 168 | 167 | win->fscol = win_alloc_color(win, WIN_FS_COLOR); | |
| 169 | 168 | win->selcol = win_alloc_color(win, SEL_COLOR); | |
| @@ -53,7 +53,6 @@ typedef struct { | |||
| 53 | 53 | Window xwin; | |
| 54 | 54 | win_env_t env; | |
| 55 | 55 | ||
| 56 | − | unsigned long white; | |
| 57 | 56 | unsigned long bgcol; | |
| 58 | 57 | unsigned long fscol; | |
| 59 | 58 | unsigned long selcol; | |