D3D显示YUV图像

来源:互联网 发布:淘宝的飞车倒点辅助 编辑:程序博客网 时间:2024/05/17 18:24
#if 0
//YUV->RGB

BYTE *rgbbuf;
rgbbuf = new BYTE[m_width*m_height*4]; 
BYTE *rgbbufBak = rgbbuf;
 // m_csc.YUV2RGB(py, pu,pv,rgbbuf, surfaceDesc.Width, surfaceDesc.Height); 
m_csc.YUV420p_to_RGB24(py, pu,pv,rgbbuf, surfaceDesc.Width, surfaceDesc.Height); 
BYTE * pTextureBuffer = NULL;
LONG  lTexturePitch;     
D3DLOCKED_RECT d3d_rect;  
    lRet=m_pDirect3DSurfaceRender->LockRect(&d3d_rect,NULL,D3DLOCK_DONOTWAIT);  
    if(FAILED(lRet))  
        return -1;  
lTexturePitch = d3d_rect.Pitch;
pTextureBuffer = static_cast<byte *>(d3d_rect.pBits);
int dwordWidth = m_width / 4; // aligned width of the row, in DWORDS
int m_lVidPitch  = (m_width * 3 + 3) & ~(3);
// (pixel by 3 bytes over sizeof(DWORD))
BYTE  * pbS = NULL;
DWORD * pdwS = NULL;
    DWORD * pdwD = NULL;
for( int row = 0; row< m_height; row++)
{
pdwS = ( DWORD*)rgbbuf;
pdwD = ( DWORD*)pTextureBuffer;

for( int col = 0; col < dwordWidth; col ++ )
{
pdwD[0] =  pdwS[0] | 0xFF000000;
pdwD[1] = ((pdwS[1]<<8)  | 0xFF000000) | (pdwS[0]>>24);
pdwD[2] = ((pdwS[2]<<16) | 0xFF000000) | (pdwS[1]>>16);
pdwD[3] = 0xFF000000 | (pdwS[2]>>8);
pdwD +=4;
pdwS +=3;
}

// we might have remaining (misaligned) bytes here
pbS = (BYTE*) pdwS;
for( col = 0; col < (UINT)m_width % 4; col++)
{
*pdwD = 0xFF000000     |
(pbS[2] << 16) |
(pbS[1] <<  8) |
(pbS[0]);
pdwD++;
pbS += 3;           
}

rgbbuf  += m_lVidPitch;
pTextureBuffer += lTexturePitch;
        }// for rows
delete [] rgbbufBak;
#endif 
 
#if 0
BYTE* pTextureBuffer = NULL;
LONG  lTexturePitch;     
D3DLOCKED_RECT d3d_rect;  
    lRet=m_pDirect3DSurfaceRender->LockRect(&d3d_rect,NULL,D3DLOCK_DONOTWAIT);  
    if(FAILED(lRet))  
        return -1;  


lTexturePitch = d3d_rect.Pitch;
BYTE *pDest = (BYTE*)d3d_rect.pBits ;
int i = 0;
for(i = 0;i < m_height;i ++){
memcpy(pDest + i * lTexturePitch,py+i * m_width, m_width);
}
for(i = 0;i < m_height/2;i ++){
memcpy(pDest + lTexturePitch * m_height + i * lTexturePitch / 2,pu+i * m_width / 2, m_width / 2);
}
for(i = 0;i < m_height/2;i ++){
memcpy(pDest + lTexturePitch * m_height + lTexturePitch * m_height / 4 + i * lTexturePitch / 2,pv+i * m_width / 2, m_width / 2);

#endif
#if 0
long m_lSize =m_width*m_height;
BYTE * pTextureBuffer = NULL;
LONG  lTexturePitch;     
D3DLOCKED_RECT d3d_rect;  
    lRet=m_pDirect3DSurfaceRender->LockRect(&d3d_rect,NULL,D3DLOCK_DONOTWAIT);  
if(FAILED(lRet))  
        return -1;  
lTexturePitch = d3d_rect.Pitch;
BYTE *pDest = (BYTE*)d3d_rect.pBits ;
if ( d3d_rect.Pitch == m_width )
{
memcpy ( pDest, py, m_lSize) ;
}
else
{
for ( int j = 0 ; j < m_height ; j++ )
{
memcpy ( pDest, py, m_width ) ;
pDest += d3d_rect.Pitch ;
}
}


#endif
0 0
原创粉丝点击