Fixed I4 and I8, as intensity is for all channels not just RGB, also added drag/drop support to image.py for displaying tpl files.

This commit is contained in:
matt 2009-07-03 15:26:18 +12:00
parent 126d9f5913
commit 7f8741a973

View File

@ -1,4 +1,5 @@
from common import * from common import *
import wx
def flatten(myTuple): def flatten(myTuple):
if (len(myTuple) == 4): if (len(myTuple) == 4):
@ -410,7 +411,7 @@ class TPL():
tex.unpack(data[head.header_offset:head.header_offset + len(tex)]) tex.unpack(data[head.header_offset:head.header_offset + len(tex)])
w = tex.width w = tex.width
h = tex.height h = tex.height
print tex.format
if(tex.format == 0): #I4, 4-bit if(tex.format == 0): #I4, 4-bit
tpldata = struct.unpack(">" + str((w * h) / 2) + "B", data[tex.data_off:tex.data_off + ((w * h) / 2)]) tpldata = struct.unpack(">" + str((w * h) / 2) + "B", data[tex.data_off:tex.data_off + ((w * h) / 2)])
rgbdata = self.I4((w, h), tpldata) rgbdata = self.I4((w, h), tpldata)
@ -605,7 +606,7 @@ class TPL():
r = (pixel >> 4) * 255 / 15 r = (pixel >> 4) * 255 / 15
g = (pixel >> 4) * 255 / 15 g = (pixel >> 4) * 255 / 15
b = (pixel >> 4) * 255 / 15 b = (pixel >> 4) * 255 / 15
a = 255 a = (pixel >> 4) * 255 / 15
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
@ -618,7 +619,7 @@ class TPL():
r = (pixel & 0x0F) * 255 / 15 r = (pixel & 0x0F) * 255 / 15
g = (pixel & 0x0F) * 255 / 15 g = (pixel & 0x0F) * 255 / 15
b = (pixel & 0x0F) * 255 / 15 b = (pixel & 0x0F) * 255 / 15
a = 255 a = (pixel & 0x0F) * 255 / 15
rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24) rgba = (r << 0) | (g << 8) | (b << 16) | (a << 24)
out[y1 * w + x1 + 1] = rgba out[y1 * w + x1 + 1] = rgba
@ -794,3 +795,7 @@ class TPL():
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)
if __name__=='__main__':
app = wx.PySimpleApp()
app.MainLoop()
TPL(*sys.argv[1:]).toScreen()