rgb色彩空间转换实现汇总

来源:互联网 发布:js blob转uint8array 编辑:程序博客网 时间:2024/06/05 11:24

转载请注明http://blog.csdn.net/u011046042/article/details/71727885
做视频和图形这块进行总结
色彩空间转换的汇总
rgb到bgr的转换
代码如下:

static void convert_rgb_to_bgr(uint8_t* src, uint8_t* dest, int width){    int x;    for (x = 0; x < width; x++) {        *dest++ = src[2];        *dest++ = src[1];        *dest++ = src[0];        src += 3;    }}

rgb到bgrx的转换

static void convert_rgb_to_bgrx(uint8_t* src, uint8_t* dest, int width){    int x;    for (x = 0; x < width; x++) {        *dest++ = src[2];        *dest++ = src[1];        *dest++ = src[0];        *dest++ = 0;        src += 3;    }}

RGB16 到RGB24

static void convert_RGB16_to_RGB24(void *line, int width, uint8_t **out_line){    uint16_t *src_line = line;    uint8_t *out_pix;    int x;    spice_assert(out_line && *out_line);    out_pix = *out_line;    for (x = 0; x < width; x++) {       uint16_t pixel = *src_line++;       *out_pix++ = ((pixel >> 7) & 0xf8) | ((pixel >> 12) & 0x7);       *out_pix++ = ((pixel >> 2) & 0xf8) | ((pixel >> 7) & 0x7);       *out_pix++ = ((pixel << 3) & 0xf8) | ((pixel >> 2) & 0x7);   }}

BGRX到RGB24

static void convert_BGRX32_to_RGB24(void *line, int width, uint8_t **out_line){    uint32_t *src_line = line;    uint8_t *out_pix;    int x;    spice_assert(out_line && *out_line);    out_pix = *out_line;    for (x = 0; x < width; x++) {        uint32_t pixel = *src_line++;        *out_pix++ = (pixel >> 16) & 0xff;        *out_pix++ = (pixel >> 8) & 0xff;        *out_pix++ = pixel & 0xff;    }}

yuyv到rgb的装换

#define clip_8bit(val) ((val) < 0 ? 0 : (val) > 255 ? 255 : (val))compress_yuyv_to_rgb (const uint8_t *src_ptr,uint8_t *rgb_ptr,const int width, const int height){    int r,g,b;    int y,u,v;    int i;    int table_ub_value;    int table_ug_value;    int table_vg_value;    int table_vr_value;    for (i = 0; i < width * height / 2; ++i)    {      y = src_ptr[0];      u = src_ptr[1];      v = src_ptr[3];      table_ub_value=table_ub[u];      table_ug_value=table_ug[u];      table_vg_value=table_vg[v];      table_vr_value=table_vr[v];      b = y + table_ub_value;      g = y - table_ug_value - table_vg_value;      r = y + table_vr_value;      *rgb_ptr++ = clip_8bit (r);               /* R */      *rgb_ptr++ = clip_8bit (g);               /* G */      *rgb_ptr++ = clip_8bit (b);               /* B */      y = src_ptr[2];      b = y + table_ub_value;      g = y - table_ug_value - table_vg_value;      r = y + table_vr_value;      *rgb_ptr++ = clip_8bit (r);               /* R */      *rgb_ptr++ = clip_8bit (g);               /* G */      *rgb_ptr++ = clip_8bit (b);               /* B */       src_ptr += 4;    }}

转载请注明http://blog.csdn.net/u011046042/article/details/71727885
纯代码 C语言,纯干货。方便以后使用,持续更新。

0 0