mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-01 07:15:32 -04:00
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:
parent
f39a62fa5e
commit
f9642e9597
2 changed files with 11 additions and 15 deletions
25
sixel.c
25
sixel.c
|
|
@ -15,16 +15,6 @@
|
||||||
|
|
||||||
static size_t count;
|
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
|
void
|
||||||
sixel_fini(struct terminal *term)
|
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;
|
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++)
|
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;
|
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 */
|
/* 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 *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 */
|
/* Copy old rows, and initialize new columns to background color */
|
||||||
for (int r = 0; r < height; r++) {
|
for (int r = 0; r < height; r++) {
|
||||||
|
|
@ -1167,7 +1162,7 @@ resize_vertically(struct terminal *term, int new_height)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t bg = get_bg(term);
|
uint32_t bg = term->sixel.default_bg;
|
||||||
|
|
||||||
/* Initialize new rows to background color */
|
/* Initialize new rows to background color */
|
||||||
for (int r = old_height; r < new_height; r++) {
|
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);
|
xassert(alloc_new_height - new_height < 6);
|
||||||
|
|
||||||
uint32_t *new_data = NULL;
|
uint32_t *new_data = NULL;
|
||||||
uint32_t bg = get_bg(term);
|
uint32_t bg = term->sixel.default_bg;
|
||||||
|
|
||||||
if (new_width == old_width) {
|
if (new_width == old_width) {
|
||||||
/* Width (and thus stride) is the same, so we can simply
|
/* Width (and thus stride) is the same, so we can simply
|
||||||
|
|
|
||||||
|
|
@ -576,6 +576,7 @@ struct terminal {
|
||||||
unsigned param_idx; /* Parameters seen */
|
unsigned param_idx; /* Parameters seen */
|
||||||
|
|
||||||
bool transparent_bg;
|
bool transparent_bg;
|
||||||
|
uint32_t default_bg;
|
||||||
|
|
||||||
/* Application configurable */
|
/* Application configurable */
|
||||||
unsigned palette_size; /* Number of colors in palette */
|
unsigned palette_size; /* Number of colors in palette */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue