Jump to content

Convert 24bit RGB to 16bit RGB (555)


Recommended Posts

From time to time I need to convert 24bit RGB color depth to 16bit depth, exactly to RGB555 (15bit: rrrrrggggg0bbbbb) and vice versa. I wrote a two simple conversion functions. Maybe there is a faster way for converting color depth, will anyone know (GDI, WinAPI)?

Func _ConvertRGB_24b_to_16b555($R, $G, $B)
    $R = BitShift($R, 3)
    $G = BitShift($G, 3)
    $B = BitShift($B, 3)

    $R = BitShift($R, -11)
    $G = BitShift($G, -6)
 Return Hex(BitOR($R, $G, $B), 4)
EndFunc 

Func _ConvertRGB_16b555_to_24b($16b, ByRef $R, ByRef $G, ByRef $B)
    $R = BitShift($16b, 11)
    $R = Hex (BitShift($R, -3), 2)
            
    $G = BitAND ($16b, "0x7C0") ;mask
    $G = Hex (BitShift($G, 3), 2)
    
    $B = BitAND ($16b, "0x1F") ;mask
    $B = Hex (BitShift($B, -3), 2)
EndFunc
Edited by Logman
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...