From 4291bc5c1f95ab1c7930e3f6deb0cbcd7d7e74e8 Mon Sep 17 00:00:00 2001 From: rdagger Date: Fri, 3 May 2024 13:06:54 -0700 Subject: [PATCH] Add PBM (portable bitmap) demo --- demo_pbm.py | 108 +++++++++++++++++++++++++++++++++++++++ images/invaders48x36.pbm | Bin 0 -> 248 bytes 2 files changed, 108 insertions(+) create mode 100644 demo_pbm.py create mode 100644 images/invaders48x36.pbm diff --git a/demo_pbm.py b/demo_pbm.py new file mode 100644 index 0000000..2076fff --- /dev/null +++ b/demo_pbm.py @@ -0,0 +1,108 @@ +"""ILI9341 demo (PBM - Portable Bitmap).""" +from ili9341 import Display, color565 +from struct import pack, unpack +from framebuf import FrameBuffer, MONO_HLSB, RGB565 # type: ignore +from machine import Pin, SPI # type: ignore +from time import sleep + + +def create_palette(foreground, background=0, invert=False): + """Create framebuffer palette to translate between MONO_HLSB and RGB565. + + Args: + foreground(int): Foreground color in RGB656 format + background(int): Background color in RGB656 format (default Black) + invert(bool): Invert foreground and background (default False) + Returns: + FrameBuffer: Color palette + """ + # Need to swap endian colors + foreground = unpack('>H', pack('H', pack(';;{(PA@|Yx0Ay5M*`4A|?_z(*TatsillmCH6gWQ8bBKZXX@a&WM literal 0 HcmV?d00001