VC_16位色和24位色转换宏
2015-09-22 10:22
253 查看
16位色和24位色转换宏
#include <assert.h>
typedef unsigned long DWORD;
typedef unsigned char BYTE;
typedef unsigned short WORD;
// 24位色和16位色转换宏
// by cheungmine
#define RGB888toRGB565(r,g,b) ((WORD)(((WORD(r)<<8)&0xF800)|((WORD(g)<<3)&0x7E0)|((WORD(b) >> 3))))
#define RGBtoRGB565(rgb) ((WORD)(((((WORD)((rgb)>>3))&(0x1F))<<11)|((((WORD)((rgb)>>10))&(0x3F))<<5)|(((WORD)((rgb)>>19))&(0x1F))))
#define RGB888toRGB555(r,g,b) ((WORD)(((WORD(r)<<7)&0x7C00)|((WORD(g)<<2)&0x3E0)|((WORD(b)>>3))))
#define RGBtoRGB555(rgb) ((WORD)(((((WORD)((rgb)>>3))&(0x1F))<<10)|((((WORD)((rgb)>>11))&(0x1F))<<5)|(((WORD)((rgb)>>19))&(0x1F))))
#define RGB555toRGB(rgb555) ((DWORD)(((BYTE)(((rgb555)>>7)&0xF8)|((WORD)((BYTE)(((rgb555)>>2)&0xF8))<<8))|(((DWORD)(BYTE)(((rgb555)<<3)&0xF8))<<16)))
#define RGB565toRGB(rgb565) ((DWORD)(((BYTE)((((rgb565)&0xF800)>>11)<<3)|((WORD)((BYTE)((((rgb565)&0x07E0)>>5)<<2))<<8))|(((DWORD)(BYTE)(((rgb565)&0x001F)<<3))<<16)))
int main(int argc, char* argv[])
{
COLORREF rgb = RGB(193,192,191);
WORD w = RGB888toRGB565(193, 192, 191);
WORD w2 = RGBtoRGB565(rgb);
assert(w==w2);
COLORREF rgb1 = RGB565toRGB(w);
WORD w5 = RGBtoRGB565(rgb1);
assert(w5==w2);
WORD w3 = RGB888toRGB555(193, 192, 191);
WORD w4 = RGBtoRGB555(rgb);
assert(w3==w4);
COLORREF clr = RGB555toRGB(w4);
w4 = RGBtoRGB555(clr);
return 0;
}
#include <assert.h>
typedef unsigned long DWORD;
typedef unsigned char BYTE;
typedef unsigned short WORD;
// 24位色和16位色转换宏
// by cheungmine
#define RGB888toRGB565(r,g,b) ((WORD)(((WORD(r)<<8)&0xF800)|((WORD(g)<<3)&0x7E0)|((WORD(b) >> 3))))
#define RGBtoRGB565(rgb) ((WORD)(((((WORD)((rgb)>>3))&(0x1F))<<11)|((((WORD)((rgb)>>10))&(0x3F))<<5)|(((WORD)((rgb)>>19))&(0x1F))))
#define RGB888toRGB555(r,g,b) ((WORD)(((WORD(r)<<7)&0x7C00)|((WORD(g)<<2)&0x3E0)|((WORD(b)>>3))))
#define RGBtoRGB555(rgb) ((WORD)(((((WORD)((rgb)>>3))&(0x1F))<<10)|((((WORD)((rgb)>>11))&(0x1F))<<5)|(((WORD)((rgb)>>19))&(0x1F))))
#define RGB555toRGB(rgb555) ((DWORD)(((BYTE)(((rgb555)>>7)&0xF8)|((WORD)((BYTE)(((rgb555)>>2)&0xF8))<<8))|(((DWORD)(BYTE)(((rgb555)<<3)&0xF8))<<16)))
#define RGB565toRGB(rgb565) ((DWORD)(((BYTE)((((rgb565)&0xF800)>>11)<<3)|((WORD)((BYTE)((((rgb565)&0x07E0)>>5)<<2))<<8))|(((DWORD)(BYTE)(((rgb565)&0x001F)<<3))<<16)))
int main(int argc, char* argv[])
{
COLORREF rgb = RGB(193,192,191);
WORD w = RGB888toRGB565(193, 192, 191);
WORD w2 = RGBtoRGB565(rgb);
assert(w==w2);
COLORREF rgb1 = RGB565toRGB(w);
WORD w5 = RGBtoRGB565(rgb1);
assert(w5==w2);
WORD w3 = RGB888toRGB555(193, 192, 191);
WORD w4 = RGBtoRGB555(rgb);
assert(w3==w4);
COLORREF clr = RGB555toRGB(w4);
w4 = RGBtoRGB555(clr);
return 0;
}
相关文章推荐
- 技术杂谈(1)——Vmware网络连接模式简介
- 有三个线程T1 T2 T3,如何保证他们按顺序执行
- 常用linux命令备忘
- keyChain保存uuid实现唯一标识
- eclipse and systemtap
- for循环小题
- 程序员的激情其实是一种痛苦
- 8月流量入口占比动态:直接访问居首 占比不变
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- The processing instruction target matching "[xX][mM][lL]" is not allowed.
- linux 0号进程 1号进程 区别(转) http://blog.csdn.net/yjzl1911/article/details/5613569
- 通过标签推荐来吸引潜在的用户去对网上的产品做出评论
- socket通讯原理以及tcp、ip三次握手机制分析
- iOS开发之UI_UIScrollView(下)
- WebService简介
- 小tips: 使用 等空格实现最小成本中文对齐