-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtn128.py
32 lines (27 loc) · 824 Bytes
/
tn128.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
# Thumbnails are 128x128, 16 bits per pixel.
# Guessed YUYV, aka interleaved YUV 4:2:2.
from PIL import Image
def decode_tn128(data):
# My download may have added an extra byte.
if len(data)%2:
assert data[-1]==0
data = data[:-1]
w,h=128,128
img = Image.new('YCbCr', (w,h))
for y in range(h):
for x in range(0,w,2):
cb = data[(y*w+x)*2+1]
cr = data[(y*w+x)*2+3]
cy = data[(y*w+x)*2]
img.putpixel((x,y), (cy,cb,cr))
cy = data[(y*w+x)*2+2]
img.putpixel((x+1,y), (cy,cb,cr))
return img
if __name__ == '__main__':
def main():
from sys import argv
for name in argv[1:]:
data = open(name, 'rb').read()
img = decode_tn128(data)
img.show()
main()