Chinaunix首页 | 论坛 | 博客
  • 博客访问: 938627
  • 博文数量: 192
  • 博客积分: 3070
  • 博客等级: 中校
  • 技术积分: 1861
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-27 23:44
个人简介

Start Linux Leave Linux a while Back to Linux

文章分类

全部博文(192)

文章存档

2023年(18)

2022年(11)

2021年(8)

2020年(14)

2019年(7)

2018年(13)

2017年(16)

2016年(4)

2012年(2)

2011年(13)

2010年(26)

2009年(13)

2008年(27)

2007年(20)

我的朋友

分类: LINUX

2011-10-09 13:28:37

转自:http://blog.csdn.net/nitghost/archive/2009/02/23/39256bitmap图片是一个RGB888,每个像素由3个字节组成,R->8bit,G->8bit,B->8bit;

RGB565 的每个pixels是由2字节组成,R->5bit,G->6bit,B->5bit。

转换的思路是取出原图的点,对没个采样进行运算。

  1. #define RGB565_MASK_RED        0xF800   
  2. #define RGB565_MASK_GREEN                         0x07E0   
  3. #define RGB565_MASK_BLUE                         0x001F   
  4.   
  5. void  rgb565_2_rgb24( BYTE  *rgb24,  WORD  rgb565)  
  6. {   
  7.  //extract RGB   
  8.  rgb24[2] = (rgb565 & RGB565_MASK_RED) >> 11;     
  9.  rgb24[1] = (rgb565 & RGB565_MASK_GREEN) >> 5;  
  10.  rgb24[0] = (rgb565 & RGB565_MASK_BLUE);  
  11.   
  12.  //amplify the image   
  13.  rgb24[2] <<= 3;  
  14.  rgb24[1] <<= 2;  
  15.  rgb24[0] <<= 3;  
  16. }   
  1. #define RGB565_MASK_RED        0xF800  
  2. #define RGB565_MASK_GREEN                         0x07E0  
  3. #define RGB565_MASK_BLUE                         0x001F  
  4. void rgb565_2_rgb24(BYTE *rgb24, WORD rgb565)  
  5. {   
  6.  //extract RGB  
  7.  rgb24[2] = (rgb565 & RGB565_MASK_RED) >> 11;     
  8.  rgb24[1] = (rgb565 & RGB565_MASK_GREEN) >> 5;  
  9.  rgb24[0] = (rgb565 & RGB565_MASK_BLUE);  
  10.  //amplify the image  
  11.  rgb24[2] <<= 3;  
  12.  rgb24[1] <<= 2;  
  13.  rgb24[0] <<= 3;  
  14. }   
  1. USHORT  rgb_24_2_565( int  r,  int  g,  int  b)  
  2. {  
  3.     return  ( USHORT )(((unsigned(r) << 8) & 0xF800) |   
  4.             ((unsigned(g) << 3) & 0x7E0)  |  
  5.             ((unsigned(b) >> 3)));  
  6. }  
  1. USHORT rgb_24_2_565(int r, int g, int b)  
  2. {  
  3.     return (USHORT)(((unsigned(r) << 8) & 0xF800) |   
  4.             ((unsigned(g) << 3) & 0x7E0)  |  
  5.             ((unsigned(b) >> 3)));  
  6. }  
  1. USHORT  rgb_24_2_555( int  r,  int  g,  int  b)  
  2. {  
  3.     return  ( USHORT )(((unsigned(r) << 7) & 0x7C00) |   
  4.             ((unsigned(g) << 2) & 0x3E0)  |  
  5.             ((unsigned(b) >> 3)));  
  6. }  
  7.   
  8. COLORREF  rgb_555_2_24( int  rgb555)  
  9. {  
  10.     unsigned r = ((rgb555 >> 7) & 0xF8);  
  11.     unsigned g = ((rgb555 >> 2) & 0xF8);  
  12.     unsigned b = ((rgb555 << 3) & 0xF8);  
  13.     return  RGB(r,g,b);  
  14. }  
  15.   
  16. void  rgb_555_2_bgr24( BYTE * p,  int  rgb555)  
  17. {  
  18.     p[0] = ((rgb555 << 3) & 0xF8);  
  19.     p[1] = ((rgb555 >> 2) & 0xF8);  
  20.     p[2] = ((rgb555 >> 7) & 0xF8);  
  21. }  
  1. USHORT rgb_24_2_555(int r, int g, int b)  
  2. {  
  3.     return (USHORT)(((unsigned(r) << 7) & 0x7C00) |   
  4.             ((unsigned(g) << 2) & 0x3E0)  |  
  5.             ((unsigned(b) >> 3)));  
  6. }  
  7. COLORREF rgb_555_2_24(int rgb555)  
  8. {  
  9.     unsigned r = ((rgb555 >> 7) & 0xF8);  
  10.     unsigned g = ((rgb555 >> 2) & 0xF8);  
  11.     unsigned b = ((rgb555 << 3) & 0xF8);  
  12.     return RGB(r,g,b);  
  13. }  
  14. void rgb_555_2_bgr24(BYTE* p, int rgb555)  
  15. {  
  16.     p[0] = ((rgb555 << 3) & 0xF8);  
  17.     p[1] = ((rgb555 >> 2) & 0xF8);  
  18.     p[2] = ((rgb555 >> 7) & 0xF8);  
  19. }  
  1. #define RGB565_Val(r,g,b) (WORD)((r)<<11 | (g)<<5 | (b))   
  2. WORD  rgb555_2_rgb565( WORD  rgb555)  
  3. {  
  4.    BYTE  r,g,b;  
  5.    FLOAT  fRate = 63/31;  
  6.    //Get R G B    
  7.    r = (BYTE )(((rgb555 >> 7) & 0xF8)>>3);  
  8.    g = (BYTE )((((rgb555 >> 2) & 0xF8)>>3)*fRate);  
  9.    b = (BYTE )(((rgb555 << 3) & 0xF8)>>3);  
  10.    *(WORD  *)pDest = RGB565_Val(RDest,GDest,BDest);  
  11. }  
阅读(2885) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~