Author Topic: Converting 16-Bit Raw Data to 24-Bit RGB  (Read 6370 times)

Alhexx

  • *
  • Posts: 1894
    • View Profile
    • http://www.alhexx.com
Converting 16-Bit Raw Data to 24-Bit RGB
« on: 2001-09-09 15:06:00 »
I'm workin' on a project called 'Texture Beast' now. For that I need a bit help with 16-Bit textures.

I know how to read out the raw data into an array of 2-Byte Integers. But I wanna save the texture as a 24-Bit bitmap. For that I've got to convert the 16-Bit data into 24-Bit data.

Any Ideas?

- Alhexx


ficedula

  • *
  • Posts: 2178
    • View Profile
    • http://www.ficedula.co.uk
Converting 16-Bit Raw Data to 24-Bit RGB
« Reply #1 on: 2001-09-09 15:17:00 »
This would be incredibly easy in Delphi, because Delphi can do all this for you.

Anyway, I'll still try and give you some help.

In 16-bit data the data is often stored in 5-6-5 format. IE: 5 bit red, 6 bit green, 5 bit blue. Lets assume that's what your data is. (It might not be, but the code is similar even if it's not).

Take one pixel, in a 2-byte variable called Orig.

You want to move it into a 3-byte (really 4, but there you go) variable called NewC, say.

R := (Orig and $1F);
G := (Orig shr 5) and $3F;
B := (Orig shr 11) and $1F;

Now you've got each colour component in it's separate variable, but it's only 5 or 6 bits, not 8 like you want.

R := Trunc(R * 8.25);
G := Trunc(G * 4.05);
B := Trunc(R * 8.25);

Scale 'em up. You scale G by less because it had more bits of data, so needs to be scaled up less.

Finally

NewC := R or (G shl 8) or (B shl 16);

Haven't tested this code but it's the sort of thing you need.

Questions (probably)..?


Qhimm

  • Founder
  • *
  • Posts: 1996
    • View Profile
    • Qhimm.com
Converting 16-Bit Raw Data to 24-Bit RGB
« Reply #2 on: 2001-09-10 01:48:00 »
Might as well comment on the fact that most 16-bit textures I've looked at was 5-5-5. True, most of it was psx-specific, but I still see more 555 than 565. Oh well.

ficedula

  • *
  • Posts: 2178
    • View Profile
    • http://www.ficedula.co.uk
Converting 16-Bit Raw Data to 24-Bit RGB
« Reply #3 on: 2001-09-10 02:15:00 »
True; I guess that's because in that case, you can use the unused bit for alpha (transparency). 1 bit alpha is useful as a simple mask, in fact the PSX can do that in its GPU, which could be why PSX games tend to use 5-5-5.

Alhexx

  • *
  • Posts: 1894
    • View Profile
    • http://www.alhexx.com
Converting 16-Bit Raw Data to 24-Bit RGB
« Reply #4 on: 2001-09-10 18:18:00 »
Whohoo! A reply from Qhimm! That's rare...

Okay, I've gotta tell u something...

I already got it. It took me the whole sunday to program this, but okay. So

THANK YOU (anyway) for your help!!!

BTW: I'm going to finish 'Texture Beast' today and perhaps upload it today. FF7 and FF8 plugins will be included.
(What's fantastic: The plugins aren't bigger than 100 Bytes (!!!))

- Alhexx

- edit -
BTW: Supported by Texture Beast are:

8-Bit Paletted
16-Bit 5-5-5 RGB
16-Bit 5-5-5 BGR
16-Bit 5-6-5 RGB
16-Bit 5-6-5 BGR
24-Bit RGB
24-Bit BGR
32-Bit RGBA
32-Bit BGRA

[This message has been edited by Alhexx (edited September 10, 2001).]