Full color mode working with fixed image_converter.py

pull/49/head
troyhy 2024-09-03 09:34:16 +03:00
rodzic d47519f82a
commit 3d6b485f3d
3 zmienionych plików z 21 dodań i 18 usunięć

Wyświetl plik

@ -49,6 +49,7 @@ _ST7789_DISPON = b"\x29"
_ST7789_CASET = b"\x2a" _ST7789_CASET = b"\x2a"
_ST7789_RASET = b"\x2b" _ST7789_RASET = b"\x2b"
_ST7789_RAMWR = b"\x2c" _ST7789_RAMWR = b"\x2c"
_ST7789_WRMEMC = b"\x3c"
_ST7789_VSCRDEF = b"\x33" _ST7789_VSCRDEF = b"\x33"
_ST7789_COLMOD = b"\x3a" _ST7789_COLMOD = b"\x3a"
_ST7789_MADCTL = b"\x36" _ST7789_MADCTL = b"\x36"
@ -261,27 +262,28 @@ class ST7789(framebuf.FrameBuffer):
self._cs(1) self._cs(1)
# Asynchronous refresh with support for reducing blocking time. # Asynchronous refresh with support for reducing blocking time.
async def ddo_refresh(self, split=5): async def do_refresh(self, split=5):
async with self._lock: async with self._lock:
lines, mod = divmod(self.height, split) # Lines per segment lines, mod = divmod(self.height, split) # Lines per segment
if mod: if mod:
raise ValueError("Invalid do_refresh arg.") raise ValueError("Invalid do_refresh arg.")
#clut = ST7789.lut
wd = -(-self.width // 2) bw = self.width * 2
lb = memoryview(self._linebuf) end = self.height * self.width * 2
cm = self._gscale # color False, greyscale True
buf = self.mvb buf = self.mvb
line = 0 line = 0
for n in range(split): for n in range(split):
if self._spi_init: # A callback was passed if self._spi_init: # A callback was passed
self._spi_init(self._spi) # Bus may be shared self._spi_init(self._spi) # Bus may be shared
self._dc(0) self._dc(0)
self._cs(0) self._cs(0)
self._spi.write(b"\x3c" if n else b"\x2c") # RAMWR/Write memory continue self._spi.write(_ST7789_WRMEMC if n else _ST7789_RAMWR) # RAMWR/Write memory continue
self._dc(1) self._dc(1)
for start in range(wd * line, wd * (line + lines), wd):
#_lcopy(lb, buf[start:], 0xffff, wd, cm) # Copy and map colors for start in range(bw * line, bw * (line + lines), bw):
self._spi.write(buf[start : start + wd]) self._spi.write(buf[start : start + bw])
line += lines line += lines
self._cs(1) self._cs(1)
await asyncio.sleep(0) await asyncio.sleep(0)

Wyświetl plik

@ -9,14 +9,14 @@
from gui.core.ugui import Widget from gui.core.ugui import Widget
from gui.core.colors import * from gui.core.colors import *
from gui.core.ugui import ssd from gui.core.ugui import ssd
import struct
def little_to_big_endian(value):
# A Helper function to convert 16 bit int from little to big endian def transform_palette(color565):
# Pack the value as little-endian # change endian of the color from little to BIG
packed = struct.pack(f'<H', value) col = (color565 & 0xFF00) >> 8 | color565 << 8
# Unpack it as big-endian # invert bitwise
return struct.unpack(f'>H', packed)[0] return col ^ 0xffff
class ColorBitMap(Widget): class ColorBitMap(Widget):
@ -36,7 +36,8 @@ class ColorBitMap(Widget):
# Transform palette to match display color format # Transform palette to match display color format
# this will be run for with all image palette members # this will be run for with all image palette members
palette_transformer_cb = lambda self, x: ~little_to_big_endian(x) & 0xffff # I did not find good way of changing other than class variable.
palette_transformer_cb = staticmethod(transform_palette)
def show(self): def show(self):
if not super().show(True): # Draw or erase border if not super().show(True): # Draw or erase border

Wyświetl plik

@ -58,7 +58,7 @@ def rgb_to_color565(r, g, b):
int: Converted color value in the 16-bit color format (565). int: Converted color value in the 16-bit color format (565).
""" """
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b & 0xF8) return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3)
def convert_to_bitmap(image_file, bits_requested): def convert_to_bitmap(image_file, bits_requested):