void RefreshCodec(HWND hW) { char buffer[255]; union { char chFCC[5]; DWORD dwFCC; } fcc; ICINFO icinfo; memset(&icinfo,0,sizeof(icinfo)); icinfo.dwSize = sizeof(icinfo); strcpy(fcc.chFCC,"VIDC"); RECORD_COMPRESSION1.hic = ICOpen(fcc.dwFCC,RECORD_COMPRESSION1.fccHandler,ICMODE_QUERY); if(RECORD_COMPRESSION1.hic) { ICGetInfo(RECORD_COMPRESSION1.hic,&icinfo,sizeof(icinfo)); ICClose(RECORD_COMPRESSION1.hic); wsprintf(buffer,"16 bit Compression: %ws",icinfo.szDescription); } else wsprintf(buffer,"16 bit Compression: Full Frames (Uncompressed)"); SetDlgItemText(hW,IDC_COMPRESSION1,buffer); memset(&icinfo,0,sizeof(icinfo)); icinfo.dwSize = sizeof(icinfo); RECORD_COMPRESSION2.hic = ICOpen(fcc.dwFCC,RECORD_COMPRESSION2.fccHandler,ICMODE_QUERY); if(RECORD_COMPRESSION2.hic) { ICGetInfo(RECORD_COMPRESSION2.hic,&icinfo,sizeof(icinfo)); ICClose(RECORD_COMPRESSION2.hic); wsprintf(buffer,"24 bit Compression: %ws",icinfo.szDescription); } else wsprintf(buffer,"24 bit Compression: Full Frames (Uncompressed)"); SetDlgItemText(hW,IDC_COMPRESSION2,buffer); }
void WatermarkSearchWorker::run() { DWORD const type = MAKEFOURCC('v', 'i', 'd', 'c'); DWORD const handler = MAKEFOURCC(handlerFCC_[0], handlerFCC_[1], handlerFCC_[2], handlerFCC_[3]); compressor_ = ScopedHIC(ICOpen(type, handler, ICMODE_COMPRESS)); decompressor_ = ScopedHIC(ICOpen(type, handler, ICMODE_DECOMPRESS)); while (true) { queueMutex_.lock(); if (queue_.empty()) { queueMutex_.unlock(); if (shouldTerminate_) { break; } std::this_thread::yield(); } else { Size size = queue_.front(); queue_.pop_front(); queueMutex_.unlock(); auto r = findWatermark(size.width_, size.height_); if (r) { std::lock_guard<std::mutex> lk(resultMutex_); results_.push_back(r); } } } }
/* 对捕获的视频做编码、解码处理 */ void CMainFrame::OnVfwCodec() { // TODO: 在此添加命令处理程序代码 DWORD fsize; /* VCM initialization */ hic1 = ICOpen(mmioFOURCC('v','i','d','c'), mmioFOURCC('X','V','I','D'), ICMODE_COMPRESS); if (hic1 == 0) AfxMessageBox(_T("打开编码器失败!")); hic2 = ICOpen(mmioFOURCC('v','i','d','c'), mmioFOURCC('X','V','I','D'), ICMODE_DECOMPRESS); if (hic2 == 0) AfxMessageBox(_T("打开解码器失败!")); fsize = capGetVideoFormatSize(m_hWndCap); capGetVideoFormat(m_hWndCap, lpbiIn, fsize); InitAVIWriteOpt(); lpbiOut->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); lpbiOut->bmiHeader.biWidth = lpbiIn->bmiHeader.biWidth; lpbiOut->bmiHeader.biHeight = lpbiIn->bmiHeader.biHeight; lpbiOut->bmiHeader.biPlanes = 1; lpbiOut->bmiHeader.biBitCount = 24; lpbiOut->bmiHeader.biCompression = BI_RGB; lpbiOut->bmiHeader.biSizeImage = lpbiIn->bmiHeader.biWidth*lpbiIn->bmiHeader.biHeight*3; lpbiOut->bmiHeader.biXPelsPerMeter = 0; lpbiOut->bmiHeader.biYPelsPerMeter = 0; lpbiOut->bmiHeader.biClrUsed = 0; lpbiOut->bmiHeader.biClrImportant = 0; // get the format of the input video if (ICCompressGetFormat(hic1,lpbiIn,lpbiTmp)!=ICERR_OK) AfxMessageBox(_T("编码器不能读取输出格式!")); if (ICCompressQuery(hic1,lpbiIn,lpbiTmp) != ICERR_OK) AfxMessageBox(_T("不能处理编码器输入输出格式!")); // set the parameters of the CODEC pc.cbSize = sizeof(COMPVARS); //结构体大小 pc.dwFlags = ICMF_COMPVARS_VALID; pc.hic = hic1; //编码器句柄 pc.fccType = mmioFOURCC('v','i','d','c'); pc.fccHandler = mmioFOURCC('X','V','I','D'); pc.lpbiOut = lpbiTmp; //输出格式 pc.lKey = 100; //key帧频率 pc.lQ = 10000; //图像质量 if(!ICSeqCompressFrameStart(&pc, lpbiIn)) return; ICDecompressBegin(hic2,lpbiTmp,lpbiOut); m_vfwState = ENCDEC; }
static void test_OpenCase(void) { HIC h; ICINFO info; /* Check if default handler works */ h = ICOpen(mmioFOURCC('v','i','d','c'),0,ICMODE_DECOMPRESS); ok(0!=h,"ICOpen(vidc.0) failed\n"); if (h) { info.dwSize = sizeof(info); info.szName[0] = 0; ICGetInfo(h, &info, sizeof(info)); trace("The default decompressor is %s\n", wine_dbgstr_w(info.szName)); ok(ICClose(h)==ICERR_OK,"ICClose failed\n"); } h = ICOpen(mmioFOURCC('v','i','d','c'),0,ICMODE_COMPRESS); ok(0!=h || broken(h == 0),"ICOpen(vidc.0) failed\n"); /* Not present in Win8 */ if (h) { info.dwSize = sizeof(info); info.szName[0] = 0; ICGetInfo(h, &info, sizeof(info)); trace("The default compressor is %s\n", wine_dbgstr_w(info.szName)); ok(ICClose(h)==ICERR_OK,"ICClose failed\n"); } /* Open a compressor with combinations of lowercase * and uppercase compressortype and handler. */ h = ICOpen(mmioFOURCC('v','i','d','c'),mmioFOURCC('m','s','v','c'),ICMODE_DECOMPRESS); ok(0!=h,"ICOpen(vidc.msvc) failed\n"); if (h) { ok(ICClose(h)==ICERR_OK,"ICClose failed\n"); } h = ICOpen(mmioFOURCC('v','i','d','c'),mmioFOURCC('M','S','V','C'),ICMODE_DECOMPRESS); ok(0!=h,"ICOpen(vidc.MSVC) failed\n"); if (h) { ok(ICClose(h)==ICERR_OK,"ICClose failed\n"); } h = ICOpen(mmioFOURCC('V','I','D','C'),mmioFOURCC('m','s','v','c'),ICMODE_DECOMPRESS); ok(0!=h,"ICOpen(VIDC.msvc) failed\n"); if (h) { ok(ICClose(h)==ICERR_OK,"ICClose failed\n"); } h = ICOpen(mmioFOURCC('V','I','D','C'),mmioFOURCC('M','S','V','C'),ICMODE_DECOMPRESS); ok(0!=h,"ICOpen(VIDC.MSVC) failed\n"); if (h) { ok(ICClose(h)==ICERR_OK,"ICClose failed\n"); } h = ICOpen(mmioFOURCC('v','i','d','c'),mmioFOURCC('m','S','v','C'),ICMODE_DECOMPRESS); ok(0!=h,"ICOpen(vidc.mSvC) failed\n"); if (h) { ok(ICClose(h)==ICERR_OK,"ICClose failed\n"); } h = ICOpen(mmioFOURCC('v','I','d','C'),mmioFOURCC('m','s','v','c'),ICMODE_DECOMPRESS); ok(0!=h,"ICOpen(vIdC.msvc) failed\n"); if (h) { ok(ICClose(h)==ICERR_OK,"ICClose failed\n"); } }
//Ver 1.2 //Note : Because the program stores the state for only one compressor (in the pVideoCompressParams), //if the user chooses "Configure" for compressor A, then chooses another compressor B and presses "Configure" again //the previous state info for compressor A will be lost. void CVideoOptions::OnConfigure() { // TODO: Add your control notification handler code here int sel = ((CComboBox *) GetDlgItem(IDC_COMPRESSORS))->GetCurSel(); if (sel != CB_ERR) { //Still unable to handle DIVX state (results in error) //if (compressor_info[sel].fccHandler==mmioFOURCC('D', 'I', 'V', 'X')) return; HIC hic = ICOpen(compressor_info[sel].fccType, compressor_info[sel].fccHandler, ICMODE_QUERY); if (hic) { //Set our current Video Compress State Info into the hic, which will update the ICConfigure Dialog SetVideoCompressState (hic , compressor_info[sel].fccHandler); ICConfigure(hic,m_hWnd); //Get Video Compress State Info from the hic after adjustment with the ICConfigure dialog //This will set the external pVideoCompressParams variable which is used by AVICOMPRESSOPTIONS //(This means the external variable pVideoCompressParams will be changed even if user press "Cancel") GetVideoCompressState (hic , compressor_info[sel].fccHandler); ICClose(hic); } } }
//*********************************************************************** BOOL SetTransparency( HIC m_hIC ) //*********************************************************************** { R4_DEC_SEQ_DATA m_DecodeSeqMsg; // Info for messages which may only be sent before initiating playback if ( !m_hIC ) if ((m_hIC = ICOpen(ICTYPE_VIDEO, mmioFOURCC('I','V','4','1'), ICMODE_DECOMPRESS)) == 0) return( FALSE ); // Get the current settings m_DecodeSeqMsg.dwSize = sizeof( R4_DEC_SEQ_DATA ); m_DecodeSeqMsg.dwFourCC = mmioFOURCC('I','V','4','1'); m_DecodeSeqMsg.dwVersion = SPECIFIC_INTERFACE_VERSION; m_DecodeSeqMsg.oeEnvironment = OE_32; // or = OE_32; m_DecodeSeqMsg.dwFlags = DECSEQ_VALID|DECSEQ_KEY|DECSEQ_SCALABILITY|DECSEQ_FILL_TRANSPARENT; m_DecodeSeqMsg.dwKey = 0; m_DecodeSeqMsg.fEnabledKey = 0; m_DecodeSeqMsg.fScalability = 0; m_DecodeSeqMsg.fFillTransparentPixels = 0; m_DecodeSeqMsg.mtType = MT_DECODE_SEQ_DEFAULT; long err = ICSendMessage(m_hIC, ICM_GETCODECSTATE, (DWORD)(LPSTR)&m_DecodeSeqMsg, sizeof( R4_DEC_SEQ_DATA )); // Set Transparency m_DecodeSeqMsg.mtType = MT_DECODE_SEQ_VALUE; m_DecodeSeqMsg.fFillTransparentPixels = TRUE; m_DecodeSeqMsg.dwFlags = DECSEQ_VALID|DECSEQ_FILL_TRANSPARENT; err = ICSendMessage(m_hIC, ICM_SETCODECSTATE, (DWORD)(LPSTR)&m_DecodeSeqMsg, sizeof( R4_DEC_SEQ_DATA )); return( err != 0 ); }
void CPgPubExtra::FillCodecs() { m_comboCodec.ResetContent(); m_codecs.Destroy(); BITMAPINFOHEADER bih; ZeroMemory( &bih, sizeof( bih ) ); bih.biSize = sizeof( bih ); bih.biPlanes = 1; bih.biCompression = BI_RGB; bih.biBitCount = 24; ICINFO ii; ZeroMemory( &ii, sizeof( ii ) ); ii.dwSize = sizeof( ii ); for ( DWORD i = 0; ICInfo( ICTYPE_VIDEO, i, &ii ); i++ ) { // This one is valid DWORD fourCC = ii.fccHandler; HIC hIc = ICOpen( ii.fccType, ii.fccHandler, ICMODE_QUERY ); if ( hIc != NULL ) { // Ensure it supports our video type if ( ii.fccType == ICTYPE_VIDEO && // ICCompressQuery( hIc, &bih, NULL ) == ICERR_OK && ICGetInfo( hIc, &ii, sizeof( ii ) ) ) { char str[ 256 ] = { 0 }; wcstombs( str, ii.szDescription, sizeof( str ) ); // Save codec info LPCODECINFO pci = (LPCODECINFO)m_codecs.NewObj( sizeof( CODECINFO ), NULL, i, str ); if ( pci != NULL ) { // Save data pci->bConfig = ICQueryConfigure( hIc ) != ICERR_OK; // Backwards??? pci->fourCC = fourCC; // Get settings int item = m_comboCodec.AddString( str ); if ( item != CB_ERR ) m_comboCodec.SetItemData( item, (DWORD)pci ); } // end if } // end if ICClose( hIc ); } // end if // Next codec ZeroMemory( &ii, sizeof( ii ) ); ii.dwSize = sizeof( ii ); i++; } // end while }
void CVideoOptions::RefreshCompressorButtons() { int sel = ((CComboBox *) GetDlgItem(IDC_COMPRESSORS))->GetCurSel(); if (sel != CB_ERR) { HIC hic = ICOpen(compressor_info[sel].fccType, compressor_info[sel].fccHandler, ICMODE_QUERY); if (hic) { if (ICQueryAbout(hic)) ((CButton *) GetDlgItem(ID_ABOUT))->EnableWindow(TRUE); else ((CButton *) GetDlgItem(ID_ABOUT))->EnableWindow(FALSE); if (ICQueryConfigure(hic)) ((CButton *) GetDlgItem(ID_CONFIGURE))->EnableWindow(TRUE); else ((CButton *) GetDlgItem(ID_CONFIGURE))->EnableWindow(FALSE); ICClose(hic); } } }
static HIC try_driver(driver_info_t *info) { HIC hic; if ((hic = ICOpen(info->fccType, info->fccHandler, info->wMode))) { if (!ICSendMessage(hic, info->querymsg, (DWORD_PTR)info->lpbiIn, (DWORD_PTR)info->lpbiOut)) return hic; ICClose(hic); } return 0; }
//Ver 1.2 // Note : Because the program stores the state for only one compressor (in the // pVideoCompressParams), if the user chooses "Configure" for compressor A, then // chooses another compressor B and presses "Configure" again the previous state // info for compressor A will be lost. void CVideoOptionsDlg::OnConfigure() { int sel = m_ctrlCBCompressor.GetCurSel(); if (sel != CB_ERR) { // Still unable to handle DIVX state (results in error) //if (pCompressorInfo[sel].fccHandler == mmioFOURCC('D', 'I', 'V', 'X')) // return; //TODO, How long is this code stil experimental and soo in use ??? #define EXPERIMENTAL_CODE #ifdef EXPERIMENTAL_CODE CHIC chic; if (chic.Open(pCompressorInfo[sel].fccType, pCompressorInfo[sel].fccHandler, ICMODE_QUERY)) { // Set our current Video Compress State Info into the hic, // which will update the ICConfigure Dialog SetVideoCompressState(chic, chic.Handler()); chic.Configure(m_hWnd); // Get Video Compress State Info from the hic after adjustment with the // ICConfigure dialog. This will set the external pVideoCompressParams // variable which is used by AVICOMPRESSOPTIONS (This means the external // variable pVideoCompressParams will be changed even if user press "Cancel") DWORD dwSize = chic.GetStateSize(); LRESULT lResult = chic.GetState(m_cOpts.State(dwSize), dwSize); // if (lResult != dwSize) ==> C4244 Warning, type mismatch if ( lResult - dwSize != 0 ) // Save { m_cOpts.State(0L); } } #else HIC hic = ICOpen(pCompressorInfo[sel].fccType, pCompressorInfo[sel].fccHandler, ICMODE_QUERY); if (hic) { // Set our current Video Compress State Info into the hic, which will // update the ICConfigure Dialog SetVideoCompressState(hic, pCompressorInfo[sel].fccHandler); ICConfigure(hic, m_hWnd); // Get Video Compress State Info from the hic after adjustment with the // ICConfigure dialog. This will set the external pVideoCompressParams // variable which is used by AVICOMPRESSOPTIONS (This means the external // variable pVideoCompressParams will be changed even if user press "Cancel") GetVideoCompressState(hic, pCompressorInfo[sel].fccHandler); ICClose(hic); } #endif #undef EXPERIMENTAL_CODE } }
static HRESULT ensure_driver(AVICompressor *This) { if(This->hic) return S_OK; This->hic = ICOpen(FCC('v','i','d','c'), This->fcc_handler, ICMODE_COMPRESS); if(!This->hic) { FIXME("ICOpen failed\n"); return E_FAIL; } return S_OK; }
static BOOL enum_compressors(HWND list, COMPVARS *pcv, BOOL enum_all) { UINT id, total = 0; ICINFO icinfo; id = 0; while (ICInfo(pcv->fccType, id, &icinfo)) { struct codec_info *ic; DWORD idx; HIC hic; id++; hic = ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_COMPRESS); if (hic) { /* for unknown reason fccHandler reported by the driver * doesn't always work, use the one returned by ICInfo instead. */ DWORD fccHandler = icinfo.fccHandler; if (!enum_all && pcv->lpbiIn) { if (ICCompressQuery(hic, pcv->lpbiIn, NULL) != ICERR_OK) { TRACE("fccHandler %s doesn't support input DIB format %d\n", wine_dbgstr_fcc(icinfo.fccHandler), pcv->lpbiIn->bmiHeader.biCompression); ICClose(hic); continue; } } ICGetInfo(hic, &icinfo, sizeof(icinfo)); icinfo.fccHandler = fccHandler; idx = SendMessageW(list, CB_ADDSTRING, 0, (LPARAM)icinfo.szDescription); ic = HeapAlloc(GetProcessHeap(), 0, sizeof(struct codec_info)); ic->icinfo = icinfo; ic->hic = hic; SendMessageW(list, CB_SETITEMDATA, idx, (LPARAM)ic); } total++; } return total != 0; }
bool CCamAvi::Initialize (char* filename) { long hr; AVISTREAMINFO info; m_init=false; m_pos=0; AVIFileInit (); hr=AVIFileOpen (&m_paf, filename, OF_READ, NULL); if (hr!=0) return false; hr=AVIFileGetStream (m_paf, &m_pas, streamtypeVIDEO, 0); if (hr!=0) return false; hr= AVIStreamInfo (m_pas, &info, sizeof (info)); if (hr!=0) return false; hr=sizeof (m_bi); hr= AVIStreamReadFormat (m_pas, 0, &m_bi, &hr); if (hr!=0) return false; if (m_bi.bmiHeader.biCompression!=0) { // find decompressor m_hic=ICOpen (ICTYPE_VIDEO, info.fccHandler ,ICMODE_DECOMPRESS); if (m_hic==0) return false; } m_data=new unsigned char[m_bi.bmiHeader.biSizeImage]; AVISTREAMINFO a; AVIStreamInfo (m_pas, &a, sizeof (a)); m_length=a.dwLength; hr=AVIStreamBeginStreaming (m_pas, 0, 100, 1000); m_init=true; m_FrameRate = (double)a.dwRate / a.dwScale; m_pos=AVIStreamStart (m_pas); m_data=new BYTE[m_bi.bmiHeader.biSizeImage]; if (m_bi.bmiHeader.biCompression!=0) { hr=ICDecompressGetFormat (m_hic, &m_bi, &m_bi_out); } else m_bi_out=m_bi; m_frame.Create (m_bi_out.bmiHeader.biWidth, m_bi_out.bmiHeader.biHeight, m_bi_out.bmiHeader.biBitCount); return true; }
void EnumVCM(bool bEnc) { ICINFO info; char buf[256]; for (int i = 0; ICInfo(ICTYPE_VIDEO, i, &info); i++) { HIC hic = ICOpen(ICTYPE_VIDEO, info.fccHandler, bEnc ? ICMODE_COMPRESS : ICMODE_DECOMPRESS); if (hic == NULL) continue; ICGetInfo(hic, &info, sizeof(info)); ICClose(hic); wsprintf(buf, "VCM\t%d\t%S\t%c%c%c%c\n", bEnc, info.szDescription, FCC4PRINTF(info.fccHandler)); printf("%s", buf); } }
void CVideoOptions::OnAbout() { // TODO: Add your control notification handler code here int sel = ((CComboBox *) GetDlgItem(IDC_COMPRESSORS))->GetCurSel(); if (sel != CB_ERR) { HIC hic = ICOpen(compressor_info[sel].fccType, compressor_info[sel].fccHandler, ICMODE_QUERY); if (hic) { ICAbout(hic,m_hWnd); ICClose(hic); } } }
QMap<std::wstring, bool> AviCodecRestrictions::getUsableCodecs(const TDimension &resolution) { QMap<std::wstring, bool> codecs; HIC hic = 0; ICINFO icinfo; memset(&icinfo, 0, sizeof(ICINFO)); char descr[2048], name[2048]; DWORD fccType = 0; BITMAPINFO inFmt; memset(&inFmt, 0, sizeof(BITMAPINFO)); inFmt.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); inFmt.bmiHeader.biWidth = inFmt.bmiHeader.biHeight = 100; inFmt.bmiHeader.biPlanes = 1; inFmt.bmiHeader.biCompression = BI_RGB; int bpp; for (bpp = 32; (bpp >= 24); bpp -= 8) { //find the codec. inFmt.bmiHeader.biBitCount = bpp; for (int i = 0; ICInfo(fccType, i, &icinfo); i++) { hic = ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_COMPRESS); ICGetInfo(hic, &icinfo, sizeof(ICINFO)); // Find out the compressor name WideCharToMultiByte(CP_ACP, 0, icinfo.szDescription, -1, descr, sizeof(descr), 0, 0); WideCharToMultiByte(CP_ACP, 0, icinfo.szName, -1, name, sizeof(name), 0, 0); std::wstring compressorName; compressorName = toWideString(std::string(name) + " '" + toString(bpp) + "' " + std::string(descr)); if (hic) { if (ICCompressQuery(hic, &inFmt, NULL) != ICERR_OK) { ICClose(hic); continue; // Skip this compressor if it can't handle the format. } codecs[compressorName] = canWork(hic, resolution, bpp); ICClose(hic); } } } return codecs; }
void CPgPubExtra::OnSettings() { CReg *pReg = (CReg*)CDlgTabFrame::GetData( GetSafeHwnd() ); if ( pReg == NULL ) return; CRKey *pRk = pReg->FindKey( "PUBINFO" ); if ( pRk == NULL ) return; int sel = m_comboCodec.GetCurSel(); if ( sel == CB_ERR ) return; // Get data pointer LPCODECINFO pci = (LPCODECINFO)m_comboCodec.GetItemData( sel ); if ( pci == NULL || !m_codecs.VerifyPointer( pci ) ) return; // Attempt to open settings dialog HIC hIc = ICOpen( ICTYPE_VIDEO, pci->fourCC, ICMODE_QUERY ); if ( hIc != NULL ) { DWORD size = pRk->GetValueSize( "CodecData" ); LPBYTE buf = (LPBYTE)pRk->GetValuePtr( "CodecData" ); // Restore settings if ( size > 0 && buf != NULL ) ICSetState( hIc, buf, size ); // Configure the compressor if ( ICConfigure( hIc, GetSafeHwnd() ) != ICERR_OK ) return; size = ICGetStateSize( hIc ); if ( size > 0 ) { TMem< BYTE > mem; if ( mem.allocate( size ) ) if ( ICGetState( hIc, mem.ptr(), size ) == ICERR_OK ) pRk->Set( "CodecData", mem.ptr(), size ); } // end if ICClose( hIc ); } // end if }
INT_PTR CALLBACK Frameserver::StatusDlgProc2( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: SetWindowLongPtr(hWnd, DWLP_USER, lParam); SetDlgItemText(hWnd, IDC_STATIC_FSNAME, ((Frameserver *)lParam)->lpszFsname); SetTimer(hWnd,1,1000,NULL); { HKEY hkey; HIC hic; BOOL fAVIFile = FALSE, fVCM = FALSE; if (RegOpenKeyEx(HKEY_CLASSES_ROOT, "CLSID\\{894288E0-0948-11D2-8109-004845000EB5}\\InProcServer32\\AVIFile", 0, KEY_QUERY_VALUE, &hkey)==ERROR_SUCCESS) { RegCloseKey(hkey); fAVIFile = TRUE; } if (hic = ICOpen('CDIV', 'TSDV', ICMODE_DECOMPRESS)) { ICClose(hic); fVCM = TRUE; } if (fAVIFile && fVCM) SetDlgItemText(hWnd, IDC_STATIC_FCINSTALLED, "AVIFile and VCM"); else if (fAVIFile) SetDlgItemText(hWnd, IDC_STATIC_FCINSTALLED, "AVIFile only"); else if (fVCM) SetDlgItemText(hWnd, IDC_STATIC_FCINSTALLED, "VCM only"); } return TRUE; case WM_COMMAND: if (LOWORD(wParam) != IDOK) break; case WM_CLOSE: mbExit = true; return TRUE; case WM_TIMER: SetDlgItemInt(hWnd, IDC_STATIC_REQCOUNT, lRequestCount, FALSE); SetDlgItemInt(hWnd, IDC_STATIC_FRAMECNT, lFrameCount, FALSE); SetDlgItemInt(hWnd, IDC_STATIC_AUDIOSEGS, lAudioSegCount, FALSE); return TRUE; } return FALSE; }
void CAviFile::GetCompressorList( CStringList &List, BITMAPINFO &SourceBitmapInfo ) { /////////////////////////////////////////////////////////// LPBITMAPINFOHEADER lpbi = 0; HIC hIC; ICINFO icinfo; int fccType = ICTYPE_VIDEO; //0 to get all installed codecs for (int i=0; ICInfo(fccType, i, &icinfo); i++) { hIC = ICOpen(icinfo.fccType, icinfo.fccHandler, ICMODE_QUERY); if (hIC) { //Find out the compressor name. ICGetInfo(hIC, &icinfo, sizeof(icinfo)); //Skip this compressor if it can't handle the format. if (fccType == ICTYPE_VIDEO ) { if( icinfo.dwFlags != 0 ) { if( ICCompressQuery( hIC, &SourceBitmapInfo, NULL ) == ICERR_OK ) { CString Temp = CString( icinfo.szDescription ); if( icinfo.fccHandler == 1129730893 ) Temp += " - Low Resolution"; Temp += " ("; Temp.Append( (const char*)&icinfo.fccHandler, 4 ); // Assuming little endian system. Temp += ")"; List.AddTail( Temp ); } } } //check here whether it is the driver you want ICClose(hIC); } } }
/*********************************************************************** * ICOpen [MSVIDEO.203] */ HIC16 VFWAPI ICOpen16(DWORD fccType, DWORD fccHandler, UINT16 wMode) { return HIC_16(ICOpen(fccType, fccHandler, wMode)); }
IplImage* CvCaptureCAM_VFW::retrieveFrame(int) { BITMAPINFO vfmt; memset( &vfmt, 0, sizeof(vfmt)); BITMAPINFOHEADER& vfmt0 = vfmt.bmiHeader; if( !capWnd ) return 0; const DWORD sz = capGetVideoFormat( capWnd, &vfmt, sizeof(vfmt)); const int prevWidth = frame ? frame->width : 0; const int prevHeight = frame ? frame->height : 0; if( !hdr || hdr->lpData == 0 || sz == 0 ) return 0; if( !frame || frame->width != vfmt0.biWidth || frame->height != vfmt0.biHeight ) { cvReleaseImage( &frame ); frame = cvCreateImage( cvSize( vfmt0.biWidth, vfmt0.biHeight ), 8, 3 ); } if ( vfmt0.biCompression == MAKEFOURCC('N','V','1','2') ) { // Frame is in YUV 4:2:0 NV12 format, convert to BGR color space // See https://msdn.microsoft.com/en-us/library/windows/desktop/dd206750(v=vs.85).aspx#nv12) IplImage src; cvInitImageHeader( &src, cvSize( vfmt0.biWidth, vfmt0.biHeight * 3 / 2 ), IPL_DEPTH_8U, 1, IPL_ORIGIN_BL, 4 ); cvSetData( &src, hdr->lpData, src.widthStep ); cvCvtColor( &src, frame, CV_YUV2BGR_NV12 ); } else if( vfmt0.biCompression != BI_RGB || vfmt0.biBitCount != 24 ) { BITMAPINFOHEADER vfmt1 = icvBitmapHeader( vfmt0.biWidth, vfmt0.biHeight, 24 ); if( hic == 0 || fourcc != vfmt0.biCompression || prevWidth != vfmt0.biWidth || prevHeight != vfmt0.biHeight ) { closeHIC(); hic = ICOpen( MAKEFOURCC('V','I','D','C'), vfmt0.biCompression, ICMODE_DECOMPRESS ); if( hic ) { if( ICDecompressBegin( hic, &vfmt0, &vfmt1 ) != ICERR_OK ) { closeHIC(); return 0; } } } if( !hic || ICDecompress( hic, 0, &vfmt0, hdr->lpData, &vfmt1, frame->imageData ) != ICERR_OK ) { closeHIC(); return 0; } cvFlip( frame, frame, 0 ); } else { IplImage src; cvInitImageHeader( &src, cvSize(vfmt0.biWidth, vfmt0.biHeight), IPL_DEPTH_8U, 3, IPL_ORIGIN_BL, 4 ); cvSetData( &src, hdr->lpData, src.widthStep ); cvFlip( &src, frame, 0 ); } return frame; }
/*********************************************************************** * DrawDibBegin [MSVFW32.@] */ BOOL VFWAPI DrawDibBegin(HDRAWDIB hdd, HDC hdc, INT dxDst, INT dyDst, LPBITMAPINFOHEADER lpbi, INT dxSrc, INT dySrc, UINT wFlags) { BOOL ret = TRUE; WINE_HDD *whdd; TRACE("(%p,%p,%d,%d,%p,%d,%d,0x%08x)\n", hdd, hdc, dxDst, dyDst, lpbi, dxSrc, dySrc, wFlags); TRACE("lpbi: %d,%d/%d,%d,%d,%d,%d,%d,%d,%d,%d\n", lpbi->biSize, lpbi->biWidth, lpbi->biHeight, lpbi->biPlanes, lpbi->biBitCount, lpbi->biCompression, lpbi->biSizeImage, lpbi->biXPelsPerMeter, lpbi->biYPelsPerMeter, lpbi->biClrUsed, lpbi->biClrImportant); if (wFlags & ~(DDF_BUFFER)) FIXME("wFlags == 0x%08x not handled\n", wFlags & ~(DDF_BUFFER)); whdd = MSVIDEO_GetHddPtr(hdd); if (!whdd) return FALSE; if (whdd->begun) DrawDibEnd(hdd); if (lpbi->biCompression) { DWORD size = 0; whdd->hic = ICOpen(ICTYPE_VIDEO, lpbi->biCompression, ICMODE_DECOMPRESS); if (!whdd->hic) { WARN("Could not open IC. biCompression == 0x%08x\n", lpbi->biCompression); ret = FALSE; } if (ret) { size = ICDecompressGetFormat(whdd->hic, lpbi, NULL); if (size == ICERR_UNSUPPORTED) { WARN("Codec doesn't support GetFormat, giving up.\n"); ret = FALSE; } } if (ret) { whdd->lpbiOut = HeapAlloc(GetProcessHeap(), 0, size); if (ICDecompressGetFormat(whdd->hic, lpbi, whdd->lpbiOut) != ICERR_OK) ret = FALSE; } if (ret) { /* FIXME: Use Ex functions if available? */ if (ICDecompressBegin(whdd->hic, lpbi, whdd->lpbiOut) != ICERR_OK) ret = FALSE; TRACE("biSizeImage == %d\n", whdd->lpbiOut->biSizeImage); TRACE("biCompression == %d\n", whdd->lpbiOut->biCompression); TRACE("biBitCount == %d\n", whdd->lpbiOut->biBitCount); } } else { DWORD dwSize; /* No compression */ TRACE("Not compressed!\n"); if (lpbi->biHeight <= 0) { /* we don't draw inverted DIBs */ TRACE("detected inverted DIB\n"); ret = FALSE; } else { dwSize = lpbi->biSize + num_colours(lpbi)*sizeof(RGBQUAD); whdd->lpbiOut = HeapAlloc(GetProcessHeap(), 0, dwSize); memcpy(whdd->lpbiOut, lpbi, dwSize); } } if (ret) { /*whdd->lpvbuf = HeapAlloc(GetProcessHeap(), 0, whdd->lpbiOut->biSizeImage);*/ whdd->hMemDC = CreateCompatibleDC(hdc); TRACE("Creating: %d, %p\n", whdd->lpbiOut->biSize, whdd->lpvbits); whdd->hDib = CreateDIBSection(whdd->hMemDC, (BITMAPINFO *)whdd->lpbiOut, DIB_RGB_COLORS, &(whdd->lpvbits), 0, 0); if (whdd->hDib) { TRACE("Created: %p,%p\n", whdd->hDib, whdd->lpvbits); } else { ret = FALSE; TRACE("Error: %d\n", GetLastError()); } whdd->hOldDib = SelectObject(whdd->hMemDC, whdd->hDib); } if (ret) { whdd->hdc = hdc; whdd->dxDst = dxDst; whdd->dyDst = dyDst; whdd->lpbi = HeapAlloc(GetProcessHeap(), 0, lpbi->biSize); memcpy(whdd->lpbi, lpbi, lpbi->biSize); whdd->dxSrc = dxSrc; whdd->dySrc = dySrc; whdd->begun = TRUE; whdd->hpal = 0; } else { if (whdd->hic) ICClose(whdd->hic); HeapFree(GetProcessHeap(), 0, whdd->lpbiOut); whdd->lpbiOut = NULL; } return ret; }
// init driver static int init(sh_video_t *sh){ HRESULT ret; // unsigned int outfmt=sh->codec->outfmt[sh->outfmtidx]; int i, o_bih_len; vd_vfw_ctx *priv; const char *dll = codec_idx2str(sh->codec->dll_idx); /* Hack for VSSH codec: new dll can't decode old files * In my samples old files have no extradata, so use that info * to decide what dll should be used (here and in vd_dshow). */ if (!strcmp(dll, "vssh264.dll") && (sh->bih->biSize > 40)) return 0; priv = malloc(sizeof(vd_vfw_ctx)); if (!priv) return 0; memset(priv, 0, sizeof(vd_vfw_ctx)); sh->context = priv; mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (VFW) VIDEO Codec init =======\n"); // win32_codec_name = dll; // sh->hic = ICOpen( 0x63646976, sh->bih->biCompression, ICMODE_FASTDECOMPRESS); // priv->handle = ICOpen( 0x63646976, sh->bih->biCompression, ICMODE_DECOMPRESS); priv->handle = ICOpen( (long)(dll), sh->bih->biCompression, ICMODE_DECOMPRESS); if(!priv->handle){ mp_msg(MSGT_WIN32,MSGL_ERR,"ICOpen failed! unknown codec / wrong parameters?\n"); return 0; } // sh->bih->biBitCount=32; o_bih_len = ICDecompressGetFormatSize(priv->handle, sh->bih); if(o_bih_len < sizeof(BITMAPINFOHEADER)){ mp_msg(MSGT_WIN32,MSGL_ERR,"ICDecompressGetFormatSize returned a bogus value: %d\n", o_bih_len); return 0; } priv->o_bih = malloc(o_bih_len); memset(priv->o_bih, 0, o_bih_len); mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressGetFormatSize ret: %d\n", o_bih_len); ret = ICDecompressGetFormat(priv->handle, sh->bih, priv->o_bih); if(ret < 0){ mp_msg(MSGT_WIN32,MSGL_ERR,"ICDecompressGetFormat failed: Error %d\n", (int)ret); for (i=0; i < o_bih_len; i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02x ", priv->o_bih[i]); return 0; } mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressGetFormat OK\n"); #if 0 // workaround for pegasus MJPEG: if(!sh_video->o_bih.biWidth) sh_video->o_bih.biWidth=sh_video->bih->biWidth; if(!sh_video->o_bih.biHeight) sh_video->o_bih.biHeight=sh_video->bih->biHeight; if(!sh_video->o_bih.biPlanes) sh_video->o_bih.biPlanes=sh_video->bih->biPlanes; #endif // ok let libvo and vd core to handshake and decide the optimal csp: if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YUY2)) return 0; if (!(sh->codec->outflags[sh->outfmtidx]&CODECS_FLAG_FLIP)) { priv->o_bih->biHeight=-sh->bih->biHeight; // flip image! } // ok, let's set the choosen colorspace: set_csp(priv->o_bih,sh->codec->outfmt[sh->outfmtidx]); // fake it to RGB for broken DLLs (divx3) if(sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_YUVHACK) priv->o_bih->biCompression = 0; // sanity check: #ifdef BUILD_VFWEX ret = ICDecompressQueryEx(priv->handle, sh->bih, priv->o_bih); #else ret = ICDecompressQuery(priv->handle, sh->bih, priv->o_bih); #endif if (ret) { mp_msg(MSGT_WIN32,MSGL_WARN,"ICDecompressQuery failed: Error %d\n", (int)ret); // return 0; } else mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressQuery OK\n"); #ifdef BUILD_VFWEX ret = ICDecompressBeginEx(priv->handle, sh->bih, priv->o_bih); #else ret = ICDecompressBegin(priv->handle, sh->bih, priv->o_bih); #endif if (ret) { mp_msg(MSGT_WIN32,MSGL_WARN,"ICDecompressBegin failed: Error %d\n", (int)ret); // return 0; } // for broken codecs set it again: if(sh->codec->outflags[sh->outfmtidx] & CODECS_FLAG_YUVHACK) set_csp(priv->o_bih,sh->codec->outfmt[sh->outfmtidx]); mp_msg(MSGT_WIN32, MSGL_V, "Input format:\n"); if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_video_header(sh->bih,MSGL_V); mp_msg(MSGT_WIN32, MSGL_V, "Output format:\n"); if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_video_header(priv->o_bih,MSGL_V); // set postprocessing level in xvid/divx4 .dll ICSendMessage(priv->handle, ICM_USER+80, (long)(&divx_quality), 0); // don't do this palette mess always, it makes div3 dll crashing... if(sh->codec->outfmt[sh->outfmtidx]==IMGFMT_BGR8){ if(ICDecompressGetPalette(priv->handle, sh->bih, priv->o_bih)){ priv->palette = (unsigned char*)(priv->o_bih+1); mp_msg(MSGT_WIN32,MSGL_V,"ICDecompressGetPalette OK\n"); } else { if(sh->bih->biSize>=40+4*4) priv->palette = (unsigned char*)(sh->bih+1); } } mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32 video codec init OK!\n"); return 1; }
int PGRAviFile::enumerateCompressors( int iRows, int iCols, int iBPP, ICINFO* picinfo, int iNumICInfo ) { // If picinfo is NULL, then we are retreiving the number of // usable compressors at the current settings so we can allocate // enough memory. bool bpicinfoNull = picinfo == NULL; ICINFO* picinfoTemp = new ICINFO[ 50 ]; HIC hic; BITMAPINFOHEADER bih; // Initialize the bitmap structure. bih.biSize = sizeof( BITMAPINFOHEADER ); bih.biPlanes = 1; bih.biCompression = BI_RGB; bih.biXPelsPerMeter = 100; bih.biYPelsPerMeter = 100; bih.biClrUsed = 0; bih.biClrImportant = 0; bih.biWidth = iCols; bih.biHeight = iRows; bih.biBitCount = (unsigned short)iBPP; bih.biSizeImage = bih.biWidth * bih.biHeight * ( bih.biBitCount / 8 ); int iNumCompressors = 0; bool bICInfoFull = false; for( int i = 0; ICInfo( 0, i, &picinfoTemp[ i ] ) && !bICInfoFull; i++ ) { // Open the compressor so we can query it. hic = ICOpen( picinfoTemp[ i ].fccType, picinfoTemp[ i ].fccHandler, ICMODE_QUERY ); if( hic ) { // Skip this compressor if it can't handle the format. if( ICCompressQuery( hic, &bih, 0 ) != ICERR_OK ) { ICClose( hic ); continue; } // Find out the compressor info. if( !bpicinfoNull ) { ICGetInfo( hic, &picinfo[ iNumCompressors ], sizeof( ICINFO ) ); } iNumCompressors++; if( !bpicinfoNull && (iNumCompressors == iNumICInfo) ) { bICInfoFull = true; } // Close the compressor. ICClose( hic ); } } delete [] picinfoTemp; return iNumCompressors; }
static void test_ICSeqCompress(void) { /* The purpose of this test is to validate sequential frame compressing * functions. The MRLE codec will be used because Wine supports it and * it is present in any Windows. */ HIC h; DWORD err, vidc = mmioFOURCC('v','i','d','c'), mrle = mmioFOURCC('m', 'r', 'l', 'e'); DWORD i; LONG frame_len; BOOL key_frame, ret; char *frame; COMPVARS pc; struct { BITMAPINFOHEADER header; RGBQUAD map[256]; } input_header = { {sizeof(BITMAPINFOHEADER), 32, 1, 1, 8, 0, 32*8, 0, 0, 256, 256}, {{255,0,0}, {0,255,0}, {0,0,255}, {255,255,255}}}; PBITMAPINFO bitmap = (PBITMAPINFO) &input_header; static BYTE input[32] = {1,2,3,3,3,3,2,3,1}; static const BYTE output_kf[] = {1,1,1,2,4,3,0,3,2,3,1,0,23,0,0,0,0,1}, /* key frame*/ output_nkf[] = {0,0,0,1}; /* non key frame */ h = ICOpen(vidc, mrle, ICMODE_COMPRESS); ok(h != NULL, "Expected non-NULL\n"); pc.cbSize = sizeof(pc); pc.dwFlags = ICMF_COMPVARS_VALID; pc.fccType = vidc; pc.fccHandler = mrle; pc.hic = h; pc.lpbiIn = NULL; pc.lpbiOut = NULL; pc.lpBitsOut = pc.lpBitsPrev = pc.lpState = NULL; pc.lQ = ICQUALITY_DEFAULT; pc.lKey = 1; pc.lDataRate = 300; pc.lpState = NULL; pc.cbState = 0; ret = ICSeqCompressFrameStart(&pc, bitmap); ok(ret == TRUE, "Expected TRUE\n"); /* Check that reserved pointers were allocated */ ok(pc.lpbiIn != NULL, "Expected non-NULL\n"); ok(pc.lpbiOut != NULL, "Expected non-NULL\n"); for(i = 0; i < 9; i++) { frame_len = 0; frame = ICSeqCompressFrame(&pc, 0, input, &key_frame, &frame_len); ok(frame != NULL, "Frame[%d]: Expected non-NULL\n", i); if (frame_len == sizeof(output_nkf)) ok(!memcmp(output_nkf, frame, frame_len), "Frame[%d]: Contents do not match\n", i); else if (frame_len == sizeof(output_kf)) ok(!memcmp(output_kf, frame, frame_len), "Frame[%d]: Contents do not match\n", i); else ok(0, "Unknown frame size of %d byten\n", frame_len); } ICSeqCompressFrameEnd(&pc); ICCompressorFree(&pc); /* ICCompressorFree already closed the HIC */ err = ICClose(h); ok(err == ICERR_BADHANDLE, "Expected -8, got %d\n", err); }
//int init_vfw_encoder(char *dll_name, BITMAPINFOHEADER *input_bih, BITMAPINFOHEADER *output_bih) static BITMAPINFOHEADER* vfw_open_encoder(char *dll_name, char *compdatafile, BITMAPINFOHEADER *input_bih,unsigned int out_fourcc) { HRESULT ret; BITMAPINFOHEADER* output_bih=NULL; int temp_len; FILE *fd=NULL; char *drvdata=NULL; struct stat st; //sh_video = malloc(sizeof(sh_video_t)); mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (VFW) VIDEO Encoder init =======\n"); CoInitRes = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); // memset(&sh_video->o_bih, 0, sizeof(BITMAPINFOHEADER)); // output_bih->biSize = sizeof(BITMAPINFOHEADER); // encoder_hic = ICOpen( 0x63646976, out_fourcc, ICMODE_COMPRESS); encoder_hic = ICOpen( (long) dll_name, out_fourcc, ICMODE_COMPRESS); if(!encoder_hic){ mp_msg(MSGT_WIN32,MSGL_ERR,"ICOpen failed! unknown codec / wrong parameters?\n"); return NULL; } mp_msg(MSGT_WIN32,MSGL_INFO,"HIC: %x\n", encoder_hic); #if 1 { ICINFO icinfo; ret = ICGetInfo(encoder_hic, &icinfo, sizeof(ICINFO)); mp_msg(MSGT_WIN32,MSGL_INFO,"%ld - %ld - %d\n", ret, icinfo.dwSize, sizeof(ICINFO)); mp_msg(MSGT_WIN32,MSGL_INFO,MSGTR_MPCODECS_CompressorType, icinfo.fccType); mp_msg(MSGT_WIN32,MSGL_INFO,MSGTR_MPCODECS_CompressorSubtype, icinfo.fccHandler); mp_msg(MSGT_WIN32,MSGL_INFO,MSGTR_MPCODECS_CompressorFlags, icinfo.dwFlags, icinfo.dwVersion, icinfo.dwVersionICM); //printf("Compressor name: %s\n", icinfo.szName); //printf("Compressor description: %s\n", icinfo.szDescription); mp_msg(MSGT_WIN32,MSGL_INFO,MSGTR_MPCODECS_Flags); if (icinfo.dwFlags & VIDCF_QUALITY) mp_msg(MSGT_WIN32,MSGL_INFO,MSGTR_MPCODECS_Quality); if (icinfo.dwFlags & VIDCF_FASTTEMPORALD) mp_msg(MSGT_WIN32,MSGL_INFO," fast-decompr"); if (icinfo.dwFlags & VIDCF_QUALITYTIME) mp_msg(MSGT_WIN32,MSGL_INFO," temp-quality"); mp_msg(MSGT_WIN32,MSGL_INFO,"\n"); } #endif if(compdatafile){ if (!strncmp(compdatafile, "dialog", 6)){ if (ICSendMessage(encoder_hic, ICM_CONFIGURE, -1, 0) != ICERR_OK){ mp_msg(MSGT_WIN32,MSGL_ERR,"Compressor doesn't have a configure dialog!\n"); return NULL; } if (ICSendMessage(encoder_hic, ICM_CONFIGURE, 0, 0) != ICERR_OK){ mp_msg(MSGT_WIN32,MSGL_ERR,"Compressor configure dialog failed!\n"); return NULL; } } else { if (stat(compdatafile, &st) < 0){ mp_msg(MSGT_WIN32,MSGL_ERR,"Compressor data file not found!\n"); return NULL; } fd = fopen(compdatafile, "rb"); if (!fd){ mp_msg(MSGT_WIN32,MSGL_ERR,"Cannot open Compressor data file!\n"); return NULL; } drvdata = (char *) malloc(st.st_size); if (fread(drvdata, st.st_size, 1, fd) != 1) { mp_msg(MSGT_WIN32,MSGL_ERR,"Cannot read Compressor data file!\n"); fclose(fd); free(drvdata); return NULL; } fclose(fd); mp_msg(MSGT_WIN32,MSGL_ERR,"Compressor data %d bytes\n", st.st_size); if (!(temp_len = (unsigned int) ICSendMessage(encoder_hic, ICM_SETSTATE, (LPARAM) drvdata, (int) st.st_size))){ mp_msg(MSGT_WIN32,MSGL_ERR,"ICSetState failed!\n"); free(drvdata); return NULL; } free(drvdata); mp_msg(MSGT_WIN32,MSGL_INFO,"ICSetState ret: %d\n", temp_len); } } temp_len = ICCompressGetFormatSize(encoder_hic, input_bih); mp_msg(MSGT_WIN32,MSGL_INFO,"ICCompressGetFormatSize ret: %d\n", temp_len); if (temp_len < sizeof(BITMAPINFOHEADER)) temp_len=sizeof(BITMAPINFOHEADER); output_bih = malloc(temp_len+4); memset(output_bih,0,temp_len); output_bih->biSize = temp_len; //sizeof(BITMAPINFOHEADER); return output_bih; }
IplImage* CvCaptureCAM_VFW::retrieveFrame(int) { BITMAPINFO vfmt; memset( &vfmt, 0, sizeof(vfmt)); BITMAPINFOHEADER& vfmt0 = vfmt.bmiHeader; if( !capWnd ) return 0; const DWORD sz = capGetVideoFormat( capWnd, &vfmt, sizeof(vfmt)); const int prevWidth = frame ? frame->width : 0; const int prevHeight = frame ? frame->height : 0; if( !hdr || hdr->lpData == 0 || sz == 0 ) return 0; if( !frame || frame->width != vfmt0.biWidth || frame->height != vfmt0.biHeight ) { cvReleaseImage( &frame ); frame = cvCreateImage( cvSize( vfmt0.biWidth, vfmt0.biHeight ), 8, 3 ); } if( vfmt0.biCompression != BI_RGB || vfmt0.biBitCount != 24 ) { BITMAPINFOHEADER vfmt1 = icvBitmapHeader( vfmt0.biWidth, vfmt0.biHeight, 24 ); if( hic == 0 || fourcc != vfmt0.biCompression || prevWidth != vfmt0.biWidth || prevHeight != vfmt0.biHeight ) { closeHIC(); hic = ICOpen( MAKEFOURCC('V','I','D','C'), vfmt0.biCompression, ICMODE_DECOMPRESS ); if( hic ) { if( ICDecompressBegin( hic, &vfmt0, &vfmt1 ) != ICERR_OK ) { closeHIC(); return 0; } } } if( !hic || ICDecompress( hic, 0, &vfmt0, hdr->lpData, &vfmt1, frame->imageData ) != ICERR_OK ) { closeHIC(); return 0; } cvFlip( frame, frame, 0 ); } else { IplImage src; cvInitImageHeader( &src, cvSize(vfmt0.biWidth, vfmt0.biHeight), IPL_DEPTH_8U, 3, IPL_ORIGIN_BL, 4 ); cvSetData( &src, hdr->lpData, src.widthStep ); cvFlip( &src, frame, 0 ); } return frame; }
int AVInfo::GetCodecListSize(int width, int height) { if (m_plCodecList) { for (int i=0; i<m_codecListSize; ++i) delete m_plCodecList[i]; delete[] m_plCodecList; m_plCodecList = NULL; m_codecListSize = 0; } BITMAPINFO bmi; Make24BitRGB(&bmi.bmiHeader, width, height); ICINFO icInfo; ZeroMemory(&icInfo, sizeof ICINFO); icInfo.dwSize = sizeof ICINFO; int count = 0; std::vector<CODECINFO *> codecList; // The first codec is always uncompressed RGB // data. We can be sure this is the case here CODECINFO *pInfo = new CODECINFO; pInfo->fcc = MAKEFOURCC('D', 'I', 'B', ' '); pInfo->alternativeFcc = BI_RGB; pInfo->bHasAboutDialog = false; pInfo->bHasConfigureDialog = false; pInfo->bSupportsKeyframes = false; pInfo->bSupportsQuality = false; pInfo->nDefaultKeyframeRate = 1; pInfo->nDefaultQuality = 100; _tcscpy(pInfo->tszDescription, _T("DIB : <uncompressed>")); codecList.push_back(pInfo); while (ICInfo(ICTYPE_VIDEO, count, &icInfo)) { HIC hic = ICOpen(icInfo.fccType, icInfo.fccHandler, ICMODE_QUERY); if (hic) { ICINFO moreInfo; ZeroMemory(&moreInfo, sizeof ICINFO); moreInfo.dwSize = sizeof ICINFO; if (ICGetInfo(hic, &moreInfo, sizeof ICINFO) > 0) { // Ignore MSVC/CRAM if (moreInfo.fccHandler != 'CVSM' && moreInfo.fccHandler != 'MARC') { if (ICERR_OK == ICCompressQuery(hic, &bmi, NULL)) { // Ok, this codec seems to be ok; put that // into the list CODECINFO *pInfo = new CODECINFO; ZeroMemory(pInfo, sizeof CODECINFO); char szFcc[5]; if (moreInfo.fccHandler != BI_RGB) { szFcc[0] = (moreInfo.fccHandler & 0x000000ff); szFcc[1] = (moreInfo.fccHandler & 0x0000ff00) >> 8; szFcc[2] = (moreInfo.fccHandler & 0x00ff0000) >> 16; szFcc[3] = (moreInfo.fccHandler & 0xff000000) >> 24; szFcc[4] = 0; } else strcpy(szFcc, "DIB "); bool bIsReallyOk = true; // We know that IV50 has restrictions. if (moreInfo.fccHandler == '05vi' || moreInfo.fccHandler == '05VI') { if (width % 4 != 0 || height % 4 != 0) bIsReallyOk = false; } // The following code should normally check if the codec // is really able encode a certain BITMAPINFO type. But, // This will fail for the HuffYUV codec. Thus, we have to // assume that it might fail for other codecs, too. /* if (moreInfo.fccHandler == BI_RGB) { bIsReallyOk = true; } else { // The codec says that the input format is ok. // Let's try to create an output format and try // again. For some resolutions, e.g. Indeo Video 5 // now fails to compress the format. AM_MEDIA_TYPE mtTmp; ZeroMemory(&mtTmp, sizeof AM_MEDIA_TYPE); bool cool = CreateStreamFormat(moreInfo.fccHandler, width, height, &mtTmp); if (cool) { BITMAPINFO bmiOut; ZeroMemory(&bmiOut, sizeof BITMAPINFO); bmiOut.bmiHeader = ((VIDEOINFOHEADER *) mtTmp.pbFormat)->bmiHeader; DWORD dwOk = ICCompressBegin(hic, &bmi, &bmiOut); if (ICERR_OK == dwOk) { // It's really ok to use this codec. bIsReallyOk = true; ICCompressEnd(hic); } } FreeMediaType(mtTmp); } */ if (bIsReallyOk) { // Copy the name #ifndef _UNICODE _TCHAR tszDesc[128]; if (WideCharToMultiByte(CP_ACP, 0, moreInfo.szDescription, -1, tszDesc, 128, NULL, NULL) == 0) strcpy(tszDesc, "<unknown>"); sprintf(pInfo->tszDescription, "(%s): %s", szFcc, tszDesc); #else _stprintf(pInfo->tszDescription, _T("(%S): %s"), szFcc, moreInfo.szDescription); #endif pInfo->fcc = moreInfo.fccHandler; pInfo->alternativeFcc = icInfo.fccHandler; pInfo->bSupportsKeyframes = (moreInfo.dwFlags & VIDCF_TEMPORAL) > 0; pInfo->bSupportsQuality = (moreInfo.dwFlags & VIDCF_QUALITY) > 0; if (pInfo->bSupportsKeyframes) pInfo->nDefaultKeyframeRate = ICGetDefaultKeyFrameRate(hic); else pInfo->nDefaultKeyframeRate = 0; if (pInfo->bSupportsQuality) pInfo->nDefaultQuality = ICGetDefaultQuality(hic) / 100; else pInfo->nDefaultQuality = 0; pInfo->bHasConfigureDialog = ICQueryConfigure(hic) == TRUE ? true : false; pInfo->bHasAboutDialog = ICQueryAbout(hic) == TRUE ? true : false; codecList.push_back(pInfo); } } } }
static void test_Locate(void) { static BITMAPINFOHEADER bi = {sizeof(BITMAPINFOHEADER),32,8, 1,8, BI_RLE8, 0,100000,100000, 0,0}; static BITMAPINFOHEADER bo = {sizeof(BITMAPINFOHEADER),32,8, 1,8, BI_RGB, 0,100000,100000, 0,0}; HIC h; DWORD err; /* Oddly, MSDN documents that ICLocate takes BITMAPINFOHEADER * pointers, while ICDecompressQuery takes the larger * BITMAPINFO. Probably it's all the same as long as the * variable length color quads are present when they are * needed. */ h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); ok(h != 0, "RLE8->RGB failed\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bo.biHeight = - bo.biHeight; h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); ok(h == 0, "RLE8->RGB height<0 succeeded\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bo.biHeight = - bo.biHeight; bi.biCompression = mmioFOURCC('c','v','i','d'); /* Cinepak */ h = ICOpen(ICTYPE_VIDEO, mmioFOURCC('c','v','i','d'), ICMODE_DECOMPRESS); if (h == 0) win_skip("Cinepak/ICCVID codec not found\n"); else { bo.biBitCount = bi.biBitCount = 32; err = ICDecompressQuery(h, &bi, &bo); ok(err == ICERR_OK, "Query cvid->RGB32: %d\n", err); err = ICDecompressQuery(h, &bi, NULL); ok(err == ICERR_OK, "Query cvid 32: %d\n", err); bo.biHeight = -bo.biHeight; err = ICDecompressQuery(h, &bi, &bo); ok(err == ICERR_OK, "Query cvid->RGB32 height<0: %d\n", err); bo.biHeight = -bo.biHeight; ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bo.biBitCount = bi.biBitCount = 8; h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); todo_wine ok(h != 0, "cvid->RGB8 failed\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bo.biHeight = - bo.biHeight; h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); todo_wine ok(h != 0, "cvid->RGB8 height<0 failed\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bo.biHeight = - bo.biHeight; bo.biBitCount = bi.biBitCount = 16; h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); ok(h != 0, "cvid->RGB16 failed\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bo.biHeight = - bo.biHeight; h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); ok(h != 0, "cvid->RGB16 height<0 failed\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bo.biHeight = - bo.biHeight; bo.biBitCount = bi.biBitCount = 32; h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); ok(h != 0, "cvid->RGB32 failed\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bo.biHeight = - bo.biHeight; h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); ok(h != 0, "cvid->RGB32 height<0 failed\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bo.biHeight = - bo.biHeight; bi.biCompression = mmioFOURCC('C','V','I','D'); /* Unlike ICOpen, upper case fails with ICLocate. */ h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); ok(h == 0, "CVID->RGB32 upper case succeeded\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); } bi.biCompression = mmioFOURCC('M','S','V','C'); /* MS Video 1 */ bo.biBitCount = bi.biBitCount = 16; h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); ok(h != 0, "MSVC->RGB16 failed\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bo.biHeight = - bo.biHeight; h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); todo_wine ok(h != 0, "MSVC->RGB16 height<0 failed\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bo.biHeight = - bo.biHeight; bo.biHeight--; h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); ok(h == 0, "MSVC->RGB16 height too small succeeded\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bo.biHeight++; /* ICLocate wants upper case MSVC */ bi.biCompression = mmioFOURCC('m','s','v','c'); h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); ok(h == 0, "msvc->RGB16 succeeded\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bi.biCompression = mmioFOURCC('M','S','V','C'); h = ICOpen(ICTYPE_VIDEO, mmioFOURCC('M','S','V','C'), ICMODE_DECOMPRESS); ok(h != 0, "No MSVC codec installed!?\n"); if (h != 0) { err = ICDecompressQuery(h, &bi, &bo); ok(err == ICERR_OK, "Query MSVC->RGB16: %d\n", err); err = ICDecompressQuery(h, &bi, NULL); ok(err == ICERR_OK, "Query MSVC 16: %d\n", err); bo.biHeight = -bo.biHeight; err = ICDecompressQuery(h, &bi, &bo); todo_wine ok(err == ICERR_OK, "Query MSVC->RGB16 height<0: %d\n", err); bo.biHeight = -bo.biHeight; bi.biCompression = mmioFOURCC('m','s','v','c'); err = ICDecompressQuery(h, &bi, &bo); ok(err == ICERR_BADFORMAT, "Query msvc->RGB16: %d\n", err); ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); } bi.biCompression = BI_RGB; bo.biBitCount = bi.biBitCount = 8; h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); ok(h != 0, "RGB8->RGB identity failed\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); bi.biCompression = BI_RLE8; h = ICLocate(ICTYPE_VIDEO, 0, &bi, &bo, ICMODE_DECOMPRESS); ok(h != 0, "RLE8->RGB again failed\n"); if (h) ok(ICClose(h) == ICERR_OK,"ICClose failed\n"); }
int imFileFormatAVI::WriteImageInfo() { if (dib) { if (dib->bmih->biWidth != width || dib->bmih->biHeight != height || imColorModeSpace(file_color_mode) != imColorModeSpace(user_color_mode)) return IM_ERR_DATA; return IM_ERR_NONE; // parameters can be set only once } // force bottom up orientation this->file_data_type = IM_BYTE; this->file_color_mode = imColorModeSpace(this->user_color_mode); int bpp; if (this->file_color_mode == IM_RGB) { this->file_color_mode |= IM_PACKED; bpp = 24; if (imColorModeHasAlpha(this->user_color_mode)) { this->file_color_mode |= IM_ALPHA; bpp = 32; this->rmask = 0x00FF0000; this->roff = 16; this->gmask = 0x0000FF00; this->goff = 8; this->bmask = 0x000000FF; this->boff = 0; } } else bpp = 8; this->line_buffer_extra = 4; // room enough for padding imAttribTable* attrib_table = AttribTable(); const void* attrib_data = attrib_table->Get("FPS"); if (attrib_data) fps = *(float*)attrib_data; else fps = 15; if (this->compression[0] == 0 || imStrEqual(this->compression, "NONE")) this->use_compressor = 0; else this->use_compressor = 1; dib = imDibCreate(width, height, bpp); if (use_compressor) { memset(&compvars, 0, sizeof(COMPVARS)); compvars.cbSize = sizeof(COMPVARS); if (imStrEqual(this->compression, "CUSTOM")) { if (ICCompressorChoose(NULL, ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME, dib->dib, NULL, &compvars, "Choose Compression") == FALSE) return IM_ERR_COMPRESS; } else { compvars.dwFlags = ICMF_COMPVARS_VALID; compvars.fccType = ICTYPE_VIDEO; int* attrib = (int*)attrib_table->Get("KeyFrameRate"); if (attrib) compvars.lKey = *attrib; else compvars.lKey = 15; // same defaults of the dialog attrib = (int*)attrib_table->Get("DataRate"); if (attrib) compvars.lDataRate = *attrib / 8; else compvars.lDataRate = 300; // same defaults of the dialog attrib = (int*)attrib_table->Get("AVIQuality"); if (attrib) compvars.lQ = *attrib; else compvars.lQ = (DWORD)ICQUALITY_DEFAULT; if (imStrEqual(this->compression, "RLE")) compvars.fccHandler = mmioFOURCC('M','R','L','E'); else if (imStrEqual(this->compression, "CINEPACK")) compvars.fccHandler = mmioFOURCC('c','v','i','d'); else compvars.fccHandler = mmioFOURCC(compression[0],compression[1],compression[2],compression[3]); compvars.hic = ICOpen(ICTYPE_VIDEO, compvars.fccHandler, ICMODE_COMPRESS); } if (compvars.hic == NULL) use_compressor = 0; } AVISTREAMINFO streaminfo; memset(&streaminfo, 0, sizeof(AVISTREAMINFO)); streaminfo.fccType = streamtypeVIDEO; streaminfo.dwScale = 1000; streaminfo.dwRate = (DWORD)(fps*1000); SetRect(&streaminfo.rcFrame, 0, 0, width, height); if (use_compressor) { streaminfo.fccHandler = compvars.fccHandler; streaminfo.dwQuality = compvars.lQ; } else { streaminfo.fccHandler = mmioFOURCC('D','I','B',' '); streaminfo.dwQuality = (DWORD)ICQUALITY_DEFAULT; } /* creates a new stream in the new file */ HRESULT hr = AVIFileCreateStream(file, &stream, &streaminfo); if (hr != 0) return IM_ERR_ACCESS; /* set stream format */ if (use_compressor) { if (!ICSeqCompressFrameStart(&compvars, dib->bmi)) return IM_ERR_COMPRESS; hr = AVIStreamSetFormat(stream, 0, compvars.lpbiOut, dib->size - dib->bits_size); } else hr = AVIStreamSetFormat(stream, 0, dib->dib, dib->size - dib->bits_size); if (hr != 0) return IM_ERR_ACCESS; return IM_ERR_NONE; }