From 1f6314978683e71abd09b8d028934705119f9633 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 5 Oct 2024 19:10:59 +0200 Subject: sixel: simplify compressSixel --- adapter/img/sixel.nim | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'adapter/img') diff --git a/adapter/img/sixel.nim b/adapter/img/sixel.nim index 7eb7be13..a668449c 100644 --- a/adapter/img/sixel.nim +++ b/adapter/img/sixel.nim @@ -322,23 +322,15 @@ proc compressSixel(outs: var string; band: SixelBand) = var x = 0 var chunk = band.head while chunk != nil: - outs &= '#' - outs &= $chunk.c - let diff = chunk.x - x - if diff > 3: - outs &= '!' & $diff & '?' - else: - for i in 0 ..< diff: - outs &= '?' - x = chunk.x + chunk.data.len - var n = 0 - var c = char(0) + outs &= '#' & $chunk.c + var n = chunk.x - x + var c = '?' for u in chunk.data: let cc = char(u + 0x3F) if c != cc: if n > 3: outs &= '!' & $n & c - else: # for char(0) n is also 0, so it is ignored. + else: for i in 0 ..< n: outs &= c c = cc @@ -349,6 +341,7 @@ proc compressSixel(outs: var string; band: SixelBand) = else: for i in 0 ..< n: outs &= c + x = chunk.x + chunk.data.len let next = chunk.next chunk.next = nil chunk = next -- cgit 1.4.1-2-gfad0