From ca562ae9f4e5e0d8415102f89e54f8fd1531920a Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Wed, 20 Feb 2019 22:22:37 +0000 Subject: [PATCH] Bugfixes and improvements Uniform the use of unsigned long in the frame number by defining a ClpULong type CalypFrame Add function to copyTo a specific position --- CMakeLists.txt | 8 +++---- app/ModulesHandle.cpp | 4 ++-- app/QualityHandle.cpp | 12 +++++----- app/VideoHandle.cpp | 10 ++++---- app/VideoHandle.h | 2 +- lib/CalypDefs.h | 1 + lib/CalypFrame.cpp | 41 ++++++++++++++++++++++++++------ lib/CalypFrame.h | 13 ++++++---- lib/CalypModuleIf.h | 6 ++++- lib/CalypStream.cpp | 4 ++-- lib/CalypStream.h | 4 ++-- lib/CalypStreamHandlerIf.h | 10 ++++---- lib/StreamHandlerLibav.cpp | 4 ++-- lib/StreamHandlerLibav.h | 2 +- lib/StreamHandlerOpenCV.cpp | 2 +- lib/StreamHandlerOpenCV.h | 2 +- lib/StreamHandlerPortableMap.cpp | 2 +- lib/StreamHandlerPortableMap.h | 2 +- lib/StreamHandlerRaw.cpp | 4 ++-- lib/StreamHandlerRaw.h | 2 +- tools/CalypTools.cpp | 4 ++-- tools/CalypTools.h | 2 +- 22 files changed, 88 insertions(+), 53 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3406f7a..093438f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,7 +157,7 @@ IF (NOT CMAKE_BUILD_TYPE ) SET(CMAKE_BUILD_TYPE "Release") ENDIF() -SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" ) +SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-deprecated-declarations" ) ADD_DEFINITIONS(-DQT_NO_CAST_TO_ASCII #-DQT_NO_CAST_FROM_ASCII @@ -167,9 +167,9 @@ ADD_DEFINITIONS(-DQT_NO_CAST_TO_ASCII #-DQT_USE_QSTRINGBUILDER ) -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") -endif() +# if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") +# endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0") diff --git a/app/ModulesHandle.cpp b/app/ModulesHandle.cpp index ed37fd5..707c7cd 100644 --- a/app/ModulesHandle.cpp +++ b/app/ModulesHandle.cpp @@ -562,8 +562,8 @@ void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf ) if( pcCurrModuleIf->m_pcModuleStream ) { unsigned int numberOfWindows = pcCurrModuleIf->m_pcModule->m_uiNumberOfFrames; - unsigned long long int currFrames = 0; - unsigned long long int numberOfFrames = INT_MAX; + ClpULong currFrames = 0; + ClpULong numberOfFrames = -1; for( unsigned int i = 0; i < numberOfWindows; i++ ) { currFrames = pcCurrModuleIf->m_pcSubWindow[i]->getInputStream()->getFrameNum(); diff --git a/app/QualityHandle.cpp b/app/QualityHandle.cpp index 8be4683..f54b29c 100644 --- a/app/QualityHandle.cpp +++ b/app/QualityHandle.cpp @@ -156,12 +156,12 @@ void QualityHandle::update( VideoSubWindow* currSubWindow ) void QualityHandle::measureQuality( QVector apcWindowList ) { - int numberOfWindows = apcWindowList.size(); - unsigned long long int currFrames = 0; - unsigned long long int numberOfFrames = INT_MAX; + unsigned numberOfWindows = apcWindowList.size(); + ClpULong currFrames = 0; + ClpULong numberOfFrames = -1; //! Check reference window - for( int i = 0; i < numberOfWindows; i++ ) + for( unsigned i = 0; i < numberOfWindows; i++ ) { if( !apcWindowList.at( i )->getRefSubWindow() ) { @@ -171,7 +171,7 @@ void QualityHandle::measureQuality( QVector apcWindowList ) VideoSubWindow* pcReferenceWindow = apcWindowList.at( 0 )->getRefSubWindow(); numberOfFrames = pcReferenceWindow->getInputStream()->getFrameNum(); - for( int i = 0; i < numberOfWindows; i++ ) + for( unsigned i = 0; i < numberOfWindows; i++ ) { currFrames = apcWindowList.at( i )->getInputStream()->getFrameNum(); if( currFrames < numberOfFrames ) @@ -186,7 +186,7 @@ void QualityHandle::measureQuality( QVector apcWindowList ) double* padAverageQuality = new double[numberOfWindows + 1]; double dCurrentQuality; - for( unsigned int i = 0; i < numberOfWindows + 1; i++ ) + for( unsigned i = 0; i < numberOfWindows + 1; i++ ) { padAverageQuality[i] = 0; } diff --git a/app/VideoHandle.cpp b/app/VideoHandle.cpp index e4b0a47..3446c4d 100644 --- a/app/VideoHandle.cpp +++ b/app/VideoHandle.cpp @@ -320,8 +320,8 @@ void VideoHandle::update() CalypStream* pcStream = m_pcCurrentVideoSubWindow->getInputStream(); CalypFrame* pcFrame = m_pcCurrentVideoSubWindow->getCurrFrame(); - int frame_num = 0; - unsigned long long int total_frame_num = 1; + unsigned long frame_num = 0; + unsigned long total_frame_num = 1; m_pcVideoFormatLabel->setText( m_pcCurrentVideoSubWindow->getStreamInformation() ); @@ -519,10 +519,10 @@ void VideoHandle::moveAllScrollBars( const double& horRatio, const double& verRa } #endif -unsigned long long int VideoHandle::getMaxFrameNumber() +unsigned long VideoHandle::getMaxFrameNumber() { - unsigned int currFrames; - unsigned long long int maxFrames = INT_MAX; + unsigned long currFrames; + unsigned long maxFrames = INT_MAX; if( m_pcCurrentVideoSubWindow ) { if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) diff --git a/app/VideoHandle.h b/app/VideoHandle.h index 360b35e..2381f57 100644 --- a/app/VideoHandle.h +++ b/app/VideoHandle.h @@ -128,7 +128,7 @@ private: QElapsedTimer* m_pcPlayControlTimer; #endif - unsigned long long int getMaxFrameNumber(); + unsigned long getMaxFrameNumber(); void setTimerStatus(); Q_SIGNALS: diff --git a/lib/CalypDefs.h b/lib/CalypDefs.h index ae7e2ad..93f1c0d 100644 --- a/lib/CalypDefs.h +++ b/lib/CalypDefs.h @@ -32,6 +32,7 @@ typedef unsigned short ClpPel; ///< 16-bit pixel type typedef unsigned char ClpByte; +typedef unsigned long long ClpULong; typedef std::string ClpString; diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index d979e8b..05cf6ab 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -388,15 +388,15 @@ unsigned int CalypFrame::getHeight( int channel ) const return CHROMASHIFT( d->m_uiHeight, channel > 0 ? d->m_pcPelFormat->log2ChromaHeight : 0 ); } -unsigned int CalypFrame::getPixels( int channel ) const +ClpULong CalypFrame::getPixels( int channel ) const { return getWidth( channel ) * getHeight( channel ); } -unsigned long CalypFrame::getTotalNumberOfPixels() const +ClpULong CalypFrame::getTotalNumberOfPixels() const { - unsigned long numberPixels = 0; - for( int i = 0; i < getNumberChannels(); i++ ) + ClpULong numberPixels = 0; + for( unsigned i = 0; i < getNumberChannels(); i++ ) { numberPixels += getPixels( i ); } @@ -413,7 +413,7 @@ unsigned char CalypFrame::getChromaHeightRatio() const return d->m_pcPelFormat->log2ChromaHeight; } -unsigned int CalypFrame::getChromaLength() const +ClpULong CalypFrame::getChromaLength() const { return getWidth( 1 ) * getHeight( 1 ); } @@ -423,12 +423,12 @@ unsigned int CalypFrame::getBitsPel() const return d->m_uiBitsPel; } -unsigned long CalypFrame::getBytesPerFrame() +ClpULong CalypFrame::getBytesPerFrame() { return getBytesPerFrame( d->m_uiWidth, d->m_uiHeight, d->m_iPixelFormat, d->m_uiBitsPel ); } -unsigned long CalypFrame::getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, int iPixelFormat, unsigned int bitsPixel ) +ClpULong CalypFrame::getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, int iPixelFormat, unsigned int bitsPixel ) { const CalypPixelFormatDescriptor* pcPelFormat = &( g_CalypPixFmtDescriptorsMap.at( iPixelFormat ) ); unsigned int bytesPerPixel = ( bitsPixel - 1 ) / 8 + 1; @@ -541,6 +541,7 @@ void CalypFrame::copyFrom( const CalypFrame& other, unsigned int xPos, unsigned { if( !haveSameFmt( other, MATCH_COLOR_SPACE | MATCH_PEL_FMT | MATCH_BITS ) ) return; + // TODO: Protect width and height ClpPel*** pInput = other.getPelBufferYUV(); for( unsigned int ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ ) { @@ -562,6 +563,32 @@ void CalypFrame::copyFrom( const CalypFrame* other, unsigned int x, unsigned int copyFrom( *other, x, y ); } +void CalypFrame::copyTo( const CalypFrame& other, unsigned int xPos, unsigned int yPos ) +{ + if( !haveSameFmt( other, MATCH_COLOR_SPACE | MATCH_PEL_FMT | MATCH_BITS ) ) + return; + ClpPel*** pInput = other.getPelBufferYUV(); + // TODO: Protect width and height + for( unsigned int ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ ) + { + int ratioH = ch > 0 ? d->m_pcPelFormat->log2ChromaWidth : 0; + int ratioW = ch > 0 ? d->m_pcPelFormat->log2ChromaHeight : 0; + for( unsigned int i = 0; i < CHROMASHIFT( other.getHeight(), ratioH ); i++ ) + { + memcpy( &( d->m_pppcInputPel[ch][( yPos >> ratioH ) + i][( xPos >> ratioW )] ), &( pInput[ch][i][0] ), + ( other.getWidth() >> ratioW ) * sizeof( ClpPel ) ); + } + } + d->m_bHasRGBPel = false; + d->m_bHasHistogram = false; +} + +void CalypFrame::copyTo( const CalypFrame* other, unsigned int x, unsigned int y ) +{ + if( other ) + copyTo( *other, x, y ); +} + void CalypFrame::frameFromBuffer( ClpByte* Buff, int iEndianness, unsigned long uiBuffSize ) { if( uiBuffSize != getBytesPerFrame() ) diff --git a/lib/CalypFrame.h b/lib/CalypFrame.h index bfa0136..2b14e5d 100644 --- a/lib/CalypFrame.h +++ b/lib/CalypFrame.h @@ -200,13 +200,13 @@ public: * @param channel/component * @return number of pixels */ - unsigned int getPixels( int channel = 0 ) const; + ClpULong getPixels( int channel = 0 ) const; /** * Get the total number of pixels of the frame * @return number of pixels */ - unsigned long getTotalNumberOfPixels() const; + ClpULong getTotalNumberOfPixels() const; /** * Get chroma width ratio @@ -224,7 +224,7 @@ public: * Get number of pixels in each chroma channel * @return number of pixels */ - unsigned int getChromaLength() const; + ClpULong getChromaLength() const; /** * Get number of bits per pixel @@ -236,13 +236,13 @@ public: * Get number of bytes per frame of an existing frame * @return number of bytes per frame */ - unsigned long getBytesPerFrame(); + ClpULong getBytesPerFrame(); /** * Get number of bytes per frame of a specific pixel format * @return number of bytes per frame */ - static unsigned long getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, int iPixelFormat, unsigned int bitsPixel ); + static ClpULong getBytesPerFrame( unsigned int uiWidth, unsigned int uiHeight, int iPixelFormat, unsigned int bitsPixel ); /** * Reset frame pixels to zero @@ -301,6 +301,9 @@ public: void copyFrom( const CalypFrame&, unsigned int, unsigned int ); void copyFrom( const CalypFrame*, unsigned int, unsigned int ); + void copyTo( const CalypFrame&, unsigned int, unsigned int ); + void copyTo( const CalypFrame*, unsigned int, unsigned int ); + void frameFromBuffer( ClpByte*, int, unsigned long ); void frameFromBuffer( ClpByte*, int ); void frameToBuffer( ClpByte*, int ); diff --git a/lib/CalypModuleIf.h b/lib/CalypModuleIf.h index 2120a9e..d15592e 100644 --- a/lib/CalypModuleIf.h +++ b/lib/CalypModuleIf.h @@ -159,7 +159,11 @@ public: virtual ClpString moduleInfo() { return ClpString(); } virtual bool needFrame() { return true; }; - virtual bool flush() { return false; }; + virtual bool flush() + { + m_iFrameBufferCount = 0; + return true; + }; }; #endif // __CALYPMODULESIF_H__ diff --git a/lib/CalypStream.cpp b/lib/CalypStream.cpp index 6a74193..b035578 100644 --- a/lib/CalypStream.cpp +++ b/lib/CalypStream.cpp @@ -401,7 +401,7 @@ bool CalypStream::isNative() return d->handler->m_bNative; } -unsigned int CalypStream::getFrameNum() +ClpULong CalypStream::getFrameNum() { return d->handler->m_uiTotalNumberFrames; } @@ -422,7 +422,7 @@ double CalypStream::getFrameRate() return d->handler->m_dFrameRate; } -int CalypStream::getCurrFrameNum() +long CalypStream::getCurrFrameNum() { return d->iCurrFrameNum; } diff --git a/lib/CalypStream.h b/lib/CalypStream.h index 730f4ce..969d0a8 100644 --- a/lib/CalypStream.h +++ b/lib/CalypStream.h @@ -79,11 +79,11 @@ public: bool isNative(); ClpString getFileName(); - unsigned int getFrameNum(); + ClpULong getFrameNum(); unsigned int getWidth() const; unsigned int getHeight() const; int getEndianess() const; - int getCurrFrameNum(); + long getCurrFrameNum(); double getFrameRate(); void getFormat( unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPel, int& rEndianness, unsigned int& rFrameRate ); diff --git a/lib/CalypStreamHandlerIf.h b/lib/CalypStreamHandlerIf.h index 12d8898..906bafb 100644 --- a/lib/CalypStreamHandlerIf.h +++ b/lib/CalypStreamHandlerIf.h @@ -70,13 +70,13 @@ public: CalypStreamHandlerIf() : m_bIsInput( true ) , m_bNative( true ) - , m_uiCurrFrameFileIdx( 0 ) , m_uiWidth( 0 ) , m_uiHeight( 0 ) , m_iPixelFormat( -1 ) , m_uiBitsPerPixel( 8 ) , m_iEndianness( -1 ) , m_dFrameRate( 30 ) + , m_uiCurrFrameFileIdx( 0 ) , m_uiTotalNumberFrames( 0 ) , m_pStreamBuffer( NULL ) , m_uiNBytesPerFrame( 0 ) @@ -89,7 +89,7 @@ public: virtual bool openHandler( ClpString strFilename, bool bInput ) = 0; virtual void closeHandler() = 0; virtual bool configureBuffer( CalypFrame* pcFrame ) = 0; - virtual bool seek( unsigned long long int iFrameNum ) = 0; + virtual bool seek( ClpULong iFrameNum ) = 0; virtual bool read( CalypFrame* pcFrame ) = 0; virtual bool write( CalypFrame* pcFrame ) = 0; @@ -105,7 +105,6 @@ protected: ClpString m_strCodecName; bool m_bIsInput; bool m_bNative; - unsigned long m_uiCurrFrameFileIdx; ClpString m_cFilename; unsigned int m_uiWidth; unsigned int m_uiHeight; @@ -113,9 +112,10 @@ protected: unsigned int m_uiBitsPerPixel; int m_iEndianness; double m_dFrameRate; - unsigned long m_uiTotalNumberFrames; + ClpULong m_uiCurrFrameFileIdx; + ClpULong m_uiTotalNumberFrames; ClpByte* m_pStreamBuffer; - unsigned long m_uiNBytesPerFrame; + ClpULong m_uiNBytesPerFrame; bool m_isEOF; }; diff --git a/lib/StreamHandlerLibav.cpp b/lib/StreamHandlerLibav.cpp index fb6a636..b1e9321 100644 --- a/lib/StreamHandlerLibav.cpp +++ b/lib/StreamHandlerLibav.cpp @@ -335,7 +335,7 @@ bool StreamHandlerLibav::configureBuffer( CalypFrame* pcFrame ) void StreamHandlerLibav::calculateFrameNumber() { - unsigned long long int num_frames; + ClpULong num_frames; /*if( m_cStream->nb_frames ) { num_frames = m_cStream->nb_frames; @@ -442,7 +442,7 @@ bool StreamHandlerLibav::write( CalypFrame* pcFrame ) return false; } -bool StreamHandlerLibav::seek( unsigned long long int iFrameNum ) +bool StreamHandlerLibav::seek( ClpULong iFrameNum ) { if( m_uiTotalNumberFrames == 1 ) return true; diff --git a/lib/StreamHandlerLibav.h b/lib/StreamHandlerLibav.h index 5fbeb2a..1e5e5b8 100644 --- a/lib/StreamHandlerLibav.h +++ b/lib/StreamHandlerLibav.h @@ -66,7 +66,7 @@ public: void closeHandler(); bool configureBuffer( CalypFrame* pcFrame ); void calculateFrameNumber(); - bool seek( unsigned long long int iFrameNum ); + bool seek( ClpULong iFrameNum ); bool read( CalypFrame* pcFrame ); bool write( CalypFrame* pcFrame ); diff --git a/lib/StreamHandlerOpenCV.cpp b/lib/StreamHandlerOpenCV.cpp index ad4464a..0779d45 100644 --- a/lib/StreamHandlerOpenCV.cpp +++ b/lib/StreamHandlerOpenCV.cpp @@ -119,7 +119,7 @@ bool StreamHandlerOpenCV::configureBuffer( CalypFrame* pcFrame ) return true; } -bool StreamHandlerOpenCV::seek( unsigned long long int iFrameNum ) +bool StreamHandlerOpenCV::seek( ClpULong iFrameNum ) { // m_uiCurrFrameFileIdx = return true; diff --git a/lib/StreamHandlerOpenCV.h b/lib/StreamHandlerOpenCV.h index a62059b..42573d0 100644 --- a/lib/StreamHandlerOpenCV.h +++ b/lib/StreamHandlerOpenCV.h @@ -43,7 +43,7 @@ public: bool openHandler( ClpString strFilename, bool bInput ); void closeHandler(); bool configureBuffer( CalypFrame* pcFrame ); - bool seek( unsigned long long int iFrameNum ); + bool seek( ClpULong iFrameNum ); bool read( CalypFrame* pcFrame ); bool write( CalypFrame* pcFrame ); diff --git a/lib/StreamHandlerPortableMap.cpp b/lib/StreamHandlerPortableMap.cpp index cb66a64..588b4a0 100644 --- a/lib/StreamHandlerPortableMap.cpp +++ b/lib/StreamHandlerPortableMap.cpp @@ -123,7 +123,7 @@ bool StreamHandlerPortableMap::configureBuffer( CalypFrame* pcFrame ) return getMem1D( &m_pStreamBuffer, pcFrame->getBytesPerFrame() ); } -bool StreamHandlerPortableMap::seek( unsigned long long int iFrameNum ) +bool StreamHandlerPortableMap::seek( ClpULong iFrameNum ) { // m_uiCurrFrameFileIdx = return true; diff --git a/lib/StreamHandlerPortableMap.h b/lib/StreamHandlerPortableMap.h index 1cd13c8..7b9c706 100644 --- a/lib/StreamHandlerPortableMap.h +++ b/lib/StreamHandlerPortableMap.h @@ -38,7 +38,7 @@ public: bool openHandler( ClpString strFilename, bool bInput ); void closeHandler(); bool configureBuffer( CalypFrame* pcFrame ); - bool seek( unsigned long long int iFrameNum ); + bool seek( ClpULong iFrameNum ); bool read( CalypFrame* pcFrame ); bool write( CalypFrame* pcFrame ); diff --git a/lib/StreamHandlerRaw.cpp b/lib/StreamHandlerRaw.cpp index f6ef451..cc9f464 100644 --- a/lib/StreamHandlerRaw.cpp +++ b/lib/StreamHandlerRaw.cpp @@ -78,13 +78,13 @@ void StreamHandlerRaw::calculateFrameNumber() if( m_pFile && m_uiNBytesPerFrame > 0 ) { fseek( m_pFile, 0, SEEK_END ); - unsigned long long int fileSize = ftell( m_pFile ); + unsigned long long fileSize = ftell( m_pFile ); fseek( m_pFile, 0, SEEK_SET ); m_uiTotalNumberFrames = fileSize / m_uiNBytesPerFrame; } } -bool StreamHandlerRaw::seek( unsigned long long int iFrameNum ) +bool StreamHandlerRaw::seek( ClpULong iFrameNum ) { if( m_bIsInput && m_pFile ) { diff --git a/lib/StreamHandlerRaw.h b/lib/StreamHandlerRaw.h index 62541be..b9aa75d 100644 --- a/lib/StreamHandlerRaw.h +++ b/lib/StreamHandlerRaw.h @@ -46,7 +46,7 @@ public: void closeHandler(); bool configureBuffer( CalypFrame* pcFrame ); void calculateFrameNumber(); - bool seek( unsigned long long int iFrameNum ); + bool seek( ClpULong iFrameNum ); bool read( CalypFrame* pcFrame ); bool write( CalypFrame* pcFrame ); }; diff --git a/tools/CalypTools.cpp b/tools/CalypTools.cpp index fe123bd..b7c71cd 100644 --- a/tools/CalypTools.cpp +++ b/tools/CalypTools.cpp @@ -118,13 +118,13 @@ int CalypTools::openInputs() } } - m_uiNumberOfFrames = UINT_MAX; + m_uiNumberOfFrames = -1; if( Opts().hasOpt( "frames" ) ) { m_uiNumberOfFrames = m_iFrames; } - m_uiNumberOfComponents = UINT_MAX; + m_uiNumberOfComponents = -1; for( unsigned int i = 0; i < m_apcInputStreams.size(); i++ ) { m_uiNumberOfFrames = std::min( m_uiNumberOfFrames, m_apcInputStreams[i]->getFrameNum() ); diff --git a/tools/CalypTools.h b/tools/CalypTools.h index 52433ad..ae72f7f 100644 --- a/tools/CalypTools.h +++ b/tools/CalypTools.h @@ -78,7 +78,7 @@ private: MODULE_OPERATION, }; - unsigned int m_uiNumberOfFrames; + ClpULong m_uiNumberOfFrames; unsigned int m_uiNumberOfComponents; std::vector m_apcInputStreams; std::vector m_apcOutputStreams;