DirectShowによる動画像の上下左右反転

カメラ映像を上下左右反転させるように中間フィルタ(TransInPlace Filter)を作成してみた.カメラの位置,向きに制約がある場合は,こういう風にソフトウェア的に処理するのが重宝する.

反転させるメソッドは以下のような感じ.
m_lVidHeight, m_lVidWidthはそれぞれ,現在のカメラ画像の縦の画素数,横の画素数を示す.

HRESULT CAddIndicator::Transform(IMediaSample *pSample)
{
	CAutoLock mylock(&m_CritSec);
	BYTE *pBmpBuffer;
    // Get the video bitmap buffer
    pSample->GetPointer( &pBmpBuffer );
    
    // 上下左右反転
    int y_end = m_lVidHeight * 0.5;
    for(int y = 0; y < y_end; y++)
    {
        for(int x = 0; x < m_lVidWidth; x++)
        {
            tmpBuffer[0] = pBmpBuffer[(x + y * m_lVidWidth) * 3 + 0];
            tmpBuffer[1] = pBmpBuffer[(x + y * m_lVidWidth) * 3 + 1];
            tmpBuffer[2] = pBmpBuffer[(x + y * m_lVidWidth) * 3 + 2];
 
            pBmpBuffer[(x + y * m_lVidWidth) * 3 + 0] = pBmpBuffer[( (m_lVidWidth - 1 - x) + (m_lVidHeight - 1 - y) * m_lVidWidth ) * 3 + 0];
            pBmpBuffer[(x + y * m_lVidWidth) * 3 + 1] = pBmpBuffer[( (m_lVidWidth - 1 - x) + (m_lVidHeight - 1 - y) * m_lVidWidth ) * 3 + 1];
            pBmpBuffer[(x + y * m_lVidWidth) * 3 + 2] = pBmpBuffer[( (m_lVidWidth - 1 - x) + (m_lVidHeight - 1 - y) * m_lVidWidth ) * 3 + 2];
            pBmpBuffer[((m_lVidWidth - 1 - x) + (m_lVidHeight - 1 - y) * m_lVidWidth) * 3 + 0] = tmpBuffer[0];
            pBmpBuffer[((m_lVidWidth - 1 - x) + (m_lVidHeight - 1 - y) * m_lVidWidth) * 3 + 1] = tmpBuffer[1];
            pBmpBuffer[((m_lVidWidth - 1 - x) + (m_lVidHeight - 1 - y) * m_lVidWidth) * 3 + 2] = tmpBuffer[2];

        }
    }
    pSample->SetActualDataLength(acSize);
    pSample->SetSyncPoint(TRUE);

    return S_OK;
}