Author Topic: tex format ff8  (Read 6501 times)

blipadeebling

  • *
  • Posts: 16
    • View Profile
tex format ff8
« 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:
  • Reading two-bytes for each pixel
  • Ommiting the first bit as it is the unused/alpha bit
  • Reading the first 5-bits as the red-color
    • Reading the next 5-bits as the green-color
      • Reading the remaining 5-bits as the blue-color (essentially treating as a ARGB format)
      I then recreate the original colours through the following calculation

      Code: [Select]
      r = (red / 31) * 255;
      g = (green / 31) * 255;
      b = (blue / 31) * 255;

      But yeah ive been stuck on this all morning and im not sure whats wrong with this as i looked up docs on the RGB555 format, and what they have stated is how ive approached it. Could any body tell me the exact format of the 16-bit colour data, and the method it is supposed to be read. Any help is appreciated.

dziugo

  • *
  • Posts: 1470
    • View Profile
    • A new copy of FF7 thanks to Salk. Pack (zip/rar/etc) your saved game before sending it to me.
Re: tex format ff8
« Reply #1 on: 2006-11-30 20:14:21 »
Can you also post your code for extracting red, green and blue from those 2 bytes?

blipadeebling

  • *
  • Posts: 16
    • View Profile
Re: tex format ff8
« Reply #2 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.
               

dziugo

  • *
  • Posts: 1470
    • View Profile
    • A new copy of FF7 thanks to Salk. Pack (zip/rar/etc) your saved game before sending it to me.
Re: tex format ff8
« Reply #3 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.

blipadeebling

  • *
  • Posts: 16
    • View Profile
Re: tex format ff8
« Reply #4 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

dziugo

  • *
  • Posts: 1470
    • View Profile
    • A new copy of FF7 thanks to Salk. Pack (zip/rar/etc) your saved game before sending it to me.
Re: tex format ff8
« Reply #5 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...

blipadeebling

  • *
  • Posts: 16
    • View Profile
Re: tex format ff8
« Reply #6 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?

dziugo

  • *
  • Posts: 1470
    • View Profile
    • A new copy of FF7 thanks to Salk. Pack (zip/rar/etc) your saved game before sending it to me.
Re: tex format ff8
« Reply #7 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.
« Last Edit: 2006-11-30 21:27:20 by dziugo »

Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: tex format ff8
« Reply #8 on: 2006-11-30 22:13:35 »
Try BGR instead. I know the PS1 version store there data that way.

Cyb

blipadeebling

  • *
  • Posts: 16
    • View Profile
Re: tex format ff8
« Reply #9 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..
« Last Edit: 2006-12-01 05:52:58 by blipadeebling »

dziugo

  • *
  • Posts: 1470
    • View Profile
    • A new copy of FF7 thanks to Salk. Pack (zip/rar/etc) your saved game before sending it to me.
Re: tex format ff8
« Reply #10 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.

blipadeebling

  • *
  • Posts: 16
    • View Profile
Re: tex format ff8
« Reply #11 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.
« Last Edit: 2006-12-01 08:23:32 by blipadeebling »

Zande

  • *
  • Posts: 55
  • 友情は武器よりも強し
    • View Profile
Re: tex format ff8
« Reply #12 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?

blipadeebling

  • *
  • Posts: 16
    • View Profile
Re: tex format ff8
« Reply #13 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...
« Last Edit: 2006-12-01 13:26:18 by blipadeebling »