Jump to content
  • Advertisement

Archived

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

ChrAIsT

DirectShow 9 problem

This topic is 5231 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!