summaryrefslogtreecommitdiff
path: root/commandline/examples/ssd1306-getpixels
diff options
context:
space:
mode:
Diffstat (limited to 'commandline/examples/ssd1306-getpixels')
-rwxr-xr-xcommandline/examples/ssd1306-getpixels27
1 files changed, 27 insertions, 0 deletions
diff --git a/commandline/examples/ssd1306-getpixels b/commandline/examples/ssd1306-getpixels
new file mode 100755
index 0000000..8527b7a
--- /dev/null
+++ b/commandline/examples/ssd1306-getpixels
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+from PIL import Image
+import sys
+
+buf_w = 128
+buf_h = 64
+
+
+def load_image(filename):
+ im = Image.open(filename)
+ w, h = im.size
+ buf = [0 for i in range(buf_w * buf_h // 8)]
+ for y in range(min(h, buf_h)):
+ for x in range(min(w, buf_w)):
+ if im.getpixel((x, y)):
+ buf[(y // 8) * buf_w + x] |= 1 << (y % 8)
+ return buf
+
+
+filename = sys.argv[1]
+offset = int(sys.argv[2])
+
+buf = load_image(filename)
+buf = buf[offset : offset + 128]
+
+print(" ".join(map(str, buf)))