Only if I got bounding box of segment's UV. I have some problems with CLUT ID. Looks like it works strictly bit style...
CLUT ID for battle stage is probably like this:
#1:00000000 00111100
#2:01000000 00111100
#3:10000000 00111100
#4:11000000 00111100
#5:00000000 00111101
#6:01000000 00111101
#7:10000000 00111101
#8:11000000 00111101
This comes a little familiar as I was coding palette.
The palette was example:
ABCD> 10101011 11001101
And spec was: A, B, G, R
So AB should be moved behind CD so it's:
11001101 10101011 and should be read from left.
In this way:
#1:00000000 00111100 > 001111
00 00000000
#8:11000000 00111101 > 001111
01 11000000
So #9 will be probably:
00111111 00000000
Maybe... Need to test it.
Random tests:
Pavement is #5, and #5 clut is gray like so it pass. a0stg027.x
Specifical blue element on a0stg012 is 403c so 001111
00 01000000 and is #2. Passed!
Okay. Made it! Max CLUT count is 1111 (with 0, so 16)
Complete CLUT reference:
Code: [Select]
Code:
#1: 00000000 00111100 (00 3C)#2: 01000000 00111100 (40 3C)#3: 10000000 00111100 (80 3C)#4: 11000000 00111100 (C0 3C)#5: 00000000 00111101 (00 3D)#6: 01000000 00111101 (40 3D)#7: 10000000 00111101 (80 3D)#8: 11000000 00111101 (C0 3D)#9: 00000000 00111110 (00 3E)#10: 01000000 00111110 (40 3E)#11: 10000000 00111110 (80 3E)#12: 11000000 00111110 (C0 3E)#13: 00000000 00111111 (00 3F)#14: 01000000 00111111 (40 3F)#15: 10000000 00111111 (80 3F)#16: 11000000 00111111 (C0 3F)
Dirty sample code #updated (Forgot about reversing I mentioned above):
Code: [Select]
Code:
byte[] bt = new byte[2]; Buffer.BlockCopy(buffer, 1, bt, 0, 1); //00 Buffer.BlockCopy(buffer, 0, bt, 1, 1); //3C BitArray ba = new BitArray(bt); BitArray CLUTbit = new BitArray(4); CLUTbit[3] = ba[15]; CLUTbit[2] = ba[14]; CLUTbit[1] = ba[1]; CLUTbit[0] = ba[0]; int[] ClutArray = new int[1]; CLUTbit.CopyTo(ClutArray, 0); return ClutArray[0];
Only texture mixing left... Like damn, I was coding today for whole day... Just this, and I'm taking a break.
Nah, reading image by image and transferring pixels algorithm would take a lot of time. I'll leave it for tomorrow or something...