-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimageDrawing.py
More file actions
68 lines (51 loc) · 2.05 KB
/
Copy pathimageDrawing.py
File metadata and controls
68 lines (51 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import numpy as np
from PIL import Image
# Scales image down to desired dimension
# Convert scaled down image to pixel array
# For PNG, sets color to (0,0,0) for transparent pixel
# Every other color +1 (Cap at 255)
# CHANGE THE IMAGE NAME AND FILE EXTENSION
image_name = "EE2026_screen"
extension = ".jpg"
# Change this to desired dimension to scale to
size = 96,32 # Screen dimension
file = open("data/" + image_name + ".txt", "w")
img = Image.open(image_name + extension)
print("Original size: ", end="")
print(img.size)
img.thumbnail(size, Image.LANCZOS)
img.save('images/small_' + image_name + extension)
arr = np.array(img)
print(np.shape(arr))
count = 0
file.write("wire [15:0] data [3071:0];\n")
for i in range(len(arr)):
for j in range(len(arr[i])):
if len(arr[i][j]) == 4:
r, g, b, a = arr[i][j]
file.write("assign data[" + str(count) + "] = ")
if (a < 100):
file.write("16'b00000_000000_00000;\n")
else:
new_r = (r//8)+1
new_g = (g//4)+1
new_b = (b//8)+1
new_r = 31 if (r//8)+1 > 31 else (r//8)+1
new_g = 63 if (g//4)+1 > 63 else (g//4)+1
new_b = 31 if (b//8)+1 > 31 else (b//8)+1
file.write("16'b" + '{0:05b}'.format(new_r) + "_" + '{0:06b}'.format(new_g) + "_" + '{0:05b}'.format(new_b) + ";")
file.write("\n")
elif len(arr[i][j]) == 3:
r, g, b = arr[i][j]
file.write("assign data[" + str(count) + "] = ")
new_r = (r//8)+1
new_g = (g//4)+1
new_b = (b//8)+1
new_r = 31 if (r//8)+1 > 31 else (r//8)+1
new_g = 63 if (g//4)+1 > 63 else (g//4)+1
new_b = 31 if (b//8)+1 > 31 else (b//8)+1
file.write("16'b" + '{0:05b}'.format(new_r) + "_" + '{0:06b}'.format(new_g) + "_" + '{0:05b}'.format(new_b) + ";")
file.write("\n")
count += 1
file.write("\n")
file.close()