From 8c8c19f7cb49ff5cb73ea12317e0ff54ecb6c53a Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 28 Aug 2024 19:32:03 +0200 Subject: sixel, term: fix off-by-1's in cropping & clean up outputSixelImage in general --- adapter/img/sixel.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'adapter/img/sixel.nim') diff --git a/adapter/img/sixel.nim b/adapter/img/sixel.nim index 7f4514d9..e06b85e7 100644 --- a/adapter/img/sixel.nim +++ b/adapter/img/sixel.nim @@ -302,10 +302,13 @@ proc encode(s: string; width, height, offx, offy, cropw: int; halfdump: bool; bands[k].data[j] = bands[k].data[j] or mask n += W outs.setLen(0) - for i in 0 ..< bands.high: + var i = 0 + while true: outs &= bands[i].compressSixel() + inc i + if i >= bands.len: + break outs &= '$' - outs &= bands[^1].compressSixel() if n >= H: outs &= ST else: @@ -314,6 +317,7 @@ proc encode(s: string; width, height, offx, offy, cropw: int; halfdump: bool; stdout.write(outs) if halfdump: ymap.putU32BE(uint32(totalLen)) + ymap.putU32BE(uint32(ymap.len)) stdout.write(ymap) proc parseDimensions(s: string): (int, int) = -- cgit 1.4.1-2-gfad0