GP32 A Bit Of Math


Akuma no Houkon

Certified Guru
Joined
Mar 4, 2004
Messages
1,194
Age
44
Location
USA > Washington > Everett
Website
akuma.gp32news.com
Ok, as you all know the GP32 uses a 16bit palette, that is in the form of R5 G5 B5 I1

Now I need to manually generate these palette values, (the palettes use unsigned short's) from 3 separate byte values (the R G & B individual values). What would be the best way to do this? (note I am using 256 color GP32 mode)
 
Use a macro if you need to do it in realitime. You want to avoid a function call for anything you will be doing over and over.

#define GP_RGB16(r,g,b) (((((r>>3))&0x1f)<<11)|((((g>>3))&0x1f)<<6)|((((b>>3))&0x1f)<<1))

note, you dont need the &0x1f parts if you know for sure the value of your colors are not above 255. (like if you were passing chars instead of ints)
 
Well, that'd be a lot easier if it was "real" 16bit instead of 15bit+luma bit.
Btw: I suggest you to use Daz's define as it's really a lot faster, even if you're not using it real time.
Gotta adapt this one, too. ;)
 
Well if it helps any, a quick explaination is that it's just diving each value by 8, shifting them to the left by the appropriate amount. 11 bits for red, 6 bits for green, and 1 bit for blue. Then these three values are OR'd together.

You can get rid of the & operations completely as all they do is keep the value inside 0-255. But since you are converting 24bit palette entries, there will be no chance of bigger numbers.

psuedo code:

value1 = ( red / 8 ) shift left 11
value2 = ( green / 8 ) shift left 6
value3 = ( blue / 8 ) shift left 1

final_color = value1 Bitwise_OR value2 Bitwise_OR value3
 
Ahh much easier, that will work :)

Edit: Worked like a charm, although I used VB since its easy to create a quick user interface with, and VB doesnt support unsigned integers (Boo) (I hate this language..I really do...), so I had to have a little work arround, but in the end I get the correct color values. Thanks :)
 
Back
Top