Engineers h3x3r Posted February 11 Engineers Posted February 11 (edited) Hi there. I have a problem with reading palette data. Not sure how big is. I have made Noesis script but I need to know how to correct read palette data and return it back to buffer. from inc_noesis import * import noesis import rapi import os def registerNoesisTypes(): handle = noesis.register("Burnout Dominator - Texture", ".ps2tex") noesis.setHandlerTypeCheck(handle, noepyCheckType) noesis.setHandlerLoadRGBA(handle, noepyLoadRGBA) noesis.logPopup() return 1 def noepyCheckType(data): bs = NoeBitStream(data) if len(data) < 20: return 0 return 1 def noepyLoadRGBA(data, texList): bs = NoeBitStream(data) baseName = rapi.getExtensionlessName(rapi.getLocalFileName(rapi.getInputName())) bs.read(4) RwRawDataOffset = bs.readUInt() RwPaletteOffset = bs.readUInt() RwTextureWidth = bs.readUInt() RwTextureHeight = bs.readUInt() RwBitDepth = bs.readUInt() bs.read(136) RwPaletteIndex = bs.readUByte() RwPaletteSize = bs.readUByte()*4 bs.read(7) RwTextureName = bs.readString() bs.seek(RwRawDataOffset, NOESEEK_ABS) RwRawDataSize = bs.readBytes(RwTextureWidth * RwTextureHeight) bs.seek(RwPaletteOffset, NOESEEK_ABS) RwPaletteDataSize = bs.readBytes(RwPaletteSize) RwRawData = rapi.imageUntwiddlePS2(RwRawDataSize, RwTextureWidth, RwTextureHeight, 8) RwPaletteData = rapi.imageDecodeRawPal(RwRawData, RwPaletteDataSize, RwTextureWidth, RwTextureHeight, 8, "R8G8B8A8", noesis.DECODEFLAG_PS2SHIFT) texFmt = noesis.NOESISTEX_RGBA32 texList.append(NoeTexture(RwTextureName, RwTextureWidth, RwTextureHeight, RwPaletteData, texFmt)) return 1 I appreciate your help guys! Anyway here is code from Edness: if palCount == 1: palData = boPS2Read32({4: 16, 8: 256}.get(bitDepth)) elif bitDepth == 8 and palCount <= 8: # Interleaved-grouped palette splitter palData = [list() for pal in range(8)] for pal in range(16): boPS2Read32(16, palData[0]) boPS2Read32(16, palData[1]) if palCount == 3 or palCount >= 5: boPS2Read32(16, palData[2]) if palCount >= 7: boPS2Read32(16, palData[3]) if palCount >= 4: for pal in range(16): boPS2Read32(16, palData[4]) boPS2Read32(16, palData[5]) if palCount >= 5: boPS2Read32(16, palData[6]) if palCount >= 7: boPS2Read32(16, palData[7]) palData = [bytearray(palData[pal]) for pal in range(8)] palNum = 1 boPS2TexPal(palData[0]) palNum = 2 boPS2TexPal(palData[1]) if palCount == 3 or palCount >= 5: palNum += 1 boPS2TexPal(palData[2]) if palCount >= 7: palNum += 1 boPS2TexPal(palData[3]) if palCount >= 4: palNum += 1 boPS2TexPal(palData[4]) palNum += 1 boPS2TexPal(palData[5]) if palCount >= 6: palNum += 1 boPS2TexPal(palData[6]) if palCount == 8: palNum += 1 boPS2TexPal(palData[7]) return else: noesis.doException(BoExcFmt + "{} {}".format(bitDepth, palCount)) texData = rapi.imageDecodeRawPal(texData, palData, texWidth, texHeight, 8, "R8G8B8A8", noesis.DECODEFLAG_PS2SHIFT if bitDepth == 8 else 0) ps2_tex.7z Edited February 11 by h3x3r
Engineers h3x3r Posted February 11 Author Engineers Posted February 11 This gives me pretty solid output, but still not perfect... RwPalette0Buffer = bytearray() for i in range(RwPaletteIndex): RwPalette0 = bs.read(32) bs.read(96) RwPalette0Buffer.extend(RwPalette0)
Engineers Solution Rabatini Posted February 11 Engineers Solution Posted February 11 try this. from inc_noesis import * import noesis import rapi def registerNoesisTypes(): handle = noesis.register("Burnout Dominator - Texture", ".ps2tex") noesis.setHandlerTypeCheck(handle, noepyCheckType) noesis.setHandlerLoadRGBA(handle, noepyLoadRGBA) return 1 def noepyCheckType(data): if len(data) < 20: return 0 return 1 def noepyLoadRGBA(data, texList): bs = NoeBitStream(data) bs.read(4) RwRawDataOffset = bs.readUInt() RwPaletteOffset = bs.readUInt() RwTextureWidth = bs.readUInt() RwTextureHeight = bs.readUInt() RwBitDepth = bs.readUInt() bs.seek(136, NOESEEK_REL) RwPaletteIndex = bs.readUByte() RwHeaderPalByte = bs.readUByte() bs.read(7) RwTextureName = bs.readString() bs.seek(RwRawDataOffset, NOESEEK_ABS) RwRawDataSize = bs.readBytes(RwTextureWidth * RwTextureHeight) RwRawData = rapi.imageUntwiddlePS2(RwRawDataSize, RwTextureWidth, RwTextureHeight, RwBitDepth) bs.seek(RwPaletteOffset, NOESEEK_ABS) fileSize = len(data) palDataSize = fileSize - RwPaletteOffset palCount = 1 if RwBitDepth == 8: palCount = palDataSize // 1024 if palCount == 0: palCount = 1 pal_arrays = [bytearray() for _ in range(8)] if RwBitDepth == 8 and palCount > 1: for i in range(16): pal_arrays[0].extend(bs.readBytes(64)) pal_arrays[1].extend(bs.readBytes(64)) if palCount == 3 or palCount >= 5: pal_arrays[2].extend(bs.readBytes(64)) if palCount >= 7: pal_arrays[3].extend(bs.readBytes(64)) if palCount >= 4: for i in range(16): pal_arrays[4].extend(bs.readBytes(64)) pal_arrays[5].extend(bs.readBytes(64)) if palCount >= 5: pal_arrays[6].extend(bs.readBytes(64)) if palCount >= 7: pal_arrays[7].extend(bs.readBytes(64)) elif RwBitDepth == 8 and palCount == 1: pal_arrays[0] = bs.readBytes(1024) elif RwBitDepth == 4: for i in range(palCount): if i < 8: pal_arrays[i] = bs.readBytes(64) for i, current_pal in enumerate(pal_arrays): if len(current_pal) > 0: texData = rapi.imageDecodeRawPal(RwRawData, current_pal, RwTextureWidth, RwTextureHeight, RwBitDepth, "R8G8B8A8", noesis.DECODEFLAG_PS2SHIFT) texName = RwTextureName if palCount > 1: texName = "{}_pal{}".format(RwTextureName, i) texList.append(NoeTexture(texName, RwTextureWidth, RwTextureHeight, texData, noesis.NOESISTEX_RGBA32)) return 1 1 1
Engineers h3x3r Posted February 12 Author Engineers Posted February 12 (edited) Thank you! You are amazing! EDiT: BTW i found palette size at 0x60 uint32() - 80, so there's no need for this except for palDataSize var: fileSize = len(data) palDataSize = fileSize - RwPaletteOffset Edited February 12 by h3x3r
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now