Add script to convert frames to raw RGB565
This commit is contained in:
parent
5b18f1644a
commit
d48eb8b2be
@ -1,2 +1,4 @@
|
||||
# Longan_GD32VF_examples
|
||||
example project for Longan Nano (GD32VF)
|
||||
# Sipeed Longan Nano movie player
|
||||
|
||||
Convert your 160x80 frames to RGB565 using `png2rgb565.py`, concat them
|
||||
into movie.bin and copy the file to the SD card.
|
||||
|
31
movies/png2rgb565.py
Executable file
31
movies/png2rgb565.py
Executable file
@ -0,0 +1,31 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Based on https://gist.github.com/hidsh/7065820
|
||||
|
||||
from PIL import Image
|
||||
import struct, os, sys
|
||||
|
||||
def write_bin(f, pixel_list):
|
||||
for pix in pixel_list:
|
||||
# RGB565: RRRR RGGG GGGB BBBB
|
||||
r = (pix[0] >> 3) & 0x1F
|
||||
g = (pix[1] >> 2) & 0x3F
|
||||
b = (pix[2] >> 3) & 0x1F
|
||||
# big endian u16
|
||||
f.write(struct.pack('>H', (r << 11) + (g << 5) + b))
|
||||
|
||||
args = sys.argv
|
||||
if len(args) != 2:
|
||||
print('./png2rgb565.py HOGE.png')
|
||||
exit(1)
|
||||
|
||||
in_path = args[1]
|
||||
|
||||
body, _ = os.path.splitext(in_path)
|
||||
out_path = body + '.rgb'
|
||||
|
||||
img = Image.open(in_path).convert('RGB')
|
||||
|
||||
with open(out_path, 'wb') as f:
|
||||
write_bin(f, img.getdata())
|
Loading…
Reference in New Issue
Block a user