void yuyv2rgb(char *newBuf,char*starter,int length)
{
unsigned char YUYV[4],RGB[6];
int j,k,i;
unsigned int location=0;
j=0;
for(i=0;i
{
YUYV[0]=starter[i];//Y0
YUYV[1]=starter[i+1];//U
YUYV[2]=starter[i+2];//Y1
YUYV[3]=starter[i+3];//V
if(YUYV[0]<1)
{
RGB[0]=0;
RGB[1]=0;
RGB[2]=0;
}
else
{
RGB[0]=YUYV[0]+1.772*(YUYV[1]-128);//b
RGB[1]=YUYV[0]-0.34413*(YUYV[1]-128)-0.71414*(YUYV[3]-128);//g
RGB[2]=YUYV[0]+1.402*(YUYV[3]-128);//r
}
if(YUYV[2]<0)
{
RGB[3]=0;
RGB[4]=0;
RGB[5]=0;
}
else
{
RGB[3]=YUYV[2]+1.772*(YUYV[1]-128);//b
RGB[4]=YUYV[2]-0.34413*(YUYV[1]-128)-0.71414*(YUYV[3]-128);//g
RGB[5]=YUYV[2]+1.402*(YUYV[3]-128);//r
}
for(k=0;k<6;k++)
{
if(RGB[k]<0)
RGB[k]=0;
if(RGB[k]>255)
RGB[k]=255;
}
#if 0
bcopy(RGB,(newBuf+j),sizeof(RGB));
#else
/*
by erain
YUYV <------> 4byte:两个像素
RGB <------> 6byte:两个像素
-------------------------------->RGB:每个像素3byte
*/
//请记住:扫描行在位图文件中是反向存储的!
if(j%(VIDEO_WIDTH*3)==0)//定位存储位置
{
location=(VIDEO_HEIGHT-j/(VIDEO_WIDTH*3)
-1)*(VIDEO_WIDTH*3);
//location=(VIDEO_HEIGHT-j/(VIDEO_WIDTH*3))*(VIDEO_WIDTH*3);
}
bcopy(RGB,(newBuf+location+(j%(VIDEO_WIDTH*3))),sizeof(RGB));
#endif
j+=6;
}
}
阅读(1561) | 评论(0) | 转发(0) |