diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c44dd13..8a26dad6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,12 @@ name is still recognized, but will log a deprecation warning. * Meson option `default-utempter-path` renamed to `utmp-default-helper-path`. +* Opaque sixels now retain the background opacity (when current + background color is the **default** background color) + ([#1360][1360]). + +[1360]: https://codeberg.org/dnkl/foot/issues/1360 + ### Deprecated diff --git a/sixel.c b/sixel.c index 592f48f8..70ec2ee5 100644 --- a/sixel.c +++ b/sixel.c @@ -73,22 +73,36 @@ sixel_init(struct terminal *term, int p1, int p2, int p3) switch (term->vt.attrs.bg_src) { case COLOR_RGB: - bg = term->vt.attrs.bg; + bg = 0xffu << 24 | term->vt.attrs.bg; break; case COLOR_BASE16: case COLOR_BASE256: - bg = term->colors.table[term->vt.attrs.bg]; + bg = 0xffu << 24 | term->colors.table[term->vt.attrs.bg]; break; case COLOR_DEFAULT: - bg = term->colors.bg; + if (term->colors.alpha == 0xffff) + bg = 0xffu << 24 | term->colors.bg; + else { + /* Alpha needs to be pre-multiplied */ + uint32_t r = (term->colors.bg >> 16) & 0xff; + uint32_t g = (term->colors.bg >> 8) & 0xff; + uint32_t b = (term->colors.bg >> 0) & 0xff; + + uint32_t alpha = term->colors.alpha; + r *= alpha; r /= 0xffff; + g *= alpha; g /= 0xffff; + b *= alpha; b /= 0xffff; + + bg = (alpha >> 8) << 24 | (r & 0xff) << 16 | (g & 0xff) << 8 | (b & 0xff); + } break; } term->sixel.default_bg = term->sixel.transparent_bg ? 0x00000000u - : 0xffu << 24 | bg; + : bg; for (size_t i = 0; i < 1 * 6; i++) term->sixel.image.data[i] = term->sixel.default_bg;