russhughes / gc9a01_mpy

Fast MicroPython driver for GC9A01 display modules written in C
Other
153 stars 31 forks source link

convert image to python module #4

Closed ALable closed 2 years ago

ALable commented 2 years ago

I want to realize the project about convert image to python module ,but when I use the command python ./imgtobitmap.py t1.png 3 >test.py an error message:

img = img.convert("P", palette=Image.ADAPTIVE, colors=2**bits) Traceback (most recent call last):

File "./imgtobitmap.py", line 101, in main() File "./imgtobitmap.py", line 43, in main ((palette[color*3] & 0xF8) << 8) IndexError: list index out of range

so I change the parameter (bits) to 2 . Luckily, it succeed ,but I execute the project code a new error coming:

Traceback (most recent call last): File "", line 60, in File "", line 59, in main TypeError: can't convert str to int

Maybe the error caused by the parameter(bits)

Here are my codes:

from machine import Pin, SPI
import gc9a01
import test

def main():
    '''
    Draw and move sprite
    '''
    spi = SPI(2, baudrate=60000000, sck=Pin(18), mosi=Pin(23))
    tft = gc9a01.GC9A01(
        spi,
        240,
        240,
        reset=Pin(26, Pin.OUT),
        cs=Pin(5, Pin.OUT),
        dc=Pin(27, Pin.OUT),
        backlight=Pin(2, Pin.OUT),
        rotation=0)

    # enable display and clear screen
    tft.init()
    tft.fill(gc9a01.BLACK)

    tft.bitmap(test,50,50)
main() 

Convert result Test.py

HEIGHT = 64
WIDTH = 64
COLORS = 4
BITS = 8192
BPP = 2
PALETTE = [0x0000,0x4049,0x609b,0x4082]

image

russhughes commented 2 years ago

That should be fixed now.