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('