bool CImageMixer_VMR9::SetBitmap(HBITMAP hbm,int Opacity,COLORREF TransColor,RECT *pDestRect) { IVMRMixerBitmap9 *pMixerBitmap; IVMRWindowlessControl9 *pWindowlessControl; LONG NativeWidth,NativeHeight; BITMAP bm; VMR9AlphaBitmap ab; HRESULT hr; if (!CreateMemDC()) return false; if (FAILED(m_pRenderer->QueryInterface(IID_IVMRMixerBitmap9, reinterpret_cast<LPVOID*>(&pMixerBitmap)))) return false; m_pRenderer->QueryInterface(IID_IVMRWindowlessControl9, reinterpret_cast<LPVOID*>(&pWindowlessControl)); if (FAILED(pWindowlessControl->GetNativeVideoSize(&NativeWidth,&NativeHeight, NULL,NULL)) || NativeWidth==0 || NativeHeight==0) { NativeWidth=1440; NativeHeight=1080; } pWindowlessControl->Release(); ::SelectObject(m_hdc,hbm); ab.dwFlags=VMR9AlphaBitmap_hDC; if (TransColor!=CLR_INVALID) ab.dwFlags|=VMR9AlphaBitmap_SrcColorKey; ab.hdc=m_hdc; ab.pDDS=NULL; ::GetObject(hbm,sizeof(BITMAP),&bm); ::SetRect(&ab.rSrc,0,0,bm.bmWidth,bm.bmHeight); ab.rDest.left=(float)pDestRect->left/(float)NativeWidth; ab.rDest.top=(float)pDestRect->top/(float)NativeHeight; ab.rDest.right=(float)pDestRect->right/(float)NativeWidth; ab.rDest.bottom=(float)pDestRect->bottom/(float)NativeHeight; ab.fAlpha=(float)Opacity/100.0f; ab.clrSrcKey=TransColor; hr=pMixerBitmap->SetAlphaBitmap(&ab); pMixerBitmap->Release(); if (FAILED(hr)) { ::SelectObject(m_hdc,m_hbmOld); return false; } return true; }
bool CImageMixer_VMR9::GetMapSize(int *pWidth,int *pHeight) { bool fOK=false; IVMRWindowlessControl9 *pWindowlessControl; if (SUCCEEDED(m_pRenderer->QueryInterface(IID_IVMRWindowlessControl9, reinterpret_cast<LPVOID*>(&pWindowlessControl)))) { LONG NativeWidth,NativeHeight; if (SUCCEEDED(pWindowlessControl->GetNativeVideoSize(&NativeWidth,&NativeHeight,NULL,NULL))) { if (pWidth) *pWidth=NativeWidth; if (pHeight) *pHeight=NativeHeight; fOK=true; } pWindowlessControl->Release(); } return fOK; }
HRESULT Movie::InitMovie(HWND hWnd){ // COMの初期化 if(FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))){ return E_FAIL; } //COMインターフェース取得 if(FAILED(CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,IID_IGraphBuilder,(void**)&pGB))){ CoUninitialize(); return E_FAIL; } //COMインターフェース取得 if(FAILED(CoCreateInstance(CLSID_VideoMixingRenderer9,NULL,CLSCTX_INPROC_SERVER,IID_IBaseFilter,(void**)&pVM))){ CoUninitialize(); return E_FAIL; } pGB->AddFilter(pVM, L"VMR9"); // VRM9をウィンドウレスモードにする IVMRFilterConfig *pVMRCfg = NULL; if(FAILED(pVM->QueryInterface( IID_IVMRFilterConfig9, (void**)&pVMRCfg ))) {pGB->Release(); CoUninitialize(); return E_FAIL;} pVMRCfg->SetRenderingMode( VMRMode_Windowless ); pVMRCfg->Release(); // IVMRFilterConfigはもう必要ない // 描画ウィンドウの指定 IVMRWindowlessControl9 *pVMRWndCont = NULL; if(FAILED(pVM->QueryInterface( IID_IVMRWindowlessControl9, (void**)&pVMRWndCont ))) { pGB->Release(); CoUninitialize(); return E_FAIL; } pVMRWndCont->SetVideoClippingWindow( hWnd ); WCHAR wFileName[] = L"OP.AVI"; IBaseFilter *pSource = NULL; pGB->AddSourceFilter(wFileName, wFileName, &pSource); pCGB2 = NULL; if(FAILED(CoCreateInstance( CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void**)&pCGB2))){ pCGB2->Release(); pGB->Release(); CoUninitialize(); return E_FAIL; } pCGB2->RenderStream(0, &MEDIATYPE_Audio, pSource, 0, 0); // 描画領域の設定(接続後でないとエラーになる) LONG W,H; RECT SrcR, DestR; pVMRWndCont->GetNativeVideoSize(&W, &H, NULL, NULL); SetRect(&SrcR, 0, 0, W, H); GetClientRect(hWnd, &DestR); pVMRWndCont->SetVideoPosition(&SrcR, &DestR); pVMRWndCont->Release(); // ウィンドウレスコントロールはもう必要ない // メディアコントロールインターフェイスの取得 if(FAILED(pGB->QueryInterface( IID_IMediaControl, (void**)&pMC ))) { pCGB2->Release(); pGB->Release(); CoUninitialize(); return E_FAIL; } // ストリームの再生(グラフの実行) pMC->Run(); return S_OK; }