YUV转RGB,无除法,无浮点运算
来源:互联网 发布:淘宝的盈利模式 编辑:程序博客网 时间:2024/06/06 19:46
项目需要,将YUV422图像转换成RGB图像,考虑到效率问题,不能使用除法,不能使用浮点运算。
参考http://blog.csdn.net/housisong/article/details/1859084
不使用浮点数:在应用时,希望避免低速的浮点运算,所以需要整数算法,我们可以将先乘上一定的倍数来实现整数运算算法.
不使用除法:通过移位运算代替除法,避免除法运算带来的效率问题。
原公式:
B= 1.164383 * (Y - 16) + 2.017232*(U - 128);
G= 1.164383 * (Y - 16) - 0.391762*(U - 128) - 0.812968*(V - 128);
R= 1.164383 * (Y - 16) + 1.596027*(V - 128);
实现公式
B= ((1.164383<<16) * (Y - 16) + (2.017232<<16) *(U - 128))>>16;
G= ((1.164383<<16) * (Y - 16) - (0.391762<<16) *(U - 128) - (0.812968<<16) *(V - 128))>>16;
R= ((1.164383<<16) * (Y - 16) + (1.596027<<16) *(V - 128))>>16;
注:这样的算法有少量的精度损失。
实现代码:
void YUV422P_To_RGB24_init() { int i; for (i = 0; i < 256 * 3; ++i) _color_table[i] = border_color(i - 256); for (i = 0; i < 256; ++i) { Ym_tableEx[i] = (csY_coeff_16 * (i - 16)) >> 16; Um_blue_tableEx[i] = (csU_blue_16 * (i - 128)) >> 16; Um_green_tableEx[i] = (csU_green_16 * (i - 128)) >> 16; Vm_green_tableEx[i] = (csV_green_16 * (i - 128)) >> 16; Vm_red_tableEx[i] = (csV_red_16 * (i - 128)) >> 16; } }void YUVToRGB24_Table(BYTE *p, const BYTE Y0, const BYTE Y1, const BYTE U, const BYTE V) { int Ye0 = Ym_tableEx[Y0]; int Ye1 = Ym_tableEx[Y1]; int Ue_blue = Um_blue_tableEx[U]; int Ue_green = Um_green_tableEx[U]; int Ve_green = Vm_green_tableEx[V]; int Ve_red = Vm_red_tableEx[V]; int UeVe_green = Ue_green + Ve_green; *p = color_table[(Ye0 + Ve_red)]; *(p + 1) = color_table[(Ye0 + UeVe_green)]; *(p + 2) = color_table[(Ye0 + Ue_blue)]; *(p + 3) = color_table[(Ye1 + Ve_red)]; *(p + 4) = color_table[(Ye1 + UeVe_green)]; *(p + 5) = color_table[(Ye1 + Ue_blue)]; printf("%d, %d, %d, %d, %d, %d\n", *p,*(p+1), *(p+2), *(p+3), *(p+4), *(p+5));} long border_color(long color) { if (color > 255) return 255; else if (color < 0) return 0; else return color; } void YUVToRGB24(const BYTE * pYUV, BYTE *pRGB, int width, int height){YUV422P_To_RGB24_init();int i, j;for (i = 0; i < height; i++){for (j = 0; j < width; j+=2){printf("%d, %d\n", i, j);YUVToRGB24_Table(pRGB, pYUV[1], pYUV[3], pYUV[0], pYUV[2]);pYUV += 4;pRGB += 3;}}}
- YUV转RGB,无除法,无浮点运算
- verilog 实现无符号整数除法运算
- 用移位和加减运算实现无符号整数除法
- RGB转YUV YUV转RGB
- YUV转RGB函数
- YUV转RGB
- YUV转RGB
- RGB转YUV
- YUV转RGB
- YUV转RGB汇总
- android YUV转RGB
- YUV转RGB
- YUV转RGB
- RGB转YUV
- yuv转rgb
- yuv转RGB
- RGB转YUV
- yuv转rgb
- PIT 配置
- 用 Eclipse 平台进行 C/C++ 开发
- poj 3648
- asp--from子句语法错误
- 求两个等长升序序列的中位数 .
- YUV转RGB,无除法,无浮点运算
- 最新的Exadata版本
- android图片资源的适配问题
- poj 1836 Alignment
- poj 3683
- SHGetFileInfo 函数用法
- C++中使用STL的hashmap
- wink,一个免费的可以在linux下用的教学视频制作软件
- js中组合使用构造函数模式和原型模式创建对象