-
Notifications
You must be signed in to change notification settings - Fork 1
/
view_pebble_image.py
35 lines (32 loc) · 1.13 KB
/
view_pebble_image.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
from unpack_pbpack import BMPResource
import Tkinter, random, sys
class App:
def __init__(self, t):
bmp = BMPResource(open(sys.argv[1], 'rb').read())
print repr(bmp)
self.i = Tkinter.PhotoImage(width=bmp.width,height=bmp.height)
row = 0; col = 0; line = 0
buffer = bmp.data
while len(buffer) > 0:
scanline = buffer[:bmp.scanlines]
buffer = buffer[bmp.scanlines:]
col = 0
for o in xrange(bmp.scanlines-1):
c = ord(scanline[o])
for i in xrange(8):
if col >= bmp.width:
break
if c & 1 == 1:
self.i.put("#FFFFFF", (col,row))
else:
self.i.put("#000000", (col,row))
c = c >> 1
col += 1
row = row + 1
if row >= bmp.height:
break
c = Tkinter.Canvas(t, width=bmp.width, height=bmp.height); c.pack()
c.create_image(0, 0, image = self.i, anchor=Tkinter.NW)
t = Tkinter.Tk()
a = App(t)
t.mainloop()