tools: rle_encode: Derive variable names from filenames

This commit is contained in:
Daniel Thompson 2020-02-03 19:07:11 +00:00
parent e21f2a79ca
commit fb252818e9
1 changed files with 8 additions and 2 deletions

View File

@ -2,8 +2,12 @@
import argparse
import sys
import os.path
from PIL import Image
def varname(p):
return os.path.basename(os.path.splitext(p)[0])
def encode(im):
pixels = im.load()
@ -82,7 +86,8 @@ def encode_8bit(im):
def render_c(image, fname):
print(f'// 1-bit RLE, generated from {fname}, {len(image[2])} bytes')
print('static const uint8_t rle[] = {\n ', end='')
print(f'static const uint8_t {varname(fname)}[] = {{')
print(' ', end='')
i = 0
for rl in image[2]:
print(f' {hex(rl)},', end='')
@ -139,7 +144,8 @@ for fname in args.files:
render_c(image, fname)
else:
print(f'# 1-bit RLE, generated from {fname}, {len(image[2])} bytes')
print(f'rle = {image}')
print(f'{varname(fname)} = {image}')
print()
if args.ascii:
print()