Created
May 17, 2017 18:25
-
-
Save Waelwindows/bae0f011b7bfd6ef3d55550fbb6a7c45 to your computer and use it in GitHub Desktop.
PDF2nd SPR Noesis script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
# Project Diva F 2nd SPR Format | |
# Script by waelwindows | |
# Made possible by Brolijah, Skyth, Stewie 1.0 | |
from inc_noesis import * | |
import noesis | |
import rapi | |
def registerNoesisTypes(): | |
handle = noesis.register('Project Diva F 2nd', '.spr') | |
# Binding Handlers | |
noesis.setHandlerTypeCheck(handle, noepyCheckType) | |
noesis.setHandlerLoadRGBA(handle, noepyLoadTexture) | |
noesis.logPopup() | |
return 1 | |
NOEPY_HEADER = 'SPRC' | |
# File check Handler: Checks if the file is a valid SPR file | |
def noepyCheckType(data): | |
bs = NoeBitStream(data) | |
if len(data) < 4: | |
return 0 | |
if bs.readBytes(4).decode('ASCII').rstrip("\0") != NOEPY_HEADER: | |
return 0 | |
return 1 | |
# SPRTex_mip: a class for a single mip texture | |
class SPRTex_mip: | |
width = 0 | |
height = 0 | |
bytesize = 0 | |
pxt_offset = 0x158 | |
#pxt_offset = 0x68c | |
mip_level = 1 | |
def __init__( | |
self, | |
bs, | |
mip_level, | |
texList, | |
pxt_offset=0x158 | |
): | |
self.mip_level = mip_level | |
self.pxt_offset=pxt_offset | |
self.bs = bs | |
self.bs.seek(self.pxt_offset, NOESEEK_ABS) | |
# If conditional for mip logic | |
if mip_level == 1: | |
self.width = bs.read('>I')[0] | |
self.bs.seek(self.pxt_offset + 6, NOESEEK_ABS) | |
self.height = bs.read('>H')[0] | |
self.bytesize = self.width * self.height | |
elif mip_level == 2: | |
t_width = bs.read('>I')[0] | |
self.bs.seek(self.pxt_offset + 6, NOESEEK_ABS) | |
t_height = bs.read('>H')[0] | |
t_bytesize = t_width * t_height | |
# MIP2 Information | |
self.pxt_offset = self.pxt_offset + 20 + t_bytesize + 4 | |
self.bs.seek(self.pxt_offset, NOESEEK_ABS) | |
self.width = bs.read('>I')[0] | |
self.bs.seek(self.pxt_offset + 6, NOESEEK_ABS) | |
self.height = bs.read('>H')[0] | |
self.bytesize = self.width * self.height | |
self.make_tex(texList) | |
def make_tex(self, texList): | |
srcName = noesis.getSelectedFile() | |
rawData = rapi.loadIntoByteArray(srcName) | |
texData = rawData[self.pxt_offset + 20:self.pxt_offset | |
+ self.bytesize + 20] | |
texData = rapi.imageDecodeDXT(texData, self.width, self.height, | |
noesis.FOURCC_ATI2) | |
texFmt = noesis.NOESISTEX_RGBA32 | |
texName = rapi.getExtensionlessName(rapi.getInputName()) \ | |
+ '_mip' + str(self.mip_level) | |
self.tex = NoeTexture(texName, self.width, self.height, | |
texData, texFmt) | |
texList.append(self.tex) | |
# SPRTex: a class of aggregate mip textures | |
class SPRTex: | |
mip1 = None | |
mip2 = None | |
def __init__(self, bs, texList): | |
self.mip1 = SPRTex_mip(bs, 1, texList) | |
self.mip2 = SPRTex_mip(bs, 2, texList) | |
def noepyLoadTexture(data, texList): | |
ctx = rapi.rpgCreateContext() | |
bs = NoeBitStream(data) | |
tex = SPRTex(bs, texList) | |
return 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment