文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>RGB转换的各种函数

RGB转换的各种函数

时间:2010-04-29  来源:usa9002

各种RGB转换的函数。用于数据采集的转换的

unsigned short RGB888toRGB555(unsigned char red, unsigned char green, unsigned char blue)
{
#if 0
    unsigned short B = (blue >> 3 ) << 11;

    unsigned short G = (green >> 2) << 5;

    unsigned short R = (red >> 3) << 0;
#endif
    unsigned short  B = (blue >> 3) & 0x001F;

       unsigned short  G = ((green >> 2) << 5) & 0x07E0;

       unsigned short  R = ((red >> 3) << 11) & 0xF800;


    return (unsigned short) (B | G | R);

}

#define RGB565_MASK_RED        0xF800
#define RGB565_MASK_GREEN      0x07E0
#define RGB565_MASK_BLUE       0x001F

void rgb565_2_rgb24(char *g_rgbbuf, char *rgb565)
{
    int i;
    unsigned short *pRGB16 = (unsigned short *) rgb565;
    for (i = 0; i < 320 * 240; i++) {
        unsigned short RGB16 = *pRGB16;
        g_rgbbuf[i * 3 + 2] = (RGB16 & RGB565_MASK_RED) >> 11;
        g_rgbbuf[i * 3 + 1] = (RGB16 & RGB565_MASK_GREEN) >> 5;
        g_rgbbuf[i * 3 + 0] = (RGB16 & RGB565_MASK_BLUE);
        g_rgbbuf[i * 3 + 2] <<= 3;
        g_rgbbuf[i * 3 + 1] <<= 2;
        g_rgbbuf[i * 3 + 0] <<= 3;
        pRGB16++;
    }   

}

void RGB555toRGB888(unsigned char *rgb888, unsigned short *RGB555)
{

    int i, j;

    unsigned short *dot;
    for (i = 0; i < 320; i++)
        for (j = 0; j < 240; j++) {
            dot = RGB555 + i * 240 + j;

            *rgb888++ = (((*dot) & 0x01F) << 3);  //R

            *rgb888++ = (((*dot) & 0x03E0) >> 2); //G

            *rgb888++ = (((*dot) & 0x7C00) >> 7); //B

        }
}

相关阅读 更多 +
排行榜 更多 +
崩溃大陆2鱼竿如何获取

崩溃大陆2鱼竿如何获取

冒险解谜 下载
狙击手行动

狙击手行动

冒险解谜 下载
狙击突围行动最新版

狙击突围行动最新版

冒险解谜 下载