diff options
author | Treeki <treeki@gmail.com> | 2012-03-27 23:15:39 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2012-03-27 23:15:39 +0200 |
commit | 8d5d27396da513fea62d99d8550923dee2f08ed8 (patch) | |
tree | 64c47893ba8f3853029f85363002c32ec2eb2b5e /src | |
parent | a6c469441954df138df6980a719ea2cb1d74c89c (diff) | |
download | koopatlas-8d5d27396da513fea62d99d8550923dee2f08ed8.tar.gz koopatlas-8d5d27396da513fea62d99d8550923dee2f08ed8.zip |
faster tileset loading
Diffstat (limited to '')
-rw-r--r-- | src/tileset.py | 46 |
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 |