From bce1d7313dfe04f92b7a37c0352637045b4881dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 15 Mar 2024 17:23:21 +0100 Subject: [PATCH] sixel: hopefully handle image height correctly when trimming When trimming trailing empty rows from the final image, handle the RA region correctly: * If image is transparent, trim down to the last non-empty pixel row, regardless of whether it is inside or outside the RA region. * If image is opaque, trim down to either the last non-empty pixel row, or the RA region, whatever is the largest height. --- sixel.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/sixel.c b/sixel.c index 1340d875..c9df4ab4 100644 --- a/sixel.c +++ b/sixel.c @@ -1148,11 +1148,23 @@ sixel_unhook(struct terminal *term) * * See https://raw.githubusercontent.com/hackerb9/vt340test/main/sixeltests/p2effect.sh */ - if (term->sixel.pos.row + 6 * term->sixel.pan >= term->sixel.image.alloc_height && - term->sixel.transparent_bg) - { + if (term->sixel.pos.row + 6 * term->sixel.pan >= term->sixel.image.alloc_height) { LOG_DBG("trimming image"); - term->sixel.image.height = term->sixel.image.alloc_height - rows_to_trim * term->sixel.pan; + const int trimmed_height = + term->sixel.image.alloc_height - rows_to_trim * term->sixel.pan; + + if (term->sixel.transparent_bg) { + /* Image is transparent - trim as much as possible */ + term->sixel.image.height = trimmed_height; + } else { + /* Image is opaque. We can't trim anything "inside" + the RA region */ + if (trimmed_height > term->sixel.image.height) { + /* There are non-empty pixels *outside* the RA + region - trim up to that point */ + term->sixel.image.height = trimmed_height; + } + } } else { LOG_DBG("only adjusting cursor position"); }