[bb] R, G, B To LockedFormat Short/Int by Snarty [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:39

Previous topic - Next topic

BlitzBot

Title : R, G, B To LockedFormat Short/Int
Author : Snarty
Posted : 1+ years ago

Description : This is an example of how you go about converting 0-255 r,g,b elements into 1 Short or Integer. Pass the mode as returned by "LockedFormat()" along with the colour you wish to convert and it will return the correct Short/Int.

Remember: Modes 1, and 2 you need to PokeShort, otherwise it's PokeInt.


Code :
Code (blitzbasic) Select
Function ConvertRGB(r,g,b,Mode=0)

Select Mode

Case 1
Col=((r/8) Shl 11) Or ((g/4) Shl 5) Or (b/8)
Return Col

Case 2
Col=((r/8) Shl 10) Or ((g/8) Shl 5) Or (b/8)
Return Col

Default
Col=(r Shl 16) Or (g Shl 8) Or b
Return Col

End Select

End Function


Comments : none...