From 692f5deb8cfae49d64fb16f919a594c4475b60d9 Mon Sep 17 00:00:00 2001 From: sandr0 Date: Sun, 12 Jan 2025 22:04:43 +0100 Subject: [PATCH] pacman + singular bits possible --- gfx/pacman.png | Bin 0 -> 746 bytes lednamebadge.py | 43 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 gfx/pacman.png diff --git a/gfx/pacman.png b/gfx/pacman.png new file mode 100644 index 0000000000000000000000000000000000000000..41c2bb8c6e3731f31d46b7bf4e269047c77ef4cf GIT binary patch literal 746 zcmV0003YX+uL$Nkc;* zaB^>EX>4Tx04R~2kg-a`P!xv0R%u1+q&SE}2G@>ea7;y0+l6 zE8C4e@AYwCDf>!OMou 127: + if monochrome_color == 255: bit_val = 1 << (7 - bit) byte_val += bit_val buf.append(byte_val) im.close() return buf, cols + @staticmethod + def bitmap_bits(rows: list[int], bits: int): + """ + Use with somethin like + [ + 0b11001100110011001100110011001100110011001100, + 0b11001100110011001100110011001100110011001100, + 0b00110011001100110011001100110011001100110011, + 0b00110011001100110011001100110011001100110011, + 0b11001100110011001100110011001100110011001100, + 0b11001100110011001100110011001100110011001100, + 0b00110011001100110011001100110011001100110011, + 0b00110011001100110011001100110011001100110011, + 0b11001100110011001100110011001100110011001100, + 0b11001100110011001100110011001100110011001100, + 0b00110011001100110011001100110011001100110011, + ] + + as an alternative to a PNG. + """ + buf = array('B') + assert len(rows) == 11 + + cols = (bits + 7) // 8 + for col in range(cols): + for row in range(11): # [0..10] + byte_val = 0 + for bit in range(8): # [0..7] + bit_val = 0 + x = 8 * col + bit + if x < bits: + pixel_color = ((rows[row] >> (bits - 1 - x)) & 1) << (7 - bit) + byte_val += pixel_color + buf.append(byte_val) + + return buf, cols + def bitmap(self, arg): """If arg is a valid and existing path name, we load it as an image. Otherwise, we take it as a string (with ":"-notation, see bitmap_text()).