RGB565 to RGB24, RGB555 & RGB24


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);
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值