Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import os
- from PIL import Image
- import numpy as np
- f = open(sys.argv[1], 'r')
- TD = None
- textures_raw = {}
- blklist = ['=','{','}','[',']']
- for x in f:
- if TD is not None:
- rn = x.replace(' ','').strip().split(',')
- vals = []
- for n in rn:
- text = n[2:]
- val = []
- if text:
- tmp = bin(int(text, 16))[2:].zfill(16)
- alpha = tmp[-1]
- rgb = tmp[:-1]
- chunks = [rgb[5*i:5*(i+1)] for i in xrange(len(rgb)//5)]
- val = [(int(x, 2) * 255 / 31) for x in chunks]
- val.append(int(alpha)*255)
- vals.append(tuple(val))
- if vals:
- textures_raw[TD].append(vals)
- if x.find('};') >= 0:
- TD = None
- if x.find('static unsigned short') >= 0:
- name = x.replace('static unsigned short','')
- name = ''.join([c for c in name if c not in blklist])
- print(name)
- TD = name.strip()
- textures_raw[TD] = []
- for tx in textures_raw:
- array = np.array(textures_raw[tx], dtype=np.uint8)
- img = Image.fromarray(array, 'RGBA')
- img.save(tx+'.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement