Archived

This topic is now archived and is closed to further replies.

ChrAIsT

DirectShow 9 problem

Recommended Posts

Hi i need som help to check the alpha value in an video stream to use in a collision func. I've used the sample CaptureTexture9 from the microsoft directx9 sdk. I need to check a specefic area (RECT)in the videostream. Heres the code...
HRESULT Camera::CopyMediaSample( IMediaSample *pSample, LONG lSamplePitch )
{
    HRESULT hr = S_OK;
    CAutoLock lock(&m_cs);
    BYTE * pSampleBuffer = NULL;
    BYTE * pTextureBuffer = NULL;
    BYTE * pbS = NULL;
    DWORD * pdwS = NULL;
    DWORD * pdwD = NULL;
    UINT row;
    UINT col;
    D3DLOCKED_RECT d3dlr;
    LONG  lTexturePitch;     // Pitch of texture


    if( !pSample )
    {
	Cleanup();
        return E_POINTER;
    }

    if( !m_pTexture )
	{
	Cleanup();
        return E_UNEXPECTED;
	}

    try
    {
        // Get the video bitmap buffer

        hr = pSample->GetPointer( &pSampleBuffer );
        if( FAILED(hr))
        {
	    Cleanup();
            return hr;
        }

        // Lock the Texture

        hr = m_pTexture->LockRect( 0, &d3dlr, 0, 0 );
        if( FAILED(hr))
        {
	    Cleanup();
            return E_FAIL;
        }

        // Get the texture buffer & pitch

        pTextureBuffer = static_cast<byte *>(d3dlr.pBits);
        lTexturePitch = d3dlr.Pitch;

        if( m_TextureFormat == D3DFMT_A1R5G5B5 )
        {
            for(row = 0; row < m_Height; row++ ) 
            {
                BYTE *pBmpBufferOld = pTextureBuffer;
                BYTE *pTxtBufferOld = pSampleBuffer;   

                for (col = 0; col < m_Width; col++) 
                {
                    *(WORD *)pTextureBuffer = (WORD)
                        (0x8000 +
                        ((pSampleBuffer[2] & 0xF8) << 7) +
                        ((pSampleBuffer[1] & 0xF8) << 2) +
                        (pSampleBuffer[0] >> 3));

                    pTextureBuffer += 2;
                    pSampleBuffer += 3;
                }
                pSampleBuffer  = pBmpBufferOld + lSamplePitch;
                pTextureBuffer = pTxtBufferOld + lTexturePitch;
            }
        }
        if( m_TextureFormat == D3DFMT_A8R8G8B8 )
        {
            for(row = 0; row < m_Height; row++ ) 
            {
                BYTE *pBmpBufferOld = pSampleBuffer;
                BYTE *pTxtBufferOld = pTextureBuffer;   

                for (col = 0; col < m_Width; col++) 
                {
                    pTextureBuffer[0] = pSampleBuffer[0];
                    pTextureBuffer[1] = pSampleBuffer[1];
                    pTextureBuffer[2] = pSampleBuffer[2];
                    pTextureBuffer[3] = pSampleBuffer[3]; //0xFF; //(BYTE)(0xFF * y / (m_lVidHeight-1));


                    pTextureBuffer += 4;
                    pSampleBuffer  += 4;
                }

                pSampleBuffer  = pBmpBufferOld + lSamplePitch;
                pTextureBuffer = pTxtBufferOld + lTexturePitch;
            }

        }

        hr = m_pTexture->UnlockRect(0);
    }
    catch(...)
    {
        hr = m_pTexture->UnlockRect(0);
        ASSERT(0);
	Cleanup();
    }
    return hr;
}
Any help would be most helpfull ps: sorry for my bad english ds: [edited by - ChrAIsT on March 22, 2004 7:32:41 AM]

Share this post


Link to post
Share on other sites