   Extracting color values from an R5G6B5 short
  I'm wondering what would be the best way to extract RGB values from a short which contains R5G6B5 formatted data.  I plan to use the following code, but I wanted to check if there is a better way.  Any suggestions?  Thanks in advance!   BYTE Red;BYTE Green;BYTE Blue;short Pixel;///...<snip>... obtain pixel data into Pixel variableRed = Pixel >> 11;Green = (Pixel << 5) >> 10;Blue = Pixel % 32;[edited by - Teric on August 18, 2003 10:00:45 AM]
  Red = Pixel >> 11;Green = (Pixel >> 5) & 0x6F;Blue = Pixel & 0x3F;?dunno, i hope that helps. ;  That''s a good idea, using the & operator.But shouldn''t your hex values be as follows? Red = Pixel >> 11;  //Bit shift right by 11Green = (Pixel >> 5) & 0x3F; //Bit shift right by 5, then & out all but last 6 bitsBlue = Pixel & 0x1F; //& out all but last 5 bits;  You may also need to convert the ranges from 0-31 and 0-63 to 0-255.The quick way is this:Red = ( Pixel >> (16-8) ) & 0xF8;    Green = ( Pixel >> (11-8) ) & 0xFC;    Blue = Pixel << (8-5);   But the colors may look bad (yellow will have a green tint)This way looks better but it is slower:Red = ( Pixel >> (16-5) ) * 255 / 31;    Green = ( ( Pixel >> (11-6) ) & 0x3F ) * 255 / 63;    Blue = ( Pixel & 0x1F )  * 255 / 31;   