MCPcopy Index your code
hub / github.com/FrameworkComputer/inputmodule-rs / image_bl

Function image_bl

python/inputmodule/inputmodule/ledmatrix.py:82–102  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

80
81
82def 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
105def camera(dev):

Callers 2

main_cliFunction · 0.90
run_guiFunction · 0.90

Calls 1

send_commandFunction · 0.90

Tested by

no test coverage detected