From fb252818e9e8c93adcefcffb99e3fad20c01bd88 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Mon, 3 Feb 2020 19:07:11 +0000 Subject: [PATCH] tools: rle_encode: Derive variable names from filenames --- tools/rle_encode.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/rle_encode.py b/tools/rle_encode.py index 98c5da8..a938c76 100755 --- a/tools/rle_encode.py +++ b/tools/rle_encode.py @@ -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()