From 74ec145c5e44a51789e9117b1ae93dfd7be24d86 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 13 Mar 2023 18:26:54 +0100 Subject: fix display upscaler (output working!) --- test/upscaler/bitmap-ball.py | 28 ---------------------------- test/upscaler/img2coe.py | 28 ++++++++++++++++++++++++++++ test/upscaler/makefile | 4 +++- 3 files changed, 31 insertions(+), 29 deletions(-) delete mode 100755 test/upscaler/bitmap-ball.py create mode 100755 test/upscaler/img2coe.py (limited to 'test') diff --git a/test/upscaler/bitmap-ball.py b/test/upscaler/bitmap-ball.py deleted file mode 100755 index 85474f1..0000000 --- a/test/upscaler/bitmap-ball.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/python3 - -from PIL import Image -import sys - -# return array of 12-bit color values (0bRRRGGGBBB) -def pixeldata(): - image = Image.open(sys.argv[-1]) # use last argument as input image file - pixels = image.load() - pixarr = [] - w,h = image.size - for x in range(w): - for y in range(h): - color = pixels[x, y] - crushed_color = ((color[0] >> 4) << 8 | (color[1] >> 4) << 4 | (color[2] >> 4) << 0) - pixarr.append(crushed_color) - return pixarr - -if __name__ == "__main__": - # get array of 12-bit pixels - pixels = pixeldata() - # coe file header - print("memory_initialization_radix=16;\nmemory_initialization_vector=", end='') - # format pixel value as 12-bit hexadecimal with padding seperated by comma and space - formatted_pixels = ','.join([f"{hex(c)[2:].zfill(3)}" for c in pixels]) - print(f"{formatted_pixels};") - - diff --git a/test/upscaler/img2coe.py b/test/upscaler/img2coe.py new file mode 100755 index 0000000..fb4c442 --- /dev/null +++ b/test/upscaler/img2coe.py @@ -0,0 +1,28 @@ +#!/bin/python3 + +from PIL import Image +import sys + +# return array of 12-bit color values (0bRRRGGGBBB) +def pixeldata(): + image = Image.open(sys.argv[-1]) # use last argument as input image file + pixels = image.load() + pixarr = [] + w,h = image.size + for y in range(h): + for x in range(w): + color = pixels[x, y] + crushed_color = ((color[0] >> 4) << 8 | (color[1] >> 4) << 4 | (color[2] >> 4) << 0) + pixarr.append(crushed_color) + return pixarr + +if __name__ == "__main__": + # get array of 12-bit pixels + pixels = pixeldata() + # coe file header + print("memory_initialization_radix=16;\nmemory_initialization_vector=", end='') + # format pixel value as 12-bit hexadecimal with padding seperated by comma and space + formatted_pixels = ','.join([f"{hex(c)[2:].zfill(3)}" for c in pixels]) + print(f"{formatted_pixels};") + + diff --git a/test/upscaler/makefile b/test/upscaler/makefile index 072d5b2..393eda4 100644 --- a/test/upscaler/makefile +++ b/test/upscaler/makefile @@ -1,2 +1,4 @@ img.coe: img.png - ./bitmap-ball.py $< > $@ + +%.coe: %.png + ./img2coe.py $< > $@ -- cgit v1.2.3