aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/display
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2020-06-11 13:28:37 -0400
committerKevin O'Connor <kevin@koconnor.net>2020-06-12 09:37:37 -0400
commit519c3ad5ee0cc84b41d091f721fc6fb006c83209 (patch)
tree44c036054746e688084a8abfc794b65c8aaddfe3 /klippy/extras/display
parent9465618adb0ad5c93209f661c0cb3c3c38926ba8 (diff)
downloadkutter-519c3ad5ee0cc84b41d091f721fc6fb006c83209.tar.gz
kutter-519c3ad5ee0cc84b41d091f721fc6fb006c83209.tar.xz
kutter-519c3ad5ee0cc84b41d091f721fc6fb006c83209.zip
uc1701: Optimize swizzle_bits() code
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/display')
-rw-r--r--klippy/extras/display/uc1701.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/klippy/extras/display/uc1701.py b/klippy/extras/display/uc1701.py
index cb6e3763..921d3be4 100644
--- a/klippy/extras/display/uc1701.py
+++ b/klippy/extras/display/uc1701.py
@@ -49,14 +49,16 @@ class DisplayBase:
self.send(new_data[col_pos:col_pos+count], is_data=True)
old_data[:] = new_data
def _swizzle_bits(self, data):
- # Convert 8x16 data into display col/row order
- bits_top = [0] * 8
- bits_bot = [0] * 8
+ # Convert from "rows of pixels" format to "columns of pixels"
+ top = bot = 0
for row in range(8):
- for col in range(8):
- bits_top[col] |= ((data[row] >> (7 - col)) & 1) << row
- bits_bot[col] |= ((data[row + 8] >> (7 - col)) & 1) << row
- return (bits_top, bits_bot)
+ spaced = (data[row] * 0x8040201008040201) & 0x8080808080808080
+ top |= spaced >> (7 - row)
+ spaced = (data[row + 8] * 0x8040201008040201) & 0x8080808080808080
+ 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):
for glyph_name, glyph_data in glyphs.items():
icon = glyph_data.get('icon16x16')