aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2024-03-15 16:23:21 +0000
committerDaniel Eklöf <daniel@ekloef.se>2024-03-18 16:11:27 +0000
commitbce1d7313dfe04f92b7a37c0352637045b4881dc (patch)
treebc31443b02332f76afe47d2a50d06df6c29ef749
parentsixel: RA region does not affect the text cursor position (diff)
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.
-rw-r--r--sixel.c20
1 files 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");
}