From 974fa27814931e875e0e050ca3b1f69937a69e23 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 21 Feb 2015 18:10:08 +0000 Subject: [PATCH 01/25] Add a small program to test the command line interface using boost lib --- CMakeLists.txt | 4 +++ lib/CMakeLists.txt | 6 +++- lib/PlaYUVerCmdParser.cpp | 53 +++++++++++++++++++++++++++++ lib/PlaYUVerCmdParser.h | 42 +++++++++++++++++++++++ tools/CMakeLists.txt | 22 ++++++++++++ tools/main.cpp | 71 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 lib/PlaYUVerCmdParser.cpp create mode 100644 lib/PlaYUVerCmdParser.h create mode 100644 tools/CMakeLists.txt create mode 100644 tools/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c6557d..0bbb827 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,9 @@ ENDIF() # Dependencies ###################################################################################### +FIND_PACKAGE(Boost COMPONENTS program_options ) +SET_PACKAGE_PROPERTIES(Boost PROPERTIES URL "http://www.boost.org" DESCRIPTION "Boost library support" TYPE REQUIRED) + OPTION( USE_OPENCV "Add OpenCV support" ON ) IF( USE_OPENCV ) FIND_PACKAGE( OpenCV ) @@ -130,6 +133,7 @@ SET( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2" ) ADD_SUBDIRECTORY( lib ) ADD_SUBDIRECTORY( modules ) +ADD_SUBDIRECTORY( tools ) ADD_SUBDIRECTORY( app ) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 72eb6d6..3af29cd 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -4,6 +4,8 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../ ) +INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} ) + set(plaYUver_Lib_SRCS # Frame PlaYUVerFrame.cpp @@ -11,6 +13,8 @@ set(plaYUver_Lib_SRCS PlaYUVerFrameStats.cpp # Stream PlaYUVerStream.cpp + # Command Line Parser + PlaYUVerCmdParser.cpp ) IF( USE_FFMPEG ) @@ -38,7 +42,7 @@ CONFIGURE_FILE( PlaYUVerConfig.cmake.in ${CMAKE_BINARY_DIR}/PlaYUVerConfig.cmake ADD_LIBRARY( PlaYUVerLib STATIC ${plaYUver_Lib_SRCS} ) INCLUDE_DIRECTORIES( ${FFMPEG_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} ) -TARGET_LINK_LIBRARIES( PlaYUVerLib ${FFMPEG_LIBRARIES} ${OpenCV_LIBRARIES} ) +TARGET_LINK_LIBRARIES( PlaYUVerLib ${FFMPEG_LIBRARIES} ${OpenCV_LIBRARIES} ${Boost_LIBRARIES} ) INSTALL(FILES ${plaYUver_Lib_HEADERS} DESTINATION include ) # INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libPlaYUVerLib${CMAKE_STATIC_LIBRARY_SUFFIX} DESTINATION lib ) diff --git a/lib/PlaYUVerCmdParser.cpp b/lib/PlaYUVerCmdParser.cpp new file mode 100644 index 0000000..a261ff4 --- /dev/null +++ b/lib/PlaYUVerCmdParser.cpp @@ -0,0 +1,53 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file PlaYUVerCmdParser.cpp + * \brief Command parser + */ + +#include "config.h" +#include +#include +#include "PlaYUVerCmdParser.h" + +namespace plaYUVer +{ + +po::options_description PlaYUVerCmdParser::GetCommandOpts() +{ + po::options_description inputOpts( "Input" ); + inputOpts.add_options() + ( "input,i", po::value(), "input file" ) + ( "width,w", po::value(), "width" ) + ( "height,h", po::value(), "height" ); + + po::options_description operationOpts( "Operation" ); + operationOpts.add_options() + ( "module", po::value(), "select a module" ) + ( "quality", po::value(),"select a quality metric" ); + + po::options_description commonOpts( "Common" ); + commonOpts.add_options() + ( "help", "produce help message" ); + commonOpts.add( inputOpts ).add( operationOpts ); + return commonOpts; +} + +} // NAMESPACE diff --git a/lib/PlaYUVerCmdParser.h b/lib/PlaYUVerCmdParser.h new file mode 100644 index 0000000..7d83161 --- /dev/null +++ b/lib/PlaYUVerCmdParser.h @@ -0,0 +1,42 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file PlaYUVerCmdParser.h + * \brief Command parser + */ + +#include "PlaYUVerDefs.h" +#include +namespace po = boost::program_options; + +namespace plaYUVer +{ + +class PlaYUVerCmdParser +{ +public: + PlaYUVerCmdParser() {} ; + ~PlaYUVerCmdParser() {} ; + + static po::options_description GetCommandOpts(); + +}; + +} // NAMESPACE diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 0000000..e6dcc56 --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,22 @@ +### +### CMakeLists for playuver app component +### + +# This is hard way - please fix +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_BINARY_DIR}/../ + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../ ) + +set(plaYUver_Tools_SRCS +# Main + main.cpp +) + +ADD_EXECUTABLE( ${PROJECT_NAME}Tools ${plaYUver_Tools_SRCS} ) + +TARGET_LINK_LIBRARIES( ${PROJECT_NAME}Tools PlaYUVerLib PlaYUVerModules ) + +INSTALL(TARGETS ${PROJECT_NAME}Tools DESTINATION bin ) + + diff --git a/tools/main.cpp b/tools/main.cpp new file mode 100644 index 0000000..7a659dd --- /dev/null +++ b/tools/main.cpp @@ -0,0 +1,71 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file main.cpp + * \brief main file + */ + +#include +#include +#include + +using namespace plaYUVer; +using namespace std; + +int main( int argc, char *argv[] ) +{ + + try + { + + po::options_description toolsOpt; + toolsOpt.add( PlaYUVerCmdParser::GetCommandOpts() ); + po::variables_map vm; + po::store( po::parse_command_line( argc, argv, toolsOpt ), vm ); + po::notify( vm ); + + if( vm.count( "help" ) ) + { + cout << toolsOpt << "\n"; + return 0; + } + + if( vm.count( "compression" ) ) + { + cout << "Compression level was set to " << vm["compression"].as() << ".\n"; + } + else + { + cout << "Compression level was not set.\n"; + } + } + catch( exception& e ) + { + cerr << "error: " << e.what() << "\n"; + return 1; + } + catch( ... ) + { + cerr << "Exception of unknown type!\n"; + } + + PlaYUVerFrame pcFrameBuffer = new PlaYUVerFrame( 1024, 768, PlaYUVerFrame::YUV420p ); + return 0; +} From 6feedc95b0861513e13585422c1d68060165aef3 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 21 Feb 2015 20:23:59 +0000 Subject: [PATCH 02/25] Add new open stream function --- lib/PlaYUVerStream.cpp | 26 ++++++++++++++++++++++++++ lib/PlaYUVerStream.h | 1 + 2 files changed, 27 insertions(+) diff --git a/lib/PlaYUVerStream.cpp b/lib/PlaYUVerStream.cpp index 7acda98..80b7529 100644 --- a/lib/PlaYUVerStream.cpp +++ b/lib/PlaYUVerStream.cpp @@ -155,6 +155,32 @@ PlaYUVerStream::~PlaYUVerStream() close(); } +Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::string input_format_name, UInt frame_rate, Bool bInput ) +{ + UInt width; + UInt height; + Int input_format = -1; + + sscanf( resolution.c_str(), "%ux%u", &width, &height ); + if( width <= 0 || height <= 0 ) + { + return false; + } + for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames().size(); i++ ) + { + if( PlaYUVerFrame::supportedPixelFormatListNames()[i] == input_format_name ) + { + input_format = i; + break; + } + } + if( width > 0 && height > 0 && input_format >= 0 ) + { + return open( filename, width, height, input_format, frame_rate, bInput ); + } + return false; +} + Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int input_format, UInt frame_rate, Bool bInput ) { if( m_bInit ) diff --git a/lib/PlaYUVerStream.h b/lib/PlaYUVerStream.h index 565d005..09245ef 100644 --- a/lib/PlaYUVerStream.h +++ b/lib/PlaYUVerStream.h @@ -115,6 +115,7 @@ public: END_OF_SEQ, }; + Bool open( std::string filename, std::string resolution, std::string input_format, UInt frame_rate, Bool bInput = true ); Bool open( std::string filename, UInt width, UInt height, Int input_format, UInt frame_rate, Bool bInput = true ); Void close(); From 5a98b50e59dac77581090aea87aa925b0154d3df Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 21 Feb 2015 20:44:35 +0000 Subject: [PATCH 03/25] Use opencv to save images --- lib/PlaYUVerStream.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/PlaYUVerStream.cpp b/lib/PlaYUVerStream.cpp index 80b7529..2d5d1c6 100644 --- a/lib/PlaYUVerStream.cpp +++ b/lib/PlaYUVerStream.cpp @@ -27,11 +27,12 @@ #include #include "LibMemory.h" #include "PlaYUVerStream.h" -#include -#include #ifdef USE_FFMPEG #include "LibAvContextHandle.h" #endif +#ifdef USE_OPENCV +#include +#endif namespace plaYUVer { @@ -555,7 +556,6 @@ Bool PlaYUVerStream::saveFrame( const std::string& filename ) Bool PlaYUVerStream::saveFrame( const std::string& filename, PlaYUVerFrame *saveFrame ) { - QString qtString = QString::fromStdString( filename ); Int iFileFormat = INVALID_HANDLER; std::string fmtExt; @@ -585,12 +585,23 @@ Bool PlaYUVerStream::saveFrame( const std::string& filename, PlaYUVerFrame *save auxFrameStream.close(); return true; } +#if 0 else { saveFrame->fillRGBBuffer(); QImage qimg = QImage( saveFrame->getRGBBuffer(), saveFrame->getWidth(), saveFrame->getHeight(), QImage::Format_RGB32 ); return qimg.save( qtString ); } +#endif +#ifdef USE_OPENCV + else + { + cv::Mat* image; + saveFrame->getCvMat( (Void**)&image ); + return cv::imwrite( filename, *image ); + } + +#endif } return false; } From 64ecfbf016717e38dafa46bd76a44ce4f34db749 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 21 Feb 2015 21:34:32 +0000 Subject: [PATCH 04/25] Add function to convert a string to lowercase --- lib/PlaYUVerDefs.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/PlaYUVerDefs.h b/lib/PlaYUVerDefs.h index 26c6516..2976e92 100644 --- a/lib/PlaYUVerDefs.h +++ b/lib/PlaYUVerDefs.h @@ -26,6 +26,7 @@ #define __TYPEDEF_H__ #include +#include namespace plaYUVer { @@ -116,6 +117,13 @@ enum RGBcomponent COLOR_A, }; +inline std::string lowercase( const std::string& in ) +{ + std::string out; + transform( in.begin(), in.end(), std::back_inserter( out ), tolower ); + return out; +} + } // NAMESPACE #endif // __TYPEDEF_H__ From a8ee5c965828ccec05a2f46464634659bf5767a0 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 21 Feb 2015 21:34:53 +0000 Subject: [PATCH 05/25] Add interface to measure quality using command line --- lib/PlaYUVerCmdParser.cpp | 60 +++++++++++++++++++++++++++++++++++++-- lib/PlaYUVerCmdParser.h | 17 +++++++++-- lib/PlaYUVerStream.cpp | 3 +- tools/CMakeLists.txt | 5 ++-- tools/main.cpp | 47 ++++++------------------------ 5 files changed, 87 insertions(+), 45 deletions(-) diff --git a/lib/PlaYUVerCmdParser.cpp b/lib/PlaYUVerCmdParser.cpp index a261ff4..c965f41 100644 --- a/lib/PlaYUVerCmdParser.cpp +++ b/lib/PlaYUVerCmdParser.cpp @@ -23,6 +23,8 @@ */ #include "config.h" +#include +#include #include #include #include "PlaYUVerCmdParser.h" @@ -30,11 +32,25 @@ namespace plaYUVer { +PlaYUVerCmdParser::PlaYUVerCmdParser( Int argc, Char *argv[] ) +{ + m_iArgc = argc; + m_apcArgv = argv; + m_ParserOptions.add( GetCommandOpts() ); +} + +PlaYUVerCmdParser::~PlaYUVerCmdParser() +{ + +} + po::options_description PlaYUVerCmdParser::GetCommandOpts() { po::options_description inputOpts( "Input" ); inputOpts.add_options() - ( "input,i", po::value(), "input file" ) + ( "input,i", po::value >(), "input file" ) + ( "size,s", po::value(), "size (WxH)" ) + ( "pel_fmt", po::value(), "pixel format name" ) ( "width,w", po::value(), "width" ) ( "height,h", po::value(), "height" ); @@ -45,9 +61,49 @@ po::options_description PlaYUVerCmdParser::GetCommandOpts() po::options_description commonOpts( "Common" ); commonOpts.add_options() - ( "help", "produce help message" ); + ( "help", "produce help message" ) + ( "version", "show version and exit" ); commonOpts.add( inputOpts ).add( operationOpts ); return commonOpts; } +Void PlaYUVerCmdParser::addOptions( po::options_description opts ) +{ + m_ParserOptions.add( opts ); +} + +Bool PlaYUVerCmdParser::parse() +{ + try + { + po::store( po::command_line_parser( m_iArgc, m_apcArgv ).options( m_ParserOptions ).allow_unregistered().run(), m_cOptionsMap ); + po::notify( m_cOptionsMap ); + + if( m_cOptionsMap.count( "help" ) ) + { + std::cout << m_ParserOptions + << "\n"; + return false; + } + if( m_cOptionsMap.count( "version" ) ) + { + std::cout << "PlaYUVer version " + << PLAYUVER_VERSION_STRING + << "\n"; + return false; + } + } + catch( std::exception& e ) + { + std::cerr << "error: " << e.what() << "\n"; + return false; + } + catch( ... ) + { + std::cerr << "Exception of unknown type!\n"; + } + return true; +} + + } // NAMESPACE diff --git a/lib/PlaYUVerCmdParser.h b/lib/PlaYUVerCmdParser.h index 7d83161..2db28df 100644 --- a/lib/PlaYUVerCmdParser.h +++ b/lib/PlaYUVerCmdParser.h @@ -32,11 +32,24 @@ namespace plaYUVer class PlaYUVerCmdParser { public: - PlaYUVerCmdParser() {} ; - ~PlaYUVerCmdParser() {} ; + PlaYUVerCmdParser( Int argc, Char *argv[] ); + ~PlaYUVerCmdParser(); + + Void addOptions( po::options_description ); + Bool parse(); + + po::variables_map getOptionsMap() + { + return m_cOptionsMap; + } static po::options_description GetCommandOpts(); +private: + Int m_iArgc; + Char** m_apcArgv; + po::options_description m_ParserOptions; + po::variables_map m_cOptionsMap; }; } // NAMESPACE diff --git a/lib/PlaYUVerStream.cpp b/lib/PlaYUVerStream.cpp index 2d5d1c6..0a08f64 100644 --- a/lib/PlaYUVerStream.cpp +++ b/lib/PlaYUVerStream.cpp @@ -167,9 +167,10 @@ Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::st { return false; } + for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames().size(); i++ ) { - if( PlaYUVerFrame::supportedPixelFormatListNames()[i] == input_format_name ) + if( lowercase( PlaYUVerFrame::supportedPixelFormatListNames()[i] ) == lowercase( input_format_name ) ) { input_format = i; break; diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index e6dcc56..3e90e92 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -9,8 +9,9 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../ ) set(plaYUver_Tools_SRCS -# Main - main.cpp + # Main + main.cpp + PlaYUVerTools.cpp ) ADD_EXECUTABLE( ${PROJECT_NAME}Tools ${plaYUver_Tools_SRCS} ) diff --git a/tools/main.cpp b/tools/main.cpp index 7a659dd..df3a9f3 100644 --- a/tools/main.cpp +++ b/tools/main.cpp @@ -1,6 +1,7 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * + * Joao Carreira (jfmcarreira@gmail.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,50 +23,20 @@ * \brief main file */ -#include -#include -#include +#include "PlaYUVerTools.h" using namespace plaYUVer; -using namespace std; int main( int argc, char *argv[] ) { + PlaYUVerTools PlaYUVerToolsApp; - try + if( PlaYUVerToolsApp.Init( argc, argv ) > 1 ) { - - po::options_description toolsOpt; - toolsOpt.add( PlaYUVerCmdParser::GetCommandOpts() ); - po::variables_map vm; - po::store( po::parse_command_line( argc, argv, toolsOpt ), vm ); - po::notify( vm ); - - if( vm.count( "help" ) ) - { - cout << toolsOpt << "\n"; - return 0; - } - - if( vm.count( "compression" ) ) - { - cout << "Compression level was set to " << vm["compression"].as() << ".\n"; - } - else - { - cout << "Compression level was not set.\n"; - } - } - catch( exception& e ) - { - cerr << "error: " << e.what() << "\n"; + printf( "Exiting\n" ); return 1; } - catch( ... ) - { - cerr << "Exception of unknown type!\n"; - } - PlaYUVerFrame pcFrameBuffer = new PlaYUVerFrame( 1024, 768, PlaYUVerFrame::YUV420p ); - return 0; + PlaYUVerToolsApp.Process(); + } From 11bb3dbf969e704a6bb4028e2c7206436e97732a Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 21 Feb 2015 22:30:23 +0000 Subject: [PATCH 06/25] Add missing file --- tools/PlaYUVerTools.cpp | 171 ++++++++++++++++++++++++++++++++++++++++ tools/PlaYUVerTools.h | 65 +++++++++++++++ 2 files changed, 236 insertions(+) create mode 100644 tools/PlaYUVerTools.cpp create mode 100644 tools/PlaYUVerTools.h diff --git a/tools/PlaYUVerTools.cpp b/tools/PlaYUVerTools.cpp new file mode 100644 index 0000000..6d2e9c6 --- /dev/null +++ b/tools/PlaYUVerTools.cpp @@ -0,0 +1,171 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file PlaYUVerTools.cpp + * \brief Main definition of the PlaYUVerTools APp + */ + +#include "PlaYUVerTools.h" + +namespace plaYUVer +{ + +PlaYUVerTools::PlaYUVerTools() +{ + m_uiOperation = INVALID_OPERATION; +} + +PlaYUVerTools::~PlaYUVerTools() +{ + for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) + { + m_apcInputStreams[i]->close(); + } + for( UInt i = 0; i < m_apcOutputStreams.size(); i++ ) + { + m_apcOutputStreams[i]->close(); + } +} + +Int PlaYUVerTools::Init( Int argc, Char *argv[] ) +{ + + PlaYUVerCmdParser cCommandLineParser( argc, argv ); + + if( !cCommandLineParser.parse() ) + { + return 1; + } + + if( cCommandLineParser.getOptionsMap().count( "input" ) ) + { + if( !cCommandLineParser.getOptionsMap().count( "size" ) ) + { + printf( "Invalid resolution! " ); + return 2; + } + std::string resolutionString = cCommandLineParser.getOptionsMap()["size"].as(); + std::string fmtString( "yuv420p" ); + if( cCommandLineParser.getOptionsMap().count( "pel_fmt" ) ) + { + fmtString = cCommandLineParser.getOptionsMap()["pel_fmt"].as(); + } + + std::vector inputFileNames = cCommandLineParser.getOptionsMap()["input"].as >(); + + PlaYUVerStream* pcStream; + for( UInt i = 0; i < inputFileNames.size(); i++ ) + { + pcStream = new PlaYUVerStream; + if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, 1 ) ) + { + printf( "Error opening file %s! ", inputFileNames[i].c_str() ); + return 2; + } + m_apcInputStreams.push_back( pcStream ); + } + m_uiNumberOfFrames = MAX_UINT; + UInt currFrameNum; + for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) + { + currFrameNum = m_apcInputStreams[i]->getFrameNum(); + if( currFrameNum < m_uiNumberOfFrames ) + m_uiNumberOfFrames = currFrameNum; + } + } + + if( cCommandLineParser.getOptionsMap().count( "quality" ) ) + { + m_uiOperationIndex = -1; + std::string qualityMetric = cCommandLineParser.getOptionsMap()["quality"].as(); + if( m_apcInputStreams.size() != 2 ) + { + printf( "Invalid number of inputs! " ); + return 2; + } + for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ ) + { + if( lowercase( PlaYUVerFrame::supportedQualityMetricsList()[i] ) == lowercase( qualityMetric ) ) + { + m_uiOperationIndex = i; + } + } + if( m_uiOperationIndex == -1 ) + { + printf( "Invalid quality metric! " ); + return 2; + } + m_uiOperation = QUALITY_OPERATION; + } + + if( m_uiOperation == INVALID_OPERATION ) + { + printf( "No operation was selected! " ); + return 2; + } + return 0; +} + +Void PlaYUVerTools::Process() +{ + switch( m_uiOperation ) + { + case QUALITY_OPERATION: + qualityOperation(); + break; + } +} + +Void PlaYUVerTools::qualityOperation() +{ + PlaYUVerFrame* apcCurrFrame[m_apcInputStreams.size()]; + Bool abEOF[m_apcInputStreams.size()]; + Double dQuality; + + for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) + abEOF[i] = false; + + for( UInt frame = 0; frame < m_uiNumberOfFrames; frame++ ) + { + printf( " %3d", frame ); + for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) + apcCurrFrame[i] = m_apcInputStreams[i]->getCurrFrame(); + + for( UInt i = 1; i < m_apcInputStreams.size(); i++ ) + { + printf( " " ); + for( Int component = 0; component < 3; component++ ) + { + dQuality = apcCurrFrame[i]->getQuality( m_uiOperationIndex, apcCurrFrame[0], component ); + printf( " %5.3f", dQuality ); + } + } + printf( "\n" ); + for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) + { + if( !abEOF[i] ) + m_apcInputStreams[i]->readFrame(); + abEOF[i] |= m_apcInputStreams[i]->checkErrors( PlaYUVerStream::LAST_FRAME ); + m_apcInputStreams[i]->setNextFrame(); + } + } +} + +} // NAMESPACE diff --git a/tools/PlaYUVerTools.h b/tools/PlaYUVerTools.h new file mode 100644 index 0000000..ce3b48d --- /dev/null +++ b/tools/PlaYUVerTools.h @@ -0,0 +1,65 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file PlaYUVerTools.h + * \brief Main definition of the PlaYUVerTools app + */ + +#ifndef __PLAYUVERAPP_H__ +#define __PLAYUVERAPP_H__ + +#include "config.h" +#include "lib/PlaYUVerDefs.h" +#include +#include +#include + +namespace plaYUVer +{ + +class PlaYUVerTools +{ +public: + PlaYUVerTools(); + ~PlaYUVerTools(); + + Int Init( Int argc, Char *argv[] ); + Void Process(); + +private: + UInt m_uiOperation; + Int m_uiOperationIndex; + enum TOOLS_OPERATIONS_LIST + { + INVALID_OPERATION, + QUALITY_OPERATION, + MODULE_OPERATION, + }; + + UInt m_uiNumberOfFrames; + std::vector m_apcInputStreams; + std::vector m_apcOutputStreams; + + Void qualityOperation(); +}; + +} // NAMESPACE + +#endif // __PLAYUVERTOOLS_H__ From cbd3a65ed19475ba723d1ef2f05af7af49d7528d Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 23 Feb 2015 18:19:59 +0000 Subject: [PATCH 07/25] minor changes in PlaYUVerFrame and Stream --- lib/PlaYUVerFrame.cpp | 2 +- lib/PlaYUVerFrame.h | 2 +- lib/PlaYUVerStream.cpp | 20 +++++++++----------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index 854f8ec..e546cba 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -120,7 +120,7 @@ Int PlaYUVerFrame::getColorSpace() const return m_pcPelFormat->colorSpace; } -Int PlaYUVerFrame::getNumberChannels() const +UInt PlaYUVerFrame::getNumberChannels() const { return m_pcPelFormat->numberChannels; } diff --git a/lib/PlaYUVerFrame.h b/lib/PlaYUVerFrame.h index a3824b1..d0562a4 100644 --- a/lib/PlaYUVerFrame.h +++ b/lib/PlaYUVerFrame.h @@ -102,7 +102,7 @@ public: static UInt64 getBytesPerFrame( UInt, UInt, Int ); Int getColorSpace() const; - Int getNumberChannels() const; + UInt getNumberChannels() const; UInt getChromaWidth() const; UInt getChromaHeight() const; UInt getChromaLength() const; diff --git a/lib/PlaYUVerStream.cpp b/lib/PlaYUVerStream.cpp index 0a08f64..79225a8 100644 --- a/lib/PlaYUVerStream.cpp +++ b/lib/PlaYUVerStream.cpp @@ -162,12 +162,14 @@ Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::st UInt height; Int input_format = -1; - sscanf( resolution.c_str(), "%ux%u", &width, &height ); - if( width <= 0 || height <= 0 ) + if( resolution.size() > 0 ) { - return false; + sscanf( resolution.c_str(), "%ux%u", &width, &height ); + if( width <= 0 || height <= 0 ) + { + return false; + } } - for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames().size(); i++ ) { if( lowercase( PlaYUVerFrame::supportedPixelFormatListNames()[i] ) == lowercase( input_format_name ) ) @@ -176,11 +178,7 @@ Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::st break; } } - if( width > 0 && height > 0 && input_format >= 0 ) - { - return open( filename, width, height, input_format, frame_rate, bInput ); - } - return false; + return open( filename, width, height, input_format, frame_rate, bInput ); } Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int input_format, UInt frame_rate, Bool bInput ) @@ -481,7 +479,7 @@ Void PlaYUVerStream::readFrame() if( !m_bInit || !m_bIsInput ) return; - if( m_iCurrFrameNum + 1 >= ( Int64 )m_uiTotalFrameNum ) + if( m_iCurrFrameNum + ( m_uiFrameBufferSize - 1 )>= ( Int64 )m_uiTotalFrameNum ) { m_iErrorStatus = LAST_FRAME; m_pcNextFrame = NULL; @@ -598,7 +596,7 @@ Bool PlaYUVerStream::saveFrame( const std::string& filename, PlaYUVerFrame *save else { cv::Mat* image; - saveFrame->getCvMat( (Void**)&image ); + saveFrame->getCvMat( ( Void** )&image ); return cv::imwrite( filename, *image ); } From 6a6fdab5e52f8f0d09bb97bec52a4b44c61fe281 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 23 Feb 2015 18:20:24 +0000 Subject: [PATCH 08/25] Add new command line tools and improve the quality measuring --- lib/PlaYUVerCmdParser.cpp | 4 +- tools/PlaYUVerTools.cpp | 101 +++++++++++++++++++++++++++++--------- tools/PlaYUVerTools.h | 6 ++- tools/main.cpp | 14 +++++- 4 files changed, 95 insertions(+), 30 deletions(-) diff --git a/lib/PlaYUVerCmdParser.cpp b/lib/PlaYUVerCmdParser.cpp index c965f41..d3b7808 100644 --- a/lib/PlaYUVerCmdParser.cpp +++ b/lib/PlaYUVerCmdParser.cpp @@ -49,10 +49,10 @@ po::options_description PlaYUVerCmdParser::GetCommandOpts() po::options_description inputOpts( "Input" ); inputOpts.add_options() ( "input,i", po::value >(), "input file" ) + ( "output,o", po::value >(), "output file" ) ( "size,s", po::value(), "size (WxH)" ) ( "pel_fmt", po::value(), "pixel format name" ) - ( "width,w", po::value(), "width" ) - ( "height,h", po::value(), "height" ); + ( "frames,f", po::value(), "number of frames" ); po::options_description operationOpts( "Operation" ); operationOpts.add_options() diff --git a/tools/PlaYUVerTools.cpp b/tools/PlaYUVerTools.cpp index 6d2e9c6..39d87a9 100644 --- a/tools/PlaYUVerTools.cpp +++ b/tools/PlaYUVerTools.cpp @@ -30,6 +30,7 @@ namespace plaYUVer PlaYUVerTools::PlaYUVerTools() { m_uiOperation = INVALID_OPERATION; + m_uiNumberOfFrames = -1; } PlaYUVerTools::~PlaYUVerTools() @@ -44,7 +45,7 @@ PlaYUVerTools::~PlaYUVerTools() } } -Int PlaYUVerTools::Init( Int argc, Char *argv[] ) +Int PlaYUVerTools::Open( Int argc, Char *argv[] ) { PlaYUVerCmdParser cCommandLineParser( argc, argv ); @@ -54,14 +55,16 @@ Int PlaYUVerTools::Init( Int argc, Char *argv[] ) return 1; } + /** + * Create input streams + */ if( cCommandLineParser.getOptionsMap().count( "input" ) ) { - if( !cCommandLineParser.getOptionsMap().count( "size" ) ) + std::string resolutionString; + if( cCommandLineParser.getOptionsMap().count( "size" ) ) { - printf( "Invalid resolution! " ); - return 2; + resolutionString = cCommandLineParser.getOptionsMap()["size"].as(); } - std::string resolutionString = cCommandLineParser.getOptionsMap()["size"].as(); std::string fmtString( "yuv420p" ); if( cCommandLineParser.getOptionsMap().count( "pel_fmt" ) ) { @@ -82,15 +85,31 @@ Int PlaYUVerTools::Init( Int argc, Char *argv[] ) m_apcInputStreams.push_back( pcStream ); } m_uiNumberOfFrames = MAX_UINT; - UInt currFrameNum; + if( cCommandLineParser.getOptionsMap().count( "frames" ) ) + { + m_uiNumberOfFrames = cCommandLineParser.getOptionsMap()["frames"].as(); + } + + m_uiNumberOfComponents = MAX_UINT; for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) { - currFrameNum = m_apcInputStreams[i]->getFrameNum(); - if( currFrameNum < m_uiNumberOfFrames ) - m_uiNumberOfFrames = currFrameNum; + if( m_apcInputStreams[i]->getFrameNum() < m_uiNumberOfFrames ) + m_uiNumberOfFrames = m_apcInputStreams[i]->getFrameNum(); + if( m_apcInputStreams[i]->getCurrFrame()->getNumberChannels() < m_uiNumberOfComponents ) + m_uiNumberOfComponents = m_apcInputStreams[i]->getCurrFrame()->getNumberChannels(); } } + /** + * Create output streams + */ + if( cCommandLineParser.getOptionsMap().count( "output" ) ) + { + + } + /** + * Check Quality operation + */ if( cCommandLineParser.getOptionsMap().count( "quality" ) ) { m_uiOperationIndex = -1; @@ -115,6 +134,14 @@ Int PlaYUVerTools::Init( Int argc, Char *argv[] ) m_uiOperation = QUALITY_OPERATION; } + /** + * Check Module operation + */ + if( cCommandLineParser.getOptionsMap().count( "module" ) ) + { + + } + if( m_uiOperation == INVALID_OPERATION ) { printf( "No operation was selected! " ); @@ -123,49 +150,75 @@ Int PlaYUVerTools::Init( Int argc, Char *argv[] ) return 0; } -Void PlaYUVerTools::Process() +Int PlaYUVerTools::Process() { switch( m_uiOperation ) { case QUALITY_OPERATION: + printf( " Measuring Quality using %s ... \n", PlaYUVerFrame::supportedQualityMetricsList()[m_uiOperationIndex].c_str() ); qualityOperation(); break; } + return 0; +} + +Int PlaYUVerTools::Close() +{ +// Finish + return 0; } Void PlaYUVerTools::qualityOperation() { PlaYUVerFrame* apcCurrFrame[m_apcInputStreams.size()]; Bool abEOF[m_apcInputStreams.size()]; + Double adAverageQuality[m_apcInputStreams.size() - 1][m_uiNumberOfComponents]; Double dQuality; - for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) - abEOF[i] = false; - + for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) + { + abEOF[s] = false; + for( UInt c = 0; c < m_uiNumberOfComponents; c++ ) + { + adAverageQuality[s][c] = 0; + } + } for( UInt frame = 0; frame < m_uiNumberOfFrames; frame++ ) { printf( " %3d", frame ); - for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) - apcCurrFrame[i] = m_apcInputStreams[i]->getCurrFrame(); + for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) + apcCurrFrame[s] = m_apcInputStreams[s]->getCurrFrame(); - for( UInt i = 1; i < m_apcInputStreams.size(); i++ ) + for( UInt s = 1; s < m_apcInputStreams.size(); s++ ) { printf( " " ); - for( Int component = 0; component < 3; component++ ) + for( UInt c = 0; c < m_uiNumberOfComponents; c++ ) { - dQuality = apcCurrFrame[i]->getQuality( m_uiOperationIndex, apcCurrFrame[0], component ); - printf( " %5.3f", dQuality ); + dQuality = apcCurrFrame[s]->getQuality( m_uiOperationIndex, apcCurrFrame[0], c ); + adAverageQuality[s - 1][c] = ( adAverageQuality[s - 1][c] * Double( frame ) + dQuality ) / Double( frame + 1 ); + printf( " %5.3f", dQuality ); } } printf( "\n" ); - for( UInt i = 0; i < m_apcInputStreams.size(); i++ ) + for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) { - if( !abEOF[i] ) - m_apcInputStreams[i]->readFrame(); - abEOF[i] |= m_apcInputStreams[i]->checkErrors( PlaYUVerStream::LAST_FRAME ); - m_apcInputStreams[i]->setNextFrame(); + m_apcInputStreams[s]->setNextFrame(); + if( !abEOF[s] ) + { + m_apcInputStreams[s]->readFrame(); + abEOF[s] = m_apcInputStreams[s]->checkErrors( PlaYUVerStream::LAST_FRAME ); + } } } + printf( "\n Mean Values: \n " ); + for( UInt s = 0; s < m_apcInputStreams.size() - 1; s++ ) + { + for( UInt c = 0; c < m_uiNumberOfComponents; c++ ) + { + printf( " %5.3f", adAverageQuality[s][c] ); + } + } + printf( "\n"); } } // NAMESPACE diff --git a/tools/PlaYUVerTools.h b/tools/PlaYUVerTools.h index ce3b48d..5e6f4a3 100644 --- a/tools/PlaYUVerTools.h +++ b/tools/PlaYUVerTools.h @@ -40,8 +40,9 @@ public: PlaYUVerTools(); ~PlaYUVerTools(); - Int Init( Int argc, Char *argv[] ); - Void Process(); + Int Open( Int argc, Char *argv[] ); + Int Process(); + Int Close(); private: UInt m_uiOperation; @@ -54,6 +55,7 @@ private: }; UInt m_uiNumberOfFrames; + UInt m_uiNumberOfComponents; std::vector m_apcInputStreams; std::vector m_apcOutputStreams; diff --git a/tools/main.cpp b/tools/main.cpp index df3a9f3..910ddc6 100644 --- a/tools/main.cpp +++ b/tools/main.cpp @@ -31,12 +31,22 @@ int main( int argc, char *argv[] ) { PlaYUVerTools PlaYUVerToolsApp; - if( PlaYUVerToolsApp.Init( argc, argv ) > 1 ) + if( PlaYUVerToolsApp.Open( argc, argv ) > 1 ) { printf( "Exiting\n" ); return 1; } - PlaYUVerToolsApp.Process(); + if( PlaYUVerToolsApp.Process() > 1 ) + { + printf( "Exiting\n" ); + return 1; + } + + if( PlaYUVerToolsApp.Close() > 1 ) + { + printf( "Exiting\n" ); + return 1; + } } From 1f12968b90351d9ce1c12547b2549ade81af5ec4 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 23 Feb 2015 18:37:10 +0000 Subject: [PATCH 09/25] Improve generic command line interface --- lib/PlaYUVerCmdParser.cpp | 65 +++++++++++++++++++++++++++++---------- lib/PlaYUVerCmdParser.h | 2 ++ 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/lib/PlaYUVerCmdParser.cpp b/lib/PlaYUVerCmdParser.cpp index d3b7808..3701c20 100644 --- a/lib/PlaYUVerCmdParser.cpp +++ b/lib/PlaYUVerCmdParser.cpp @@ -28,6 +28,7 @@ #include #include #include "PlaYUVerCmdParser.h" +#include "PlaYUVerFrame.h" namespace plaYUVer { @@ -47,27 +48,29 @@ PlaYUVerCmdParser::~PlaYUVerCmdParser() po::options_description PlaYUVerCmdParser::GetCommandOpts() { po::options_description inputOpts( "Input" ); - inputOpts.add_options() - ( "input,i", po::value >(), "input file" ) - ( "output,o", po::value >(), "output file" ) - ( "size,s", po::value(), "size (WxH)" ) - ( "pel_fmt", po::value(), "pixel format name" ) - ( "frames,f", po::value(), "number of frames" ); + inputOpts.add_options()/**/ + ( "input,i", po::value >(), "input file" ) /**/ + ( "output,o", po::value >(), "output file" ) /**/ + ( "size,s", po::value(), "size (WxH)" ) /**/ + ( "pel_fmt", po::value(), "pixel format" ) /**/ + ( "pel_fmts", "list pixel formats" ) /**/ + ( "frames,f", po::value(), "number of frames" ); po::options_description operationOpts( "Operation" ); - operationOpts.add_options() - ( "module", po::value(), "select a module" ) - ( "quality", po::value(),"select a quality metric" ); + operationOpts.add_options() /**/ + ( "module", po::value(), "select a module" ) /**/ + ( "quality", po::value(), "select a quality metric" ) /**/ + ( "quality_metrics", "list supported quality metrics" ); po::options_description commonOpts( "Common" ); - commonOpts.add_options() - ( "help", "produce help message" ) - ( "version", "show version and exit" ); + commonOpts.add_options()/**/ + ( "help", "produce help message" )/**/ + ( "version", "show version and exit" ); commonOpts.add( inputOpts ).add( operationOpts ); return commonOpts; } -Void PlaYUVerCmdParser::addOptions( po::options_description opts ) +Void PlaYUVerCmdParser::addOptions( po::options_description opts ) { m_ParserOptions.add( opts ); } @@ -88,14 +91,20 @@ Bool PlaYUVerCmdParser::parse() if( m_cOptionsMap.count( "version" ) ) { std::cout << "PlaYUVer version " - << PLAYUVER_VERSION_STRING - << "\n"; + << PLAYUVER_VERSION_STRING + << "\n"; + return false; + } + if( checkListingOpts() ) + { return false; } } catch( std::exception& e ) { - std::cerr << "error: " << e.what() << "\n"; + std::cerr << "error: " + << e.what() + << "\n"; return false; } catch( ... ) @@ -105,5 +114,29 @@ Bool PlaYUVerCmdParser::parse() return true; } +Bool PlaYUVerCmdParser::checkListingOpts() +{ + Bool bRet = false; + if( m_cOptionsMap.count( "pel_fmts" ) ) + { + printf( "PlaYUVer supported pixel formats: \n" ); + for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames().size(); i++ ) + { + printf( " %s\n", PlaYUVerFrame::supportedPixelFormatListNames()[i].c_str() ); + } + bRet |= true; + } + + if( m_cOptionsMap.count( "quality_metrics" ) ) + { + printf( "PlaYUVer supported quality metrics: \n" ); + for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ ) + { + printf( " %s\n", PlaYUVerFrame::supportedQualityMetricsList()[i].c_str() ); + } + bRet |= true; + } + return bRet; +} } // NAMESPACE diff --git a/lib/PlaYUVerCmdParser.h b/lib/PlaYUVerCmdParser.h index 2db28df..6831788 100644 --- a/lib/PlaYUVerCmdParser.h +++ b/lib/PlaYUVerCmdParser.h @@ -50,6 +50,8 @@ private: Char** m_apcArgv; po::options_description m_ParserOptions; po::variables_map m_cOptionsMap; + + Bool checkListingOpts(); }; } // NAMESPACE From 7c608e9d38299a4a0253b88af107805e81fd31eb Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 23 Feb 2015 21:38:12 +0000 Subject: [PATCH 10/25] Reorganize functions --- lib/PlaYUVerCmdParser.cpp | 12 +++++-- lib/PlaYUVerCmdParser.h | 3 +- tools/PlaYUVerTools.cpp | 74 +++++++++++++++++++++------------------ tools/PlaYUVerTools.h | 10 +++++- tools/main.cpp | 8 ++++- 5 files changed, 67 insertions(+), 40 deletions(-) diff --git a/lib/PlaYUVerCmdParser.cpp b/lib/PlaYUVerCmdParser.cpp index 3701c20..7a9ef94 100644 --- a/lib/PlaYUVerCmdParser.cpp +++ b/lib/PlaYUVerCmdParser.cpp @@ -33,10 +33,10 @@ namespace plaYUVer { -PlaYUVerCmdParser::PlaYUVerCmdParser( Int argc, Char *argv[] ) +PlaYUVerCmdParser::PlaYUVerCmdParser() { - m_iArgc = argc; - m_apcArgv = argv; + m_iArgc = 0; + m_apcArgv = NULL; m_ParserOptions.add( GetCommandOpts() ); } @@ -45,6 +45,12 @@ PlaYUVerCmdParser::~PlaYUVerCmdParser() } +Void PlaYUVerCmdParser::Config( Int argc, Char *argv[] ) +{ + m_iArgc = argc; + m_apcArgv = argv; +} + po::options_description PlaYUVerCmdParser::GetCommandOpts() { po::options_description inputOpts( "Input" ); diff --git a/lib/PlaYUVerCmdParser.h b/lib/PlaYUVerCmdParser.h index 6831788..6dbee30 100644 --- a/lib/PlaYUVerCmdParser.h +++ b/lib/PlaYUVerCmdParser.h @@ -32,9 +32,10 @@ namespace plaYUVer class PlaYUVerCmdParser { public: - PlaYUVerCmdParser( Int argc, Char *argv[] ); + PlaYUVerCmdParser(); ~PlaYUVerCmdParser(); + Void Config( Int argc, Char *argv[] ); Void addOptions( po::options_description ); Bool parse(); diff --git a/tools/PlaYUVerTools.cpp b/tools/PlaYUVerTools.cpp index 39d87a9..116c47e 100644 --- a/tools/PlaYUVerTools.cpp +++ b/tools/PlaYUVerTools.cpp @@ -45,33 +45,25 @@ PlaYUVerTools::~PlaYUVerTools() } } -Int PlaYUVerTools::Open( Int argc, Char *argv[] ) +Int PlaYUVerTools::openInputs() { - - PlaYUVerCmdParser cCommandLineParser( argc, argv ); - - if( !cCommandLineParser.parse() ) - { - return 1; - } - /** * Create input streams */ - if( cCommandLineParser.getOptionsMap().count( "input" ) ) + if( m_cCommandLineParser.getOptionsMap().count( "input" ) ) { std::string resolutionString; - if( cCommandLineParser.getOptionsMap().count( "size" ) ) + if( m_cCommandLineParser.getOptionsMap().count( "size" ) ) { - resolutionString = cCommandLineParser.getOptionsMap()["size"].as(); + resolutionString = m_cCommandLineParser.getOptionsMap()["size"].as(); } std::string fmtString( "yuv420p" ); - if( cCommandLineParser.getOptionsMap().count( "pel_fmt" ) ) + if( m_cCommandLineParser.getOptionsMap().count( "pel_fmt" ) ) { - fmtString = cCommandLineParser.getOptionsMap()["pel_fmt"].as(); + fmtString = m_cCommandLineParser.getOptionsMap()["pel_fmt"].as(); } - std::vector inputFileNames = cCommandLineParser.getOptionsMap()["input"].as >(); + std::vector inputFileNames = m_cCommandLineParser.getOptionsMap()["input"].as >(); PlaYUVerStream* pcStream; for( UInt i = 0; i < inputFileNames.size(); i++ ) @@ -85,9 +77,9 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) m_apcInputStreams.push_back( pcStream ); } m_uiNumberOfFrames = MAX_UINT; - if( cCommandLineParser.getOptionsMap().count( "frames" ) ) + if( m_cCommandLineParser.getOptionsMap().count( "frames" ) ) { - m_uiNumberOfFrames = cCommandLineParser.getOptionsMap()["frames"].as(); + m_uiNumberOfFrames = m_cCommandLineParser.getOptionsMap()["frames"].as(); } m_uiNumberOfComponents = MAX_UINT; @@ -99,21 +91,38 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) m_uiNumberOfComponents = m_apcInputStreams[i]->getCurrFrame()->getNumberChannels(); } } + return 0; +} - /** - * Create output streams - */ - if( cCommandLineParser.getOptionsMap().count( "output" ) ) +Int PlaYUVerTools::openOutputs() +{ + if( m_cCommandLineParser.getOptionsMap().count( "output" ) ) { } + return 0; +} + +Int PlaYUVerTools::Open( Int argc, Char *argv[] ) +{ + m_cCommandLineParser.Config( argc, argv ); + if( !m_cCommandLineParser.parse() ) + { + return 1; + } + + if( openInputs() > 0 || openOutputs() > 0 ) + { + return 2; + } + /** * Check Quality operation */ - if( cCommandLineParser.getOptionsMap().count( "quality" ) ) + if( m_cCommandLineParser.getOptionsMap().count( "quality" ) ) { m_uiOperationIndex = -1; - std::string qualityMetric = cCommandLineParser.getOptionsMap()["quality"].as(); + std::string qualityMetric = m_cCommandLineParser.getOptionsMap()["quality"].as(); if( m_apcInputStreams.size() != 2 ) { printf( "Invalid number of inputs! " ); @@ -132,12 +141,13 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) return 2; } m_uiOperation = QUALITY_OPERATION; + m_fpProcess = &PlaYUVerTools::QualityOperation; } /** * Check Module operation */ - if( cCommandLineParser.getOptionsMap().count( "module" ) ) + if( m_cCommandLineParser.getOptionsMap().count( "module" ) ) { } @@ -152,14 +162,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) Int PlaYUVerTools::Process() { - switch( m_uiOperation ) - { - case QUALITY_OPERATION: - printf( " Measuring Quality using %s ... \n", PlaYUVerFrame::supportedQualityMetricsList()[m_uiOperationIndex].c_str() ); - qualityOperation(); - break; - } - return 0; + return (this->*m_fpProcess)(); } Int PlaYUVerTools::Close() @@ -168,13 +171,15 @@ Int PlaYUVerTools::Close() return 0; } -Void PlaYUVerTools::qualityOperation() +Int PlaYUVerTools::QualityOperation() { PlaYUVerFrame* apcCurrFrame[m_apcInputStreams.size()]; Bool abEOF[m_apcInputStreams.size()]; Double adAverageQuality[m_apcInputStreams.size() - 1][m_uiNumberOfComponents]; Double dQuality; + printf( " Measuring Quality using %s ... \n", PlaYUVerFrame::supportedQualityMetricsList()[m_uiOperationIndex].c_str() ); + for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) { abEOF[s] = false; @@ -218,7 +223,8 @@ Void PlaYUVerTools::qualityOperation() printf( " %5.3f", adAverageQuality[s][c] ); } } - printf( "\n"); + printf( "\n" ); + return 0; } } // NAMESPACE diff --git a/tools/PlaYUVerTools.h b/tools/PlaYUVerTools.h index 5e6f4a3..75314f1 100644 --- a/tools/PlaYUVerTools.h +++ b/tools/PlaYUVerTools.h @@ -45,6 +45,8 @@ public: Int Close(); private: + PlaYUVerCmdParser m_cCommandLineParser; + UInt m_uiOperation; Int m_uiOperationIndex; enum TOOLS_OPERATIONS_LIST @@ -59,7 +61,13 @@ private: std::vector m_apcInputStreams; std::vector m_apcOutputStreams; - Void qualityOperation(); + Int openInputs(); + Int openOutputs(); + + typedef Int (PlaYUVerTools::*FpProcess) (); + FpProcess m_fpProcess; + + Int QualityOperation(); }; } // NAMESPACE diff --git a/tools/main.cpp b/tools/main.cpp index 910ddc6..4c31c20 100644 --- a/tools/main.cpp +++ b/tools/main.cpp @@ -29,9 +29,15 @@ using namespace plaYUVer; int main( int argc, char *argv[] ) { + Int iRet = 0; PlaYUVerTools PlaYUVerToolsApp; - if( PlaYUVerToolsApp.Open( argc, argv ) > 1 ) + iRet = PlaYUVerToolsApp.Open( argc, argv ); + if( iRet == 1 ) + { + return 0; + } + if( iRet > 1 ) { printf( "Exiting\n" ); return 1; From 65c19e3e170ed8abffcd7e517ae2d07e0430434c Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 24 Feb 2015 00:46:45 +0000 Subject: [PATCH 11/25] Fix issues with configuration --- tools/PlaYUVerTools.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tools/PlaYUVerTools.cpp b/tools/PlaYUVerTools.cpp index 116c47e..358a558 100644 --- a/tools/PlaYUVerTools.cpp +++ b/tools/PlaYUVerTools.cpp @@ -69,12 +69,20 @@ Int PlaYUVerTools::openInputs() for( UInt i = 0; i < inputFileNames.size(); i++ ) { pcStream = new PlaYUVerStream; - if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, 1 ) ) + try { - printf( "Error opening file %s! ", inputFileNames[i].c_str() ); - return 2; + if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, 1 ) ) + { + printf( "Cannot open input stream %s! ", inputFileNames[i].c_str() ); + return 2; + } + m_apcInputStreams.push_back( pcStream ); + } + catch( const char *msg ) + { + printf( "Cannot open input stream %s with the following error: \n%s", inputFileNames[i].c_str(), msg ); + return false; } - m_apcInputStreams.push_back( pcStream ); } m_uiNumberOfFrames = MAX_UINT; if( m_cCommandLineParser.getOptionsMap().count( "frames" ) ) @@ -111,7 +119,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) return 1; } - if( openInputs() > 0 || openOutputs() > 0 ) + if( openInputs() > 0 ) { return 2; } @@ -162,7 +170,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) Int PlaYUVerTools::Process() { - return (this->*m_fpProcess)(); + return ( this->*m_fpProcess )(); } Int PlaYUVerTools::Close() From 6ff4a53d87e80fc88a96b602588283577fd7da18 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 24 Feb 2015 00:47:33 +0000 Subject: [PATCH 12/25] Organize cmake file. Put all qt dependencies in app CMakeLists --- CMakeLists.txt | 64 ++++++++++-------------------------------- app/CMakeLists.txt | 35 +++++++++++++++++++++++ modules/CMakeLists.txt | 2 ++ 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bbb827..8418ee5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ SET( PLAYUVER_VERSION_PATCH "0" ) SET( PLAYUVER_VERSION "${PLAYUVER_VERSION_MAJOR}.${PLAYUVER_VERSION_MINOR}.${PLAYUVER_VERSION_PATCH}") ###################################################################################### -# CMake Definitions +# CMake Defin1itions ###################################################################################### SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ) @@ -30,56 +30,17 @@ IF(DEFINED CMAKE_BUILD_TYPE AND CMAKE_VERSION VERSION_GREATER "2.8") ENDIF() SET( CMAKE_CXX_FLAGS "" ) +cmake_policy(SET CMP0043 NEW) ###################################################################################### # Variables ###################################################################################### +OPTION( PLAYUVER_BUILD_APP "Build GUI Application" ON ) +OPTION( PLAYUVER_BUILD_TOOLS "Build Command Line Application" ON ) + OPTION( USE_FERVOR "Add Fervor support" OFF ) -OPTION( PLAYUVER_LONGVERSIONNAME "Use long version name in deb" OFF ) -OPTION( PLAYUVER_WERROR "Warnings as errors" OFF ) -OPTION( PLAYUVER_THREADED_MODULES "Use threads for modules" OFF ) -OPTION( USE_QT4 "Build with QT4" OFF ) - -##################################################################################### -# Qt library -###################################################################################### - -IF( USE_QT4 ) - SET( DEPENDENCIES_STRING "${DEPENDENCIES_STRING}QT4" ) - FIND_PACKAGE( Qt4 REQUIRED COMPONENTS QtCore QtGui QtDBus QtNetwork QtWebKit ) - - SET( USE_QTDBUS TRUE ) - - IF( NOT QT4_FOUND ) - SET(USE_QT4 FALSE) - ELSE() - INCLUDE( ${QT_USE_FILE} ) - ADD_DEFINITIONS( ${QT_DEFINITIONS} ) - SET( QT_LINKER_LIBS ${QT_LIBRARIES} ) - ENDIF() -ENDIF() - -IF( NOT USE_QT4 ) - - SET( DEPENDENCIES_STRING "${DEPENDENCIES_STRING}QT5" ) - - FIND_PACKAGE( Qt5 REQUIRED COMPONENTS Core Gui Widgets PrintSupport ) - FIND_PACKAGE( Qt5DBus ) - - - LIST(APPEND QT_LINKER_LIBS Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport ) - LIST(APPEND QT_MODULES Core Gui Widgets ) - IF( ${Qt5DBus_FOUND} ) - SET( USE_QTDBUS ${Qt5DBus_FOUND} ) - LIST(APPEND QT_LINKER_LIBS Qt5::DBus ) - LIST(APPEND QT_MODULES DBus ) - ENDIF() - - INCLUDE_DIRECTORIES( ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}) - SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}" ) - -ENDIF() +OPTION( USE_WERROR "Warnings as errors" OFF ) ###################################################################################### # Dependencies @@ -133,9 +94,14 @@ SET( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2" ) ADD_SUBDIRECTORY( lib ) ADD_SUBDIRECTORY( modules ) -ADD_SUBDIRECTORY( tools ) -ADD_SUBDIRECTORY( app ) +IF( PLAYUVER_BUILD_TOOLS ) + ADD_SUBDIRECTORY( tools ) +ENDIF() + +IF( PLAYUVER_BUILD_APP ) + ADD_SUBDIRECTORY( app ) +ENDIF() @@ -146,8 +112,8 @@ MESSAGE("") MESSAGE( STATUS "${PROJECT_NAME} INFORMATION" ) MESSAGE( STATUS "Version: " "${PLAYUVER_VERSION}" ) MESSAGE( STATUS "Configuration:" ) -MESSAGE( STATUS " Build type:" "${CMAKE_BUILD_TYPE}" ) -MESSAGE( STATUS " Build flags:" "${CMAKE_CXX_FLAGS}" ) +MESSAGE( STATUS " Build type: " "${CMAKE_BUILD_TYPE}" ) +MESSAGE( STATUS " Build flags:" "${CMAKE_CXX_FLAGS}" ) FEATURE_SUMMARY(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index f7eabd8..be5c85a 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -10,6 +10,41 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR}/../ ${CMAKE_CURRENT_SOURCE_DIR}/../modules ${CMAKE_CURRENT_BINARY_DIR}/../modules ) +##################################################################################### +# Qt library +###################################################################################### + +OPTION( USE_QT4 "Build with QT4" OFF ) + +IF( USE_QT4 ) + + FIND_PACKAGE( Qt4 REQUIRED COMPONENTS QtCore QtGui QtDBus QtNetwork QtWebKit ) + SET( USE_QTDBUS TRUE ) + IF( NOT QT4_FOUND ) + SET(USE_QT4 FALSE) + ELSE() + INCLUDE( ${QT_USE_FILE} ) + ADD_DEFINITIONS( ${QT_DEFINITIONS} ) + SET( QT_LINKER_LIBS ${QT_LIBRARIES} ) + ENDIF() +ENDIF() + +IF( NOT USE_QT4 ) + FIND_PACKAGE( Qt5 REQUIRED COMPONENTS Core Gui Widgets PrintSupport ) + FIND_PACKAGE( Qt5DBus ) + LIST(APPEND QT_LINKER_LIBS Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport ) + LIST(APPEND QT_MODULES Core Gui Widgets ) + IF( ${Qt5DBus_FOUND} ) + SET( USE_QTDBUS ${Qt5DBus_FOUND} ) + LIST(APPEND QT_LINKER_LIBS Qt5::DBus ) + LIST(APPEND QT_MODULES DBus ) + ENDIF() + + #INCLUDE_DIRECTORIES( ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}) + #SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS}" ) + +ENDIF() + set(plaYUver_App_SRCS # Main main.cpp diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 703d107..d420f11 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -2,6 +2,8 @@ ### CMakeLists for playuver modules component ### +OPTION( MODULE_THREADED_MODULES "Use threads for modules" OFF ) + INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../ ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) set(plaYUver_Mod_SRCS From e924a06a9eeedd83606cdb50f722374c9622537b Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 24 Feb 2015 01:45:54 +0000 Subject: [PATCH 13/25] Add class to handle command line args in the Tools App --- lib/PlaYUVerCmdParser.cpp | 12 ++++++---- tools/CMakeLists.txt | 2 +- tools/CommandLineHandle.cpp | 41 +++++++++++++++++++++++++++++++++ tools/CommandLineHandle.h | 46 +++++++++++++++++++++++++++++++++++++ tools/PlaYUVerTools.cpp | 6 ++--- tools/PlaYUVerTools.h | 12 +++++----- 6 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 tools/CommandLineHandle.cpp create mode 100644 tools/CommandLineHandle.h diff --git a/lib/PlaYUVerCmdParser.cpp b/lib/PlaYUVerCmdParser.cpp index 7a9ef94..ae9c4f8 100644 --- a/lib/PlaYUVerCmdParser.cpp +++ b/lib/PlaYUVerCmdParser.cpp @@ -62,17 +62,21 @@ po::options_description PlaYUVerCmdParser::GetCommandOpts() ( "pel_fmts", "list pixel formats" ) /**/ ( "frames,f", po::value(), "number of frames" ); - po::options_description operationOpts( "Operation" ); - operationOpts.add_options() /**/ - ( "module", po::value(), "select a module" ) /**/ + po::options_description qualityOpts( "Quality" ); + qualityOpts.add_options() /**/ ( "quality", po::value(), "select a quality metric" ) /**/ ( "quality_metrics", "list supported quality metrics" ); + po::options_description moduleOpts( "Module" ); + moduleOpts.add_options() /**/ + ( "module", po::value(), "select a module" ) /**/ + ( "module_list", "list supported modules" ); + po::options_description commonOpts( "Common" ); commonOpts.add_options()/**/ ( "help", "produce help message" )/**/ ( "version", "show version and exit" ); - commonOpts.add( inputOpts ).add( operationOpts ); + commonOpts.add( inputOpts ).add( qualityOpts ).add( moduleOpts ); return commonOpts; } diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 3e90e92..f45ce07 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -9,9 +9,9 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../ ) set(plaYUver_Tools_SRCS - # Main main.cpp PlaYUVerTools.cpp + CommandLineHandle.cpp ) ADD_EXECUTABLE( ${PROJECT_NAME}Tools ${plaYUver_Tools_SRCS} ) diff --git a/tools/CommandLineHandle.cpp b/tools/CommandLineHandle.cpp new file mode 100644 index 0000000..be0f49d --- /dev/null +++ b/tools/CommandLineHandle.cpp @@ -0,0 +1,41 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file CommandLineHandle.cpp + * \brief Handle for command line + */ + +#include "CommandLineHandle.h" + +namespace plaYUVer +{ + +CommandLineHandle::CommandLineHandle() +{ + +} + +CommandLineHandle::~CommandLineHandle() +{ + +} + + +} // NAMESPACE diff --git a/tools/CommandLineHandle.h b/tools/CommandLineHandle.h new file mode 100644 index 0000000..b4a6ad6 --- /dev/null +++ b/tools/CommandLineHandle.h @@ -0,0 +1,46 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file CommandLineHandle.h + * \brief Handle for command line + */ + +#ifndef __COMMANDLINEHANDLE_H__ +#define __COMMANDLINEHANDLE_H__ + +#include "config.h" +#include "lib/PlaYUVerDefs.h" +#include "lib/PlaYUVerCmdParser.h" + +namespace plaYUVer +{ + +class CommandLineHandle: public PlaYUVerCmdParser +{ +public: + CommandLineHandle(); + ~CommandLineHandle(); + + +}; + +} // NAMESPACE + +#endif // __COMMANDLINEHANDLE_H__ diff --git a/tools/PlaYUVerTools.cpp b/tools/PlaYUVerTools.cpp index 358a558..1216b2d 100644 --- a/tools/PlaYUVerTools.cpp +++ b/tools/PlaYUVerTools.cpp @@ -52,7 +52,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(); @@ -80,8 +80,8 @@ Int PlaYUVerTools::openInputs() } catch( const char *msg ) { - printf( "Cannot open input stream %s with the following error: \n%s", inputFileNames[i].c_str(), msg ); - return false; + printf( "Cannot open input stream %s with the following error: \n%s\n", inputFileNames[i].c_str(), msg ); + return 2; } } m_uiNumberOfFrames = MAX_UINT; diff --git a/tools/PlaYUVerTools.h b/tools/PlaYUVerTools.h index 75314f1..4d1464b 100644 --- a/tools/PlaYUVerTools.h +++ b/tools/PlaYUVerTools.h @@ -22,14 +22,14 @@ * \brief Main definition of the PlaYUVerTools app */ -#ifndef __PLAYUVERAPP_H__ -#define __PLAYUVERAPP_H__ +#ifndef __PLAYUVERTOOLS_H__ +#define __PLAYUVERTOOLS_H__ #include "config.h" #include "lib/PlaYUVerDefs.h" -#include -#include -#include +#include "lib/PlaYUVerFrame.h" +#include "lib/PlaYUVerStream.h" +#include "CommandLineHandle.h" namespace plaYUVer { @@ -45,7 +45,7 @@ public: Int Close(); private: - PlaYUVerCmdParser m_cCommandLineParser; + CommandLineHandle m_cCommandLineParser; UInt m_uiOperation; Int m_uiOperationIndex; From 40aa4f95f35af36dffe85f899e5aee44d252ab4f Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 24 Feb 2015 01:53:54 +0000 Subject: [PATCH 14/25] Seperate command opts by app --- lib/PlaYUVerCmdParser.cpp | 22 +--------------------- tools/CommandLineHandle.cpp | 35 +++++++++++++++++++++++++++++++++++ tools/CommandLineHandle.h | 1 + tools/PlaYUVerTools.cpp | 8 +++++--- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/lib/PlaYUVerCmdParser.cpp b/lib/PlaYUVerCmdParser.cpp index ae9c4f8..0d9c1c8 100644 --- a/lib/PlaYUVerCmdParser.cpp +++ b/lib/PlaYUVerCmdParser.cpp @@ -62,21 +62,11 @@ po::options_description PlaYUVerCmdParser::GetCommandOpts() ( "pel_fmts", "list pixel formats" ) /**/ ( "frames,f", po::value(), "number of frames" ); - po::options_description qualityOpts( "Quality" ); - qualityOpts.add_options() /**/ - ( "quality", po::value(), "select a quality metric" ) /**/ - ( "quality_metrics", "list supported quality metrics" ); - - po::options_description moduleOpts( "Module" ); - moduleOpts.add_options() /**/ - ( "module", po::value(), "select a module" ) /**/ - ( "module_list", "list supported modules" ); - po::options_description commonOpts( "Common" ); commonOpts.add_options()/**/ ( "help", "produce help message" )/**/ ( "version", "show version and exit" ); - commonOpts.add( inputOpts ).add( qualityOpts ).add( moduleOpts ); + commonOpts.add( inputOpts ); return commonOpts; } @@ -136,16 +126,6 @@ Bool PlaYUVerCmdParser::checkListingOpts() } bRet |= true; } - - if( m_cOptionsMap.count( "quality_metrics" ) ) - { - printf( "PlaYUVer supported quality metrics: \n" ); - for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ ) - { - printf( " %s\n", PlaYUVerFrame::supportedQualityMetricsList()[i].c_str() ); - } - bRet |= true; - } return bRet; } diff --git a/tools/CommandLineHandle.cpp b/tools/CommandLineHandle.cpp index be0f49d..418f083 100644 --- a/tools/CommandLineHandle.cpp +++ b/tools/CommandLineHandle.cpp @@ -23,6 +23,7 @@ */ #include "CommandLineHandle.h" +#include "lib/PlaYUVerFrame.h" namespace plaYUVer { @@ -37,5 +38,39 @@ CommandLineHandle::~CommandLineHandle() } +Int CommandLineHandle::ParseToolsArgs() +{ + Int iRet = 0; + + po::options_description qualityOpts( "Quality" ); + qualityOpts.add_options() /**/ + ( "quality", po::value(), "select a quality metric" ) /**/ + ( "quality_metrics", "list supported quality metrics" ); + + po::options_description moduleOpts( "Module" ); + moduleOpts.add_options() /**/ + ( "module", po::value(), "select a module" ) /**/ + ( "module_list", "list supported modules" ); + + addOptions( qualityOpts ); + addOptions( moduleOpts ); + + if( !parse() ) + { + iRet = 1; + } + + if( getOptionsMap().count( "quality_metrics" ) ) + { + printf( "PlaYUVer supported quality metrics: \n" ); + for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ ) + { + printf( " %s\n", PlaYUVerFrame::supportedQualityMetricsList()[i].c_str() ); + } + iRet = 1; + } + + return iRet; +} } // NAMESPACE diff --git a/tools/CommandLineHandle.h b/tools/CommandLineHandle.h index b4a6ad6..1d8565a 100644 --- a/tools/CommandLineHandle.h +++ b/tools/CommandLineHandle.h @@ -38,6 +38,7 @@ public: CommandLineHandle(); ~CommandLineHandle(); + Int ParseToolsArgs(); }; diff --git a/tools/PlaYUVerTools.cpp b/tools/PlaYUVerTools.cpp index 1216b2d..23d9636 100644 --- a/tools/PlaYUVerTools.cpp +++ b/tools/PlaYUVerTools.cpp @@ -113,10 +113,12 @@ Int PlaYUVerTools::openOutputs() Int PlaYUVerTools::Open( Int argc, Char *argv[] ) { + Int iRet = 0; + m_cCommandLineParser.Config( argc, argv ); - if( !m_cCommandLineParser.parse() ) + if( ( iRet = m_cCommandLineParser.ParseToolsArgs() ) > 0 ) { - return 1; + return iRet; } if( openInputs() > 0 ) @@ -165,7 +167,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) printf( "No operation was selected! " ); return 2; } - return 0; + return iRet; } Int PlaYUVerTools::Process() From db4b6fa1a10b464f15f88a20c680a3128ec5da83 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 24 Feb 2015 02:11:18 +0000 Subject: [PATCH 15/25] Remove spaces from modules names --- modules/FilterComponent.cpp | 10 +++++----- modules/LumaAverage.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/FilterComponent.cpp b/modules/FilterComponent.cpp index a030bdf..6102704 100644 --- a/modules/FilterComponent.cpp +++ b/modules/FilterComponent.cpp @@ -60,7 +60,7 @@ FilterComponentLuma::FilterComponentLuma() /* Module Definition */ m_iModuleType = FRAME_PROCESSING_MODULE; // Apply module to the frames or to the whole sequence. // Currently only support for frame - m_pchModuleCategory = "Filter Component"; // Category (sub-menu) + m_pchModuleCategory = "FilterComponent"; // Category (sub-menu) m_pchModuleName = "Luma"; // Name m_pchModuleTooltip = "Filter Y matrix of YUV frame"; // Description m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; // Number of Frames required (ONE_FRAME, TWO_FRAMES, THREE_FRAMES) @@ -83,8 +83,8 @@ FilterComponentChromaU::FilterComponentChromaU() { /* Module Definition */ m_iModuleType = FRAME_PROCESSING_MODULE; - m_pchModuleCategory = "Filter Component"; - m_pchModuleName = "Chroma U"; + m_pchModuleCategory = "FilterComponent"; + m_pchModuleName = "ChromaU"; m_pchModuleTooltip = "Filter U matrix of YUV frame"; m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; @@ -105,8 +105,8 @@ FilterComponentChromaV::FilterComponentChromaV() { /* Module Definition */ m_iModuleType = FRAME_PROCESSING_MODULE; - m_pchModuleCategory = "Filter Component"; - m_pchModuleName = "Chroma V"; + m_pchModuleCategory = "FilterComponent"; + m_pchModuleName = "ChromaV"; m_pchModuleTooltip = "Filter V matrix of YUV frame"; m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; diff --git a/modules/LumaAverage.cpp b/modules/LumaAverage.cpp index 9d8cd6a..c32a79d 100644 --- a/modules/LumaAverage.cpp +++ b/modules/LumaAverage.cpp @@ -32,7 +32,7 @@ LumaAverage::LumaAverage() /* Module Definition */ m_iModuleType = FRAME_MEASUREMENT_MODULE; m_pchModuleCategory = "Measurements"; - m_pchModuleName = "Luma Average"; + m_pchModuleName = "LumaAverage"; m_pchModuleTooltip = "Measure the average of luma component"; m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; m_uiModuleRequirements = MODULE_REQUIRES_SIDEBAR; From c3ec5268db166e42c9d8e44b74fc7c7d15c1daf7 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 24 Feb 2015 03:00:06 +0000 Subject: [PATCH 16/25] Add support for module operation (only measurement modules are supported) --- tools/CommandLineHandle.cpp | 56 ++++++++++++++++++- tools/CommandLineHandle.h | 3 +- tools/PlaYUVerTools.cpp | 106 +++++++++++++++++++++++++++++++++--- tools/PlaYUVerTools.h | 8 ++- 4 files changed, 163 insertions(+), 10 deletions(-) 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 From c86a5faf70703ce3c4736591a3a5d78bc1bbcc0b Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 24 Feb 2015 03:16:45 +0000 Subject: [PATCH 17/25] Fix module list --- tools/CommandLineHandle.cpp | 65 ++++++++++++++++++++++--------------- tools/PlaYUVerTools.cpp | 1 + 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/tools/CommandLineHandle.cpp b/tools/CommandLineHandle.cpp index 18ac1e1..0c60759 100644 --- a/tools/CommandLineHandle.cpp +++ b/tools/CommandLineHandle.cpp @@ -52,8 +52,9 @@ Int CommandLineHandle::parseToolsArgs() po::options_description moduleOpts( "Module" ); moduleOpts.add_options() /**/ - ( "module", po::value(), "select a module" ) /**/ - ( "module_list", "list supported modules" ); + ( "module", po::value(), "select a module (use internal name)" ) /**/ + ( "module_list", "list supported modules" ) /**/ + ( "module_list_full", "detailed list supported modules" ); addOptions( qualityOpts ); addOptions( moduleOpts ); @@ -73,7 +74,7 @@ Int CommandLineHandle::parseToolsArgs() iRet = 1; } - if( getOptionsMap().count( "module_list" ) ) + if( getOptionsMap().count( "module_list" ) || getOptionsMap().count( "module_list_full" ) ) { listModules(); iRet = 1; @@ -84,45 +85,57 @@ Int CommandLineHandle::parseToolsArgs() Void CommandLineHandle::listModules() { + Bool bDetailed = false; + + if( getOptionsMap().count( "module_list_full" ) ) + bDetailed = true; + 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( " [Internal Name] " ); + if( bDetailed ) + { + printf( " [Full 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 ) + printf( "%-30s", it->first ); + if( bDetailed ) { - strcat( ModuleNameString, pcCurrModuleIf->m_pchModuleCategory ); - strcat( ModuleNameString, "/" ); + ModuleNameString[0] = '\0'; + pcCurrModuleIf = it->second(); + + 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 ); + pcCurrModuleIf->Delete(); } - 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(); } } diff --git a/tools/PlaYUVerTools.cpp b/tools/PlaYUVerTools.cpp index ab461a0..4f39716 100644 --- a/tools/PlaYUVerTools.cpp +++ b/tools/PlaYUVerTools.cpp @@ -319,6 +319,7 @@ Int PlaYUVerTools::ModuleOperation() abEOF[s] = m_apcInputStreams[s]->checkErrors( PlaYUVerStream::LAST_FRAME ); } } + } if( m_pcCurrModuleIf->m_iModuleType == FRAME_MEASUREMENT_MODULE ) From 659ce9fb8d3406394adf4d5234a5ceae7454260f Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 24 Feb 2015 11:03:42 +0000 Subject: [PATCH 18/25] Fix cmake file --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8418ee5..53a8fa4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,10 @@ SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" ) SET( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g" ) SET( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2" ) + +ADD_FEATURE_INFO(PlaYUVerApp PLAYUVER_BUILD_TOOLS "Build Graphical Interface") +ADD_FEATURE_INFO(PlaYUVerTools PLAYUVER_BUILD_APP "Build Command line tool" ) + ADD_SUBDIRECTORY( lib ) ADD_SUBDIRECTORY( modules ) From c3a82f758b9636ae731fc32a023ccaf36484a027 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Thu, 26 Feb 2015 15:26:18 +0000 Subject: [PATCH 19/25] Avoid using fillRGBBuffer when no necessary --- app/VideoHandle.cpp | 2 -- app/VideoSubWindow.cpp | 1 + lib/PlaYUVerFrame.cpp | 2 +- lib/PlaYUVerFrame.h | 54 +++++++++++++++++++++++++++++++++--------- lib/PlaYUVerStream.cpp | 8 ++++++- lib/PlaYUVerStream.h | 4 +++- 6 files changed, 55 insertions(+), 16 deletions(-) diff --git a/app/VideoHandle.cpp b/app/VideoHandle.cpp index c48200a..99f89e7 100644 --- a/app/VideoHandle.cpp +++ b/app/VideoHandle.cpp @@ -467,7 +467,6 @@ Void VideoHandle::stop() } } emit changed(); - //update(); m_arrayActions[VIDEO_LOCK_ACT]->setVisible( false ); } @@ -496,7 +495,6 @@ Void VideoHandle::playEvent() m_pcCurrentVideoSubWindow->close(); } emit changed(); - //update(); } Void VideoHandle::seekEvent( Int direction ) diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index caedd80..c245d30 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -459,6 +459,7 @@ Bool VideoSubWindow::playEvent() return true; } m_pCurrStream->readFrame(); + m_pCurrStream->getNextFrame()->fillRGBBuffer(); } return false; } diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index e546cba..15af2f8 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -163,7 +163,7 @@ Void PlaYUVerFrame::frameFromBuffer( Pel *Buff, UInt64 uiBuffSize ) m_pcPelFormat->frameFromBuffer( Buff, m_pppcInputPel, m_uiWidth, m_uiHeight ); m_bHasRGBPel = false; m_bHasHistogram = false; - fillRGBBuffer(); + //fillRGBBuffer(); } Void PlaYUVerFrame::frameToBuffer( Pel *output_buffer ) diff --git a/lib/PlaYUVerFrame.h b/lib/PlaYUVerFrame.h index d0562a4..c301331 100644 --- a/lib/PlaYUVerFrame.h +++ b/lib/PlaYUVerFrame.h @@ -37,7 +37,7 @@ class PixFcSSE; namespace plaYUVer { -class PlaYUVerFrame : public PlaYUVerFrameStats +class PlaYUVerFrame: public PlaYUVerFrameStats { public: class Pixel @@ -60,14 +60,38 @@ public: PixelComponents[1] = c1; PixelComponents[2] = c2; } - Int ColorSpace() { return m_iColorSpace; } - Pel* Components() { return PixelComponents; } - Pel& Y() { return PixelComponents[0]; } - Pel& Cb() { return PixelComponents[1]; } - Pel& Cr() { return PixelComponents[2]; } - Pel& R() { return PixelComponents[0]; } - Pel& G() { return PixelComponents[1]; } - Pel& B() { return PixelComponents[2]; } + Int ColorSpace() + { + return m_iColorSpace; + } + Pel* Components() + { + return PixelComponents; + } + Pel& Y() + { + return PixelComponents[0]; + } + Pel& Cb() + { + return PixelComponents[1]; + } + Pel& Cr() + { + return PixelComponents[2]; + } + Pel& R() + { + return PixelComponents[0]; + } + Pel& G() + { + return PixelComponents[1]; + } + Pel& B() + { + return PixelComponents[2]; + } }; enum ColorSpace @@ -161,8 +185,16 @@ public: m_bHasRGBPel = false; return m_pppcInputPel; } - UChar* getRGBBuffer() const +// UChar* getRGBBuffer() const +// { +// return m_pcRGB32; +// } + UChar* getRGBBuffer() { + if( !m_bHasRGBPel ) + { + fillRGBBuffer(); + } return m_pcRGB32; } @@ -185,7 +217,7 @@ public: NUMBER_METRICS, }; - static std::vector supportedQualityMetricsList() + static std::vector supportedQualityMetricsList() { std::vector metrics; metrics.push_back( "PSNR" ); diff --git a/lib/PlaYUVerStream.cpp b/lib/PlaYUVerStream.cpp index 79225a8..0021a8e 100644 --- a/lib/PlaYUVerStream.cpp +++ b/lib/PlaYUVerStream.cpp @@ -514,7 +514,7 @@ Void PlaYUVerStream::readFrame() } m_pcNextFrame->frameFromBuffer( m_pStreamBuffer, bytes_read ); } - m_pcNextFrame->fillRGBBuffer(); + //m_pcNextFrame->fillRGBBuffer(); return; } @@ -639,6 +639,12 @@ PlaYUVerFrame* PlaYUVerStream::getCurrFrame() return m_pcCurrFrame; } +PlaYUVerFrame* PlaYUVerStream::getNextFrame() +{ + return m_pcNextFrame; +} + + Bool PlaYUVerStream::seekInput( UInt64 new_frame_num ) { if( !m_bInit || new_frame_num < 0 || new_frame_num >= m_uiTotalFrameNum || ( Int64 )new_frame_num == m_iCurrFrameNum ) diff --git a/lib/PlaYUVerStream.h b/lib/PlaYUVerStream.h index 09245ef..7c26796 100644 --- a/lib/PlaYUVerStream.h +++ b/lib/PlaYUVerStream.h @@ -134,8 +134,10 @@ public: static Bool saveFrame( const std::string& filename, PlaYUVerFrame *saveFrame ); Void setNextFrame(); - PlaYUVerFrame* getCurrFrame(); + PlaYUVerFrame* getCurrFrame( PlaYUVerFrame * ); + PlaYUVerFrame* getCurrFrame(); + PlaYUVerFrame* getNextFrame(); Bool seekInput( UInt64 new_frame_num ); From f4b9f4d4f480d449c18cc45269419738872c906d Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Thu, 26 Feb 2015 15:30:38 +0000 Subject: [PATCH 20/25] Remove cmake_policy_set not compatible with older versions --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e88edcf..7a2eb93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,6 @@ IF(DEFINED CMAKE_BUILD_TYPE AND CMAKE_VERSION VERSION_GREATER "2.8") ENDIF() SET( CMAKE_CXX_FLAGS "" ) -cmake_policy(SET CMP0043 NEW) - ###################################################################################### # Variables ###################################################################################### From fa8e3b49cd851766fd6827519bc6db173a26e44c Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Thu, 26 Feb 2015 16:39:45 +0000 Subject: [PATCH 21/25] Add debugging routines for Fps --- app/VideoHandle.cpp | 3 +++ app/VideoHandle.h | 9 +++++++++ lib/PlaYUVerFramePixelFormats.h | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/VideoHandle.cpp b/app/VideoHandle.cpp index 99f89e7..0446158 100644 --- a/app/VideoHandle.cpp +++ b/app/VideoHandle.cpp @@ -27,6 +27,9 @@ #include "PlaYUVerSubWindowHandle.h" #include "VideoHandle.h" #include "DialogSubWindowSelector.h" +#if( _CONTROL_PLAYING_TIME_ == 1 ) +#include +#endif namespace plaYUVer { diff --git a/app/VideoHandle.h b/app/VideoHandle.h index df11798..3383168 100644 --- a/app/VideoHandle.h +++ b/app/VideoHandle.h @@ -36,6 +36,10 @@ #include "WidgetFrameNumber.h" #include "FramePropertiesSidebar.h" +#define _CONTROL_PLAYING_TIME_ 1 + +class QElapsedTimer; + namespace plaYUVer { @@ -99,6 +103,11 @@ private: QTimer *m_pcPlayingTimer; Bool m_bIsPlaying; +#if( _CONTROL_PLAYING_TIME_ == 1 ) + UInt m_uiNumberPlayedFrames; + Double m_dAverageFps; + QElapsedTimer* m_pcPlayControlTimer; +#endif UInt64 getMaxFrameNumber(); Void setTimerStatus(); diff --git a/lib/PlaYUVerFramePixelFormats.h b/lib/PlaYUVerFramePixelFormats.h index 82a2bb2..7185131 100644 --- a/lib/PlaYUVerFramePixelFormats.h +++ b/lib/PlaYUVerFramePixelFormats.h @@ -33,7 +33,7 @@ namespace plaYUVer { template -Void yuvToRgb( T iY, T iU, T iV, T &iR, T &iG, T &iB ) +static inline Void yuvToRgb( T iY, T iU, T iV, T &iR, T &iG, T &iB ) { iR = iY + 1402 * iV / 1000; iG = iY - ( 101004 * iU + 209599 * iV ) / 293500; @@ -55,7 +55,7 @@ Void yuvToRgb( T iY, T iU, T iV, T &iR, T &iG, T &iB ) } template -Void rgbToYuv( T iR, T iG, T iB, T &iY, T &iU, T &iV ) +static inline Void rgbToYuv( T iR, T iG, T iB, T &iY, T &iU, T &iV ) { iY = ( 299 * iR + 587 * iG + 114 * iB + 500 ) / 1000; iU = ( 1000 * ( iB - iY ) + 226816 ) / 1772; From a37c5359859300586d7c591b8b3ca8472de3602f Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Thu, 26 Feb 2015 17:24:05 +0000 Subject: [PATCH 22/25] Do not fillRGBBuffer in last frame --- app/VideoSubWindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index c245d30..c83bd20 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -459,7 +459,8 @@ Bool VideoSubWindow::playEvent() return true; } m_pCurrStream->readFrame(); - m_pCurrStream->getNextFrame()->fillRGBBuffer(); + if( m_pCurrStream->getNextFrame() ) + m_pCurrStream->getNextFrame()->fillRGBBuffer(); } return false; } From c24e71bf5539e27c43b85cdf5bd9bff58497f50f Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 27 Feb 2015 01:01:04 +0000 Subject: [PATCH 23/25] Minor changes and code format --- app/VideoHandle.cpp | 24 +++++++++++------------- lib/PlaYUVerFrame.cpp | 4 ++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/VideoHandle.cpp b/app/VideoHandle.cpp index a36636c..4e39229 100644 --- a/app/VideoHandle.cpp +++ b/app/VideoHandle.cpp @@ -327,16 +327,16 @@ Void VideoHandle::moveAllScrollBars( const QPoint offset ) scrollBar = m_pcCurrentVideoSubWindow->horizontalScrollBar(); // Do not move other images, if current image reached maximum or minimum scroll position - if(scrollBar->value()==scrollBar->maximum() && offset.x()>0) - newOffset.setX(0); - if(scrollBar->value()==scrollBar->minimum() && offset.x()<0) - newOffset.setX(0); + if( scrollBar->value() == scrollBar->maximum() && offset.x() > 0 ) + newOffset.setX( 0 ); + if( scrollBar->value() == scrollBar->minimum() && offset.x() < 0 ) + newOffset.setX( 0 ); scrollBar = m_pcCurrentVideoSubWindow->verticalScrollBar(); - if(scrollBar->value()==scrollBar->maximum() && offset.y()>0) - newOffset.setY(0); - if(scrollBar->value()==scrollBar->minimum() && offset.y()<0) - newOffset.setY(0); + if( scrollBar->value() == scrollBar->maximum() && offset.y() > 0 ) + newOffset.setY( 0 ); + if( scrollBar->value() == scrollBar->minimum() && offset.y() < 0 ) + newOffset.setY( 0 ); for( Int i = 0; i < subWindowList.size(); i++ ) { @@ -505,16 +505,14 @@ Void VideoHandle::playEvent() QString warningMsg = "Error while playing " + QFileInfo( m_pcCurrentVideoSubWindow->getCurrentFileName() ).fileName() + " with the following error: \n" + msg; QMessageBox::warning( this, QApplication::applicationName(), warningMsg ); - //statusBar()->showMessage( warningMsg, 2000 ); qDebug( ) << warningMsg; stop(); m_pcCurrentVideoSubWindow->close(); } #if( _CONTROL_PLAYING_TIME_ == 1 ) - m_dAverageFps = Double( m_dAverageFps * m_uiNumberPlayedFrames + m_pcPlayControlTimer->elapsed() ) - / Double( m_uiNumberPlayedFrames + 1 ); - m_uiNumberPlayedFrames++; - m_pcPlayControlTimer->restart(); + m_dAverageFps = Double( m_dAverageFps * m_uiNumberPlayedFrames + m_pcPlayControlTimer->elapsed() ) / Double( m_uiNumberPlayedFrames + 1 ); + m_uiNumberPlayedFrames++; + m_pcPlayControlTimer->restart(); #endif emit changed(); } diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index 15af2f8..4913562 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -249,14 +249,14 @@ PlaYUVerFrame::Pixel PlaYUVerFrame::ConvertPixel( PlaYUVerFrame::Pixel inputPixe if( eOutputSpace == COLOR_RGB ) { - yuvToRgb( inputPixel.Y(), inputPixel.Cb(), inputPixel.Cr(), outA, outB, outC ); + yuvToRgb( inputPixel.Y(), inputPixel.Cb(), inputPixel.Cr(), outA, outB, outC ); outPixel.R() = outA; outPixel.G() = outB; outPixel.B() = outC; } if( eOutputSpace == COLOR_YUV ) { - rgbToYuv( inputPixel.R(), inputPixel.G(), inputPixel.B(), outA, outB, outC ); + rgbToYuv( inputPixel.R(), inputPixel.G(), inputPixel.B(), outA, outB, outC ); outPixel.Y() = outA; outPixel.Cb() = outB; outPixel.Cr() = outC; From eac8f23798a496870f29ce48bd6ca17c313f9bb2 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 27 Feb 2015 01:01:19 +0000 Subject: [PATCH 24/25] Remove template functions --- lib/PlaYUVerFramePixelFormats.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/PlaYUVerFramePixelFormats.h b/lib/PlaYUVerFramePixelFormats.h index 7185131..9b57c5f 100644 --- a/lib/PlaYUVerFramePixelFormats.h +++ b/lib/PlaYUVerFramePixelFormats.h @@ -32,8 +32,7 @@ namespace plaYUVer { -template -static inline Void yuvToRgb( T iY, T iU, T iV, T &iR, T &iG, T &iB ) +static inline Void yuvToRgb( Int iY, Int iU, Int iV, Int &iR, Int &iG, Int &iB ) { iR = iY + 1402 * iV / 1000; iG = iY - ( 101004 * iU + 209599 * iV ) / 293500; @@ -54,8 +53,7 @@ static inline Void yuvToRgb( T iY, T iU, T iV, T &iR, T &iG, T &iB ) iB = 255; } -template -static inline Void rgbToYuv( T iR, T iG, T iB, T &iY, T &iU, T &iV ) +static inline Void rgbToYuv( Int iR, Int iG, Int iB, Int &iY, Int &iU, Int &iV ) { iY = ( 299 * iR + 587 * iG + 114 * iB + 500 ) / 1000; iU = ( 1000 * ( iB - iY ) + 226816 ) / 1772; From 6bc2406e3ad141db47948902212607fcb67d58d1 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 27 Feb 2015 13:57:40 +0000 Subject: [PATCH 25/25] Optimize pixel conversion from yuv to rgb --- lib/PlaYUVerFrame.cpp | 2 +- lib/PlaYUVerFramePixelFormats.cpp | 44 +++++++++++++++++++------------ lib/PlaYUVerFramePixelFormats.h | 32 ++++++---------------- 3 files changed, 36 insertions(+), 42 deletions(-) diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index 4913562..e90a383 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -249,7 +249,7 @@ PlaYUVerFrame::Pixel PlaYUVerFrame::ConvertPixel( PlaYUVerFrame::Pixel inputPixe if( eOutputSpace == COLOR_RGB ) { - yuvToRgb( inputPixel.Y(), inputPixel.Cb(), inputPixel.Cr(), outA, outB, outC ); + YUV2RGB( inputPixel.Y(), inputPixel.Cb(), inputPixel.Cr(), outA, outB, outC ); outPixel.R() = outA; outPixel.G() = outB; outPixel.B() = outC; diff --git a/lib/PlaYUVerFramePixelFormats.cpp b/lib/PlaYUVerFramePixelFormats.cpp index ddce223..df05e68 100644 --- a/lib/PlaYUVerFramePixelFormats.cpp +++ b/lib/PlaYUVerFramePixelFormats.cpp @@ -67,23 +67,34 @@ Void bufferFromFrameYUVProgressive( Pel*** in, Pel *out, UInt width, UInt height Void fillRGBbufferYUV( Pel*** in, UChar* out, UInt width, UInt height, UInt ratioChromaHor, UInt ratioChromaVer ) { - Pel** pY = in[LUMA]; - Pel** pU = in[CHROMA_U]; - Pel** pV = in[CHROMA_V]; + Pel* pY = in[LUMA][0]; + Pel* pU = in[CHROMA_U][0]; + Pel* pV = in[CHROMA_V][0]; Int iY, iU, iV, iR, iG, iB; UInt* buff = ( UInt* )out; - for( UInt y = 0; y < height; y++ ) + pU -= width >> ratioChromaHor; + pV -= width >> ratioChromaHor; + for( UInt y = 0; y < height >> ratioChromaVer; y++ ) { - for( UInt x = 0; x < width; x++ ) + pU += width >> ratioChromaHor; + pV += width >> ratioChromaHor; + for( Int i = 0; i < 1 << ratioChromaVer; i++ ) { - // Pixel (x, y). - iY = pY[y][x]; - iU = pU[y >> ratioChromaVer][x >> ratioChromaHor] - 128; - iV = pV[y >> ratioChromaVer][x >> ratioChromaHor] - 128; - yuvToRgb( iY, iU, iV, iR, iG, iB ); - *buff = pelRgb( iR, iG, iB ); - buff++; + for( UInt x = 0; x < width >> ratioChromaHor; x++ ) + { + iU = *pU++ - 128; + iV = *pV++ - 128; + for( Int j = 0; j < 1 << ratioChromaHor; j++ ) + { + iY = *pY++; + YUV2RGB( iY, iU, iV, iR, iG, iB ); + *buff = PEL_RGB( iR, iG, iB ); + buff++; + } + } + pU -= width >> ratioChromaHor; + pV -= width >> ratioChromaHor; } } } @@ -234,7 +245,7 @@ Void fillRGBbufferGray( Pel*** in, UChar* out, UInt width, UInt height ) for( UInt i = 0; i < height * width; i++ ) { iY = *inPel; - *buff++ = pelRgb( iY, iY, iY ); + *buff++ = PEL_RGB( iY, iY, iY ); inPel++; } } @@ -259,9 +270,9 @@ Void frameFromBufferRGB( Pel *in, Pel*** out, UInt64 size, Pel* pFirst, Pel* pSe { for( UInt i = 0; i < size; i++ ) { - *pFirst++ = *in++; + *pFirst++ = *in++; *pSecond++ = *in++; - *pthird++ = *in++; + *pthird++ = *in++; } } Void bufferFromFrameRGB( Pel ***in, Pel* out, UInt64 size, Pel* pFirst, Pel* pSecond, Pel* pthird ) @@ -285,7 +296,7 @@ Void fillRGBbufferRGB( Pel*** in, UChar* out, UInt width, UInt height ) iR = *pR++; iG = *pG++; iB = *pB++; - *buff++ = pelRgb( iR, iG, iB ); + *buff++ = PEL_RGB( iR, iG, iB ); } } @@ -343,5 +354,4 @@ PlaYUVerFramePelFormat g_PlaYUVerFramePelFormatsList[PLAYUVER_NUMBER_FORMATS] = RGB24, BGR24, }; - } // NAMESPACE diff --git a/lib/PlaYUVerFramePixelFormats.h b/lib/PlaYUVerFramePixelFormats.h index 9b57c5f..b3439ea 100644 --- a/lib/PlaYUVerFramePixelFormats.h +++ b/lib/PlaYUVerFramePixelFormats.h @@ -22,7 +22,6 @@ * \brief Handling the pixel formats definition */ - #ifndef __PLAYUVERFRAMEPIXELFORMATS_H__ #define __PLAYUVERFRAMEPIXELFORMATS_H__ @@ -32,26 +31,13 @@ namespace plaYUVer { -static inline Void yuvToRgb( Int iY, Int iU, Int iV, Int &iR, Int &iG, Int &iB ) -{ - iR = iY + 1402 * iV / 1000; - iG = iY - ( 101004 * iU + 209599 * iV ) / 293500; - iB = iY + 1772 * iU / 1000; +#define CLAMP(X) X = X < 0 ? 0 : X > 255 ? 255 : X; - if( iR < 0 ) - iR = 0; - if( iG < 0 ) - iG = 0; - if( iB < 0 ) - iB = 0; - - if( iR > 255 ) - iR = 255; - if( iG > 255 ) - iG = 255; - if( iB > 255 ) - iB = 255; -} +#define YUV2RGB( iY, iU, iV, iR, iG, iB ) \ + iR = iY + ( ( 1436 * iV ) >> 10 ); \ + iG = iY - ( ( 352 * iU + 731 * iV ) >> 10 ); \ + iB = iY + ( ( 1812 * iU ) >> 10 ); \ + CLAMP(iR) CLAMP(iG) CLAMP(iB) static inline Void rgbToYuv( Int iR, Int iG, Int iB, Int &iY, Int &iU, Int &iV ) { @@ -80,10 +66,8 @@ inline Int pelAlpha( UInt rgb ) // get alpha part of RGBA return rgb >> 24; } -inline UInt pelRgb( Int r, Int g, Int b ) // set RGB value -{ - return ( 0xffu << 24 ) | ( ( r & 0xff ) << 16 ) | ( ( g & 0xff ) << 8 ) | ( b & 0xff ); -} +#define PEL_RGB( r, g, b ) \ + ( 0xffu << 24 ) | ( ( r & 0xff ) << 16 ) | ( ( g & 0xff ) << 8 ) | ( b & 0xff ) struct structPlaYUVerFramePelFormat {