From eaa9987314e02e25b22c7256dae3b0fb4d3ad41e Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 10 Jul 2021 12:33:27 +0100 Subject: [PATCH] Change includes and minor fixes --- CMakeLists.txt | 6 +-- lib/CalypDefs.h | 12 ++--- lib/CalypFrame.cpp | 81 +++++++++++++------------------- lib/CalypFrame.h | 14 ++++-- lib/CalypModuleIf.h | 2 + lib/CalypPixel.cpp | 21 +++++---- lib/CalypStreamHandlerIf.h | 5 +- lib/LibMemory.h | 57 +++++----------------- lib/StreamHandlerLibav.cpp | 8 ++-- lib/StreamHandlerPortableMap.cpp | 10 ++-- lib/StreamHandlerRaw.cpp | 11 ++--- modules/HEVCIntraPrediction.cpp | 6 +-- modules/HEVCIntraPrediction.h | 2 +- modules/OptimiseDisplay.cpp | 5 +- tools/CalypTools.h | 2 + tools/CalypToolsCmdParser.h | 2 + 16 files changed, 98 insertions(+), 146 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1206066..ad5a8ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,10 +218,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) # Compiler options # #################################################################################################################################################### -SET(CMAKE_CXX_STANDARD 14) -IF(CMAKE_COMPILER_IS_GNUCXX) - ADD_DEFINITIONS(-std=gnu++0x) -ENDIF() +SET(CMAKE_CXX_STANDARD 20) +ADD_DEFINITIONS(-std=gnu++20) IF(NOT CMAKE_BUILD_TYPE) MESSAGE(STATUS "No build type selected, default to Release") diff --git a/lib/CalypDefs.h b/lib/CalypDefs.h index f425f81..971e05b 100644 --- a/lib/CalypDefs.h +++ b/lib/CalypDefs.h @@ -26,16 +26,14 @@ #ifndef __CALYPDEFS_H__ #define __CALYPDEFS_H__ -#include #include +#include #include -#include -typedef unsigned short ClpPel; ///< 16-bit pixel type -typedef unsigned char ClpByte; -typedef unsigned long long ClpULong; - -typedef std::string ClpString; +using ClpByte = std::uint8_t; +using ClpPel = std::uint16_t; +using ClpULong = std::uint64_t; +using ClpString = std::string; enum CLP_LOG_LEVEL { diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index c827e74..cda50b1 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -26,6 +26,10 @@ #include #include +#include +#include +#include +#include #include "LibMemory.h" #include "PixelFormats.h" @@ -88,7 +92,7 @@ int CalypFrame::pelformatColorSpace( const int idx ) return g_CalypPixFmtDescriptorsMap.at( idx ).colorSpace; } -struct CalypFramePrivate +class CalypFrame::CalypFramePrivate { public: bool m_bInit; @@ -106,14 +110,14 @@ public: ClpPel*** m_pppcInputPel; - bool m_bHasRGBPel; //!< Flag indicating that the ARGB buffer was computed - unsigned char* m_pcARGB32; //!< Buffer with the ARGB pixels used in Qt libs + bool m_bHasRGBPel; //!< Flag indicating that the ARGB buffer was computed + std::vector m_pcARGB32; //!< Buffer with the ARGB pixels used in Qt libs /** Histogram control variables **/ bool m_bHasHistogram; bool m_bHistogramRunning; /** The histogram data.*/ - unsigned int* m_puiHistogram; + std::vector m_puiHistogram; /** If the image is RGB and calcLuma is true, we have 1 more channel */ unsigned int m_uiHistoChannels; /** Numbers of histogram segments depending of image bytes depth*/ @@ -124,8 +128,6 @@ public: m_bInit = false; m_bHasRGBPel = false; m_pppcInputPel = nullptr; - m_pcARGB32 = nullptr; - m_puiHistogram = nullptr; } void init( unsigned int width, unsigned int height, int pel_format, unsigned bitsPixel ) @@ -144,7 +146,7 @@ public: if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > 16 ) { - throw CalypFailure( "CalypFrame", "Cannot create a PlYUVerFrame of this type" ); + throw CalypFailure( "CalypFrame", "Cannot create a CalypFrame of this type" ); } m_pcPelFormat = &( g_CalypPixFmtDescriptorsMap.at( pel_format ) ); @@ -181,9 +183,8 @@ public: } /* Alloc ARGB memory */ - getMem1D( &m_pcARGB32, m_uiHeight * m_uiWidth * 4 ); + m_pcARGB32.resize( m_uiHeight * m_uiWidth * 4 ); - m_puiHistogram = NULL; m_bHasHistogram = false; m_bHistogramRunning = false; @@ -195,7 +196,7 @@ public: else m_uiHistoChannels = m_pcPelFormat->numberChannels; - getMem1D( &( m_puiHistogram ), m_uiHistoSegments * m_uiHistoChannels ); + m_puiHistogram.resize( m_uiHistoSegments * m_uiHistoChannels ); m_cPelFmtName = CalypFrame::supportedPixelFormatListNames()[m_iPixelFormat].c_str(); @@ -247,15 +248,10 @@ public: { while( m_bHistogramRunning ) ; - if( m_puiHistogram ) - freeMem1D( m_puiHistogram ); m_bHasHistogram = false; if( m_pppcInputPel ) xFreeMem( m_pppcInputPel ); - - if( m_pcARGB32 ) - freeMem1D( m_pcARGB32 ); } }; @@ -264,26 +260,25 @@ public: */ CalypFrame::CalypFrame() - : d( new CalypFramePrivate ) + : d{ std::make_unique() } { } CalypFrame::CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel ) - : d( new CalypFramePrivate ) + : d{ std::make_unique() } { d->init( width, height, pelFormat, bitsPixel ); } CalypFrame::CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel, bool has_negative_values ) - : d( new CalypFramePrivate ) + : d{ std::make_unique() } { d->init( width, height, pelFormat, bitsPixel, has_negative_values ); } CalypFrame::CalypFrame( CalypFrame&& other ) noexcept - : d( other.d ) + : d{ std::move( other.d ) } { - other.d = nullptr; // we'll talk more about this line below } CalypFrame& CalypFrame::operator=( CalypFrame&& other ) noexcept @@ -292,25 +287,21 @@ CalypFrame& CalypFrame::operator=( CalypFrame&& other ) noexcept if( &other == this ) return *this; - // Release any resource we're holding - delete d; - // Transfer ownership of a.m_ptr to m_ptr - d = other.d; - other.d = nullptr; + d = std::move( other.d ); return *this; } CalypFrame::CalypFrame( const CalypFrame& other ) - : d( new CalypFramePrivate ) + : d{ std::make_unique() } { d->init( other.getWidth(), other.getHeight(), other.getPelFormat(), other.getBitsPel(), other.getHasNegativeValues() ); copyFrom( &other ); } CalypFrame::CalypFrame( const CalypFrame* other ) - : d( new CalypFramePrivate ) + : d{ std::make_unique() } { if( other ) { @@ -325,11 +316,8 @@ CalypFrame& CalypFrame::operator=( const CalypFrame& other ) if( &other == this ) return *this; - // Release any resource we're holding - delete d; - // Copy the resource - d = new CalypFramePrivate; + d = std::make_unique(); d->init( other.getWidth(), other.getHeight(), other.getPelFormat(), other.getBitsPel(), other.getHasNegativeValues() ); copyFrom( &other ); @@ -337,7 +325,7 @@ CalypFrame& CalypFrame::operator=( const CalypFrame& other ) } CalypFrame::CalypFrame( const CalypFrame& other, unsigned int x, unsigned int y, unsigned int width, unsigned int height ) - : d( new CalypFramePrivate ) + : d{ std::make_unique() } { const CalypPixelFormatDescriptor* pcPelFormat = &( g_CalypPixFmtDescriptorsMap.at( other.getPelFormat() ) ); if( pcPelFormat->log2ChromaWidth ) @@ -362,7 +350,7 @@ CalypFrame::CalypFrame( const CalypFrame& other, unsigned int x, unsigned int y, } CalypFrame::CalypFrame( const CalypFrame* other, unsigned int posX, unsigned int posY, unsigned int areaWidth, unsigned int areaHeight ) - : d( new CalypFramePrivate ) + : d{ std::make_unique() } { if( !other ) return; @@ -389,10 +377,7 @@ CalypFrame::CalypFrame( const CalypFrame* other, unsigned int posX, unsigned int copyFrom( other, posX, posY ); } -CalypFrame::~CalypFrame() -{ - delete d; -} +CalypFrame::~CalypFrame() = default; bool CalypFrame::haveSameFmt( const CalypFrame& other, unsigned int match ) const { @@ -544,7 +529,7 @@ unsigned char* CalypFrame::getRGBBuffer() const { if( d->m_bHasRGBPel ) { - return d->m_pcARGB32; + return d->m_pcARGB32.data(); } return NULL; } @@ -663,7 +648,7 @@ void CalypFrame::copyTo( const CalypFrame* other, unsigned x, unsigned y ) copyTo( *other, x, y ); } -void CalypFrame::frameFromBuffer( ClpByte* Buff, int iEndianness, unsigned long uiBuffSize ) +void CalypFrame::frameFromBuffer( const std::vector& Buff, int iEndianness, unsigned long uiBuffSize ) { if( uiBuffSize != getBytesPerFrame() ) return; @@ -671,9 +656,9 @@ void CalypFrame::frameFromBuffer( ClpByte* Buff, int iEndianness, unsigned long frameFromBuffer( Buff, iEndianness ); } -void CalypFrame::frameFromBuffer( ClpByte* Buff, int iEndianness ) +void CalypFrame::frameFromBuffer( const std::vector& Buff, int iEndianness ) { - ClpByte* ppBuff[MAX_NUMBER_PLANES]; + const ClpByte* ppBuff[MAX_NUMBER_PLANES]; unsigned int bytesPixel = ( d->m_uiBitsPel - 1 ) / 8 + 1; int startByte = 0; int endByte = bytesPixel; @@ -687,7 +672,7 @@ void CalypFrame::frameFromBuffer( ClpByte* Buff, int iEndianness ) incByte = -1; } - ppBuff[0] = Buff; + ppBuff[0] = Buff.data(); for( unsigned i = 1; i < MAX_NUMBER_PLANES; i++ ) { int ratioW = i > 1 ? d->m_pcPelFormat->log2ChromaWidth : 0; @@ -704,7 +689,7 @@ void CalypFrame::frameFromBuffer( ClpByte* Buff, int iEndianness ) int step = ( d->m_pcPelFormat->comp[ch].step_minus1 ) * bytesPixel; ClpPel* pPel = d->m_pppcInputPel[ch][0]; - ClpByte* pTmpBuff = ppBuff[d->m_pcPelFormat->comp[ch].plane] + ( d->m_pcPelFormat->comp[ch].offset_plus1 - 1 ) * bytesPixel; + const ClpByte* pTmpBuff = ppBuff[d->m_pcPelFormat->comp[ch].plane] + ( d->m_pcPelFormat->comp[ch].offset_plus1 - 1 ) * bytesPixel; for( unsigned p = 0; p < CHROMASHIFT( d->m_uiHeight, ratioH ) * CHROMASHIFT( d->m_uiWidth, ratioW ); p++ ) { @@ -724,7 +709,7 @@ void CalypFrame::frameFromBuffer( ClpByte* Buff, int iEndianness ) d->m_bHasHistogram = false; } -void CalypFrame::frameToBuffer( ClpByte* output_buffer, int iEndianness ) +void CalypFrame::frameToBuffer( std::vector& output_buffer, int iEndianness ) { unsigned int bytesPixel = ( d->m_uiBitsPel - 1 ) / 8 + 1; ClpByte* ppBuff[MAX_NUMBER_PLANES]; @@ -744,7 +729,7 @@ void CalypFrame::frameToBuffer( ClpByte* output_buffer, int iEndianness ) incByte = -1; } - ppBuff[0] = output_buffer; + ppBuff[0] = output_buffer.data(); for( int i = 1; i < MAX_NUMBER_PLANES; i++ ) { ratioW = i > 1 ? d->m_pcPelFormat->log2ChromaWidth : 0; @@ -826,7 +811,7 @@ void CalypFrame::fillRGBBuffer() d->m_bHasRGBPel = true; // 4 bytes for A, R, G and B - uint32_t* pARGB = (uint32_t*)d->m_pcARGB32; + uint32_t* pARGB = (uint32_t*)d->m_pcARGB32.data(); if( d->m_pcPelFormat->colorSpace == CLP_COLOR_GRAY ) { ClpPel* pY = d->m_pppcInputPel[CLP_LUMA][0]; @@ -911,12 +896,12 @@ void CalypFrame::fillRGBBuffer() void CalypFrame::calcHistogram() { - if( d->m_bHasHistogram || !d->m_puiHistogram ) + if( d->m_bHasHistogram || d->m_puiHistogram.empty() ) return; d->m_bHistogramRunning = true; - xMemSet( unsigned int, d->m_uiHistoSegments * d->m_uiHistoChannels, d->m_puiHistogram ); + std::fill( d->m_puiHistogram.begin(), d->m_puiHistogram.end(), 0 ); unsigned int numberChannels = d->m_pcPelFormat->numberChannels; for( unsigned int ch = 0; ch < numberChannels; ch++ ) diff --git a/lib/CalypFrame.h b/lib/CalypFrame.h index 6ddce11..1ba95f3 100644 --- a/lib/CalypFrame.h +++ b/lib/CalypFrame.h @@ -26,6 +26,8 @@ #ifndef __CALYPFRAME_H__ #define __CALYPFRAME_H__ +#include + #include "CalypDefs.h" namespace cv @@ -73,7 +75,8 @@ public: CalypPixel convertPixel( CalypColorSpace eOutputSpace ); private: - struct CalypPixelPrivate* d; + class CalypPixelPrivate; + std::unique_ptr d; }; /** @@ -369,9 +372,9 @@ public: void copyTo( const CalypFrame& other, unsigned x, unsigned y ); void copyTo( const CalypFrame* other, unsigned x, unsigned y ); - void frameFromBuffer( ClpByte*, int, unsigned long ); - void frameFromBuffer( ClpByte*, int ); - void frameToBuffer( ClpByte*, int ); + void frameFromBuffer( const std::vector&, int, unsigned long ); + void frameFromBuffer( const std::vector&, int ); + void frameToBuffer( std::vector&, int ); void fillRGBBuffer(); @@ -443,7 +446,8 @@ public: /** @} */ private: - struct CalypFramePrivate* d; + class CalypFramePrivate; + std::unique_ptr d; }; #endif // __CALYPFRAME_H__ diff --git a/lib/CalypModuleIf.h b/lib/CalypModuleIf.h index 3d24e20..ee01fcd 100644 --- a/lib/CalypModuleIf.h +++ b/lib/CalypModuleIf.h @@ -34,6 +34,8 @@ * @} */ +#include + #include "CalypFrame.h" #include "CalypOptions.h" diff --git a/lib/CalypPixel.cpp b/lib/CalypPixel.cpp index 2fe83f2..94a360e 100644 --- a/lib/CalypPixel.cpp +++ b/lib/CalypPixel.cpp @@ -22,14 +22,17 @@ * \brief Video Frame handling */ +#include + #include "CalypFrame.h" #include "PixelFormats.h" #include "config.h" #define MAX_NUMBER_COMPONENTS 4 -struct CalypPixelPrivate +class CalypPixel::CalypPixelPrivate { +public: CalypPixelPrivate( const int& ColorSpace ) { iColorSpace = ColorSpace == CLP_COLOR_GRAY ? @@ -71,18 +74,18 @@ int CalypPixel::getMaxNumberOfComponents() } CalypPixel::CalypPixel( const int& ColorSpace ) - : d( new CalypPixelPrivate( ColorSpace ) ) + : d{ std::make_unique( ColorSpace ) } { } CalypPixel::CalypPixel( const int& ColorSpace, const ClpPel& c0 ) - : d( new CalypPixelPrivate( ColorSpace ) ) + : d{ std::make_unique( ColorSpace ) } { d->PelComp[0] = c0; } CalypPixel::CalypPixel( const int& ColorSpace, const ClpPel& c0, const ClpPel& c1, const ClpPel& c2 ) - : d( new CalypPixelPrivate( ColorSpace ) ) + : d{ std::make_unique( ColorSpace ) } { d->PelComp[0] = c0; d->PelComp[1] = c1; @@ -90,7 +93,7 @@ CalypPixel::CalypPixel( const int& ColorSpace, const ClpPel& c0, const ClpPel& c } CalypPixel::CalypPixel( const int& ColorSpace, const ClpPel& c0, const ClpPel& c1, const ClpPel& c2, const ClpPel& c3 ) - : d( new CalypPixelPrivate( ColorSpace ) ) + : d{ std::make_unique( ColorSpace ) } { d->PelComp[0] = c0; d->PelComp[1] = c1; @@ -99,7 +102,8 @@ CalypPixel::CalypPixel( const int& ColorSpace, const ClpPel& c0, const ClpPel& c } CalypPixel::CalypPixel( const CalypPixel& other ) - : d( new CalypPixelPrivate( other.colorSpace() ) ) + : d{ std::make_unique( other.colorSpace() ) } + { for( int i = 0; i < MAX_NUMBER_COMPONENTS; i++ ) { @@ -107,10 +111,7 @@ CalypPixel::CalypPixel( const CalypPixel& other ) } } -CalypPixel::~CalypPixel() -{ - delete d; -} +CalypPixel::~CalypPixel() = default; int CalypPixel::colorSpace() const { diff --git a/lib/CalypStreamHandlerIf.h b/lib/CalypStreamHandlerIf.h index 94da3c0..2aa2752 100644 --- a/lib/CalypStreamHandlerIf.h +++ b/lib/CalypStreamHandlerIf.h @@ -25,6 +25,8 @@ #ifndef __CALYPSTREAMHANDLERIF_H__ #define __CALYPSTREAMHANDLERIF_H__ +#include + #include "CalypStream.h" #define INI_REGIST_CALYP_SUPPORTED_FMT \ @@ -78,7 +80,6 @@ public: , m_dFrameRate( 30 ) , m_uiCurrFrameFileIdx( 0 ) , m_uiTotalNumberFrames( 0 ) - , m_pStreamBuffer( NULL ) , m_uiNBytesPerFrame( 0 ) , m_isEOF( false ) { @@ -114,7 +115,7 @@ protected: double m_dFrameRate; ClpULong m_uiCurrFrameFileIdx; ClpULong m_uiTotalNumberFrames; - ClpByte* m_pStreamBuffer; + std::vector m_pStreamBuffer; ClpULong m_uiNBytesPerFrame; bool m_isEOF; }; diff --git a/lib/LibMemory.h b/lib/LibMemory.h index 0e49280..235db0b 100644 --- a/lib/LibMemory.h +++ b/lib/LibMemory.h @@ -40,7 +40,7 @@ #endif #define xMemSet( type, len, ptr ) memset( ptr, 0, ( len ) * sizeof( type ) ) -static inline void* xMallocMem( size_t nitems ) +[[deprecated]] static inline void* xMallocMem( size_t nitems ) { void* d; if( ( d = xMalloc( nitems ) ) == NULL ) @@ -51,7 +51,7 @@ static inline void* xMallocMem( size_t nitems ) return d; } -static inline void* xCallocMem( size_t nitems, size_t size ) +[[deprecated]] static inline void* xCallocMem( size_t nitems, size_t size ) { size_t padded_size = nitems * size; void* d = xMallocMem( padded_size ); @@ -61,7 +61,7 @@ static inline void* xCallocMem( size_t nitems, size_t size ) } template -int getMem1D( T** array1D, int dim0 ) +[[deprecated]] int getMem1D( T** array1D, int dim0 ) { if( ( *array1D = (T*)xCallocMem( dim0, sizeof( T ) ) ) == NULL ) return 0; @@ -69,6 +69,16 @@ int getMem1D( T** array1D, int dim0 ) return ( sizeof( T* ) + dim0 * sizeof( T ) ); } +template +[[deprecated]] void freeMem1D( T*& array1D ) +{ + if( array1D ) + { + xFreeMem( array1D ); + array1D = NULL; + } +} + template int getMem2D( T*** array2D, int dim0, int dim1 ) { @@ -85,32 +95,6 @@ int getMem2D( T*** array2D, int dim0, int dim1 ) return dim0 * ( sizeof( T* ) + dim1 * sizeof( T ) ); } -template -int getMem3D( T**** array3D, int dim0, int dim1, int dim2 ) -{ - int i, mem_size = dim0 * sizeof( T** ); - - if( ( ( *array3D ) = (T***)xMallocMem( dim0 * sizeof( T** ) ) ) == NULL ) - printf( "get_mem3Dint: array3D" ); - - mem_size += getMem2D( *array3D, dim0 * dim1, dim2 ); - - for( i = 1; i < dim0; i++ ) - ( *array3D )[i] = ( *array3D )[i - 1] + dim1; - - return mem_size; -} - -template -void freeMem1D( T*& array1D ) -{ - if( array1D ) - { - xFreeMem( array1D ); - array1D = NULL; - } -} - template void freeMem2D( T**& array2D ) { @@ -130,19 +114,4 @@ void freeMem2D( T**& array2D ) } } -template -void freeMem3D( T***& array3D ) -{ - if( array3D ) - { - freeMem2D( *array3D ); - xFreeMem( array3D ); - array3D = NULL; - } - else - { - printf( "free_mem3Dint: trying to free unused memory" ); - } -} - #endif // __LIBMEMORY_H__ diff --git a/lib/StreamHandlerLibav.cpp b/lib/StreamHandlerLibav.cpp index e5dcafd..9f25050 100644 --- a/lib/StreamHandlerLibav.cpp +++ b/lib/StreamHandlerLibav.cpp @@ -323,14 +323,12 @@ void StreamHandlerLibav::closeHandler() av_free( m_cFrame ); } m_bHasStream = false; - - if( m_pStreamBuffer ) - freeMem1D( m_pStreamBuffer ); } bool StreamHandlerLibav::configureBuffer( CalypFrame* pcFrame ) { - return getMem1D( &m_pStreamBuffer, pcFrame->getBytesPerFrame() ); + m_pStreamBuffer.resize( pcFrame->getBytesPerFrame() ); + return true; } void StreamHandlerLibav::calculateFrameNumber() @@ -427,7 +425,7 @@ bool StreamHandlerLibav::read( CalypFrame* pcFrame ) decFrame = m_cConvertedFrame; } - av_image_copy_to_buffer( m_pStreamBuffer, m_uiFrameBufferSize, decFrame->data, + av_image_copy_to_buffer( m_pStreamBuffer.data(), m_uiFrameBufferSize, decFrame->data, decFrame->linesize, AVPixelFormat( m_ffPixFmt ), m_uiWidth, m_uiHeight, 1 ); pcFrame->frameFromBuffer( m_pStreamBuffer, m_iEndianness ); diff --git a/lib/StreamHandlerPortableMap.cpp b/lib/StreamHandlerPortableMap.cpp index 3260cb3..cf06750 100644 --- a/lib/StreamHandlerPortableMap.cpp +++ b/lib/StreamHandlerPortableMap.cpp @@ -124,14 +124,12 @@ void StreamHandlerPortableMap::closeHandler() { if( m_pFile ) fclose( m_pFile ); - - if( m_pStreamBuffer ) - freeMem1D( m_pStreamBuffer ); } bool StreamHandlerPortableMap::configureBuffer( CalypFrame* pcFrame ) { - return getMem1D( &m_pStreamBuffer, pcFrame->getBytesPerFrame() ); + m_pStreamBuffer.resize( pcFrame->getBytesPerFrame() ); + return true; } bool StreamHandlerPortableMap::seek( ClpULong iFrameNum ) @@ -142,7 +140,7 @@ bool StreamHandlerPortableMap::seek( ClpULong iFrameNum ) bool StreamHandlerPortableMap::read( CalypFrame* pcFrame ) { - unsigned long long int processed_bytes = fread( m_pStreamBuffer, sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile ); + unsigned long long int processed_bytes = fread( m_pStreamBuffer.data(), sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile ); if( processed_bytes != m_uiNBytesPerFrame ) return false; pcFrame->frameFromBuffer( m_pStreamBuffer, CLP_BIG_ENDIAN ); @@ -162,7 +160,7 @@ bool StreamHandlerPortableMap::write( CalypFrame* pcFrame ) fprintf( m_pFile, "%d\n", m_iMaxValue ); } pcRGBFrame.frameToBuffer( m_pStreamBuffer, m_iEndianness ); - unsigned long long int processed_bytes = fwrite( m_pStreamBuffer, sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile ); + unsigned long long int processed_bytes = fwrite( m_pStreamBuffer.data(), sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile ); if( processed_bytes != m_uiNBytesPerFrame ) return false; return true; diff --git a/lib/StreamHandlerRaw.cpp b/lib/StreamHandlerRaw.cpp index 84f08f6..026a3de 100644 --- a/lib/StreamHandlerRaw.cpp +++ b/lib/StreamHandlerRaw.cpp @@ -64,13 +64,12 @@ void StreamHandlerRaw::closeHandler() { if( m_pFile ) fclose( m_pFile ); - if( m_pStreamBuffer ) - freeMem1D( m_pStreamBuffer ); } bool StreamHandlerRaw::configureBuffer( CalypFrame* pcFrame ) { - return getMem1D( &m_pStreamBuffer, pcFrame->getBytesPerFrame() ); + m_pStreamBuffer.resize( pcFrame->getBytesPerFrame() ); + return true; } void StreamHandlerRaw::calculateFrameNumber() @@ -97,9 +96,9 @@ bool StreamHandlerRaw::seek( ClpULong iFrameNum ) bool StreamHandlerRaw::read( CalypFrame* pcFrame ) { - if( !m_pFile || !m_pStreamBuffer || m_uiNBytesPerFrame == 0 ) + if( !m_pFile || m_pStreamBuffer.empty() || m_uiNBytesPerFrame == 0 ) return false; - unsigned long long int processed_bytes = fread( m_pStreamBuffer, sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile ); + unsigned long long int processed_bytes = fread( m_pStreamBuffer.data(), sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile ); if( processed_bytes != m_uiNBytesPerFrame ) return false; m_uiCurrFrameFileIdx++; @@ -110,7 +109,7 @@ bool StreamHandlerRaw::read( CalypFrame* pcFrame ) bool StreamHandlerRaw::write( CalypFrame* pcFrame ) { pcFrame->frameToBuffer( m_pStreamBuffer, m_iEndianness ); - unsigned long long int processed_bytes = fwrite( m_pStreamBuffer, sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile ); + unsigned long long int processed_bytes = fwrite( m_pStreamBuffer.data(), sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile ); if( processed_bytes != m_uiNBytesPerFrame ) return false; return true; diff --git a/modules/HEVCIntraPrediction.cpp b/modules/HEVCIntraPrediction.cpp index 1076ff6..c7d00a5 100644 --- a/modules/HEVCIntraPrediction.cpp +++ b/modules/HEVCIntraPrediction.cpp @@ -52,7 +52,6 @@ HEVCIntraPrediction::HEVCIntraPrediction() ; m_pcPredBlock = NULL; - m_referenceMem = NULL; m_uiMode = 26; m_iBlockSize = 4; @@ -66,7 +65,8 @@ bool HEVCIntraPrediction::create( std::vector apcFrameList ) m_pcPredBlock = NULL; m_pcPredBlock = new CalypFrame( m_iBlockSize * 2 + 1, m_iBlockSize * 2 + 1, CLP_GRAY, apcFrameList[0]->getBitsPel() ); - getMem1D( &m_referenceMem, m_iBlockSize * 4 ); + m_referenceMem.resize( m_iBlockSize * 4 ); + return true; } @@ -210,7 +210,5 @@ void HEVCIntraPrediction::destroy() { if( m_pcPredBlock ) delete m_pcPredBlock; - if( m_referenceMem ) - freeMem1D( m_referenceMem ); m_pcPredBlock = NULL; } diff --git a/modules/HEVCIntraPrediction.h b/modules/HEVCIntraPrediction.h index 79080a5..9e3756a 100644 --- a/modules/HEVCIntraPrediction.h +++ b/modules/HEVCIntraPrediction.h @@ -39,7 +39,7 @@ private: unsigned int m_uiYpel; bool m_bShowResidue; int m_iBlockSize; - ClpPel* m_referenceMem; + std::vector m_referenceMem; public: HEVCIntraPrediction(); diff --git a/modules/OptimiseDisplay.cpp b/modules/OptimiseDisplay.cpp index 477e6fa..1129763 100644 --- a/modules/OptimiseDisplay.cpp +++ b/modules/OptimiseDisplay.cpp @@ -62,11 +62,10 @@ bool OptimiseDisplay::create( std::vector apcFrameList ) CalypFrame* OptimiseDisplay::process( std::vector apcFrameList ) { unsigned numValues = 1u << apcFrameList[0]->getBitsPel(); - ClpPel* lookUpTable; + std::vector lookUpTable( numValues, 0 ); const ClpPel* pInput1PelYUV = apcFrameList[0]->getPelBufferYUV()[0][0]; ClpPel* pOutputPelYUV = m_pcOptimisedFrame->getPelBufferYUV()[0][0]; - getMem1D( &lookUpTable, numValues ); apcFrameList[0]->calcHistogram(); m_pcOptimisedFrame->reset(); @@ -92,8 +91,6 @@ CalypFrame* OptimiseDisplay::process( std::vector apcFrameList ) } } } - - freeMem1D( lookUpTable ); return m_pcOptimisedFrame; } diff --git a/tools/CalypTools.h b/tools/CalypTools.h index d46023a..a7a96c1 100644 --- a/tools/CalypTools.h +++ b/tools/CalypTools.h @@ -44,6 +44,8 @@ * */ +#include + #include "CalypToolsCmdParser.h" #include "lib/CalypFrame.h" diff --git a/tools/CalypToolsCmdParser.h b/tools/CalypToolsCmdParser.h index aa4c16a..0447a06 100644 --- a/tools/CalypToolsCmdParser.h +++ b/tools/CalypToolsCmdParser.h @@ -25,6 +25,8 @@ #ifndef __CALYPTOOLSCMDPARSER_H__ #define __CALYPTOOLSCMDPARSER_H__ +#include + #include "config.h" #include "lib/CalypOptions.h"