最近在看dvd2dvi程序时,遇到问题
1.7600GS的显卡在YUV422格式下,显示为黑屏(调试下也如此)
2.7300LE的显卡在YUV422格式下,显示为灰屏(调试下可显示为彩色)
3.HD2600的显卡在YUV422格式下,显示正常
可能与显卡支持有关,写了一个显卡测试程序
#define FOURCC_YV12 0x32315659 // MAKEFOURCC('Y','V','1','2')
#define FOURCC_Y411 0x31313459 // MAKEFOURCC('Y','4','1','1')
#define FOURCC_YUY2 0x32595559 // MAKEFOURCC('Y','U','Y','2')
#define FOURCC_UYVY 0x59565955 // MAKEFOURCC('U','Y','V','Y')
LPDIRECTDRAW m_lpDD = NULL;
LPDIRECTDRAW2 m_lpDD2 = NULL;
LPDIRECTDRAWSURFACE m_lpDDSPrimary = NULL;
LPDIRECTDRAWSURFACE m_lpDDSOverlay[6] = {0};
void YUYVFormatTest()
{
HRESULT hr=0;
//创建DirectDraw对象
hr=DirectDrawCreate(NULL,&m_lpDD,NULL);
if(hr==DD_OK){
if(m_lpDD->QueryInterface(IID_IDirectDraw2, (LPVOID*)&m_lpDD2)==DD_OK)
{
hr=m_lpDD2->SetCooperativeLevel(GetActiveWindow(), DDSCL_NORMAL);
if(hr==DD_OK){
DDSURFACEDESC ddsd; //表面描述
ddsd.dwSize=sizeof( ddsd );
//创建主表面
ddsd.dwFlags=DDSD_CAPS;
ddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE ;
ddsd.dwBackBufferCount = 1;
hr=m_lpDD2->CreateSurface(&ddsd,&m_lpDDSPrimary,NULL);
if(hr==DD_OK){
// Get driver capabilities
DDCAPS capsDrv;
memset(&capsDrv,0,sizeof(capsDrv));
capsDrv.dwSize=sizeof(DDCAPS);
hr=m_lpDD2->GetCaps(&capsDrv, NULL);
if(hr==DD_OK && (capsDrv.dwCaps & DDCAPS_OVERLAY)){ // determine Overlay support.
DDPIXELFORMAT PixelFormat[] = {
{ sizeof(DDPIXELFORMAT), DDPF_FOURCC, FOURCC_UYVY, 0, 0, 0, 0, 0 }, // UYVY
{ sizeof(DDPIXELFORMAT), DDPF_FOURCC, FOURCC_Y411, 0, 0, 0, 0, 0 }, // Y411
{ sizeof(DDPIXELFORMAT), DDPF_FOURCC, FOURCC_YV12, 0, 0, 0, 0, 0 }, // YV12
{ sizeof(DDPIXELFORMAT), DDPF_FOURCC, FOURCC_YUY2, 0, 0, 0, 0, 0 }, // YUY2
};
int i, nPixelFormat=sizeof(PixelFormat)/sizeof(DDPIXELFORMAT);
for(i=0;i // 创建覆盖表面
ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
ddsd.dwSize = sizeof(DDSURFACEDESC);
ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY; // Overlay related APIs will fail without hardware support.
ddsd.dwWidth = 352;
ddsd.dwHeight = 288;
memcpy(&ddsd.ddpfPixelFormat,&PixelFormat[i],sizeof(DDPIXELFORMAT));
ddsd.ddpfPixelFormat.dwYUVBitCount = 16;
hr=m_lpDD2->CreateSurface(&ddsd, &m_lpDDSOverlay[i], NULL);
if(hr==DD_OK){
char tmpBuf[256];
sprintf(tmpBuf,"创建第%d种OVERLAY表面成功 !", i);
//MessageBox(hWndCopy, tmpBuf,"DirectDraw初始化", MB_ICONINFORMATION);
m_lpDDSOverlay[i]->UpdateOverlay(NULL, m_lpDDSPrimary, NULL, DDOVER_HIDE, NULL);
m_lpDDSOverlay[i]->Release();
m_lpDDSOverlay[i]=NULL;
//break;
}
}
DDPIXELFORMAT ddPixelFormat;
ddPixelFormat.dwFlags = DDPF_FOURCC;
ddPixelFormat.dwFourCC = FOURCC_YUY2;//mmioFOURCC('Y','U','Y','2');
ddPixelFormat.dwYUVBitCount = 16;
ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
ddsd.dwSize = sizeof(DDSURFACEDESC);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
//ddsd.ddsCaps.dwCaps = /*DDSCAPS_BACKBUFFER*/ DDSCAPS_OVERLAY| DDSCAPS_VIDEOMEMORY;//DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;
ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY| DDSCAPS_SYSTEMMEMORY;
ddsd.dwWidth = 720;
ddsd.dwHeight = 480;
memcpy(&(ddsd.ddpfPixelFormat), &ddPixelFormat, sizeof(DDPIXELFORMAT));
hr = m_lpDD2->CreateSurface(&ddsd, &m_lpDDSOverlay[0], NULL);
if (hr==DD_OK)
{
printf("创建第2种OVERLAY表面成功 !");
}
}
}
m_lpDDSPrimary->Release();
m_lpDDSPrimary=NULL;
}
m_lpDD2->Release();
m_lpDD2=NULL;
}
m_lpDD->Release();
m_lpDD=NULL;
}
}
在函数void RenderYUY2()中加上:
if (IDirectDrawSurface_Unlock(lpOverlay, 0)==DD_OK)
{
IDirectDrawSurface_Flip(lpOverlay, NULL, DDFLIP_WAIT);//(新增加)
......................
}
则7300LE的显卡颜色正常,但闪烁比较厉害,7600GS能显示了(不知为什么原因)但颜色变成暗红
本想抓屏贴张图给看看效果,overlay方式好象不能抓屏
阅读(3785) | 评论(2) | 转发(0) |