-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl27_colorwalk.py
More file actions
67 lines (60 loc) · 1.81 KB
/
l27_colorwalk.py
File metadata and controls
67 lines (60 loc) · 1.81 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
from PIL import Image
import bz2
im = Image.open("C:/zigzag.gif")
l = list(im.getdata())
## l now contains a list of pixels,
## which are indexes to the color table since this is a paletted image
pal = im.palette
colors = map(ord, pal.tostring()[::3])
## since the colors in this image are all greys (R=G=B), we only
## need one component (e.g. R)
def walkIt(table1=l, table2=colors):
pos = 0
found = []
right = []
cnt = 0
while pos < len(table1)-1:
pixel = table1[pos]
color = table2[pixel]
pos += 1
## check if the next pixel's color index =
## the "real" color of the previous one
if table1[pos] == color:
continue
else:
## anomaly found -> data!
pixel = table1[pos]
found.append(pixel)
## also keep the "right" colors!!
right.append(abs(pixel - color))
## print "found at pos %i : '%s' (%d)" % (pos, chr(pixel), pixel)
print "len of found = %d" % len(found)
print "len of right = %d" % len(right)
return (found, right)
def walkItFindNormal(table1=l, table2=colors):
pos = 0
normal = []
cnt = 0
while pos < len(table1)-1:
pixel = table1[pos]
normal.append(pixel)
color = table2[pixel]
pos += 1
## move forward until we found a "normal" pixel
while table1[pos] != color:
pos += 1
if pos >= len(l):
break
print "len of normal = %d" % len(normal)
return normal
def writeFiles(found):
data = "".join(map(chr, found))
## just show a little bit of data
print data[:10]
fo = open("C:/data.bz2", "wb")
fo.write(data)
fo.close()
uncomp = bz2.decompress(data)
fo = open("C:/words.txt", "w")
fo.write(uncomp)
fo.close()