From f9642e959725fc43ad7dac0e3c8be842d53aa903 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 5 Sep 2021 10:27:13 +0200 Subject: 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 --- sixel.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'sixel.c') diff --git a/sixel.c b/sixel.c index 18a9c146..170ef4e4 100644 --- a/sixel.c +++ b/sixel.c @@ -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 -- cgit v1.3 From 47c32d5913044912f5e0974ab6554de1f2a62b3b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 5 Sep 2021 11:08:13 +0200 Subject: sixel: avoid looking up color from palette for each sixel Instead, do the palette lookup when we receive the DECGCI (i.e. when the palette entry is selected), and store the actual color value in our sixel struct. --- sixel.c | 6 +++--- terminal.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'sixel.c') diff --git a/sixel.c b/sixel.c index 170ef4e4..3298f3f4 100644 --- a/sixel.c +++ b/sixel.c @@ -1272,8 +1272,6 @@ sixel_add(struct terminal *term, int col, int width, uint32_t color, uint8_t six static void sixel_add_many(struct terminal *term, uint8_t c, unsigned count) { - uint32_t color = term->sixel.palette[term->sixel.color_idx]; - int col = term->sixel.pos.col; int width = term->sixel.image.width; @@ -1283,6 +1281,7 @@ sixel_add_many(struct terminal *term, uint8_t c, unsigned count) return; } + uint32_t color = term->sixel.color; for (unsigned i = 0; i < count; i++, col++) sixel_add(term, col, width, color, c); @@ -1509,7 +1508,8 @@ decgci(struct terminal *term, uint8_t c) break; } } - } + } else + term->sixel.color = term->sixel.palette[term->sixel.color_idx]; term->sixel.state = SIXEL_DECSIXEL; sixel_put(term, c); diff --git a/terminal.h b/terminal.h index 26dcd847..620678b1 100644 --- a/terminal.h +++ b/terminal.h @@ -560,6 +560,7 @@ struct terminal { uint32_t *private_palette; /* Private palette, used when private mode 1070 is enabled */ uint32_t *shared_palette; /* Shared palette, used when private mode 1070 is disabled */ uint32_t *palette; /* Points to either private_palette or shared_palette */ + uint32_t color; struct { uint32_t *data; /* Raw image data, in ARGB */ -- cgit v1.3 From b1a4d4384571a6aa2bfc97644a6dff7066afef0b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 5 Sep 2021 11:09:45 +0200 Subject: sixel: call decsixel() directly, instead of going through sixel_put() --- sixel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sixel.c') diff --git a/sixel.c b/sixel.c index 3298f3f4..acb3f31b 100644 --- a/sixel.c +++ b/sixel.c @@ -1401,7 +1401,7 @@ decgra(struct terminal *term, uint8_t c) } term->sixel.state = SIXEL_DECSIXEL; - sixel_put(term, c); + decsixel(term, c); break; } } @@ -1512,7 +1512,7 @@ decgci(struct terminal *term, uint8_t c) term->sixel.color = term->sixel.palette[term->sixel.color_idx]; term->sixel.state = SIXEL_DECSIXEL; - sixel_put(term, c); + decsixel(term, c); break; } } -- cgit v1.3