XeNTaX Forum Index
Forum MultiEx Commander Tools Tools Home
It is currently Thu May 25, 2017 9:52 am

All times are UTC + 1 hour


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: A PsVIta swizzled 2d texture
PostPosted: Wed Apr 19, 2017 4:14 pm 
Offline
n00b

Joined: Mon Nov 09, 2009 7:26 pm
Posts: 12
Has thanked: 1 time
Have thanks: 2 times

I am playing around with the textures of a NIS PsVita game, and I could see all of them are swizzled.
I could unswizzled them using a modified code from viewtopic.php?f=18&t=2640&hilit=UnSwizzle

But there are some kind of files I dont get completely well.
One of them is this one:
https://drive.google.com/file/d/0B2552r ... sp=sharing

And I get this wrong PNG. To see why is wrong, just do zooming in.
https://drive.google.com/file/d/0B2552r ... sp=sharing

Maybe my code is wrong or I need another unswizzling code. I have done a lot of tests but I dont get a right image of this texture.

The working code is this, maybe it could be useful for someone else:
Code:
import os
import png

#Set to false for yx swizzle order
xy = False


def chunks(l, n):
    for i in range(0, len(l), n):
        yield l[i:i + n]


def unswizzle(writebuf, readbuf, writeoffset, segwidth, segheight, datawidth):
    global readoffset, buffer
    if segwidth == 2 and segheight == 2:
        if xy:
            writebuf[writeoffset:writeoffset + 2] = readbuf[readoffset:readoffset + 2]
            writebuf[writeoffset + datawidth:writeoffset + datawidth + 2] = readbuf[readoffset + 2:readoffset + 4]
        else:
            writebuf[writeoffset] = readbuf[readoffset]
            writebuf[writeoffset + datawidth] = readbuf[readoffset + 1]
            writebuf[writeoffset + 1] = readbuf[readoffset + 2]
            writebuf[writeoffset + datawidth + 1] = readbuf[readoffset + 3]
        readoffset += 4
    else:
        if xy:
            unswizzle(writebuf, readbuf, writeoffset, segwidth // 2, segheight // 2, datawidth)
            unswizzle(writebuf, readbuf, writeoffset + segwidth // 2, segwidth // 2, segheight // 2, datawidth)
            unswizzle(writebuf, readbuf, writeoffset + datawidth * (segheight // 2), segwidth // 2, segheight // 2,
                      datawidth)
            unswizzle(writebuf, readbuf, writeoffset + datawidth * (segheight // 2) + segwidth // 2, segwidth // 2,
                      segheight // 2, datawidth)
        else:
            unswizzle(writebuf, readbuf, writeoffset, segwidth // 2, segheight // 2, datawidth)
            unswizzle(writebuf, readbuf, writeoffset + datawidth * (segheight // 2), segwidth // 2, segheight // 2,
                      datawidth)
            unswizzle(writebuf, readbuf, writeoffset + segwidth // 2, segwidth // 2, segheight // 2, datawidth)
            unswizzle(writebuf, readbuf, writeoffset + datawidth * (segheight // 2) + segwidth // 2, segwidth // 2,
                      segheight // 2, datawidth)


def vita2bitmap(fileName1, width, height):
    global readoffset, bufferz
    if width == height:
        unswizzle(buffer, bitmap, 0, width, height, width)
    elif width > height:
        for w in range(0, width, height):
            unswizzle(buffer, bitmap, w, height, height, width)
    elif height > width:
        for h in range(0, height * width, width ** 2):
            unswizzle(buffer, bitmap, h, width, width, width)
    else:
        print('error')

    p = list(chunks(buffer, width))
    with open(fileName1, 'wb') as f:
        w = png.Writer(len(p[0]), len(p), greyscale=True)
        w.write(f, p)

fileName = "1ch6020.BTM"
#This file has not palette
paletteSize = 0
#In this case, all the file is bitmap
bitmapSize = os.path.getsize(fileName)
width = 1024
height = 1024

fileName1 = fileName.rsplit(".", 1)[0] + ".png"
with open(fileName, 'rb') as f:
    palette = f.read(paletteSize)
    bitmap = f.read(bitmapSize)
buffer = bytearray(len(bitmap))  #Output buffer
readoffset = 0  #Input position counter
vita2bitmap(fileName1, width, height)


You can make the ads go away by registering



Top
 Profile  
 
 Post subject: Re: A PsVIta swizzled 2d texture
PostPosted: Wed Apr 26, 2017 4:36 pm 
Offline
n00b

Joined: Mon Nov 09, 2009 7:26 pm
Posts: 12
Has thanked: 1 time
Have thanks: 2 times
Fixed :P


Top
 Profile  
 
 Post subject: Re: A PsVIta swizzled 2d texture
PostPosted: Fri Apr 28, 2017 11:44 am 
Offline
n00b

Joined: Mon Nov 09, 2009 7:26 pm
Posts: 12
Has thanked: 1 time
Have thanks: 2 times
Another texture, funny, dont you think so?

This is the original file
https://drive.google.com/file/d/0B2552r ... sp=sharing

Image

Some idea?


Top
 Profile  
 
 Post subject: Re: A PsVIta swizzled 2d texture
PostPosted: Sun May 07, 2017 2:59 pm 
Offline
n00b

Joined: Mon Nov 09, 2009 7:26 pm
Posts: 12
Has thanked: 1 time
Have thanks: 2 times
Fixed! haha



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group