diff --git a/source/app/ModulesHandle.cpp b/source/app/ModulesHandle.cpp index 9b7c6b8..3d6cdd8 100644 --- a/source/app/ModulesHandle.cpp +++ b/source/app/ModulesHandle.cpp @@ -86,6 +86,10 @@ SubWindowHandle* ModulesHandle::processModuleHandlingOpt() case SWAP_FRAMES_OPT: pcSubWindow->swapModuleFrames(); break; + case APPLY_ALL_OPT: + openModuleIfStream( pcSubWindow->getModule() ); + pcSubWindow->applyModuleAllFrames(); + break; default: Q_ASSERT( 0 ); } @@ -184,16 +188,18 @@ Void ModulesHandle::destroyAllModulesIf() } } -Bool ModulesHandle::applyModuleIf( PlaYUVerModuleIf *pcCurrModuleIf, Bool isPlaying ) +Bool ModulesHandle::applyModuleIf( PlaYUVerModuleIf *pcCurrModuleIf, Bool isPlaying, Bool disableThreads ) { Bool bRet = false; if( !isPlaying || ( isPlaying && pcCurrModuleIf->m_cModuleDef.m_bApplyWhilePlaying ) ) { #ifdef PLAYUVER_THREADED_MODULES - pcCurrModuleIf->start(); -#else - pcCurrModuleIf->run(); + if( !disableThreads ) + pcCurrModuleIf->start(); + else #endif + pcCurrModuleIf->run(); + if( pcCurrModuleIf->m_pcDisplaySubWindow ) { bRet = true; @@ -208,7 +214,63 @@ Bool ModulesHandle::applyModuleIf( PlaYUVerModuleIf *pcCurrModuleIf, Bool isPlay Void ModulesHandle::applyAllModuleIf( PlaYUVerModuleIf *pcCurrModuleIf ) { + if( pcCurrModuleIf->m_pcModuleStream ) + { + UInt numberOfWindows = pcCurrModuleIf->m_cModuleDef.m_uiNumberOfFrames; + UInt currFrames; + UInt64 numberOfFrames = INT_MAX; + for( UInt i = 0; i < numberOfWindows; i++ ) + { + currFrames = pcCurrModuleIf->m_pcSubWindow[i]->getInputStream()->getFrameNum(); + if( currFrames < numberOfFrames ) + numberOfFrames = currFrames; + } + for( UInt f = 0; f < numberOfFrames; f++ ) + { + for( UInt i = 0; i < numberOfWindows; i++ ) + { + pcCurrModuleIf->m_pcSubWindow[i]->play(); + pcCurrModuleIf->m_pcSubWindow[i]->playEvent(); + } + applyModuleIf( pcCurrModuleIf, false, false ); + pcCurrModuleIf->m_pcModuleStream->writeFrame( pcCurrModuleIf->m_pcProcessedFrame ); + } + } +} +Void ModulesHandle::openModuleIfStream( PlaYUVerModuleIf *pcCurrModuleIf ) +{ + if( pcCurrModuleIf ) + { + if( !pcCurrModuleIf->m_pcModuleStream ) + { + UInt Width = 0, Height = 0, FrameRate = 30; + Int InputFormat = -1; + + QString supported = tr( "Supported Files" ); + QString formats = PlaYUVerStream::supportedWriteFormats(); + formats.prepend( " (" ); + formats.append( ")" ); + supported.append( formats ); // supported=="Supported Files (*.pbm *.jpg...)" + + QStringList filter; + filter << supported + << PlaYUVerStream::supportedWriteFormatsList() + << tr( "All Files (*)" ); + + QString fileName = QFileDialog::getSaveFileName( m_pcParent, tr( "Open File" ), QString(), filter.join( ";;" ) ); + + pcCurrModuleIf->m_pcSubWindow[0]->getInputStream()->getFormat( Width, Height, InputFormat, FrameRate ); + + pcCurrModuleIf->m_pcModuleStream = new PlaYUVerStream; + if( !pcCurrModuleIf->m_pcModuleStream->open( fileName, Width, Height, InputFormat, FrameRate, false ) ) + { + delete pcCurrModuleIf->m_pcModuleStream; + pcCurrModuleIf->m_pcModuleStream = NULL; + return; + } + } + } } Bool ModulesHandle::showModuleIf( PlaYUVerModuleIf *pcCurrModuleIf, PlaYUVerFrame* processedFrame ) @@ -300,8 +362,6 @@ QMenu* ModulesHandle::createMenus( QMenuBar *MainAppMenuBar ) pcCurrModuleIf->m_pcAction = currAction; } - m_arrayActions[DISABLE_ALL_ACT] = new QAction( "Disable All Modules", parent() ); - connect( m_arrayActions[DISABLE_ALL_ACT], SIGNAL( triggered() ), this, SLOT( destroyAllModulesIf() ) ); m_arrayActions[FORCE_NEW_WINDOW_ACT] = new QAction( "Use New Window", parent() ); m_arrayActions[FORCE_NEW_WINDOW_ACT]->setStatusTip( "Show module result in a new window. Some modules already force this feature" ); m_arrayActions[FORCE_NEW_WINDOW_ACT]->setCheckable( true ); @@ -309,12 +369,21 @@ QMenu* ModulesHandle::createMenus( QMenuBar *MainAppMenuBar ) m_arrayActions[FORCE_PLAYING_REFRESH_ACT]->setStatusTip( "Force module refreshing while playing" ); m_arrayActions[FORCE_PLAYING_REFRESH_ACT]->setCheckable( true ); + m_arrayActions[APPLY_ALL_ACT] = new QAction( "Apply to All", parent() ); + m_arrayActions[APPLY_ALL_ACT]->setStatusTip( "Apply module to all frames and save the result" ); + connect( m_arrayActions[APPLY_ALL_ACT], SIGNAL( triggered() ), m_pcActionMapper, SLOT( map() ) ); + m_pcActionMapper->setMapping( m_arrayActions[APPLY_ALL_ACT], APPLY_ALL_OPT ); + m_arrayActions[SWAP_FRAMES_ACT] = new QAction( "Swap frames", parent() ); m_arrayActions[SWAP_FRAMES_ACT]->setStatusTip( "Swap Sub Window order" ); connect( m_arrayActions[SWAP_FRAMES_ACT], SIGNAL( triggered() ), m_pcActionMapper, SLOT( map() ) ); m_pcActionMapper->setMapping( m_arrayActions[SWAP_FRAMES_ACT], SWAP_FRAMES_OPT ); + m_arrayActions[DISABLE_ALL_ACT] = new QAction( "Disable All Modules", parent() ); + connect( m_arrayActions[DISABLE_ALL_ACT], SIGNAL( triggered() ), this, SLOT( destroyAllModulesIf() ) ); + m_pcModulesMenu->addSeparator(); + m_pcModulesMenu->addAction( m_arrayActions[APPLY_ALL_ACT] ); m_pcModulesMenu->addAction( m_arrayActions[SWAP_FRAMES_ACT] ); m_pcModulesMenu->addAction( m_arrayActions[DISABLE_ALL_ACT] ); m_pcModulesMenu->addAction( m_arrayActions[FORCE_NEW_WINDOW_ACT] ); diff --git a/source/app/ModulesHandle.h b/source/app/ModulesHandle.h index 51466a3..161b800 100644 --- a/source/app/ModulesHandle.h +++ b/source/app/ModulesHandle.h @@ -56,7 +56,7 @@ public: SubWindowHandle* processModuleHandlingOpt(); static Void destroyModuleIf( PlaYUVerModuleIf* pcCurrModuleIf ); - static Bool applyModuleIf( PlaYUVerModuleIf* pcCurrModuleIf, Bool isPlaying = false ); + static Bool applyModuleIf( PlaYUVerModuleIf* pcCurrModuleIf, Bool isPlaying, Bool disableThreads = false ); static Void swapModulesWindowsIf( PlaYUVerModuleIf *pcCurrModuleIf ); static Bool showModuleIf( PlaYUVerModuleIf *pcCurrModuleIf, PlaYUVerFrame* processedFrame ); @@ -72,6 +72,7 @@ private: { INVALID_OPT = -1, SWAP_FRAMES_OPT = -2, + APPLY_ALL_OPT = -3, }; QMenu* m_pcModulesMenu; @@ -84,14 +85,17 @@ private: { FORCE_NEW_WINDOW_ACT = 0, FORCE_PLAYING_REFRESH_ACT, - DISABLE_ALL_ACT, + APPLY_ALL_ACT, SWAP_FRAMES_ACT, + DISABLE_ALL_ACT, MODULES_TOTAL_ACT }; QVector m_arrayActions; Void appendModule( PlaYUVerModuleIf* pcCurrModuleIf ); SubWindowHandle* enableModuleIf( PlaYUVerModuleIf* pcCurrModuleIf ); + Void openModuleIfStream( PlaYUVerModuleIf *pcCurrModuleIf ); + Void customEvent( QEvent *event ); private Q_SLOTS: diff --git a/source/app/PlaYUVerModuleIf.cpp b/source/app/PlaYUVerModuleIf.cpp index c432393..7e1d36e 100644 --- a/source/app/PlaYUVerModuleIf.cpp +++ b/source/app/PlaYUVerModuleIf.cpp @@ -30,7 +30,9 @@ namespace plaYUVer PlaYUVerModuleIf::PlaYUVerModuleIf() : m_pcAction( NULL ), - m_pcDisplaySubWindow( NULL ) + m_pcDisplaySubWindow( NULL ), + m_pcProcessedFrame( NULL ), + m_pcModuleStream( NULL ) { for( Int i = 0; i < MAX_NUMBER_FRAMES; i++ ) { @@ -40,20 +42,19 @@ PlaYUVerModuleIf::PlaYUVerModuleIf() : void PlaYUVerModuleIf::run() { - PlaYUVerFrame* pcProcessedFrame = NULL; switch( m_cModuleDef.m_uiNumberOfFrames ) { case MODULE_REQUIRES_ONE_FRAME: - pcProcessedFrame = process( m_pcSubWindow[0]->getCurrFrame() ); + m_pcProcessedFrame = process( m_pcSubWindow[0]->getCurrFrame() ); break; case MODULE_REQUIRES_TWO_FRAMES: - pcProcessedFrame = process( m_pcSubWindow[0]->getCurrFrame(), m_pcSubWindow[1]->getCurrFrame() ); + m_pcProcessedFrame = process( m_pcSubWindow[0]->getCurrFrame(), m_pcSubWindow[1]->getCurrFrame() ); break; case MODULE_REQUIRES_THREE_FRAMES: - pcProcessedFrame = process( m_pcSubWindow[0]->getCurrFrame(), m_pcSubWindow[1]->getCurrFrame(), m_pcSubWindow[2]->getCurrFrame() ); + m_pcProcessedFrame = process( m_pcSubWindow[0]->getCurrFrame(), m_pcSubWindow[1]->getCurrFrame(), m_pcSubWindow[2]->getCurrFrame() ); break; } - postProgress( true, pcProcessedFrame ); + postProgress( true, m_pcProcessedFrame ); } Void PlaYUVerModuleIf::postProgress( Bool success, PlaYUVerFrame* pcProcessedFrame ) @@ -62,8 +63,8 @@ Void PlaYUVerModuleIf::postProgress( Bool success, PlaYUVerFrame* pcProcessedFra eventData->m_bSuccess = success; eventData->m_pcProcessedFrame = pcProcessedFrame; eventData->m_pcModule = this; - if( parent() ) - QCoreApplication::postEvent( parent(), eventData ); + if( parent() && pcProcessedFrame ) + QCoreApplication::postEvent( parent(), eventData ); } } // NAMESPACE diff --git a/source/app/PlaYUVerModuleIf.h b/source/app/PlaYUVerModuleIf.h index d18bb99..7bb1f27 100644 --- a/source/app/PlaYUVerModuleIf.h +++ b/source/app/PlaYUVerModuleIf.h @@ -97,7 +97,9 @@ private: SubWindowHandle* m_pcSubWindow[MAX_NUMBER_FRAMES]; SubWindowHandle* m_pcDisplaySubWindow; PlaYUVerModuleDefinition m_cModuleDef; + PlaYUVerStream* m_pcModuleStream; + PlaYUVerFrame* m_pcProcessedFrame; Void postProgress( Bool success, PlaYUVerFrame* pcProcessedFrame ); public: diff --git a/source/app/SubWindowHandle.cpp b/source/app/SubWindowHandle.cpp index 2968a36..a866484 100644 --- a/source/app/SubWindowHandle.cpp +++ b/source/app/SubWindowHandle.cpp @@ -153,6 +153,15 @@ Void SubWindowHandle::swapModuleFrames() } } +Void SubWindowHandle::applyModuleAllFrames() +{ + if( m_pcCurrentModule ) + { + ModulesHandle::applyAllModuleIf( m_pcCurrentModule ); + stop(); + } +} + Void SubWindowHandle::setCurrFrame( PlaYUVerFrame* pcCurrFrame ) { m_pcCurrFrame = pcCurrFrame; diff --git a/source/app/SubWindowHandle.h b/source/app/SubWindowHandle.h index e90e9db..16cb400 100644 --- a/source/app/SubWindowHandle.h +++ b/source/app/SubWindowHandle.h @@ -112,6 +112,10 @@ public: { m_pcCurrentModule = pcCurrentModule; } + PlaYUVerModuleIf* getModule() + { + return m_pcCurrentModule; + } /** * Functions to enable a module in the @@ -120,6 +124,8 @@ public: Void enableModule( PlaYUVerModuleIf* select_module ); Void disableModule(); Void swapModuleFrames(); + Void applyModuleAllFrames(); + /** * Show the image at its original size */ diff --git a/source/lib/PlaYUVerStream.cpp b/source/lib/PlaYUVerStream.cpp index 270129a..426171e 100644 --- a/source/lib/PlaYUVerStream.cpp +++ b/source/lib/PlaYUVerStream.cpp @@ -69,23 +69,12 @@ QString PlaYUVerStream::supportedReadFormats() formats = "*.yuv " // Raw video #ifdef USE_FFMPEG "*.avi " // Audio video interleaved - "*.mp4 " + "*.mp4 "// MP4 "*.wmv "// Windows media video #endif ; return formats; } -QString PlaYUVerStream::supportedWriteFormats() -{ - QString formats; - formats = "*.bmp " // Windows Bitmap - "*.jpg "// Joint Photographic Experts Group - "*.jpeg "// Joint Photographic Experts Group - "*.png "// Portable Network Graphics - ; - return formats; -} - QStringList PlaYUVerStream::supportedReadFormatsList() { QStringList formats; @@ -99,7 +88,32 @@ QStringList PlaYUVerStream::supportedReadFormatsList() return formats; } +QString PlaYUVerStream::supportedWriteFormats() +{ + QString formats; + formats = "*.yuv " // raw video + ; + return formats; +} + QStringList PlaYUVerStream::supportedWriteFormatsList() +{ + QStringList formats; + formats << "Raw video (*.yuv)"; + return formats; +} + +QString PlaYUVerStream::supportedSaveFormats() +{ + QString formats; + formats = "*.jpg " // Joint Photographic Experts Group + "*.jpeg "// Joint Photographic Experts Group + "*.png "// Portable Network Graphics + ; + return formats; +} + +QStringList PlaYUVerStream::supportedSaveFormatsList() { QStringList formats; formats << "Windows Bitmap (*.bmp)" @@ -203,6 +217,9 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ m_cStreamInformationString.append( QFileInfo( m_cFilename ).fileName() ); m_iCurrFrameNum = -1; + + m_bInit = true; + seekInput( 0 ); //loadAll(); @@ -308,7 +325,7 @@ Bool PlaYUVerStream::guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Void PlaYUVerStream::loadAll() { - if( m_bLoadAll ) + if( m_bLoadAll || !m_bIsInput ) return; if( m_ppcFrameBuffer ) @@ -410,10 +427,10 @@ Void PlaYUVerStream::readFrame() return; } -Void PlaYUVerStream::writeFrame( const QString& filename ) +Void PlaYUVerStream::writeFrame() { - UInt64 frame_bytes_input = m_pcNextFrame->getBytesPerFrame(); - m_pcNextFrame->FrameToBuffer( m_pStreamBuffer ); + UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame(); + m_pcCurrFrame->FrameToBuffer( m_pStreamBuffer ); UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile ); if( bytes_read != frame_bytes_input ) { @@ -422,6 +439,23 @@ Void PlaYUVerStream::writeFrame( const QString& filename ) return; } +Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame ) +{ + UInt64 frame_bytes_input = pcFrame->getBytesPerFrame(); + pcFrame->FrameToBuffer( m_pStreamBuffer ); + UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile ); + if( bytes_read != frame_bytes_input ) + { + m_iErrorStatus = WRITING; + } + return; +} + +Void PlaYUVerStream::saveFrame( const QString& filename ) +{ + return; +} + Void PlaYUVerStream::setNextFrame() { if( m_pcNextFrame ) diff --git a/source/lib/PlaYUVerStream.h b/source/lib/PlaYUVerStream.h index f6ecf95..f4bef0e 100644 --- a/source/lib/PlaYUVerStream.h +++ b/source/lib/PlaYUVerStream.h @@ -88,9 +88,11 @@ public: ~PlaYUVerStream(); static QString supportedReadFormats(); - static QString supportedWriteFormats(); static QStringList supportedReadFormatsList(); + static QString supportedWriteFormats(); static QStringList supportedWriteFormatsList(); + static QString supportedSaveFormats(); + static QStringList supportedSaveFormatsList(); enum PlaYUVerStreamFormats { @@ -116,8 +118,10 @@ public: Void loadAll(); Void readFrame(); + Void writeFrame(); + Void writeFrame( PlaYUVerFrame *pcFrame ); - Void writeFrame( const QString& filename ); + Void saveFrame( const QString& filename ); Void setNextFrame(); PlaYUVerFrame* getCurrFrame();