aboutsummaryrefslogtreecommitdiff
path: root/sixel.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-02-22 10:52:22 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-02-22 10:52:22 +0000
commita8dc61d0ffbe9f95ab2fb5d39474d66d5e57de2e (patch)
tree4fb7df3ab5b965aa76185eb43e5abc1f28947013 /sixel.c
parentsixel: mention why we add one (diff)
sixel: resize: initialize new rows/columns with the background color
Diffstat (limited to 'sixel.c')
-rw-r--r--sixel.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/sixel.c b/sixel.c
index 7e547822..f7966b80 100644
--- a/sixel.c
+++ b/sixel.c
@@ -29,10 +29,13 @@ sixel_init(struct terminal *term)
term->sixel.param_idx = 0;
memset(term->sixel.params, 0, sizeof(term->sixel.params));
term->sixel.palette = calloc(COLOR_COUNT, sizeof(term->sixel.palette[0]));
- term->sixel.image.data = calloc(1 * 6, sizeof(term->sixel.image.data[0]));
+ term->sixel.image.data = malloc(1 * 6 * sizeof(term->sixel.image.data[0]));
term->sixel.image.width = 1;
term->sixel.image.height = 6;
+ for (size_t i = 0; i < 1 * 6; i++)
+ term->sixel.image.data[i] = term->colors.alpha / 256 << 24 | term->sixel.palette[0];
+
count = 0;
/* TODO: default palette */
@@ -124,25 +127,28 @@ resize(struct terminal *term, int new_width, int new_height)
}
assert(new_height > old_height);
- memset(&new_data[old_height * new_width], 0, (new_height - old_height) * new_width * sizeof(uint32_t));
+
} else {
/* Width (and thus stride) change - need to allocate a new buffer */
assert(new_width > old_width);
new_data = malloc(new_width * new_height * sizeof(uint32_t));
- /* Copy old rows, and zero-initialize the tail of each row */
+ /* Copy old rows, and initialize new columns to background color */
for (int r = 0; r < old_height; r++) {
memcpy(&new_data[r * new_width], &old_data[r * old_width], old_width * sizeof(uint32_t));
- memset(&new_data[r * new_width + old_width], 0, (new_width - old_width) * sizeof(uint32_t));
- }
-
- /* Zero-initiailize new rows */
- for (int r = old_height; r < new_height; r++)
- memset(&new_data[r * new_width], 0, new_width * sizeof(uint32_t));
+ for (int c = old_width; c < new_width; c++)
+ new_data[r * new_width + c] = term->colors.alpha / 256 << 24 | term->sixel.palette[0];
+ }
free(old_data);
}
+ /* Initialize new rows to background color */
+ for (int r = old_height; r < new_height; r++) {
+ for (int c = 0; c < new_width; c++)
+ new_data[r * new_width + c] = term->colors.alpha / 256 << 24 | term->sixel.palette[0];
+ }
+
assert(new_data != NULL);
term->sixel.image.data = new_data;
term->sixel.image.width = new_width;