Author Topic: 24 Bit to 16 Bit this time...  (Read 3655 times)

Alhexx

  • *
  • Posts: 1894
    • View Profile
    • http://www.alhexx.com
24 Bit to 16 Bit this time...
« on: 2001-10-16 21:01:00 »
Once again, I need your help.
I'm trying to convert a 24 Bit Palette into an 16 Bit Palette. But I've got no success...can anyone help me?

 - Alhexx

ficedula

  • *
  • Posts: 2178
    • View Profile
    • http://www.ficedula.co.uk
24 Bit to 16 Bit this time...
« Reply #1 on: 2001-10-16 21:46:00 »
Hmm.

Well, understanding that I'm writing this off the top of my head (ie: could be complete bs ... but I don't think it is :wink: ) this is how I'd do it:

var
R,G,B:     Byte;
Src,Dst:   Integer;
begin

R := (Src shr 3) and $1F;
G := (Src shr 11) and $1F;
B := (Src shr 19) and $1F;

Dst := (R) or (G shl 5) or (B shl 10);

end;

Takes a 24-bit value in Src, puts a 16-bit value in Dst.

How? Well, first of all extract the colour components R/G/B from the source. Not hard if you know anything about pixel layouts. However: Instead of extracting the top 8 bits, we shift 3 bits more than normal (3/11/19 instead of 0/8/16) and extract 5 bits ($1F = 11111 in binary) into each colour component.

So, now we've got a 5 bit value in each component. Now we just recombine them into a single 16 (well, 15 bit really) bit value by the standard shift, or methods for combining components.

I emphasise: NOT TESTED! May be wrong! But it should give you the basic idea...

[edited] 68 2001-10-16 22:46

Alhexx

  • *
  • Posts: 1894
    • View Profile
    • http://www.alhexx.com
24 Bit to 16 Bit this time...
« Reply #2 on: 2001-10-17 18:26:00 »
Whohoo! :smile: Looks kinda...complicated.

Okay, as the last time, I found a way myself...it's was a 'hard birth', like we would say in Germany...

Here's my (VB) Code:

Code: [Select]

Private Function Red24Bit(Bits As Byte) As Integer
  Red24Bit = CInt(CInt(Bits / 255 * 31) * 32 * 32)
End Function

Private Function Green24Bit(Bits As Byte) As Integer
  Green24Bit = CInt(CInt(Bits / 255 * 31) * 32)
End Function

Private Function Blue24Bit(Bits As Byte) As Integer
  Blue24Bit = CInt(Bits / 255 * 31 * 1)
End Function


works, too :smile:

 - Alhexx

ficedula

  • *
  • Posts: 2178
    • View Profile
    • http://www.ficedula.co.uk
24 Bit to 16 Bit this time...
« Reply #3 on: 2001-10-17 18:32:00 »
Damn .. VB doesn't have bitwise shifts? That's crap. But you already knew that :wink:

Darkness

  • *
  • Posts: 2181
    • View Profile
    • http://www.x0r.net
24 Bit to 16 Bit this time...
« Reply #4 on: 2001-10-17 23:15:00 »
thank god im learning c++. i havent touched VB in months. The school classes go a bit slow though......

Alhexx

  • *
  • Posts: 1894
    • View Profile
    • http://www.alhexx.com
24 Bit to 16 Bit this time...
« Reply #5 on: 2001-10-18 16:14:00 »
Well, it has. Otherwise I wouldn't be able to convert 24Bit into 16Bit. But, as you see above, there's no need to use Bitshifts here. :wink:

Darkness: Yep, that's a better choice than VB ! :grin:

 - Alhexx