RGB888转RGB565 C语言代码

之前做过一个项目,需要把视频格式RGB888转换成RGB565的,算法有很多

下面这个是自己优化过的一些

static int rgb888_to_rgb565(void * psrc, int w, int h, void * pdst)
{
    unsigned char * psrc_temp;
    unsigned short * pdst_temp;

    u32 i,j;//这里init,有问题

    if (!psrc || !pdst || w <= 0 || h <= 0) {
        DISPERR("rgb888_to_rgb565 : parameter error\n");
        return -1;
    }

    psrc_temp = (unsigned char *)psrc;
    pdst_temp = (unsigned short *)pdst;
    for (i=0; i<h; i++) {
        for (j=0; j<w; j++) {
            //888 r|g|b -> 565 b|g|r
            *pdst_temp =(((psrc_temp[2] >> 3) & 0x1F) << 11)//b
                        |(((psrc_temp[1] >> 2) & 0x3F) << 5)//g
                        |(((psrc_temp[0] >> 3) & 0x1F) << 0);//r

            psrc_temp += 3;
            pdst_temp ++;
        }
        psrc_temp +=(3*16);
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/u013255351/article/details/79946797