aboutsummaryrefslogtreecommitdiff
path: root/src/bitmap-ball.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/bitmap-ball.py')
-rwxr-xr-xsrc/bitmap-ball.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/bitmap-ball.py b/src/bitmap-ball.py
new file mode 100755
index 0000000..d28609c
--- /dev/null
+++ b/src/bitmap-ball.py
@@ -0,0 +1,30 @@
+#!/bin/python3
+
+from PIL import Image
+import os
+
+WIDTH = 10
+HEIGHT = 10
+
+# return array of 12-bit color values (0bRRRGGGBBB)
+def pixeldata():
+ image = Image.open("./ball.png")
+ pixels = image.load()
+ pixarr = []
+ for x in range(WIDTH):
+ for y in range(HEIGHT):
+ 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()
+ # declare rom_t as array with size len(pixels) and word width of 12 bits
+ print(f"type rom_t is array (0 to {len(pixels) - 1}) of std_logic_vector(11 downto 0);")
+ # format pixel value as x"rgb" (12-bit hexadecimal with padding)
+ formatted_pixels = [f"x\"{hex(c)[2:].zfill(3)}\"" for c in pixels]
+ # print constant bitmap_ball
+ print(f"constant bitmap_ball: rom_t := ({', '.join(formatted_pixels)});")
+