From fce3ac131a6e8f04b4a024df58a87af8904218d0 Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Mon, 10 Aug 2026 12:11:40 +0100 Subject: [PATCH] sixel: scale source raster bounds --- image-sixel.c | 18 ++++++++++++++---- image.c | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/image-sixel.c b/image-sixel.c index 69405f40a..324f46b65 100644 --- a/image-sixel.c +++ b/image-sixel.c @@ -602,6 +602,7 @@ sixel_scale(struct sixel_image *si, u_int cell_w, u_int cell_h, u_int ox, u_int oy, u_int sx, u_int sy, int colours) { struct sixel_image *new; + uint64_t x0, x1, y0, y1; u_int cx, cy, pox, poy, psx, psy, tsx, tsy, px, py; u_int x, y, i; @@ -625,10 +626,19 @@ sixel_scale(struct sixel_image *si, u_int cell_w, u_int cell_h, u_int ox, if (cell_h == 0) cell_h = si->cell_h; - pox = ox * si->cell_w; - poy = oy * si->cell_h; - psx = sx * si->cell_w; - psy = sy * si->cell_h; + /* + * Map cell boundaries over the actual raster, not the rounded-up cell + * canvas. Otherwise a raster shorter than its last cell row produces an + * empty strip when it is scaled for output. + */ + x0 = (uint64_t)ox * si->sx / cx; + x1 = (uint64_t)(ox + sx) * si->sx / cx; + y0 = (uint64_t)oy * si->sy / cy; + y1 = (uint64_t)(oy + sy) * si->sy / cy; + pox = x0; + poy = y0; + psx = x1 - x0; + psy = y1 - y0; tsx = sx * cell_w; tsy = sy * cell_h; diff --git a/image.c b/image.c index 7e4fe40c4..1f53a63b5 100644 --- a/image.c +++ b/image.c @@ -685,7 +685,7 @@ image_write(struct screen_write_ctx *ctx, struct image *im, u_int bg) u_int cx = s->cx, cy = s->cy; u_int x, y, sx, sy, lines; - image_get_cell_size(im, &sx, &sy); + image_get_size_in_cells(im, &sx, &sy); if (sx > screen_size_x(s) - cx) sx = screen_size_x(s) - cx; if (sy > screen_size_y(s) - 1)