diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-09-05 08:27:13 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-09-05 08:27:13 +0000 |
| commit | f9642e959725fc43ad7dac0e3c8be842d53aa903 (patch) | |
| tree | 37e70b4ce0051e9dc38e8b3c0170072001de8fb9 | |
| parent | server: no need to clone the config to handle -N,--no-wait (diff) | |
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
| -rw-r--r-- | sixel.c | 25 | ||||
| -rw-r--r-- | terminal.h | 1 |
2 files changed, 11 insertions, 15 deletions
@@ -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 @@ -576,6 +576,7 @@ struct terminal { unsigned param_idx; /* Parameters seen */ bool transparent_bg; + uint32_t default_bg; /* Application configurable */ unsigned palette_size; /* Number of colors in palette */ |
