summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tileset.py46
1 files changed, 32 insertions, 14 deletions
diff --git a/src/tileset.py b/src/tileset.py
index 2528d8a..ab77223 100644
--- a/src/tileset.py
+++ b/src/tileset.py
@@ -425,29 +425,47 @@ class KPTileset(object):
@staticmethod
def RGB4A3Decode(tex):
+ import time
+ b = time.clock()
+
+ out = bytearray(1024*512*4)
dest = QtGui.QImage(1024,512,QtGui.QImage.Format_ARGB32)
dest.fill(Qt.transparent)
+ # Some fairly ugly code, in an attempt to make it run faster
+ dest_setPixel = dest.setPixel
+ _xrange = xrange
+
+ tex = bytearray(tex)
+
i = 0
- for ytile in xrange(0, 512, 4):
- for xtile in xrange(0, 1024, 4):
- for ypixel in xrange(ytile, ytile + 4):
- for xpixel in xrange(xtile, xtile + 4):
- if(xpixel >= 1024 or ypixel >= 512):
- continue
+ xtile_range = _xrange(0, 1024, 4)
+ ytile_range = _xrange(0, 512, 4)
+
+ for ytile in ytile_range:
+ ypixel_range = _xrange(ytile, ytile + 4)
- newpixel = struct.unpack_from('>H', tex, i)[0]
- # newpixel = (int(tex[i]) << 8) | int(tex[i+1])
+ for xtile in xtile_range:
+ xpixel_range = _xrange(xtile, xtile + 4)
- alpha = ((newpixel & 0x7000) >> 12) * 255 / 0x7
- red = ((newpixel & 0xF00) >> 8) * 255 / 0xF
- green = ((newpixel & 0xF0) >> 4) * 255 / 0xF
- blue = (newpixel & 0xF) * 255 / 0xF
+ for ypixel in ypixel_range:
+ for xpixel in xpixel_range:
- argb = (blue) | (green << 8) | (red << 16) | (alpha << 24)
- dest.setPixel(xpixel, ypixel, argb)
+ bit1 = tex[i]
+ bit2 = tex[i+1]
+
+ dest_setPixel(xpixel, ypixel,
+ ((((bit1 & 0x70) >> 4) * 255 / 7) << 24) |
+ (((bit1 & 0xF) * 255 / 15) << 16) |
+ ((((bit2 & 0xF0) >> 4) * 255 / 15) << 8) |
+ ((bit2 & 0xF) * 255 / 15)
+ )
i += 2
+
+ e = time.clock()
+ print(e - b)
+
return dest