summaryrefslogtreecommitdiff
path: root/src/exporter.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/exporter.py')
-rw-r--r--src/exporter.py44
1 files changed, 39 insertions, 5 deletions
diff --git a/src/exporter.py b/src/exporter.py
index b1afaaa..d396eb2 100644
--- a/src/exporter.py
+++ b/src/exporter.py
@@ -9,6 +9,35 @@ u32 = struct.Struct('>I')
u16 = struct.Struct('>H')
zero32 = u32.pack(0)
+def RGBA8Encode(tex):
+ tex = tex.toImage()
+ w, h = tex.width(), tex.height()
+ padW = (w + 3) & ~3
+ padH = (h + 3) & ~3
+
+ destBuffer = create_string_buffer(padW * padH * 4)
+
+ shortstruct = struct.Struct('>H')
+ sspack = shortstruct.pack_into
+ offset = 0
+
+ for ytile in xrange(0, padH, 4):
+ for xtile in xrange(0, padW, 4):
+ for ypixel in xrange(ytile, ytile + 4):
+ for xpixel in xrange(xtile, xtile + 4):
+
+ if xpixel >= w or ypixel >= h:
+ sspack(destBuffer, offset, 0)
+ sspack(destBuffer, offset+32, 0)
+ else:
+ pixel = tex.pixel(xpixel, ypixel)
+
+ sspack(destBuffer, offset, pixel>>16)
+ sspack(destBuffer, offset+32, pixel&0xFFFF)
+ offset += 2
+ offset += 32
+
+ return destBuffer.raw
def RGB5A3Encode(tex):
tex = tex.toImage()
@@ -257,10 +286,11 @@ class KPMapExporter:
w, h = doodad.size
data += struct.pack('>fffffii', x, y, w, h, doodad.angle, 0, len(doodad.animations))
+ is_rgba8 = (doodad.source[0].startswith('Cloud'))
- texInfo.add((doodad.source[0], doodad.source[1].height() * doodad.source[1].width() * 2))
+ texInfo.add((doodad.source[0], doodad.source[1].height() * doodad.source[1].width() * (4 if is_rgba8 else 2)))
texture = doodad.source[1]
- textures.add(texture)
+ textures.add((is_rgba8, texture))
requiredFixUps.append((len(data) - 8, texture))
for anim in doodad.animations:
@@ -478,11 +508,15 @@ class KPMapExporter:
else:
data += self._buildGXTexObjRGB5A3(896, 448, offsets[setname])
- for tex in textures:
+ for is_rgba8, tex in textures:
offsets[tex] = len(data)
- data += self._buildGXTexObjRGB5A3(tex.width(), tex.height(), currentTexOffset)
- converted = RGB5A3Encode(tex)
+ if is_rgba8:
+ data += self._buildGXTexObjRGBA8(tex.width(), tex.height(), currentTexOffset)
+ converted = RGBA8Encode(tex)
+ else:
+ data += self._buildGXTexObjRGB5A3(tex.width(), tex.height(), currentTexOffset)
+ converted = RGB5A3Encode(tex)
imageData.append(converted)
currentTexOffset += len(converted)