From 6416319a998917149d2fb13aea9d8ae2b86e4a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 7 Mar 2021 00:03:34 +0100 Subject: [PATCH] Revert "sixel: resize: always round up height to a multiple of 6" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 5a9d70da837c20a9641d6cbadccc962a8e5a4283. This broke jexer. Comparing with what XTerm does, we can see that it updates its image height for *each* pixel in *each* sixel. I.e. empty pixels at the bottom of a sixel will not increase the image size. Foot currently bumps the image height 6 pixels at a time, i.e. always a whole pixel. Given this, always rounding up the height to the nearest multiple of 6 (say, for example, when responding to a DECGRA command), is wrong. Now, we use the image size specified in DECGRA as is, while still allowing the image to grow beyond that if necessary. What’s left to do, if we want to behave *exactly* like XTerm, is stop growing the image with 6 pixels at a time when dynamically adjusting the image size. --- sixel.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sixel.c b/sixel.c index 48d89a9e..ae05ec45 100644 --- a/sixel.c +++ b/sixel.c @@ -853,8 +853,10 @@ resize(struct terminal *term, int new_width, int new_height) const int old_width = term->sixel.image.width; const int old_height = term->sixel.image.height; - new_height = (new_height + 6 - 1) / 6 * 6; - xassert(new_height % 6 == 0); + int alloc_new_width = new_width; + int alloc_new_height = (new_height + 6 - 1) / 6 * 6; + xassert(alloc_new_height >= new_height); + xassert(alloc_new_height - new_height < 6); if (new_width > term->sixel.max_width) return false; @@ -876,7 +878,7 @@ resize(struct terminal *term, int new_width, int new_height) /* Width (and thus stride) is the same, so we can simply * re-alloc the existing buffer */ - new_data = realloc(old_data, new_width * new_height * sizeof(uint32_t)); + new_data = realloc(old_data, alloc_new_width * alloc_new_height * sizeof(uint32_t)); if (new_data == NULL) { LOG_ERRNO("failed to reallocate sixel image buffer"); return false; @@ -887,7 +889,7 @@ resize(struct terminal *term, int new_width, int new_height) } else { /* Width (and thus stride) change - need to allocate a new buffer */ xassert(new_width > old_width); - new_data = xmalloc(new_width * new_height * sizeof(uint32_t)); + new_data = xmalloc(alloc_new_width * alloc_new_height * sizeof(uint32_t)); /* Copy old rows, and initialize new columns to background color */ for (int r = 0; r < min(old_height, new_height); r++) {