summaryrefslogtreecommitdiff
path: root/commandline/examples/ssd1306-getpixels
blob: 8527b7abc1654d47433568155b8c495d6cb60eda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)))