From 2a5245cefa5a3ab1ac1d11e2dcaaa853f349f088 Mon Sep 17 00:00:00 2001 From: Linus Date: Mon, 19 Aug 2019 17:42:01 +0200 Subject: [PATCH 1/3] Add support for 1-bit colors as input --- led-badge-11x44.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/led-badge-11x44.py b/led-badge-11x44.py index f6b3efc..ff9f199 100755 --- a/led-badge-11x44.py +++ b/led-badge-11x44.py @@ -328,7 +328,15 @@ def bitmap_img(file): for bit in range(8): bit_val = 0 x = 8*col+bit - if x < im.width and sum(im.getpixel( (x, row) )) > 384: + pixel_color = im.getpixel( (x, row) ) + print(pixel_color) + if isinstance(pixel_color, tuple): + monochrome_color = sum(pixel_color) / len(pixel_color) + elif isinstance(pixel_color, int): + monochrome_color = pixel_color + else: + sys.exit("%s: Unknown pixel format detected (%s)!" % (file, pixel_color)) + if x < im.width and monochrome_color > 127: bit_val = 1 << (7-bit) byte_val += bit_val buf.append(byte_val) From 1310ce45281b8ab38987527e33d0b194441c315d Mon Sep 17 00:00:00 2001 From: Linus Date: Mon, 19 Aug 2019 17:43:22 +0200 Subject: [PATCH 2/3] Ignore alpha value for average color calculation --- led-badge-11x44.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/led-badge-11x44.py b/led-badge-11x44.py index ff9f199..876a76d 100755 --- a/led-badge-11x44.py +++ b/led-badge-11x44.py @@ -331,7 +331,7 @@ def bitmap_img(file): pixel_color = im.getpixel( (x, row) ) print(pixel_color) if isinstance(pixel_color, tuple): - monochrome_color = sum(pixel_color) / len(pixel_color) + monochrome_color = sum(pixel_color[:3]) / len(pixel_color[:3]) elif isinstance(pixel_color, int): monochrome_color = pixel_color else: From 9da5717f443b654e18a59abeffee812d9d2201c1 Mon Sep 17 00:00:00 2001 From: Linus Date: Mon, 19 Aug 2019 17:46:46 +0200 Subject: [PATCH 3/3] Remove forgotten debug message --- led-badge-11x44.py | 1 - 1 file changed, 1 deletion(-) diff --git a/led-badge-11x44.py b/led-badge-11x44.py index 876a76d..46389c9 100755 --- a/led-badge-11x44.py +++ b/led-badge-11x44.py @@ -329,7 +329,6 @@ def bitmap_img(file): bit_val = 0 x = 8*col+bit pixel_color = im.getpixel( (x, row) ) - print(pixel_color) if isinstance(pixel_color, tuple): monochrome_color = sum(pixel_color[:3]) / len(pixel_color[:3]) elif isinstance(pixel_color, int):