diff --git a/tools/CommandLineHandle.cpp b/tools/CommandLineHandle.cpp index 418f083..18ac1e1 100644 --- a/tools/CommandLineHandle.cpp +++ b/tools/CommandLineHandle.cpp @@ -22,8 +22,11 @@ * \brief Handle for command line */ +#include #include "CommandLineHandle.h" #include "lib/PlaYUVerFrame.h" +#include "modules/PlaYUVerModuleIf.h" +#include "modules/PlaYUVerModuleFactory.h" namespace plaYUVer { @@ -38,7 +41,7 @@ CommandLineHandle::~CommandLineHandle() } -Int CommandLineHandle::ParseToolsArgs() +Int CommandLineHandle::parseToolsArgs() { Int iRet = 0; @@ -70,7 +73,58 @@ Int CommandLineHandle::ParseToolsArgs() iRet = 1; } + if( getOptionsMap().count( "module_list" ) ) + { + listModules(); + iRet = 1; + } + return iRet; } +Void CommandLineHandle::listModules() +{ + PlaYUVerModuleIf* pcCurrModuleIf; + PlaYUVerModuleFactoryMap& PlaYUVerModuleFactoryMap = PlaYUVerModuleFactory::Get()->getMap(); + PlaYUVerModuleFactoryMap::iterator it = PlaYUVerModuleFactoryMap.begin(); + + printf( "PlaYUVer available modules: \n" ); + //printf( " " ); + printf( " [Name] " ); + printf( " [Type] " ); + printf( " [Description]" ); + printf( " \n" ); + + Char ModuleNameString[40]; + + for( UInt i = 0; it != PlaYUVerModuleFactoryMap.end(); ++it, i++ ) + { + ModuleNameString[0] = '\0'; + + pcCurrModuleIf = it->second(); + + printf( " " ); + if( pcCurrModuleIf->m_pchModuleCategory ) + { + strcat( ModuleNameString, pcCurrModuleIf->m_pchModuleCategory ); + strcat( ModuleNameString, "/" ); + } + strcat( ModuleNameString, pcCurrModuleIf->m_pchModuleName ); + printf( "%-40s", ModuleNameString ); + switch( pcCurrModuleIf->m_iModuleType ) + { + case FRAME_PROCESSING_MODULE: + printf( " Processing " ); + break; + case FRAME_MEASUREMENT_MODULE: + printf( " Measurement " ); + break; + } + printf( " %s", pcCurrModuleIf->m_pchModuleTooltip ); + printf( "\n" ); + pcCurrModuleIf->Delete(); + } + +} + } // NAMESPACE diff --git a/tools/CommandLineHandle.h b/tools/CommandLineHandle.h index 1d8565a..1fa6a35 100644 --- a/tools/CommandLineHandle.h +++ b/tools/CommandLineHandle.h @@ -38,7 +38,8 @@ public: CommandLineHandle(); ~CommandLineHandle(); - Int ParseToolsArgs(); + Int parseToolsArgs(); + Void listModules(); }; diff --git a/tools/PlaYUVerTools.cpp b/tools/PlaYUVerTools.cpp index 23d9636..ab461a0 100644 --- a/tools/PlaYUVerTools.cpp +++ b/tools/PlaYUVerTools.cpp @@ -23,6 +23,8 @@ */ #include "PlaYUVerTools.h" +#include "modules/PlaYUVerModuleIf.h" +#include "modules/PlaYUVerModuleFactory.h" namespace plaYUVer { @@ -31,6 +33,10 @@ PlaYUVerTools::PlaYUVerTools() { m_uiOperation = INVALID_OPERATION; m_uiNumberOfFrames = -1; + + m_uiQualityMetric = -1; + + m_pcCurrModuleIf = NULL; } PlaYUVerTools::~PlaYUVerTools() @@ -52,7 +58,7 @@ Int PlaYUVerTools::openInputs() */ if( m_cCommandLineParser.getOptionsMap().count( "input" ) ) { - std::string resolutionString(""); + std::string resolutionString( "" ); if( m_cCommandLineParser.getOptionsMap().count( "size" ) ) { resolutionString = m_cCommandLineParser.getOptionsMap()["size"].as(); @@ -116,7 +122,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) Int iRet = 0; m_cCommandLineParser.Config( argc, argv ); - if( ( iRet = m_cCommandLineParser.ParseToolsArgs() ) > 0 ) + if( ( iRet = m_cCommandLineParser.parseToolsArgs() ) > 0 ) { return iRet; } @@ -131,7 +137,6 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) */ if( m_cCommandLineParser.getOptionsMap().count( "quality" ) ) { - m_uiOperationIndex = -1; std::string qualityMetric = m_cCommandLineParser.getOptionsMap()["quality"].as(); if( m_apcInputStreams.size() != 2 ) { @@ -142,16 +147,17 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) { if( lowercase( PlaYUVerFrame::supportedQualityMetricsList()[i] ) == lowercase( qualityMetric ) ) { - m_uiOperationIndex = i; + m_uiQualityMetric = i; } } - if( m_uiOperationIndex == -1 ) + if( m_uiQualityMetric == -1 ) { printf( "Invalid quality metric! " ); return 2; } m_uiOperation = QUALITY_OPERATION; m_fpProcess = &PlaYUVerTools::QualityOperation; + printf( "PlaYUVer Quality\n" ); } /** @@ -159,7 +165,30 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) */ if( m_cCommandLineParser.getOptionsMap().count( "module" ) ) { + std::string moduleName = m_cCommandLineParser.getOptionsMap()["module"].as(); + PlaYUVerModuleFactoryMap& PlaYUVerModuleFactoryMap = PlaYUVerModuleFactory::Get()->getMap(); + PlaYUVerModuleFactoryMap::iterator it = PlaYUVerModuleFactoryMap.begin(); + for( UInt i = 0; it != PlaYUVerModuleFactoryMap.end(); ++it, i++ ) + { + if( strcmp( it->first, moduleName.c_str() ) == 0 ) + { + m_pcCurrModuleIf = it->second(); + break; + } + } + + if( m_apcInputStreams.size() != m_pcCurrModuleIf->m_uiNumberOfFrames ) + { + printf( "Invalid number of inputs! " ); + return 2; + } + + m_pcCurrModuleIf->create( m_apcInputStreams[0]->getCurrFrame() ); + + m_uiOperation = MODULE_OPERATION; + m_fpProcess = &PlaYUVerTools::ModuleOperation; + printf( "PlaYUVer Module\n" ); } if( m_uiOperation == INVALID_OPERATION ) @@ -188,7 +217,7 @@ Int PlaYUVerTools::QualityOperation() Double adAverageQuality[m_apcInputStreams.size() - 1][m_uiNumberOfComponents]; Double dQuality; - printf( " Measuring Quality using %s ... \n", PlaYUVerFrame::supportedQualityMetricsList()[m_uiOperationIndex].c_str() ); + printf( " Measuring Quality using %s ... \n", PlaYUVerFrame::supportedQualityMetricsList()[m_uiQualityMetric].c_str() ); for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) { @@ -209,7 +238,7 @@ Int PlaYUVerTools::QualityOperation() printf( " " ); for( UInt c = 0; c < m_uiNumberOfComponents; c++ ) { - dQuality = apcCurrFrame[s]->getQuality( m_uiOperationIndex, apcCurrFrame[0], c ); + dQuality = apcCurrFrame[s]->getQuality( m_uiQualityMetric, apcCurrFrame[0], c ); adAverageQuality[s - 1][c] = ( adAverageQuality[s - 1][c] * Double( frame ) + dQuality ) / Double( frame + 1 ); printf( " %5.3f", dQuality ); } @@ -237,4 +266,67 @@ Int PlaYUVerTools::QualityOperation() return 0; } +Int PlaYUVerTools::ModuleOperation() +{ + printf( " Applying Module %s/%s ... \n", m_pcCurrModuleIf->m_pchModuleCategory, m_pcCurrModuleIf->m_pchModuleName ); + + PlaYUVerFrame* pcProcessedFrame = NULL; + Double dMeasurementResult = 0.0; + Double dAveragedMeasurementResult = 0; + Bool abEOF[m_apcInputStreams.size()]; + + for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) + { + abEOF[s] = false; + } + + for( UInt frame = 0; frame < m_uiNumberOfFrames; frame++ ) + { + + if( m_pcCurrModuleIf->m_iModuleType == FRAME_PROCESSING_MODULE ) + { + switch( m_pcCurrModuleIf->m_uiNumberOfFrames ) + { + case MODULE_REQUIRES_ONE_FRAME: + pcProcessedFrame = m_pcCurrModuleIf->process( m_apcInputStreams[0]->getCurrFrame() ); + break; + case MODULE_REQUIRES_TWO_FRAMES: + pcProcessedFrame = m_pcCurrModuleIf->process( m_apcInputStreams[0]->getCurrFrame(), m_apcInputStreams[1]->getCurrFrame() ); + break; + } + } + else if( m_pcCurrModuleIf->m_iModuleType == FRAME_MEASUREMENT_MODULE ) + { + switch( m_pcCurrModuleIf->m_uiNumberOfFrames ) + { + case MODULE_REQUIRES_ONE_FRAME: + dMeasurementResult = m_pcCurrModuleIf->measure( m_apcInputStreams[0]->getCurrFrame() ); + break; + case MODULE_REQUIRES_TWO_FRAMES: + dMeasurementResult = m_pcCurrModuleIf->measure( m_apcInputStreams[0]->getCurrFrame(), m_apcInputStreams[1]->getCurrFrame() ); + break; + } + printf( " %3d %8.3f \n", frame, dMeasurementResult ); + dAveragedMeasurementResult = ( dAveragedMeasurementResult * Double( frame ) + dMeasurementResult ) / Double( frame + 1 ); + } + + for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) + { + m_apcInputStreams[s]->setNextFrame(); + if( !abEOF[s] ) + { + m_apcInputStreams[s]->readFrame(); + abEOF[s] = m_apcInputStreams[s]->checkErrors( PlaYUVerStream::LAST_FRAME ); + } + } + } + + if( m_pcCurrModuleIf->m_iModuleType == FRAME_MEASUREMENT_MODULE ) + { + printf( "\n Mean Value: \n %8.3f\n", dAveragedMeasurementResult ); + } + + return 0; +} + } // NAMESPACE diff --git a/tools/PlaYUVerTools.h b/tools/PlaYUVerTools.h index 4d1464b..6082ad7 100644 --- a/tools/PlaYUVerTools.h +++ b/tools/PlaYUVerTools.h @@ -34,6 +34,8 @@ namespace plaYUVer { +class PlaYUVerModuleIf; + class PlaYUVerTools { public: @@ -48,7 +50,6 @@ private: CommandLineHandle m_cCommandLineParser; UInt m_uiOperation; - Int m_uiOperationIndex; enum TOOLS_OPERATIONS_LIST { INVALID_OPERATION, @@ -67,7 +68,12 @@ private: typedef Int (PlaYUVerTools::*FpProcess) (); FpProcess m_fpProcess; + + Int m_uiQualityMetric; Int QualityOperation(); + + PlaYUVerModuleIf* m_pcCurrModuleIf; + Int ModuleOperation(); }; } // NAMESPACE