-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (51 loc) · 1.42 KB
/
main.py
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
from PIL import Image
import numpy as np
import sys
import math
# Make sure the args are passed
if len(sys.argv) != 3:
print("Invalid Arguments, please pass [filename.bin] and [output.png]!")
exit(1)
else:
print("Tring to open \'", sys.argv[1], "\'!")
# make a file object
f = open(sys.argv[1], "rb")
# Convert the file object to an array
ByteArray = list(f.read())
# Make some temp arrays for constructing the main pixel array
ColorArray = []
pixels = []
# Constrct pixel map
print("Constructing pixel map")
for i in ByteArray:
# Make a cool color
Red = math.tan(i) * 255
Green = math.cos(i) * 255
Blue = math.sin(i) * 255
# Make NULL black
if Green == 255 and Blue == 0 and Red == 0:
Green = 0
# Construct the color
Color = (Red, Green, Blue)
# Add the color to the array
ColorArray.append(Color)
if len(ColorArray) >= 1000:
pixels.append(ColorArray)
ColorArray = []
# Clean up old arrays
ByteArray = []
ColorArray = []
# Tell the user the image size
print(len(pixels[0]), "x", len(pixels), " Constructed!")
# Convert to pixels to a 'np array'
print("Converting Array type")
array = np.array(pixels, dtype=np.uint8)
# Clean up the old array
pixels = []
# Construct the image
print("Constructing Image from Array")
new_image = Image.fromarray(array)
# Save the final product
print("Saving Image")
new_image.save(sys.argv[2])
print("done!")