From 493206d552628511259e4f1d579f755e2f7f6a17 Mon Sep 17 00:00:00 2001 From: June Tate-Gans Date: Sun, 2 May 2021 15:23:07 -0500 Subject: [PATCH] g13gui: g13: Add a bitwidgets backend for displaying to the G13 --- g13gui/g13gui/g13/displaydevice.py | 57 ++++++++++++++++++++++++ g13gui/g13gui/g13/displaydevice_tests.py | 34 ++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 g13gui/g13gui/g13/displaydevice.py create mode 100644 g13gui/g13gui/g13/displaydevice_tests.py diff --git a/g13gui/g13gui/g13/displaydevice.py b/g13gui/g13gui/g13/displaydevice.py new file mode 100644 index 0000000..633befb --- /dev/null +++ b/g13gui/g13gui/g13/displaydevice.py @@ -0,0 +1,57 @@ +import PIL +import struct +from io import BytesIO + +from g13gui.bitwidgets.displaydevice import DisplayDevice + + +class DisplayMetrics(object): + WIDTH_PIXELS = 160 + HEIGHT_PIXELS = 48 + + +def ImageToLPBM(image): + """Simple function to convert a PIL Image into LPBM format.""" + + i = PIL.PyAccess.new(image, readonly=True) + bio = BytesIO() + + maxBytes = (DisplayMetrics.WIDTH_PIXELS * + DisplayMetrics.HEIGHT_PIXELS // 8) + row = 0 + col = 0 + + for byteNum in range(0, maxBytes): + b = int() + + if row == 40: + maxSubrow = 3 + else: + maxSubrow = 8 + + for subrow in range(0, maxSubrow): + b |= i[col, row + subrow] << subrow + + bio.write(struct.pack('