From 31f7e46e947328f2f77cbe4e1d426a754ee62b2f Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 29 Nov 2019 00:36:54 +0000 Subject: [PATCH] Add new option in calypTools to process video with negative values --- lib/CalypStream.cpp | 16 +++++++++++----- lib/CalypStream.h | 5 ++++- tools/CalypTools.cpp | 15 ++++++++++----- tools/CalypToolsCmdParser.cpp | 9 +++++---- tools/CalypToolsCmdParser.h | 1 + 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/lib/CalypStream.cpp b/lib/CalypStream.cpp index eaeddb9..dd60dcd 100644 --- a/lib/CalypStream.cpp +++ b/lib/CalypStream.cpp @@ -103,11 +103,11 @@ private: unsigned int m_uiIndex; public: - CalypStreamBufferPrivate( unsigned int size, unsigned int width, unsigned int height, int pelFormat, int bitsPixel ) + CalypStreamBufferPrivate( unsigned int size, unsigned int width, unsigned int height, int pelFormat, int bitsPixel, bool hasNegative ) { for( unsigned int i = 0; i < size; i++ ) { - CalypFrame* pFrame = new CalypFrame( width, height, pelFormat, bitsPixel ); + CalypFrame* pFrame = new CalypFrame( width, height, pelFormat, bitsPixel, hasNegative ); m_apcFrameBuffer.push_back( pFrame ); } m_uiIndex = 0; @@ -238,7 +238,7 @@ ClpString CalypStream::getCodecName() const return !d->handler ? "" : d->handler->getCodecName(); } -bool CalypStream::open( ClpString filename, ClpString resolution, ClpString input_format_name, unsigned int bitsPel, int endianness, +bool CalypStream::open( ClpString filename, ClpString resolution, ClpString input_format_name, unsigned int bitsPel, int endianness, bool hasNegative, unsigned int frame_rate, bool bInput ) { unsigned int width = 0; @@ -261,11 +261,17 @@ bool CalypStream::open( ClpString filename, ClpString resolution, ClpString inpu break; } } - return open( filename, width, height, input_format, bitsPel, endianness, frame_rate, bInput ); + return open( filename, width, height, input_format, bitsPel, endianness, hasNegative, frame_rate, bInput ); } bool CalypStream::open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, unsigned int frame_rate, bool bInput ) +{ + return open( filename, width, height, input_format, bitsPel, endianness, false, frame_rate, bInput ); +} + +bool CalypStream::open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool hasNegative, + unsigned int frame_rate, bool bInput ) { if( d->isInit ) { @@ -314,7 +320,7 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei try { d->frameBuffer = new CalypStreamBufferPrivate( d->isInput ? 3 : 1, d->handler->m_uiWidth, d->handler->m_uiHeight, - d->handler->m_iPixelFormat, d->handler->m_uiBitsPerPixel ); + d->handler->m_iPixelFormat, d->handler->m_uiBitsPerPixel, hasNegative ); } catch( CalypFailure& e ) { diff --git a/lib/CalypStream.h b/lib/CalypStream.h index 8c3c2ff..2fd0e79 100644 --- a/lib/CalypStream.h +++ b/lib/CalypStream.h @@ -72,10 +72,13 @@ public: ClpString getCodecName() const; ; - bool open( ClpString filename, ClpString resolution, ClpString input_format, unsigned int bitsPel, int endianness, unsigned int frame_rate, + bool open( ClpString filename, ClpString resolution, ClpString input_format, unsigned int bitsPel, int endianness, bool hasNegative, unsigned int frame_rate, bool bInput ); bool open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, unsigned int frame_rate, bool bInput ); + bool open( ClpString filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool hasNegative, unsigned int frame_rate, + bool bInput ); + bool reload(); void close(); diff --git a/tools/CalypTools.cpp b/tools/CalypTools.cpp index 16f5557..9463caa 100644 --- a/tools/CalypTools.cpp +++ b/tools/CalypTools.cpp @@ -23,12 +23,12 @@ */ #include "CalypTools.h" -#include "config.h" #include #include #include +#include "config.h" #include "lib/CalypFrame.h" #include "lib/CalypModuleIf.h" #include "lib/CalypStream.h" @@ -79,13 +79,14 @@ int CalypTools::openInputs() ClpString fmtString( "yuv420p" ); unsigned int uiBitsPerPixel = 8; unsigned int uiEndianness = 0; + bool hasNegativeValues = false; CalypStream* pcStream; for( unsigned int i = 0; i < inputFileNames.size() && i < MAX_NUMBER_INPUTS; i++ ) { if( Opts().hasOpt( "size" ) ) { - resolutionString = GET_PARAM( m_strResolution, 0 ); + resolutionString = GET_PARAM( m_strResolution, i ); } if( Opts().hasOpt( "pel_fmt" ) ) { @@ -106,10 +107,14 @@ int CalypTools::openInputs() uiEndianness = 1; } } + if( Opts().hasOpt( "has_negative" ) ) + { + hasNegativeValues = std::stoi( GET_PARAM( m_strHasNegativeValues, i ).c_str() ) == 0 ? false : true; + } pcStream = new CalypStream; try { - if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, uiBitsPerPixel, uiEndianness, 1, true ) ) + if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, uiBitsPerPixel, uiEndianness, hasNegativeValues, 1, true ) ) { log( CLP_LOG_ERROR, "Cannot open input stream %s! ", inputFileNames[i].c_str() ); return -1; @@ -172,11 +177,11 @@ int CalypTools::Open( int argc, char* argv[] ) m_uiOutEndianness = 0; if( Opts().hasOpt( "endianness" ) ) { - if( m_strEndianness[0] == "big" ) + if( GET_PARAM( m_strEndianness, 9999 ) == "big" ) { m_uiOutEndianness = 0; } - else if( m_strEndianness[0] == "little" ) + else if( GET_PARAM( m_strEndianness, 9999 ) == "little" ) { m_uiOutEndianness = 1; } diff --git a/tools/CalypToolsCmdParser.cpp b/tools/CalypToolsCmdParser.cpp index 0b7d8fc..1a4efce 100644 --- a/tools/CalypToolsCmdParser.cpp +++ b/tools/CalypToolsCmdParser.cpp @@ -24,15 +24,15 @@ #include "CalypToolsCmdParser.h" +#include +#include +#include + #include "lib/CalypFrame.h" #include "lib/CalypModuleIf.h" #include "lib/CalypStream.h" #include "modules/CalypModulesFactory.h" -#include -#include -#include - CalypToolsCmdParser::CalypToolsCmdParser() { m_uiLogLevel = 0; @@ -66,6 +66,7 @@ int CalypToolsCmdParser::parseToolsArgs( int argc, char* argv[] ) ( "pel_fmt,p", m_strPelFmt, "pixel format" ) /**/ ( "bits_pel", m_strBitsPerPixel, "bits per pixel" ) /**/ ( "endianness", m_strEndianness, "File endianness (big, little)" ) /**/ + ( "has_negative", m_strHasNegativeValues, "Flag for files with negatie values" ) /**/ ( "frames,f", m_iFrames, "number of frames to parse" ) /**/ ( "quality", m_strQualityMetric, "select a quality metric" ) /**/ ( "module", m_strModule, "select a module (use internal name)" ) /**/ diff --git a/tools/CalypToolsCmdParser.h b/tools/CalypToolsCmdParser.h index 180b3f0..4e8bb2f 100644 --- a/tools/CalypToolsCmdParser.h +++ b/tools/CalypToolsCmdParser.h @@ -69,6 +69,7 @@ protected: std::vector m_strPelFmt; std::vector m_strBitsPerPixel; std::vector m_strEndianness; + std::vector m_strHasNegativeValues; ClpString m_strOutput; long m_iFrames; unsigned m_uiOutEndianness;