Skip to content

Instantly share code, notes, and snippets.

@smealum
Created March 15, 2014 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smealum/9570204 to your computer and use it in GitHub Desktop.
Save smealum/9570204 to your computer and use it in GitHub Desktop.
texconv.py
import struct
import math
import os
import sys
from PIL import Image
tileOrder=[0,1,8,9,2,3,10,11,16,17,24,25,18,19,26,27,4,5,12,13,6,7,14,15,20,21,28,29,22,23,30,31,32,33,40,41,34,35,42,43,48,49,56,57,50,51,58,59,36,37,44,45,38,39,46,47,52,53,60,61,54,55,62,63]
def parseTile(im, l, x, y):
global tileOrder
for k in range(8*8):
i=tileOrder[k]%8
j=int((tileOrder[k]-i)/8)
pixel=im.getpixel((x+i,y+j))
l.append(((pixel[0]&0xFF)<<24)|((pixel[1]&0xFF)<<16)|((pixel[2]&0xFF)<<8)|(0xFF))
srcfn=sys.argv[1]
dstname=sys.argv[2]
#RGBA8
h=64
w=64
im = Image.open(srcfn)
l=[]
for j in range(0,h,8):
for i in range(0,w,8):
parseTile(im, l, i, j)
dst=open(dstname,"wb")
for k in l:
dst.write(struct.pack("I", k))
dst.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment