分享

RGB565 to RGB24, RGB555 & RGB24

 w_hf的图书馆 2012-01-06

RGB565 to RGB24, RGB555 & RGB24

分类: Digital Image Processing4850人阅读评论(2)收藏举报

For a image is RGB565 format, sometimes we want convert it to RGB888, we can simply extract the RGB.

The following is some piece of my codes. It's no optimized, you can optimize it. Also, you can have you own way to implement it.

#define RGB565_MASK_RED        0xF800
#define RGB565_MASK_GREEN                         0x07E0
#define RGB565_MASK_BLUE                         0x001F

void rgb565_2_rgb24(BYTE *rgb24, WORD rgb565)

 
//extract RGB
 rgb24[2= (rgb565 & RGB565_MASK_RED) >> 11;   
 rgb24[
1= (rgb565 & RGB565_MASK_GREEN) >> 5;
 rgb24[
0= (rgb565 & RGB565_MASK_BLUE);

 
//amplify the image
 rgb24[2<<= 3;
 rgb24[
1<<= 2;
 rgb24[
0<<= 3;
}
 

 

USHORT rgb_24_2_565(int r, int g, int b)
{
    
return (USHORT)(((unsigned(r) << 8& 0xF800| 
            ((unsigned(g) 
<< 3& 0x7E0)  |
            ((unsigned(b) 
>> 3)));
}

 

the following is conversion RGB24 with RGB555 

USHORT rgb_24_2_555(int r, int g, int b)
{
    
return (USHORT)(((unsigned(r) << 7& 0x7C00| 
            ((unsigned(g) 
<< 2& 0x3E0)  |
            ((unsigned(b) 
>> 3)));
}


COLORREF rgb_555_2_24(
int rgb555)
{
    unsigned r 
= ((rgb555 >> 7& 0xF8);
    unsigned g 
= ((rgb555 >> 2& 0xF8);
    unsigned b 
= ((rgb555 << 3& 0xF8);
    
return RGB(r,g,b);
}


void rgb_555_2_bgr24(BYTE* p, int rgb555)
{
    p[
0= ((rgb555 << 3& 0xF8);
    p[
1= ((rgb555 >> 2& 0xF8);
    p[
2= ((rgb555 >> 7& 0xF8);
}

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多