Jump to content

strange swizzle ps2 4bit


Go to solution Solved by DKDave,

Recommended Posts

Hello, help me solve the problem with the Noesis plugin. it incorrectly shows the ps2 swizzle 4bpp texture, but some programs also do this incorrectly. thanks in advance

if use MummGGTool:

width = 64, height = 32, bpp = 4

4bqkebi.png

inside Noesis i use:

data = rapi.imageUntwiddlePS2(data, width, height,  4)
data = rapi.imageDecodeRawPal(data, palette, width, height,  4, 'r8g8b8a8', 1)

if width = 32, height = 64

ZQHCsgf.png

if width = 64, height = 32

sUVf89Q.png

if use "Console Texture Explorer":

1XyTKXk.png

s0000_023.zip

Link to comment
Share on other sites

22 hours ago, DKDave said:

It looks like the data is in blocks of 32x32 (0x200 bytes)

thank its true, i so suspected it. but the first program led me astray

3LDxoP1.png

offtopic:

I found the code on github and 8bits work well, but 4bits look bad, what's wrong with them? swizzle_ps2.py

need: pkFsVXF.png have:bPqcZoc.png

Spoiler
def unswizzle_ps2_8bit(image_data, img_width, img_height):
    unswizzled_data = bytearray(img_width * img_height)
    for y in range(img_height):
        for x in range(img_width):
            block_location = (y & (~0xF)) * img_width + (x & (~0xF)) * 2
            swap_selector = (((y + 2) >> 2) & 0x1) * 4
            pos_y = (((y & (~3)) >> 1) + (y & 1)) & 0x7
            column_location = pos_y * img_width * 2 + ((x + swap_selector) & 0x7) * 4
            byte_num = ((y >> 1) & 1) + ((x >> 2) & 2)
            swizzle_id = block_location + column_location + byte_num
            unswizzled_data[y * img_width + x] = image_data[swizzle_id]
    return unswizzled_data

def unswizzle_ps2_4bit(image_data, img_width, img_height):
    pixels = bytearray(img_width * img_height)

    for i in range(img_width * img_height // 2):
        index = image_data[i]
        id2 = (index >> 4) & 0xF
        id1 = index & 0xF
        pixels[i * 2] = id1
        pixels[i * 2 + 1] = id2

    new_pixels = unswizzle_ps2_8bit(pixels, img_width, img_height)

    unswizzled_data = bytearray(img_width * img_height)
    for i in range(img_width * img_height // 2):
        idx1 = new_pixels[i * 2]
        idx2 = new_pixels[i * 2 + 1]
        idx = ((idx2 << 4) | idx1) & 0xFF
        unswizzled_data[i] = idx

    return unswizzled_data

 

en013_01.zip

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...