现在的位置: 首页 > 综合 > 正文

bitmap convert to RGB565 display

2018年04月05日 ⁄ 综合 ⁄ 共 2271字 ⁄ 字号 评论关闭

bitmap图片是一个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. 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. }  

http://blog.csdn.net/nitghost/archive/2009/02/23/3925678.aspx

抱歉!评论已关闭.