From b4312bc51b28cc5c8fc69c0b98b4f41ce4cd808b Mon Sep 17 00:00:00 2001 From: Benjamin Collins Date: Thu, 13 Aug 2020 21:00:24 +0900 Subject: [PATCH] pvr header --- NinjaTexture.py | 69 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/NinjaTexture.py b/NinjaTexture.py index 151ac6b..a9b5b0a 100644 --- a/NinjaTexture.py +++ b/NinjaTexture.py @@ -24,6 +24,7 @@ """ import os +import sys import struct class NinjaTexture: # { @@ -142,10 +143,12 @@ class NinjaTexture: # { # Read Header bytes = self.file.read(8) p = struct.unpack('BBHHH', bytes) - color_format = p[0] - data_format = p[1] - width = p[3] - height = p[4] + + self.color_format = p[0] + self.data_format = p[1] + self.width = p[3] + self.height = p[4] + print("Color Format: %d" % color_format) print("Data Format: %d" % data_format) print("Width: %d" % width) @@ -153,6 +156,8 @@ class NinjaTexture: # { self.isTwiddled = False self.isMipmap = False + self.isCompressed = False + self.codebook_size = 0 twiddled = ( NinjaTexture.TWIDDLED, @@ -160,8 +165,60 @@ class NinjaTexture: # { NinjaTexture.TWIDDLED_RECTANGLE, NinjaTexture.TWIDDLED_MM_ALIAS ) + + mipmap = ( + NinjaTexture.TWIDDLED_MM, + NinjaTexture.PALETTIZE4_MM, + NinjaTexture.PALETTIZE8_MM, + NinjaTexture.ABGR_MM, + NinjaTexture.VQ_MM, + NinjaTexture.SMALLVQ_MM + ) + + palette = ( + NinjaTexture.PALETTIZE4 + NinjaTexture.PALETTIZE4_MM + NinjaTexture.PALETTIZE8 + NinjaTexture.PALETTIZE8_MM + ) - if data_format in twiddled: + not_supported = ( + NinjaTexture.STRIDE, + NinjaTexture.ABGR, + NinjaTexture.ABGR_MM + ) + + if self.data_format in twiddled: self.isTwiddled = True - + + if self.data_format in mipmap: + self.isMipmap = True + + if self.data_format == NinjaTexture.VQ: + self.isCompressed = true + if self.width <= 16: + self.codebook_size = 16 + elif self.width == 32: + self.codebook_size = 32 + elif self.width == 64: + self.codebook_size = 128 + else: + self.codebook_size = 256 + elif self.data_format == NinjaTexture.VQ_MM: + self.isCompressed = true + if self.width <= 16: + self.codebook_size = 16 + elif self.width == 32: + self.codebook_size = 64 + else: + self.codebook_size = 256 + + if self.data_format in palette: + print("NEED TO DEFINE A PALETTE!!!") + sys.exit() + + if self.data_format innot_supported: + print("THIS DATA FORMAT IS NOT SUPPORTED") + sys.exit() + return None