Display an image in black and white Confirmed working with PNG and GIF. Must be 9x34 in size. Sends everything in a single command
(dev, image_file)
| 80 | |
| 81 | |
| 82 | def image_bl(dev, image_file): |
| 83 | """Display an image in black and white |
| 84 | Confirmed working with PNG and GIF. |
| 85 | Must be 9x34 in size. |
| 86 | Sends everything in a single command |
| 87 | """ |
| 88 | vals = [0 for _ in range(39)] |
| 89 | |
| 90 | from PIL import Image |
| 91 | |
| 92 | im = Image.open(image_file).convert("RGB") |
| 93 | width, height = im.size |
| 94 | assert width == 9 |
| 95 | assert height == 34 |
| 96 | pixel_values = list(im.getdata()) |
| 97 | for i, pixel in enumerate(pixel_values): |
| 98 | brightness = sum(pixel) / 3 |
| 99 | if brightness > 0xFF / 2: |
| 100 | vals[int(i / 8)] |= 1 << i % 8 |
| 101 | |
| 102 | send_command(dev, CommandVals.Draw, vals) |
| 103 | |
| 104 | |
| 105 | def camera(dev): |
no test coverage detected