sixel: implement private mode 1070 - private color palette

When enabled (the default), sixels use private color registers. That
is, the color palette from the last sixel is *not* re-used.

When disabled, sixels share (i.e. re-use) the same color palette.

Closes #362
This commit is contained in:
Daniel Eklöf 2021-02-16 19:37:49 +01:00
parent 313431800e
commit 4aa980a6a2
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 43 additions and 7 deletions

32
sixel.c
View file

@ -18,7 +18,8 @@ static size_t count;
void
sixel_fini(struct terminal *term)
{
free(term->sixel.palette);
free(term->sixel.private_palette);
free(term->sixel.shared_palette);
}
static uint32_t
@ -46,17 +47,36 @@ sixel_init(struct terminal *term)
term->sixel.image.height = 6;
term->sixel.image.autosize = true;
if (term->sixel.palette == NULL) {
term->sixel.palette = xcalloc(
term->sixel.palette_size, sizeof(term->sixel.palette[0]));
/* TODO: default palette */
if (term->sixel.use_private_palette) {
if (term->sixel.private_palette == NULL) {
term->sixel.private_palette = xcalloc(
term->sixel.palette_size, sizeof(term->sixel.private_palette[0]));
} else {
/* Private palette - i.e. each sixel starts with a clean palette */
memset(
term->sixel.private_palette,
0,
term->sixel.palette_size * sizeof(term->sixel.private_palette[0]));
}
term->sixel.palette = term->sixel.private_palette;
} else {
if (term->sixel.shared_palette == NULL) {
term->sixel.shared_palette = xcalloc(
term->sixel.palette_size, sizeof(term->sixel.shared_palette[0]));
} else {
/* Shared palette - do *not* reset palette for new sixels */
}
term->sixel.palette = term->sixel.shared_palette;
}
for (size_t i = 0; i < 1 * 6; i++)
term->sixel.image.data[i] = color_with_alpha(term, term->colors.bg);
count = 0;
/* TODO: default palette */
}
void