uc1701: Optimize swizzle_bits() code
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
9465618adb
commit
519c3ad5ee
|
@ -49,14 +49,16 @@ class DisplayBase:
|
||||||
self.send(new_data[col_pos:col_pos+count], is_data=True)
|
self.send(new_data[col_pos:col_pos+count], is_data=True)
|
||||||
old_data[:] = new_data
|
old_data[:] = new_data
|
||||||
def _swizzle_bits(self, data):
|
def _swizzle_bits(self, data):
|
||||||
# Convert 8x16 data into display col/row order
|
# Convert from "rows of pixels" format to "columns of pixels"
|
||||||
bits_top = [0] * 8
|
top = bot = 0
|
||||||
bits_bot = [0] * 8
|
|
||||||
for row in range(8):
|
for row in range(8):
|
||||||
for col in range(8):
|
spaced = (data[row] * 0x8040201008040201) & 0x8080808080808080
|
||||||
bits_top[col] |= ((data[row] >> (7 - col)) & 1) << row
|
top |= spaced >> (7 - row)
|
||||||
bits_bot[col] |= ((data[row + 8] >> (7 - col)) & 1) << row
|
spaced = (data[row + 8] * 0x8040201008040201) & 0x8080808080808080
|
||||||
return (bits_top, bits_bot)
|
bot |= spaced >> (7 - row)
|
||||||
|
bits_top = [(top >> s) & 0xff for s in range(0, 64, 8)]
|
||||||
|
bits_bot = [(bot >> s) & 0xff for s in range(0, 64, 8)]
|
||||||
|
return (bytearray(bits_top), bytearray(bits_bot))
|
||||||
def set_glyphs(self, glyphs):
|
def set_glyphs(self, glyphs):
|
||||||
for glyph_name, glyph_data in glyphs.items():
|
for glyph_name, glyph_data in glyphs.items():
|
||||||
icon = glyph_data.get('icon16x16')
|
icon = glyph_data.get('icon16x16')
|
||||||
|
|
Loading…
Reference in New Issue