The textures appear to be kept in a container where there can be multiple images and multiple image palettes for each image.
I'm examining a container with just a single palette and image so that I know they belong to each other.
Ran PCSX2 and dumped the texture so I know what its suppose to look like
I've read the image data and palette and tried to marry them but the output appears wrong
I tried doing some colour manipulation to atleast get the right colours, but that appears not working either
I believe the images are swizzled, the only information I could find are on 4bit and 8bit by nick7
https://gta.nick7.com/ps2/swizzling/
Code: Select all
private void readTexPSMT8(int dbp, int dbw, int dsax, int dsay, int rrw, int rrh, ref byte[] data)
{
dbw = dbw >> 1;
int index = 0;
int num2 = dbp * 0x40;
for (int i = dsay; i < (dsay + rrh); i++)
{
for (int j = dsax; j < (dsax + rrw); j++)
{
int num5 = j / 0x80;
int num6 = i / 0x40;
int num7 = num5 + (num6 * dbw);
int num8 = j - (num5 * 0x80);
int num9 = i - (num6 * 0x40);
int num10 = num8 / 0x10;
int num11 = num9 / 0x10;
int num12 = this.block8[num10 + (num11 * 8)];
int num13 = num8 - (num10 * 0x10);
int num14 = num9 - (num11 * 0x10);
int num15 = num14 / 4;
int num16 = num13;
int num17 = num14 - (num15 * 4);
int num18 = this.columnWord8[num15 & 1, num16 + (num17 * 0x10)];
int num19 = this.columnByte8[num16 + (num17 * 0x10)];
int num20 = ((((num2 + (num7 * 0x800)) + (num12 * 0x40)) + (num15 * 0x10)) + num18) * 4;
data[index] = this.gsmem[num20 + num19];
index++;
}
}
}
private void writeTexPSMCT16(int dbp, int dbw, int dsax, int dsay, int rrw, int rrh, byte[] data)
{
int index = 0;
int num2 = dbp * 0x40;
for (int i = dsay; i < (dsay + rrh); i++)
{
for (int j = dsax; j < (dsax + rrw); j++)
{
int num5 = j / 0x40;
int num6 = i / 0x40;
int num7 = num5 + (num6 * dbw);
int num8 = j - (num5 * 0x40);
int num9 = i - (num6 * 0x40);
int num10 = num8 / 0x10;
int num11 = num9 / 8;
int num12 = this.block16[num10 + (num11 * 4)];
int num13 = num8 - (num10 * 0x10);
int num14 = num9 - (num11 * 8);
int num15 = num14 / 2;
int num16 = num13;
int num17 = num14 - (num15 * 2);
int num18 = this.columnWord16[num16 + (num17 * 0x10)];
int num19 = this.columnHalf16[num16 + (num17 * 0x10)];
int num20 = ((((num2 + (num7 * 0x800)) + (num12 * 0x40)) + (num15 * 0x10)) + num18) * 4;
this.gsmem[num20 + num19] = data[index];
this.gsmem[(num20 + num19) + 1] = data[index + 1];
index += 2;
}
}
}
public byte[] Unswizzle(byte[] data, int width, int height)
{
byte[] buffer = new byte[data.Length];
this.gsmem = new byte[0x400000];
if (this.textureInfo.BitsPerPixel == 8)
{
int rrw = width / 2;
int rrh = height / 2;
this.readTexPSMT8(0, width / 0x40, 0, 0, width, height, ref buffer);
}
this.gsmem = null;
GC.Collect();
return buffer;
}
Sample:
texture_sample1.zip