From aeced13908c8f701e43d67528ea0d50906ec024c Mon Sep 17 00:00:00 2001 From: June Tate-Gans Date: Thu, 29 Apr 2021 20:20:15 -0500 Subject: [PATCH] g13gui: Add LPBM image conversion and tests This is the first step to actually rendering to the G13's display by way of the g13d daemon. The bitmap format is kinda weird: it's actually 860 bytes of useable pixel data, but padded out to 960. Each byte corresponds with one vertical column of 8-pixels, going from top to bottom. The tests for this effectively check to make sure the length is correct, and also dumps it out to a running g13d (if there is one). This should probably be automated a bit more by checking the bytes directly, but given that this is a visual task anyway, I'm being a bit lazy. --- g13gui/g13gui/bitwidgets/__init__.py | 5 ++- g13gui/g13gui/bitwidgets/display.py | 45 +++++++++++++++++++++-- g13gui/g13gui/bitwidgets/display_tests.py | 39 ++++++++++++-------- g13gui/g13gui/bitwidgets/fonts.py | 7 ++-- g13gui/g13gui/bitwidgets/fonts_tests.py | 33 +++++++++++++++++ 5 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 g13gui/g13gui/bitwidgets/fonts_tests.py diff --git a/g13gui/g13gui/bitwidgets/__init__.py b/g13gui/g13gui/bitwidgets/__init__.py index b798c30..2877bb0 100644 --- a/g13gui/g13gui/bitwidgets/__init__.py +++ b/g13gui/g13gui/bitwidgets/__init__.py @@ -1,3 +1,4 @@ -from g13gui.bitwidgets.display import Fonts -from g13gui.bitwidgets.display import FontManager +from g13gui.bitwidgets.fonts import Fonts +from g13gui.bitwidgets.fonts import FontManager from g13gui.bitwidgets.display import Display +from g13gui.bitwidgets.display import DisplayMetrics diff --git a/g13gui/g13gui/bitwidgets/display.py b/g13gui/g13gui/bitwidgets/display.py index 4687207..67a2f92 100644 --- a/g13gui/g13gui/bitwidgets/display.py +++ b/g13gui/g13gui/bitwidgets/display.py @@ -1,12 +1,51 @@ +import struct +import PIL.ImageDraw +import PIL.PyAccess +import sys +from io import BytesIO from PIL import Image -from PIL.ImageDraw import ImageDraw from g13gui.observer import Subject from g13gui.observer import ChangeType class DisplayMetrics(object): WIDTH_PIXELS = 160 - HEIGHT_PIXELS = 48 + HEIGHT_PIXELS = 43 + + +LPBM_LENGTH = 960 + + +def ImageToLPBM(image): + 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('