directdraw如何显示yuy2数据
现在已得到yuv420的一帧数据 char* y,char *u, char *v, int width, int height
由于显卡无法创建planner格式的overlay,打算用yuy2的overlay进行updateoverlay显示,
所以先把数据转换为yuy2格式,转换函数如下:
int yuv420toyuy2(unsigned char* p420y,unsigned char* p420u, unsigned char* p420v ,
unsigned char* pyuy2,int width ,int height)
{
int y0, y1, y2, y3;
int u;
int v;
if(!p420y|| !p420u|| !p420v || !pyuy2)
return 0;
int size = ((width + 31) & ~31) * height;
if(size <= 0)
return 0;
BYTE * pY = p420y;
BYTE * pU = p420u;
BYTE * pV = p420v ;
BYTE * yuy2 = pyuy2;
int i = 0, j = 0;
for(i = 0; i< height/2 ; i ++)
{
for(j = 0; j < width/2 ; j ++)
{
y0 = *pY;
y1 = *(pY + 1);
y2 = *(pY + width) ;
y3 = *(pY + width + 1);
u = *pU++;
v = *pV++;
pY += 2;
*(yuy2 + 2 * i * width * 2 + 4 * j ) = y0;
*(yuy2 + 2 * i * width * 2 + 4 * j + 1) = u;
*(yuy2 + 2 * i * width * 2 + 4 * j + 2) = y1;
*(yuy2 + 2 * i * width * 2 + 4 * j + 3) = v;
*(yuy2 + (2 * i + 1) * width * 2 + 4 * j) = y2;
*(yuy2 + (2 * i + 1) * width * 2 + 4 * j + 1)= u;
*(yuy2 + (2 * i + 1) * width * 2 + 4 * j + 2)= y3;
*(yuy2 + (2 * i + 1) * width * 2 + 4 * j + 3)= v;
}
pY += width;
}
return 1;
}
假设所有的表面和directdraw对象都创建好,然后填充overlay表面,填充表面代码如下:
m_lpOverlay->Lock(NULL,&ddsd,DDLOCK_WAITNOTBUSY,NULL);
//填充表面
unsigned char* lpsurf=(unsigned char*)ddsd.lpSurface;
int linebyte=ddsd.dwWidth*3/2;
for(i=0;i<ddsd.dwHeight;i++)
{
memcpy(lpsurf,pYuv2,linebyte);
pYuv2+=linebyte;
lpsurf+=linebyte;
}
m_lpOverlay->Unlock(NULL);
显示出来后,全是条纹。请问是yuv420转换到yuy2的问题,还是填充表面的问题?
(解码出来的yuv420是没问题的,因为转换为rgb格式,可以显示)
[解决办法]
http://blog.csdn.net/RobertBaker/archive/2010/03/15/5380946.aspx