Qhimm.com Forums

Miscellaneous Forums => Scripting and Reverse Engineering => Topic started by: blipadeebling on 2006-11-30 20:09:00

Title: tex format ff8
Post by: blipadeebling on 2006-11-30 20:09:00
hello im a long time reader, but just newly registered.

im working on an editor for the PC TEX files that are used within both FF7 and FF8, but am having trouble with 16-bit images. i read that the each pixel is in a 16-bit RGB555 format, but still the pictures display weird (the right shape is there, but the colours are all wrong).

My method of extracting the colour data was:
Title: Re: tex format ff8
Post by: dziugo on 2006-11-30 20:14:21
Can you also post your code for extracting red, green and blue from those 2 bytes?
Title: Re: tex format ff8
Post by: blipadeebling on 2006-11-30 20:25:48
Well since im using VB :( theres no shifting functions, i had to convert individual bytes into binary, and extract the neccessary 5-bits, then again reconverting them to decimal numbers.

Code: [Select]
Red = CBinToByte(Mid(PXD, 2, 5))
Green = CBinToByte(Mid(PXD, 7, 6))
Blue = CBinToByte(Mid(PXD, 12, 5))

where PXD refers to a 16-bit binary string.
               
Title: Re: tex format ff8
Post by: dziugo on 2006-11-30 20:39:30
Not sure about that: I thought that it was the most significant bit that should be ommited. Blue starts from the least significant one, goes through green, ends with red + 1 extra bit.

Anyway, if you can't use shift operators, just use integer division - shifting 5 bits to the right is the same as dividing by 32.
Title: Re: tex format ff8
Post by: blipadeebling on 2006-11-30 20:49:41
Wasnt what i was doing correct

if the most significant bit is ommitted, thats the first bit,

so my statement,

Code: [Select]
Red = CBinToByte(Mid(PXD, 2, 5))
Green = CBinToByte(Mid(PXD, 7, 6))
Blue = CBinToByte(Mid(PXD, 12, 5))

Red = bits 2,3,4,5,6 from the left
Green = bits 7,8,9,10,11 from the left
Blue = bits 12,13,14,15,16 from the left?

so do i have it the right way..or the wrong way..

p.s. thanks for the super quick replies :D
Title: Re: tex format ff8
Post by: dziugo on 2006-11-30 21:02:18
Hmm... I was taught that the least significant bit is the one with the lowest index :) It all depends on how you create that array of bits. If you're sure that you're reading the right bits (which is most likely true), make sure you're reading them in right order.

So, to test it all, assuming that you have a 16bit integer:
0x6783
What are the Red, Green and Blue values (before converting them to 8bit version)?

Nothing else comes to mind...
Title: Re: tex format ff8
Post by: blipadeebling on 2006-11-30 21:16:02
0x6783 = 0110 0111 1000 0011

so r = 11001 (25), g = 11100 (28) , b = 00011 (3)

so yeah is that right?
Title: Re: tex format ff8
Post by: dziugo on 2006-11-30 21:24:49
Yeah. Of course in file it's probably stored as little (...) endian integer, but you most likely got that solved. Out of ideas.
Title: Re: tex format ff8
Post by: Cyberman on 2006-11-30 22:13:35
Try BGR instead. I know the PS1 version store there data that way.

Cyb
Title: Re: tex format ff8
Post by: blipadeebling on 2006-12-01 05:21:55
i tried so many combinations man, did RGB, RBG, BGR, BRG, GRB, GBR..hehe all of them, and tried using both the first AND last bits, but still my thingo is weird

i have no idea whats wrong!! i was suspecting maybe my method of converting to 8-bit, but i dont get it..

Also heres another thing im stuck on. I used Qhimm's internal tex viewer and viewed Face_b00.tex, and you can see that the first or so pixesl are white, when viewing the file in a text editor, the 16-bit data for that pixel is as follows 0xFF7F = 1111111101111111,

so 0xFF7F is white, but aint white FFFFFF (RGB 8-bit inflated) so that 0 in the 9th place screws stuff up and by using the standard RGB555 format, it wont display white.. so im confused..
Title: Re: tex format ff8
Post by: dziugo on 2006-12-01 07:36:04
If in your file, the data looks like this:
Code: [Select]
FF 7F 56 6A FE 20 ... 16bit integers you'd read would be:
Code: [Select]
0x7FFF
0x6A56
0x20FE
...
Which is how regular integers are read in little edian system.
Title: Re: tex format ff8
Post by: blipadeebling on 2006-12-01 08:08:10
If in your file, the data looks like this:
Code: [Select]
FF 7F 56 6A FE 20 ... 16bit integers you'd read would be:
Code: [Select]
0x7FFF
0x6A56
0x20FE
...
Which is how regular integers are read in little edian system.

Really.. aint that "Big edian system" cuz i thought little eddian was the normal system like reading as is, and big edian was that flippy crap..hehe ill try loading it like that never-the-less, thanks!


Edit: Hey that seemed to help! But its still a bit weird, if i read in ARGB order, the image looks much better (compared to some Infra-red mapping look-alike image) but if read as ARGB the image still has a blue-green tinge. If i read as ABGR, it will then have a red-green tinge.

[can you upload images here..i dont see a button id upload it if i could], but ill try and explain in the ARGB order it looks like it has a sort of aqua mask, and in the ABGR format it has a yellowy mask..must be somehting to do with the green colour im guessing but im not sure..



Edit 2: Hahaha i had the length of green as 6bits instead of 5 bits..woops


BUT THANKS SO MUCH MAN!!! dziugo your the best.. it works 100% :D:D:D!



FINAL EDIT: For anyone who needs help and lokos at this post, the correct format for the colors of 16-bit TEX textures is ABGR1555!


Another edit: seriously thanks everyone who helped me out..i was stuck on this for hours!!! thanks alot.
Title: Re: tex format ff8
Post by: Zande on 2006-12-01 13:20:23
Well since im using VB :( theres no shifting functions, i had to convert individual bytes into binary, and extract the neccessary 5-bits, then again reconverting them to decimal numbers.

It was a while ago I last used VB, but doesn't it have RShift/LShift for bitwise shift?
Title: Re: tex format ff8
Post by: blipadeebling on 2006-12-01 13:24:32
I didnt think it did and...

Quote
One of the problems with Visual Basic 6 (VB 6) is its lack of operators. ....
But there are other operators which, while not in VB 6, can be reasonably easily simulated. Bit shifting is one such.

but this site seems good demonstration an alternative...

http://www.bitwisemag.com/2/Bit-Shifting-in-Visual-Basic-6

Yeah so hehe i might actually take a look at that then...