Chinaunix首页 | 论坛 | 博客
  • 博客访问: 94716
  • 博文数量: 41
  • 博客积分: 866
  • 博客等级: 准尉
  • 技术积分: 282
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-22 22:49
文章分类

全部博文(41)

文章存档

2011年(41)

我的朋友

分类: LINUX

2011-11-27 18:38:48

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);
}
发表于 @ 2007年03月14日 19:32:00 | 评论( 2 ) | 编辑| 举报| 收藏

旧一篇:The day of my birthday | 新一篇:The storage memory of 16BPP Bitmap
-
查看最新精华文章 请访问博客首页相关文章
(codes)a program convert a dec into a hexMarrakech快速排序优化(QuickSort Optimization)(codes)a program convert a dec into a hexOptimization of JPEG (JPG) images: good quality and small sizeGiraffe and Gorilla Wood PuzzlesHow can I play a wav-file from memory or BLOB-field?ZIP,TARsudamj 发表于2009年1月20日 14:04:15  IP:举报回复删除
帮你补充一个

#define RGB565_Val(r,g,b) (WORD)((r)<<11 | (g)<<5 | (b))
WORD rgb555_2_rgb565(WORD rgb555)
{
BYTE r,g,b;
FLOAT fRate = 63/31;
//Get R G B
r = (BYTE)(((rgb555 >> 7) & 0xF8)>>3);
g = (BYTE)((((rgb555 >> 2) & 0xF8)>>3)*fRate);
b = (BYTE)(((rgb555 << 3) & 0xF8)>>3);
*(WORD *)pDest = RGB565_Val(RDest,GDest,BDest);
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/anufa/archive/2007/03/14/1529484.aspx

阅读(1346) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~