-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorspace-decompile
executable file
·76 lines (63 loc) · 1.34 KB
/
colorspace-decompile
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
69
70
71
72
73
74
75
76
#!/usr/bin/env python
from PIL import Image
from sys import argv
from os import system
from math import sqrt, ceil
def put_pixel(char):
if (char==' '):
r=255
g=0
b=0
elif (char== ' '):
r=0
g=255
b=0
elif (char=='\n'):
r=0
g=0
b=255
else:
r=255
g=255
b=255
return (r,g,b)
print
print " Colorspace - decompile"
print
print " Tool for \"decompiling\" whitespace program into the simpliest colorspace image"
print
print "(C) GNU GPLv2+ 2010 Sebastian Krzyszkowiak and Agata Kurczewska"
print "---------------------------------------------------------------"
if len(argv)<3:
print "Usage: "+argv[0]+" file.ws result.png"
exit(0)
chars = []
newdata = []
f = open(argv[1], "r")
i=0
for line in f.readlines():
for char in line:
if (char==' ') or (char=='\t') or (char=='\n'):
chars.append(char)
n=int(ceil(sqrt(len(chars))))
for char in chars:
newdata.append(put_pixel(char))
i=i+1
f.close()
#print "n: " + str(n)
#print "i: " + str(i)
#print "len(chars): " + str(len(chars))
#print "len(data): " + str(len(data))
#print "len(newdata): " + str(len(newdata))
j=0
while (i<n*n):
newdata.append((255-j,255-j,255-j))
i=i+1
j=j+2
if (j>255):
j=0
#print "len(newdata): " + str(len(newdata))
im = Image.new("RGB", (n,n))
im.putdata(newdata)
im.save(argv[2], "PNG")
print "Done."