Merge branch 'master' of git@github.com:icefire/Wii.py

This commit is contained in:
axe97 2009-06-22 23:01:48 -07:00
commit d60418ba3e

50
TPL.py
View File

@ -7,7 +7,10 @@ from Struct import Struct
from common import * from common import *
def flatten(myTuple): def flatten(myTuple):
return myTuple[0] << 24 | myTuple[1] << 16 | myTuple[2] << 8 | myTuple[3] << 0 if (len(myTuple) == 4):
return myTuple[0] << 24 | myTuple[1] << 16 | myTuple[2] << 8 | myTuple[3] << 0
else:
return myTuple[0] << 24 | myTuple[1] << 16 | myTuple[2] << 8 | 0xff << 0
def round_up(x, n): def round_up(x, n):
left = x % n left = x % n
@ -448,15 +451,16 @@ class TPL():
tpldata = struct.unpack(">" + str(w * h) + "H", data[tex.data_off:tex.data_off + (w * h * 2)]) tpldata = struct.unpack(">" + str(w * h) + "H", data[tex.data_off:tex.data_off + (w * h * 2)])
rgbdata = self.CI14X2((w, h), tpldata, paldata) rgbdata = self.CI14X2((w, h), tpldata, paldata)
elif(tex.format == 14): elif(tex.format == 14):
sz = ((w + 7) >> 3) * ((w + 7) >> 3) * 32 #sz = ((w + 7) >> 3) * ((w + 7) >> 3) * 32
tpldata = struct.unpack(">" + str(sz / 2) + "H", data[tex.data_off:tex.data_off + sz]) #tpldata = struct.unpack(">" + str(sz / 2) + "H", data[tex.data_off:tex.data_off + sz])
tpldata = ''.join(data[tex.data_off:])
rgbdata = self.CMP((w, h), tpldata) rgbdata = self.CMP((w, h), tpldata)
else: else:
raise TypeError("Unsupported TPL Format: " + str(tex.format)) raise TypeError("Unsupported TPL Format: " + str(tex.format))
output = Image.fromstring("RGBA", (w, h), rgbdata) output = Image.fromstring("RGBA", (w, h), rgbdata)
ext = outfile[outfile.rfind("."):] ext = outfile[outfile.rfind(".")+1:]
output.save(outfile, ext) output.save(outfile, ext)
return outfile return outfile
@ -488,13 +492,13 @@ class TPL():
"""This will draw a simple window with the TPL image displayed on it. It uses WxPython for the window creation and management. The window has a minimum width and height of 300 x 200. Does not return a value. """This will draw a simple window with the TPL image displayed on it. It uses WxPython for the window creation and management. The window has a minimum width and height of 300 x 200. Does not return a value.
Again, only a single texture is supported.""" Again, only a single texture is supported."""
import wx
class imp(wx.Panel): class imp(wx.Panel):
def __init__(self, parent, id, im): def __init__(self, parent, id, im):
wx.Panel.__init__(self, parent, id) wx.Panel.__init__(self, parent, id)
w, h = im.size w, h = im.size
wx.StaticBitmap(self, -1, im, ( ((max(w, 300) - w) / 2), ((max(h, 200) - h) / 2) ), (w, h)) wx.StaticBitmap(self, -1, im, ( ((max(w, 300) - w) / 2), ((max(h, 200) - h) / 2) ), (w, h))
import wx
self.toImage("tmp.png") self.toImage("tmp.png")
img = Image.open("tmp.png") img = Image.open("tmp.png")
w, h = img.size w, h = img.size
@ -552,7 +556,7 @@ class TPL():
out[y1*w+x1] = rgba out[y1*w+x1] = rgba
return ''.join(Struct.uint32(p) for p in out) return ''.join(Struct.uint32(p) for p in out)
def RGB565(self, (w, h), jar): def RGB565(self, (w, h), jar):
out = [0 for i in range(x * y)] out = [0 for i in range(w * h)]
i = 0 i = 0
for y in range(0, h, 4): for y in range(0, h, 4):
for x in range(0, w, 4): for x in range(0, w, 4):
@ -572,7 +576,7 @@ class TPL():
out[y1*w+x1] = rgba out[y1*w+x1] = rgba
return ''.join(Struct.uint32(p) for p in out) return ''.join(Struct.uint32(p) for p in out)
def I4(self, (w, h), jar): def I4(self, (w, h), jar):
out = [0 for i in range(x * y)] out = [0 for i in range(w * h)]
i = 0 i = 0
for y in range(0, h, 8): for y in range(0, h, 8):
for x in range(0, w, 8): for x in range(0, w, 8):
@ -587,10 +591,8 @@ class TPL():
b = (pixel >> 4) * 255 / 15 b = (pixel >> 4) * 255 / 15
a = 255 a = 255
out[y1][(x1 * 4) + 0] = r rgba = (r<<0) | (g<<8) | (b<<16) | (a<<24)
out[y1][(x1 * 4) + 1] = g out[y1*w+x1] = rgba
out[y1][(x1 * 4) + 2] = b
out[y1][(x1 * 4) + 3] = a
if(y1 >= h or x1 >= w): if(y1 >= h or x1 >= w):
continue continue
@ -602,13 +604,11 @@ class TPL():
b = (pixel & 0x0F) * 255 / 15 b = (pixel & 0x0F) * 255 / 15
a = 255 a = 255
out[y1][((x1 + 1) * 4) + 0] = r rgba = (r<<0) | (g<<8) | (b<<16) | (a<<24)
out[y1][((x1 + 1) * 4) + 1] = g out[y1*w+x1+1] = rgba
out[y1][((x1 + 1) * 4) + 2] = b return ''.join(Struct.uint32(p) for p in out)
out[y1][((x1 + 1) * 4) + 3] = a
return out
def IA4(self, (w, h), jar): def IA4(self, (w, h), jar):
out = [0 for i in range(x * y)] out = [0 for i in range(w * h)]
i = 0 i = 0
for y in range(0, h, 4): for y in range(0, h, 4):
for x in range(0, w, 8): for x in range(0, w, 8):
@ -619,16 +619,16 @@ class TPL():
pixel = jar[i] pixel = jar[i]
i += 1 i += 1
r = (pixel & 0x0F) * 255 / 15 r = ((pixel & 0x0F) * 255 / 15) & 0xff
g = (pixel & 0x0F) * 255 / 15 g = ((pixel & 0x0F) * 255 / 15) & 0xff
b = (pixel & 0x0F) * 255 / 15 b = ((pixel & 0x0F) * 255 / 15) & 0xff
a = 255 - ((pixel & 0xFF) * 255 / 15) a = (255 - ((pixel & 0xFF) * 255 / 15)) & 0xff
rgba = (r<<0) | (g<<8) | (b<<16) | (a<<24) rgba = (r<<0) | (g<<8) | (b<<16) | (a<<24)
out[y1*w+x1] = rgba out[y1*w+x1] = rgba
return ''.join(Struct.uint32(p) for p in out) return ''.join(Struct.uint32(p) for p in out)
def I8(self, (w, h), jar): def I8(self, (w, h), jar):
out = [0 for i in range(x * y)] out = [0 for i in range(w * h)]
i = 0 i = 0
for y in range(0, h, 4): for y in range(0, h, 4):
for x in range(0, w, 8): for x in range(0, w, 8):
@ -648,7 +648,7 @@ class TPL():
out[y1*w+x1] = rgba out[y1*w+x1] = rgba
return ''.join(Struct.uint32(p) for p in out) return ''.join(Struct.uint32(p) for p in out)
def IA8(self, (w, h), jar): def IA8(self, (w, h), jar):
out = [0 for i in range(x * y)] out = [0 for i in range(w * h)]
i = 0 i = 0
for y in range(0, h, 4): for y in range(0, h, 4):
for x in range(0, w, 4): for x in range(0, w, 4):
@ -668,7 +668,7 @@ class TPL():
out[y1*w+x1] = rgba out[y1*w+x1] = rgba
return ''.join(Struct.uint32(p) for p in out) return ''.join(Struct.uint32(p) for p in out)
def CI4(self, (w, h), jar, pal): def CI4(self, (w, h), jar, pal):
out = [0 for i in range(x * y)] out = [0 for i in range(w * h)]
i = 0 i = 0
for y in range(0, h, 8): for y in range(0, h, 8):
for x in range(0, w, 8): for x in range(0, w, 8):
@ -700,7 +700,7 @@ class TPL():
out[y1*w+x1+1] = rgba out[y1*w+x1+1] = rgba
return ''.join(Struct.uint32(p) for p in out) return ''.join(Struct.uint32(p) for p in out)
def CI8(self, (w, h), jar, pal): def CI8(self, (w, h), jar, pal):
out = [0 for i in range(x * y)] out = [0 for i in range(w * h)]
i = 0 i = 0
for y in range(0, h, 4): for y in range(0, h, 4):
for x in range(0, w, 8): for x in range(0, w, 8):