Add option to output the module frames into a file. write frame is not complete yet

This commit is contained in:
2014-06-25 00:05:55 +01:00
parent 0ee5f300df
commit 6774248987
8 changed files with 163 additions and 34 deletions
+75 -6
View File
@@ -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] );
+6 -2
View File
@@ -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<QAction*> m_arrayActions;
Void appendModule( PlaYUVerModuleIf* pcCurrModuleIf );
SubWindowHandle* enableModuleIf( PlaYUVerModuleIf* pcCurrModuleIf );
Void openModuleIfStream( PlaYUVerModuleIf *pcCurrModuleIf );
Void customEvent( QEvent *event );
private Q_SLOTS:
+9 -8
View File
@@ -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
+2
View File
@@ -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:
+9
View File
@@ -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;
+6
View File
@@ -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
*/
+50 -16
View File
@@ -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 )
+6 -2
View File
@@ -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();