#include #include #include #include #include #include BmpCap::BmpCap() : mSequence(0), mSaveFrames(0), mUseSequence(false) { } BmpCap::BmpCap(HWND hParentWnd,DWORD driverIndex) : mSequence(0), mSaveFrames(false), mUseSequence(false) { initialize(hParentWnd,driverIndex); } BmpCap::~BmpCap() { // mVideoCodec.driverEnable(false); } void BmpCap::initialize(HWND hParentWnd,DWORD driverIndex) { DWORD previewWidth; DWORD previewHeight; DriverCaps driverCaps; ICMOpen icmOpen; VidReg vidReg; mUseSequence=vidReg.getSequencing(); mCaptureWidth=vidReg.getCaptureWidth(); mCaptureHeight=vidReg.getCaptureHeight(); mCaptureFile=vidReg.getCaptureFile(); mQuality=vidReg.getQuality(); previewWidth=vidReg.getPreviewWidth(); previewHeight=vidReg.getPreviewHeight(); create(hParentWnd,vidReg.getPreviewWidth(),vidReg.getPreviewHeight()); connect(driverIndex); if(!isConnected())return; getDriverCaps(driverCaps); getVideoFormat(mBitmapInfo); mBitmapInfo.width(previewWidth); mBitmapInfo.height(previewHeight); setVideoFormat(mBitmapInfo); if(mVideoCodec.openDriver(mBitmapInfo.compression()))message("[BmpCap::initialize]Failed to open decompressor."); icmOpen.fccType(FOURCC("vidc")); icmOpen.fccHandler(mBitmapInfo.compression()); icmOpen.flags(ICMOpen::DeCompress); icmOpen.version(0); if(!mVideoCodec.driverProc(icmOpen)){message("[BmpCap::initialize]ICMOpen failed");return;}; if(!mVideoCodec.driverEnable()){message("[BmpCap::initialize]DriverEnable failed");return;} getVideoFormat(mBitmapInfo); } // virtuals #if 0 void BmpCap::frameHandler(VIDEOHDR &videoHeader) { if(!saveFrames())return; MovieData movieData(MovieData::DIBCompressed); MovieData dstMovieData; DiskInfo diskInfo; String srcPathFileName; String dstPathFileName; String dstPathFileTempName; String strTime; SystemTime systemTime; strTime.reserve(512); ::sprintf(strTime,"%04d%02d%02d%02d%02d%02d%02d", systemTime.year(),systemTime.month(),systemTime.day(), systemTime.hour(),systemTime.minute(),systemTime.second(), systemTime.milliseconds()); srcPathFileName=strTime+".bmp"; dstPathFileTempName=strTime+"tmp.jpg"; if(mUseSequence)dstPathFileName=mCaptureFile.betweenString(0,'.')+String().fromInt(mSequence++)+String(".jpg"); else dstPathFileName=mCaptureFile; movieData.size(videoHeader.dwBufferLength); ::memcpy((BYTE*)&movieData[0],videoHeader.lpData,videoHeader.dwBufferLength); if(!mVideoCodec.getFormat(mBitmapInfo,mDstBitmapInfo))return; mDstBitmapInfo.width(mCaptureWidth); mDstBitmapInfo.height(mCaptureHeight); if(!mVideoCodec.decompressFrame(mBitmapInfo,mDstBitmapInfo,movieData,dstMovieData)) { if(!mVideoCodec.decompressFrame(mBitmapInfo,movieData,dstMovieData))return; if(!mVideoCodec.getFormat(mBitmapInfo,mDstBitmapInfo))return; } Bitmap frameBitmap(srcPathFileName,mDstBitmapInfo,dstMovieData); if(BitmapInfo::Bit8==mDstBitmapInfo.bitCount()) { PurePalette purePalette(mCaptureStatus.currentPalette()); frameBitmap.setPalette(purePalette.getPalette(),FALSE); } frameBitmap.saveBitmap(); ImageConverter::convert(srcPathFileName,dstPathFileTempName,mQuality); diskInfo.rename(dstPathFileTempName,dstPathFileName); diskInfo.unlink(srcPathFileName); } #endif void BmpCap::frameHandler(VIDEOHDR &videoHeader) { if(!saveFrames())return; MovieData movieData(MovieData::DIBCompressed); MovieData dstMovieData; DiskInfo diskInfo; String srcPathFileName; String dstPathFileName; String dstPathFileTempName; String strTime; SystemTime systemTime; DWORD elapsedTime; String strMessage; strMessage.reserve(512); elapsedTime=::GetTickCount(); strTime.reserve(512); ::sprintf(strTime,"%04d%02d%02d%02d%02d%02d%02d", systemTime.year(),systemTime.month(),systemTime.day(), systemTime.hour(),systemTime.minute(),systemTime.second(), systemTime.milliseconds()); srcPathFileName=strTime+".bmp"; dstPathFileTempName=strTime+"tmp.jpg"; if(mUseSequence)dstPathFileName=mCaptureFile.betweenString(0,'.')+String().fromInt(mSequence++)+String(".jpg"); else dstPathFileName=mCaptureFile; movieData.size(videoHeader.dwBufferLength); ::memcpy((BYTE*)&movieData[0],videoHeader.lpData,videoHeader.dwBufferLength); // if(!mVideoCodec.getFormat(mBitmapInfo,mDstBitmapInfo))return; if(!(ICERR_OK==mVideoCodec.getFormat(mBitmapInfo,mDstBitmapInfo)))return; mDstBitmapInfo.width(mCaptureWidth); mDstBitmapInfo.height(mCaptureHeight); elapsedTime=::GetTickCount()-elapsedTime; ::sprintf(strMessage,"[BmpCap::frameHandler] Prologue took (ms) "+String().fromInt(elapsedTime)); message(strMessage); elapsedTime=::GetTickCount(); if(ICERR_OK!=mVideoCodec.decompressFrame(mBitmapInfo,mDstBitmapInfo,movieData,dstMovieData)) { if(ICERR_OK!=mVideoCodec.decompressFrame(mBitmapInfo,movieData,dstMovieData))return; if(ICERR_OK!=mVideoCodec.getFormat(mBitmapInfo,mDstBitmapInfo))return; } elapsedTime=::GetTickCount()-elapsedTime; ::sprintf(strMessage,"[BmpCap::frameHandler] Decompress frame took (ms) "+String().fromInt(elapsedTime)); message(strMessage); elapsedTime=::GetTickCount(); Bitmap frameBitmap(srcPathFileName,mDstBitmapInfo,dstMovieData); if(BitmapInfo::Bit8==mDstBitmapInfo.bitCount()) { PurePalette purePalette(mCaptureStatus.currentPalette()); frameBitmap.setPalette(purePalette.getPalette(),FALSE); } frameBitmap.saveBitmap(); elapsedTime=::GetTickCount()-elapsedTime; ::sprintf(strMessage,"[BmpCap::frameHandler] Save bitmap took (ms) "+String().fromInt(elapsedTime)); message(strMessage); elapsedTime=::GetTickCount(); ImageConverter::convert(srcPathFileName,dstPathFileTempName,mQuality); elapsedTime=::GetTickCount()-elapsedTime; ::sprintf(strMessage,"[BmpCap::frameHandler] Convert to jpeg took (ms) "+String().fromInt(elapsedTime)); message(strMessage); diskInfo.rename(dstPathFileTempName,dstPathFileName); diskInfo.unlink(srcPathFileName); } void BmpCap::message(const String &message) { return; }