converting from 24bit rgb to 16bit 565 and back

Share your advanced PureBasic knowledge/code with the community.
User avatar
idle
Always Here
Always Here
Posts: 5919
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

converting from 24bit rgb to 16bit 565 and back

Post by idle »

might save some google time if you ever want to do this.

Code: Select all


;RGB ->16bit

wCout.w
lCout.l

r = Red(color1) >> 3 
g = Green(color1) >> 2 
b = Blue(color1) >> 3
              
wCout = (r << 11) | (g << 5) | b;

;16 bit -> RGB 

color1 = wCout & $FFFF) 
        
r =(((color1 & $F800) >> 11) <<3)
g =(((color1 & $07E0) >> 5) <<2 )
b =((color1 & $001f) <<3 )
            
lCout = RGB(r,g,b)