summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-01-23 18:55:03 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-01-23 18:55:03 (GMT)
commit1ec5c11ea737412537580e9efbf66d5e0226f662 (patch)
tree0589c4f89140dcf14265993a9ffb78c12bd0f924 /tools
parent7ea3acc21ac587058498f912d6bf86d820acc051 (diff)
WIP: tools: Simple RLE encoder
Diffstat (limited to 'tools')
-rw-r--r--tools/rle_encode.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/rle_encode.py b/tools/rle_encode.py
new file mode 100644
index 0000000..3117ee1
--- /dev/null
+++ b/tools/rle_encode.py
@@ -0,0 +1,51 @@
+from PIL import Image
+
+im = Image.open('pine64.png')
+pixels = im.load()
+
+rle = []
+rl = 0
+px = 0
+
+for y in range(im.height):
+ for x in range(im.width):
+ newpx = pixels[x, y]
+ if newpx == px:
+ rl += 1
+ continue
+ assert(rl < 255)
+ rle.append(rl)
+ rl = 1
+ px = newpx
+rle.append(rl)
+
+sx = 240
+sy = 240
+image = bytes(rle)
+
+
+data = bytearray(2*sx)
+dp = 0
+black = ord('#')
+white = ord(' ')
+color = black
+
+for rl in image:
+ while rl:
+ data[dp] = color
+ data[dp+1] = color
+ dp += 2
+ rl -= 1
+
+ if dp >= (2*sx):
+ print(data.decode('utf-8'))
+ dp = 0
+
+ if color == black:
+ color = white
+ else:
+ color = black
+
+assert(dp == 0)
+
+print(image)