From: Kevin Lamonte Date: Sun, 4 Aug 2019 18:18:24 +0000 (-0500) Subject: RLE for sixel backend X-Git-Tag: fanfix-swing-0.0.1~12^2~13^2~116 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=fa535516b7a3aeb9aedc90bac9a5bfcc9abcb17f;p=fanfix-swing.git RLE for sixel backend --- diff --git a/src/jexer/backend/ECMA48Terminal.java b/src/jexer/backend/ECMA48Terminal.java index 08010cef..dfc3edbe 100644 --- a/src/jexer/backend/ECMA48Terminal.java +++ b/src/jexer/backend/ECMA48Terminal.java @@ -2958,6 +2958,8 @@ public class ECMA48Terminal extends LogicalScreen // colored pixels, and select the color. sb.append(String.format("$#%d", i)); + int oldData = -1; + int oldDataCount = 0; for (int imageX = 0; imageX < image.getWidth(); imageX++) { // Add up all the pixels that match this color. @@ -2990,10 +2992,30 @@ public class ECMA48Terminal extends LogicalScreen } } assert (data >= 0); - assert (data < 127); + assert (data < 64); data += 63; - sb.append((char) data); + if (data == oldData) { + oldDataCount++; + } else { + if (oldDataCount == 1) { + sb.append((char) oldData); + } else if (oldDataCount > 1) { + sb.append(String.format("!%d", oldDataCount)); + sb.append((char) oldData); + } + oldDataCount = 1; + oldData = data; + } } // for (int imageX = 0; imageX < image.getWidth(); imageX++) + + // Emit the last sequence. + if (oldDataCount == 1) { + sb.append((char) oldData); + } else if (oldDataCount > 1) { + sb.append(String.format("!%d", oldDataCount)); + sb.append((char) oldData); + } + } // for (int i = 0; i < MAX_COLOR_REGISTERS; i++) // Advance to the next scan line.