diff --git a/README.md b/README.md index 45a29df..6bffdfa 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/movies/png2rgb565.py b/movies/png2rgb565.py new file mode 100755 index 0000000..9113f04 --- /dev/null +++ b/movies/png2rgb565.py @@ -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())