Ooops
November 25, 2020, 05:44:59 AM

Author Topic: [bb] R, G, B To LockedFormat Short/Int by Snarty [ 1+ years ago ]  (Read 532 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
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
  1. Function ConvertRGB(r,g,b,Mode=0)
  2.  
  3.         Select Mode
  4.                
  5.                 Case 1
  6.                         Col=((r/8) Shl 11) Or ((g/4) Shl 5) Or (b/8)
  7.                         Return Col
  8.                
  9.                 Case 2
  10.                         Col=((r/8) Shl 10) Or ((g/8) Shl 5) Or (b/8)
  11.                         Return Col
  12.                                        
  13.                 Default
  14.                         Col=(r Shl 16) Or (g Shl 8) Or b
  15.                         Return Col
  16.                        
  17.         End Select
  18.  
  19. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal