如何用C++将YUV420格式数据转化为RGB888格式
#include <iostream>#include<string.h>
using namespace std;
void YUV2RGB(unsigned char *a , unsigned char *b , int w , int h)
{
long posu = w*h;
for(int i= 0;i<w*h;i++)
{
if( i % 2==0 && i!=0)
{
if(i%w ==0 && i%(2*w)==0)
{
posu=posu-w+2;
}
else
{
posu +=2;
}
}
b = a + 1.4075 * (a-128);
b = a - 0.3455 * (a-128) - 0.7169*(a-128);
b = a + 1.779 * (a-128);
}
cout<<"YUV2RGB函数运行了"<<endl;
}
int main()
{
FILE *in;
int w= 5664 , h = 4248;
long len =w*h;
unsigned char* YUV = new unsigned char;
unsigned char* RGB = new unsigned char;
cout<<"函数定义没有问题"<<endl;
in = fopen("E:\\cam0_5664x4248_nv12.yuv","rb");
if(in == nullptr)
{
cout << "open cam0_5664x4248_nv12 failed" << endl;
return 0;
}
fread(&YUV,sizeof(unsigned char),len*1.5,in);
fclose(in);
cout<<"YUV数据已经打开了,并且读完了\n"<<endl;
YUV2RGB(YUV,RGB,w,h);
cout<<"YUV转RGB完成!"<<endl;
in = fopen("E:\\RGB.rgb","wb");
if(in == nullptr)
{
cout << "open RGB.rgb failed" << endl;
return 0;
}
fwrite(&RGB,sizeof(unsigned char),len*3,in);
fclose(in);
cout<<"Hello World"<<endl;
return 0;
}
//运行上面的代码,得不到响应的.rgb格式文件,有大神可以帮帮忙康康吗
https://img-my.csdn.net/uploads/201208/31/1346422959_6364.png 最下面那个图是YUV420nv12中Y、U、V的储存方式
页:
[1]