From 3555257afb2cc3b11aefb31cef1520f7eac85750 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 16 Apr 2021 01:11:08 -0400 Subject: [PATCH] kitty: use supplied alpha value directly In Sixel, we map the alpha value to either 0 or 255, as it has no alpha concept. Kitty can freely reproduce eight bits of alpha, so go ahead and use them. Improves image quality of translucent bitmaps in Kitty at the expense of some behavioral divergence depending on bitmap backend. --- src/lib/kitty.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/kitty.c b/src/lib/kitty.c index 3f3ca565d..327fed923 100644 --- a/src/lib/kitty.c +++ b/src/lib/kitty.c @@ -59,7 +59,12 @@ base64_rgba3(const uint32_t* pixels, size_t pcount, char* b64, bool wipe[static unsigned r = ncpixel_r(pixel); unsigned g = ncpixel_g(pixel); unsigned b = ncpixel_b(pixel); - unsigned a = wipe[0] ? 0 : rgba_trans_p(pixel, transcolor) ? 0 : 255; + // we go ahead and take advantage of kitty's ability to reproduce 8-bit + // alphas by copying it in directly, rather than mapping to {0, 255}. + unsigned a = ncpixel_a(pixel); + if(wipe[0] || rgba_trans_p(pixel, transcolor)){ + a = 0; + } b64[0] = b64subs[(r & 0xfc) >> 2]; b64[1] = b64subs[(r & 0x3 << 4) | ((g & 0xf0) >> 4)]; b64[2] = b64subs[((g & 0xf) << 2) | ((b & 0xc0) >> 6)];