YUYV格式到RGB格式的转换
来源:互联网 发布:唱歌软件下载 编辑:程序博客网 时间:2024/04/29 18:43
http://blog.chinaunix.net/uid-21410064-id-3248638.html
YUYV格式到RGB格式的转换:
为什么YUYV格式要转到RGB格式,视频的显示调用的多数API都是基于RGB格式,所以需要进行格式的转换。
YUYV格式如下:
Y0U0Y1V0 Y2U1Y3V1..........
说 明:一个Y代表一个像素,而一个Y和UV组合起来构成一个像素,所以第0个像素Y0和第一个像素Y1都是共用第0个像素的U0和V0。而每个分量 Y,U,V都是占用一个字节的存储空间。所以Y0U0Y1V0相当于两个像素,占用了4个字节的存储空间,平均一个像素占用两个字节。
RGB格式:
R0G0B0 R1G1B1.........
说明:一个像素由三个分量构成,即一个像素占用三个字节。
YUV到RGB的转换有如下公式:
R = 1.164*(Y-16) + 1.159*(V-128);
G = 1.164*(Y-16) - 0.380*(U-128)+ 0.813*(V-128);
B = 1.164*(Y-16) + 2.018*(U-128));
int yuvtorgb0(unsigned char *yuv, unsigned char *rgb, unsigned int
width, unsigned int height)
{
unsigned int in, out;
int y0, u, y1, v;
unsigned int pixel24;
unsigned char *pixel = (unsigned char *)&pixel24;
unsigned int size = width*height*2;/*yuyv中一个像素占据两个字节*/
for(in = 0, out = 0; in < size; in += 4, out += 6)
{
y0 = yuv[in+0];/*分离出Y U V*/
u = yuv[in+1];
y1 = yuv[in+2];
v = yuv[in+3];
sign3 = true;
pixel24 = yuvtorgb(y0, u, v);/*转化第0个像素*/
rgb[out+0] = pixel[0]; //for QT
rgb[out+1] = pixel[1];
rgb[out+2] = pixel[2];
//rgb[out+0] = pixel[2]; //for iplimage
//rgb[out+1] = pixel[1];
//rgb[out+2] = pixel[0];
//sign3 = true;
pixel24 = yuvtorgb(y1, u, v);/*转化第1个像素*/
rgb[out+3] = pixel[0];
rgb[out+4] = pixel[1];
rgb[out+5] = pixel[2];
//rgb[out+3] = pixel[2];
//rgb[out+4] = pixel[1];
//rgb[out+5] = pixel[0];
}
return 0;
}
int yuvtorgb(int y, int u, int v)
{
unsigned int pixel24 = 0;
unsigned char *pixel = (unsigned char *)&pixel24;
int r, g, b;
static long int ruv, guv, buv;
if(sign3)
{
sign3 = false;
ruv = 1159*(v-128);
guv = 380*(u-128) + 813*(v-128);
buv = 2018*(u-128);
}
r = (1164*(y-16) + ruv) / 1000;
g = (1164*(y-16) - guv) / 1000;
b = (1164*(y-16) + buv) / 1000;
if(r > 255) r = 255;
if(g > 255) g = 255;
if(b > 255) b = 255;
if(r < 0) r = 0;
if(g < 0) g = 0;
if(b < 0) b = 0;
pixel[0] = r;
pixel[1] = g;
pixel[2] = b;
return pixel24;
}
0 0
- YUYV格式到RGB格式的转换
- YUV格式到RGB格式的转换
- yuy2(yuyv)到 yuv420 semi planer格式的转换
- 关于RGB、YUY2、YUYV、YVYU、UYVY、AYUV DirectShow中常见的RGB/YUV格式
- 关于RGB、YUY2、YUYV、YVYU、UYVY、AYUV DirectShow中常见的RGB/YUV格式
- RGB格式转换的实现
- RGB、YUY2、YUYV、YVYU、UYVY、AYUV格式详解
- RGB、YUY2、YUYV、YVYU、UYVY、AYUV格式详解
- RGB、YUY2、YUYV、YVYU、UYVY、AYUV格式详解
- RGB、YUY2、YUYV、YVYU、UYVY、AYUV格式详解
- linux下usb摄像头采集的YUYV格式转换成JPEG格式的图片
- linux下usb摄像头采集的YUYV格式转换成JPEG格式的图片
- RGB/YUV 格式转换
- 各种RGB格式转换
- 各种格式的yuv ,RGB转换
- RGB与YUV的格式转换
- YUV格式、RGB格式、JPEG格式、MJPEG格式之间的转换(C程序)之一
- MapInfo格式到ArcInfo格式的转换
- Linux之V4L2基础编程
- IP地址、子网掩码、网关的关系
- 第十四周 OJ平台-国家排序
- 解决安卓中页脚被输入法顶起的有关问题
- 杨氏三角形
- YUYV格式到RGB格式的转换
- Phonegap解决错误:Error initializing Cordova:Class not found
- Ubuntu Mysql应用小记
- Filter Solutions 10.0+破解
- 自定义jsp标签的一般步骤
- iOS 通讯录修改操作
- C++编译错误(1):缺少;(在using前)
- Search for a Range
- oracle的resetlogs机制浅析