From fa535516b7a3aeb9aedc90bac9a5bfcc9abcb17f Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Sun, 4 Aug 2019 13:18:24 -0500 Subject: [PATCH] RLE for sixel backend --- src/jexer/backend/ECMA48Terminal.java | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/jexer/backend/ECMA48Terminal.java b/src/jexer/backend/ECMA48Terminal.java index 08010ce..dfc3edb 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. -- 2.27.0