pvr header

This commit is contained in:
Benjamin Collins 2020-08-13 21:00:24 +09:00
parent 6d199d5a21
commit b4312bc51b

View File

@ -24,6 +24,7 @@
""" """
import os import os
import sys
import struct import struct
class NinjaTexture: # { class NinjaTexture: # {
@ -142,10 +143,12 @@ class NinjaTexture: # {
# Read Header # Read Header
bytes = self.file.read(8) bytes = self.file.read(8)
p = struct.unpack('BBHHH', bytes) p = struct.unpack('BBHHH', bytes)
color_format = p[0]
data_format = p[1] self.color_format = p[0]
width = p[3] self.data_format = p[1]
height = p[4] self.width = p[3]
self.height = p[4]
print("Color Format: %d" % color_format) print("Color Format: %d" % color_format)
print("Data Format: %d" % data_format) print("Data Format: %d" % data_format)
print("Width: %d" % width) print("Width: %d" % width)
@ -153,6 +156,8 @@ class NinjaTexture: # {
self.isTwiddled = False self.isTwiddled = False
self.isMipmap = False self.isMipmap = False
self.isCompressed = False
self.codebook_size = 0
twiddled = ( twiddled = (
NinjaTexture.TWIDDLED, NinjaTexture.TWIDDLED,
@ -160,8 +165,60 @@ class NinjaTexture: # {
NinjaTexture.TWIDDLED_RECTANGLE, NinjaTexture.TWIDDLED_RECTANGLE,
NinjaTexture.TWIDDLED_MM_ALIAS 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 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 return None