From 88bd41265bdad461a637ee9af7b7bbf622c8128a Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Fri, 7 Aug 2026 11:34:16 +0100 Subject: [PATCH] Fix underlay bookkeeping bug. --- image.c | 4 ++-- regress/image-support.sh | 5 +++++ tty-draw.c | 35 +++++++++++------------------------ 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/image.c b/image.c index f6fd2fa5e..16dc9d402 100644 --- a/image.c +++ b/image.c @@ -458,7 +458,7 @@ image_get_brightness(struct image *im, u_int x, u_int y) void image_set_cell(struct grid_cell *gc, struct image *im, u_int x, u_int y) { - memcpy(gc, &grid_default_cell, sizeof *gc); + /* Keep the cell contents as the underlay for transparent pixels. */ gc->flags |= GRID_FLAG_IMAGE; gc->image_id = im->id; gc->image_x = x; @@ -644,8 +644,8 @@ image_write(struct screen_write_ctx *ctx, struct image *im, u_int bg) for (y = 0; y < sy; y++) { for (x = 0; x < sx; x++) { + grid_view_get_cell(gd, cx + x, cy + y, &gc); image_set_cell(&gc, im, x, y); - gc.bg = bg; grid_view_set_cell(gd, cx + x, cy + y, &gc); } } diff --git a/regress/image-support.sh b/regress/image-support.sh index e3b4262ab..41e60e191 100755 --- a/regress/image-support.sh +++ b/regress/image-support.sh @@ -80,5 +80,10 @@ sleep 1 $TMUX capture-pane -pS0 -E3 >$TMP || exit 1 [ -n "$(sed -n 1p $TMP)" ] || exit 1 [ -z "$(sed -n 2p $TMP)" ] || exit 1 +$TMUX resize-window -x 10 -y 4 || exit 1 +sleep 1 +$TMUX capture-pane -pS0 -E3 >$TMP || exit 1 +[ "$(sed -n 1p $TMP | wc -c)" = 61 ] || exit 1 +[ -z "$(sed -n 2p $TMP)" ] || exit 1 exit 0 diff --git a/tty-draw.c b/tty-draw.c index 51d2d7dcd..fa62da774 100644 --- a/tty-draw.c +++ b/tty-draw.c @@ -29,7 +29,6 @@ enum tty_draw_line_state { TTY_DRAW_LINE_NEW1, TTY_DRAW_LINE_NEW2, TTY_DRAW_LINE_EMPTY, - TTY_DRAW_LINE_IMAGE, TTY_DRAW_LINE_SAME, TTY_DRAW_LINE_DONE }; @@ -39,7 +38,6 @@ static const char* tty_draw_line_states[] = { "NEW1", "NEW2", "EMPTY", - "IMAGE", "SAME", "DONE" }; @@ -132,7 +130,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, struct grid_line *gl; u_int i, j, last_i, cx, ex, width; u_int cellsize, bg; - int flags, empty, skip, wrapped = 0; + int flags, empty, wrapped = 0; char buf[1000]; size_t len; enum tty_draw_line_state current_state, next_state; @@ -237,8 +235,6 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, width = 0; current_state = TTY_DRAW_LINE_FIRST; for (;;) { - skip = 0; - /* Work out the next state. */ if (i == nx) { /* @@ -262,24 +258,22 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, grid_view_get_cell(gd, px + i, py, &gc); #ifdef ENABLE_IMAGES - /* Text terminals render image blocks as ASCII. */ + /* + * Graphical terminals draw the saved cell underlay + * before the image; text terminals use ASCII. + */ if (gc.flags & GRID_FLAG_IMAGE) { im = image_find(gc.image_id); if (image_tty_is_graphical(tty)) { memcpy(&image_gc, &gc, sizeof image_gc); - utf8_set(&image_gc.data, ' '); - image_gc.flags &= - ~GRID_FLAG_IMAGE; - skip = 1; + image_gc.flags &= ~(GRID_FLAG_IMAGE| + GRID_FLAG_SELECTED); } else { image_get_text_cell(tty, im, gc.image_x, gc.image_y, &gc, &image_gc, style_ctx); } - if (skip) - image_gc.flags &= - ~GRID_FLAG_SELECTED; gcp = &image_gc; } else gcp = &gc; @@ -288,12 +282,8 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, #endif /* Work out empty cells. */ - if (skip) - empty = 0; - else - empty = tty_draw_line_get_empty(gcp, - &last, nx - i); - if (empty != 0 || skip) + empty = tty_draw_line_get_empty(gcp, &last, nx - i); + if (empty != 0) ; else { /* Update for codeset if needed. */ @@ -310,9 +300,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, } /* Work out the next state. */ - if (skip) - next_state = TTY_DRAW_LINE_IMAGE; - else if (empty != 0) + if (empty != 0) next_state = TTY_DRAW_LINE_EMPTY; else if (current_state == TTY_DRAW_LINE_FIRST) next_state = TTY_DRAW_LINE_SAME; @@ -359,8 +347,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, } /* Append the cell if it is not empty and not padding. */ - if (next_state != TTY_DRAW_LINE_EMPTY && - next_state != TTY_DRAW_LINE_IMAGE) { + if (next_state != TTY_DRAW_LINE_EMPTY) { memcpy(buf + len, gcp->data.data, gcp->data.size); len += gcp->data.size; width += gcp->data.width;