jnweiger / led-name-badge-ls32

Upload tool for an led name tag with USB-HID interface
GNU General Public License v2.0
230 stars 86 forks source link

Support for 1-Bit color depth and ignore transparency #17

Closed LinusCDE closed 5 years ago

LinusCDE commented 5 years ago

I run into the problem by accident while a generated an animation in 1-Bit mode (since I only need those colors).

using [LSicroelectronics LS32 Custm HID] bus=2 dev=11
fetching bitmap from file ../strip.png -> (1536 x 11)
Traceback (most recent call last):
  File "led-badge-11x44.py", line 462, in <module>
    msgs.append(bitmap(arg))
  File "led-badge-11x44.py", line 345, in bitmap
    return bitmap_text(arg)
  File "led-badge-11x44.py", line 304, in bitmap_text
    text = re.sub(r':([^:]*):', colonrepl, text)
  File "/usr/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "led-badge-11x44.py", line 299, in colonrepl
    bitmap_preloaded.append(bitmap_img(name))
  File "led-badge-11x44.py", line 331, in bitmap_img
    if x < im.width and sum(im.getpixel( (x, row) )) > 384:
TypeError: 'int' object is not iterable

The pixel was here simply an int instead of a tuple. Even if the tuple would've contained one element, all pixels would've been recognized black anyway.

The changes also include discarding the alpha value which would've been able to change the calculated average color, too.

Great software btw!