Пример #1
0
def show_img(f):
    tft.fill(TFT.BLACK)
    if f.read(2) == b'BM':  #header
        dummy = f.read(8)  #file size(4), creator bytes(4)
        offset = int.from_bytes(f.read(4), 'little')
    hdrsize = int.from_bytes(f.read(4), 'little')
    width = int.from_bytes(f.read(4), 'little')
    height = int.from_bytes(f.read(4), 'little')
    if int.from_bytes(f.read(2), 'little') == 1:  #planes must be 1
        depth = int.from_bytes(f.read(2), 'little')
        if depth == 24 and int.from_bytes(
                f.read(4), 'little') == 0:  #compress method == uncompressed
            print("Image size:", width, "x", height)
            rowsize = (width * 3 + 3) & ~3
            if height < 0:
                height = -height
                flip = False
            else:
                flip = True
            w, h = width, height
            if w > 128: w = 128
            if h > 160: h = 160
            tft._setwindowloc((0, 0), (w - 1, h - 1))
            for row in range(h):
                if flip:
                    pos = offset + (height - 1 - row) * rowsize
                else:
                    pos = offset + row * rowsize
                if f.tell() != pos:
                    dummy = f.seek(pos)
                for col in range(w):
                    bgr = f.read(3)
                    tft._pushcolor(TFTColor(bgr[2], bgr[1], bgr[0]))
Пример #2
0
def tft_splash(tft1, tft2):
  print("SPI TFT display rectangles")
  # tft1
  tft1.rect([26,1], [80,160], TFT.PURPLE)
  tft1.fillrect([27,2], [20,20], TFTColor(42, 111, 123))
  tft1.fillrect([40,50], [25,15], TFT.RED)
  tft1.fillrect([50,70], [25,15], TFT.BLUE)
  tft1.fillrect([60,90], [25,15], TFT.GREEN)
  tft1.fillrect([85,140], [20,20], TFTColor(123, 111, 42))

  # tft2
  tft2.rect([26,1], [80,160], TFT.PURPLE)
  tft2.fillrect([27,2], [20,20], TFTColor(42, 111, 123))
  tft2.fillrect([40,50], [25,15], TFT.GREEN)
  tft2.fillrect([50,70], [25,15], TFT.RED)
  tft2.fillrect([60,90], [25,15], TFT.BLUE)
  tft2.fillrect([85,140], [20,20], TFTColor(123, 111, 42))
Пример #3
0
 def __init__(self, x, y):
     self.x = x
     self.y = y
     self.x_org = 0
     self.y_org = 0
     self.rotation_org = 0
     self.type = random.randint(0, len(self.figures) - 1)
     tcolor = random.choice(list(colours.items()))
     self.color = TFTColor(tcolor[1][0], tcolor[1][1], tcolor[1][2])
     self.rotation = 0
Пример #4
0
def display_weact_logo():
    tft.fill(TFT.BLACK)
    f = open('WeAct_logo_128_160.bmp', 'rb')
    if f.read(2) == b'BM':  # header
        dummy = f.read(8)  # file size(4), creator bytes(4)
        offset = int.from_bytes(f.read(4), 'little')
        hdrsize = int.from_bytes(f.read(4), 'little')
        width = int.from_bytes(f.read(4), 'little')
        height = int.from_bytes(f.read(4), 'little')
        buf = bytearray(width * 2)  # init buf
        if int.from_bytes(f.read(2), 'little') == 1:  # planes must be 1
            depth = int.from_bytes(f.read(2), 'little')
            if depth == 24 and int.from_bytes(
                    f.read(4),
                    'little') == 0:  # compress method == uncompressed
                print("Image size:", width, "x", height)
                rowsize = (width * 3 + 3) & ~3
                if height < 0:
                    height = -height
                    flip = False
                else:
                    flip = True
                w, h = width, height
                if w > 128: w = 128
                if h > 160: h = 160
                tft._setwindowloc((0, 0), (w - 1, h - 1))
                count = 0
                for row in range(height):
                    if flip:
                        pos = offset + (height - 1 - row) * rowsize
                    else:
                        pos = offset + row * rowsize
                    if f.tell() != pos:
                        dummy = f.seek(pos)
                    for col in range(w):
                        bgr = f.read(3)
                        rgb_color = TFTColor(bgr[2], bgr[1], bgr[0])
                        buf[col * 2] = rgb_color >> 8
                        buf[col * 2 + 1] = rgb_color
                    tft.image(0, row, 128 - 1, row - 1, buf)
Пример #5
0
def LCD_ShowBmp(_tft, FileName):
    f = open(FileName, 'rb')
    print(FileName)
    if f.read(2) == b'BM':  #header
        dummy = f.read(8)  #file size(4), creator bytes(4)
        offset = int.from_bytes(f.read(4), 'little')
        hdrsize = int.from_bytes(f.read(4), 'little')
        width = int.from_bytes(f.read(4), 'little')
        height = int.from_bytes(f.read(4), 'little')
        if int.from_bytes(f.read(2), 'little') == 1:  #planes must be 1
            depth = int.from_bytes(f.read(2), 'little')
            if depth == 24 and int.from_bytes(
                    f.read(4),
                    'little') == 0:  #compress method == uncompressed
                print("Image size:", width, "x", height)
                rowsize = (width * 3 + 3) & ~3
                if height < 0:
                    height = -height
                    flip = False
                else:
                    flip = True
                w, h = width, height
                if w > 160: w = 60
                if h > 80: h = 80
                tft._setwindowloc((0, 0), (w - 1, h - 1))
                for row in range(h):
                    if flip:
                        pos = offset + (height - 1 - row) * rowsize
                    else:
                        pos = offset + row * rowsize
                    if f.tell() != pos:
                        dummy = f.seek(pos)
                    for col in range(w):
                        bgr = f.read(3)
                        _tft._pushcolor(TFTColor(bgr[2], bgr[1], bgr[0]))
            else:
                print(FileName + 'is not 24bit pic')
Пример #6
0
    offset = int.from_bytes(f.read(4), 'little')
    hdrsize = int.from_bytes(f.read(4), 'little')
    width = int.from_bytes(f.read(4), 'little')
    height = int.from_bytes(f.read(4), 'little')
    if int.from_bytes(f.read(2), 'little') == 1:  #planes must be 1
        depth = int.from_bytes(f.read(2), 'little')
        if depth == 24 and int.from_bytes(
                f.read(4), 'little') == 0:  #compress method == uncompressed
            print("Image size:", width, "x", height)
            rowsize = (width * 3 + 3) & ~3
            if height < 0:
                height = -height
                flip = False
            else:
                flip = True
            w, h = width, height
            if w > 128: w = 128
            if h > 160: h = 160
            tft._setwindowloc((0, 0), (w - 1, h - 1))
            for row in range(h):
                if flip:
                    pos = offset + (height - 1 - row) * rowsize
                else:
                    pos = offset + row * rowsize
                if f.tell() != pos:
                    dummy = f.seek(pos)
                for col in range(w):
                    bgr = f.read(3)
                    tft._pushcolor(TFTColor(bgr[2], bgr[1], bgr[0]))
spi.deinit()