Remove black bars from sixel images and add... (#107)

...support for transparency. Technically, the sixels do not have transparency,
but empty pixels are now rendered with the current background color instead
of black to make the them appear transparent. Same goes for the black bars.
The current background color makes them disappear.

There is one technical limitation with the alpha focus highlight patch.
The alpha value and background color is taken from the current background color,
so when the window is unfocused, images may have the wrong alpha and/or
background color. This can't be fixed easily.
This commit is contained in:
veltza 2023-11-23 22:45:20 +02:00 committed by GitHub
parent 1af2184c87
commit 003ab067da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 7 deletions

View file

@ -3,6 +3,9 @@ sixel_state_t sixel_st;
void
dcshandle(void)
{
int bgcolor;
unsigned char r, g, b, a = 255;
switch (csiescseq.mode[0]) {
default:
fprintf(stderr, "erresc: unknown csi ");
@ -10,7 +13,19 @@ dcshandle(void)
/* die(""); */
break;
case 'q': /* DECSIXEL */
if (sixel_parser_init(&sixel_st, 0, 0 << 16 | 0 << 8 | 0, 1, win.cw, win.ch) != 0)
if (IS_TRUECOL(term.c.attr.bg)) {
r = term.c.attr.bg >> 16 & 255;
g = term.c.attr.bg >> 8 & 255;
b = term.c.attr.bg >> 0 & 255;
} else {
xgetcolor(term.c.attr.bg, &r, &g, &b);
#if ALPHA_PATCH
if (term.c.attr.bg == defaultbg)
a = dc.col[defaultbg].pixel >> 24 & 255;
#endif // ALPHA_PATCH
}
bgcolor = a << 24 | b << 16 | g << 8 | r;
if (sixel_parser_init(&sixel_st, 255 << 24, bgcolor, 1, win.cw, win.ch) != 0)
perror("sixel_parser_init() failed");
term.mode |= MODE_SIXEL;
break;
@ -39,4 +54,4 @@ scroll_images(int n) {
im->should_delete = 1;
}
}
}
}