sixel: calculate default bg once, in init

We have all information we need to calculate the default background
color in sixel_init():

* Whether the image have transparency or not
* The current ANSI background color
This commit is contained in:
Daniel Eklöf 2021-09-05 10:27:13 +02:00
parent f39a62fa5e
commit f9642e9597
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 11 additions and 15 deletions

25
sixel.c
View file

@ -15,16 +15,6 @@
static size_t count;
static uint32_t
get_bg(const struct terminal *term)
{
return term->sixel.transparent_bg
? 0x00000000u
: 0xffu << 24 | (term->vt.attrs.have_bg
? term->vt.attrs.bg
: term->colors.bg);
}
void
sixel_fini(struct terminal *term)
{
@ -78,9 +68,14 @@ sixel_init(struct terminal *term, int p1, int p2, int p3)
term->sixel.palette = term->sixel.shared_palette;
}
uint32_t bg = get_bg(term);
term->sixel.default_bg = term->sixel.transparent_bg
? 0x00000000u
: 0xffu << 24 | (term->vt.attrs.have_bg
? term->vt.attrs.bg
: term->colors.bg);
for (size_t i = 0; i < 1 * 6; i++)
term->sixel.image.data[i] = bg;
term->sixel.image.data[i] = term->sixel.default_bg;
count = 0;
}
@ -1118,7 +1113,7 @@ resize_horizontally(struct terminal *term, int new_width)
/* Width (and thus stride) change - need to allocate a new buffer */
uint32_t *new_data = xmalloc(new_width * alloc_height * sizeof(uint32_t));
uint32_t bg = get_bg(term);
uint32_t bg = term->sixel.default_bg;
/* Copy old rows, and initialize new columns to background color */
for (int r = 0; r < height; r++) {
@ -1167,7 +1162,7 @@ resize_vertically(struct terminal *term, int new_height)
return false;
}
uint32_t bg = get_bg(term);
uint32_t bg = term->sixel.default_bg;
/* Initialize new rows to background color */
for (int r = old_height; r < new_height; r++) {
@ -1204,7 +1199,7 @@ resize(struct terminal *term, int new_width, int new_height)
xassert(alloc_new_height - new_height < 6);
uint32_t *new_data = NULL;
uint32_t bg = get_bg(term);
uint32_t bg = term->sixel.default_bg;
if (new_width == old_width) {
/* Width (and thus stride) is the same, so we can simply