about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-10-05 19:10:59 +0200
committerbptato <nincsnevem662@gmail.com>2024-10-05 20:10:59 +0200
commit1f6314978683e71abd09b8d028934705119f9633 (patch)
tree6a9d3a94f924b115f34fa012d8c62ff79a0ddf02
parent23ee21daeeda2b7b76ac104ec50c59d93404fbaf (diff)
downloadchawan-1f6314978683e71abd09b8d028934705119f9633.tar.gz
sixel: simplify compressSixel
-rw-r--r--adapter/img/sixel.nim17
1 files changed, 5 insertions, 12 deletions
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