Qhimm.com Forums
Miscellaneous Forums => Scripting and Reverse Engineering => Topic started by: Alhexx 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
-
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
-
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:
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
-
Damn .. VB doesn't have bitwise shifts? That's crap. But you already knew that :wink:
-
thank god im learning c++. i havent touched VB in months. The school classes go a bit slow though......
-
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