mirror of
https://github.com/grp/Wii.py.git
synced 2025-06-19 07:15:49 -04:00
fixed tpl shit
This commit is contained in:
parent
aa304dc2d5
commit
4d3171c60f
43
TPL.py
43
TPL.py
@ -83,7 +83,7 @@ class TPL():
|
||||
else:
|
||||
self.file = None
|
||||
self.data = file
|
||||
def toTPL(self, outfile, width = 0, height = 0, format="RGBA8"): #single texture only
|
||||
def toTPL(self, outfile, (width, height) = (None, None), format = "RGBA8"): #single texture only
|
||||
"""This converts a PNG image into a TPL. The PNG image is specified as the file parameter to the class initializer, while the output filename is specified here as the parameter outfile. Width and height are optional parameters and specify the size to resize the image to, if needed. Returns the output filename.
|
||||
|
||||
This only can create TPL images with a single texture."""
|
||||
@ -98,8 +98,8 @@ class TPL():
|
||||
|
||||
img = Image.open(self.file)
|
||||
theWidth, theHeight = img.size
|
||||
if(width !=0 and height != 0 and (width != theWidth or height != theHeight)):
|
||||
img.resize(width, height)
|
||||
if(width != None and height != None and (width != theWidth or height != theHeight)):
|
||||
img = img.resize((width, height), Image.ANTIALIAS)
|
||||
w, h = img.size
|
||||
|
||||
texhead = self.TPLTextureHeader()
|
||||
@ -146,6 +146,7 @@ class TPL():
|
||||
''' ADD toCMP '''
|
||||
raise Exception("toCMP not done")
|
||||
#tpldata = self.toCMP((w, h), img)
|
||||
|
||||
texhead.data_off = 0x14 + len(texhead)
|
||||
texhead.wrap = [0, 0]
|
||||
texhead.filter = [1, 1]
|
||||
@ -188,7 +189,6 @@ class TPL():
|
||||
f.close()
|
||||
|
||||
return outfile
|
||||
|
||||
def toI4(self, (w, h), img):
|
||||
out = [0 for i in range(align(w, 4) * align(h, 4) / 2)]
|
||||
outp = 0
|
||||
@ -201,9 +201,15 @@ class TPL():
|
||||
newpixel = 0
|
||||
else:
|
||||
rgba = flatten(inp[x+y*w])
|
||||
i1 = (rgba >> 0) & 0xff
|
||||
r = (rgba >> 0) & 0xff
|
||||
g = (rgba >> 8) & 0xff
|
||||
b = (rgba >> 16) & 0xff
|
||||
i1 = ((r + g + b) / 3) & 0xff
|
||||
rgba = flatten(inp[x+1+y*w])
|
||||
i2 = (rgba >> 0) & 0xff
|
||||
r = (rgba >> 0) & 0xff
|
||||
g = (rgba >> 8) & 0xff
|
||||
b = (rgba >> 16) & 0xff
|
||||
i2 = ((r + g + b) / 3) & 0xff
|
||||
|
||||
newpixel = (((i1 * 15) / 255) << 4)
|
||||
newpixel |= (((i2 * 15) / 255) & 0xf)
|
||||
@ -222,7 +228,10 @@ class TPL():
|
||||
if x>= w or y>=h:
|
||||
i1 = 0
|
||||
else:
|
||||
i1 = (rgba >> 0) & 0xff
|
||||
r = (rgba >> 0) & 0xff
|
||||
g = (rgba >> 8) & 0xff
|
||||
b = (rgba >> 16) & 0xff
|
||||
i1 = ((r + g + b) / 3) & 0xff
|
||||
out[outp] = i1
|
||||
outp += 1
|
||||
return out
|
||||
@ -238,7 +247,10 @@ class TPL():
|
||||
newpixel = 0
|
||||
else:
|
||||
rgba = flatten(inp[x + (y * w)])
|
||||
i1 = (rgba >> 0) & 0xff
|
||||
r = (rgba >> 0) & 0xff
|
||||
g = (rgba >> 8) & 0xff
|
||||
b = (rgba >> 16) & 0xff
|
||||
i1 = ((r + g + b) / 3) & 0xff
|
||||
a1 = (rgba >> 24) & 0xff
|
||||
|
||||
newpixel = (((i1 * 15) / 255) & 0xf)
|
||||
@ -258,7 +270,10 @@ class TPL():
|
||||
newpixel = 0
|
||||
else:
|
||||
rgba = flatten(inp[x + (y * w)])
|
||||
i1 = (rgba >> 0) & 0xff
|
||||
r = (rgba >> 0) & 0xff
|
||||
g = (rgba >> 8) & 0xff
|
||||
b = (rgba >> 16) & 0xff
|
||||
i1 = ((r + g + b) / 3) & 0xff
|
||||
a1 = (rgba >> 24) & 0xff
|
||||
|
||||
newpixel = a1 << 8
|
||||
@ -496,13 +511,15 @@ class TPL():
|
||||
class imp(wx.Panel):
|
||||
def __init__(self, parent, id, im):
|
||||
wx.Panel.__init__(self, parent, id)
|
||||
w, h = im.size
|
||||
w = img.GetWidth()
|
||||
h = img.GetHeight()
|
||||
wx.StaticBitmap(self, -1, im, ( ((max(w, 300) - w) / 2), ((max(h, 200) - h) / 2) ), (w, h))
|
||||
|
||||
self.toImage("tmp.png")
|
||||
img = Image.open("tmp.png")
|
||||
w, h = img.size
|
||||
app = wx.App(redirect = True)
|
||||
img = wx.Image("tmp.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap()
|
||||
w = img.GetWidth()
|
||||
h = img.GetHeight()
|
||||
app = wx.App(redirect = False)
|
||||
frame = wx.Frame(None, -1, "TPL (" + str(w) + ", " + str(h) + ")", size = (max(w, 300), max(h, 200)))
|
||||
image = imp(frame, -1, img)
|
||||
frame.Show(True)
|
||||
|
Loading…
Reference in New Issue
Block a user