aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-03-06 21:05:40 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-03-11 16:32:57 +0000
commit8c65c68b734b3a0711e8d0a7282d6c7d9def5ddf (patch)
treeeedb13a43a94508ea721cb669ad72cb33b401f40
parentsixel: add: resize is already checking against the current max geometry (diff)
sixel: get rid of an ‘imul’ in sixel_add()
By storing the current row’s byte offset into the backing image in the terminal struct. This replaces the ‘imul’ with a load, which can potentially be slow. But, this data should already be in the cache.
-rw-r--r--sixel.c6
-rw-r--r--terminal.h1
2 files changed, 5 insertions, 2 deletions
diff --git a/sixel.c b/sixel.c
index 6e7002d0..e0d5933a 100644
--- a/sixel.c
+++ b/sixel.c
@@ -37,6 +37,7 @@ sixel_init(struct terminal *term)
term->sixel.state = SIXEL_DECSIXEL;
term->sixel.pos = (struct coord){0, 0};
+ term->sixel.row_byte_ofs = 0;
term->sixel.color_idx = 0;
term->sixel.max_col = 0;
term->sixel.param = 0;
@@ -908,6 +909,7 @@ resize(struct terminal *term, int new_width, int new_height)
term->sixel.image.data = new_data;
term->sixel.image.width = new_width;
term->sixel.image.height = new_height;
+ term->sixel.row_byte_ofs = term->sixel.pos.row * new_width;
return true;
}
@@ -931,8 +933,7 @@ sixel_add(struct terminal *term, uint32_t color, uint8_t sixel)
return;
}
- size_t ofs = term->sixel.pos.row * term->sixel.image.width;
- ofs += term->sixel.pos.col;
+ size_t ofs = term->sixel.row_byte_ofs + term->sixel.pos.col;
for (int i = 0; i < 6; i++, sixel >>= 1) {
if (sixel & 1)
@@ -978,6 +979,7 @@ decsixel(struct terminal *term, uint8_t c)
term->sixel.max_col = term->sixel.pos.col;
term->sixel.pos.row += 6;
term->sixel.pos.col = 0;
+ term->sixel.row_byte_ofs += term->sixel.image.width * 6;
break;
case '?': case '@': case 'A': case 'B': case 'C': case 'D': case 'E':
diff --git a/terminal.h b/terminal.h
index e4e662fb..2a8bb6f9 100644
--- a/terminal.h
+++ b/terminal.h
@@ -521,6 +521,7 @@ struct terminal {
} state;
struct coord pos; /* Current sixel coordinate */
+ size_t row_byte_ofs; /* Byte position into image, for current row */
int color_idx; /* Current palette index */
int max_col; /* Largest column index we've seen (aka the image width) */
uint32_t *private_palette; /* Private palette, used when private mode 1070 is enabled */