diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2023-05-31 14:27:48 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2023-05-31 14:27:48 +0000 |
| commit | 1433a81c08d696cad8c5460ca739bc0cd97a9a5c (patch) | |
| tree | 1b82646e8543ef658febb7df4b9300d9860bdd14 | |
| parent | ci: try alpine edge instead of latest (diff) | |
sixel: apply background alpha when P2=0 or P2=2, and current bg color is the default bg color
Closes #1360
| -rw-r--r-- | CHANGELOG.md | 6 | ||||
| -rw-r--r-- | sixel.c | 22 |
2 files changed, 24 insertions, 4 deletions
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 @@ -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; |
