diff --git a/app/ModulesHandle.cpp b/app/ModulesHandle.cpp index bd9059c..19a605b 100644 --- a/app/ModulesHandle.cpp +++ b/app/ModulesHandle.cpp @@ -579,7 +579,7 @@ void ModulesHandle::applyAllModuleIf( CalypAppModuleIf* pcCurrModuleIf ) { pcCurrModuleIf->apply( false, true ); QCoreApplication::processEvents(); - pcCurrModuleIf->m_pcModuleStream->writeFrame( pcCurrModuleIf->m_pcProcessedFrame ); + pcCurrModuleIf->m_pcModuleStream->writeFrame( *pcCurrModuleIf->m_pcProcessedFrame ); for( unsigned int i = 0; i < numberOfWindows; i++ ) { pcCurrModuleIf->m_pcSubWindow[i]->play(); diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index 8e9a6b8..cb8c743 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -800,7 +800,7 @@ bool VideoSubWindow::save( QString filename ) { return false; } - iRet = CalypStream::saveFrame( filename.toStdString(), saveFrame ); + iRet = CalypStream::saveFrame( filename.toStdString(), *saveFrame ); QApplication::restoreOverrideCursor(); return iRet; } diff --git a/app/docks/FramePropertiesDock.cpp b/app/docks/FramePropertiesDock.cpp index 4867b80..d05c902 100644 --- a/app/docks/FramePropertiesDock.cpp +++ b/app/docks/FramePropertiesDock.cpp @@ -365,7 +365,7 @@ void FramePropertiesDock::setFrame( CalypFrame* pcFrame, bool isPlaying ) if( pcFrame ) { m_bHasFrame = true; - m_cFrame = CalypFrame( pcFrame ); + m_pcFrame = std::make_shared( *pcFrame ); } else { @@ -389,8 +389,10 @@ void FramePropertiesDock::setSelection( const QRect& selectionArea ) */ if( bSelectionChanged ) { - m_cSelectedFrame = CalypFrame( m_cFrame, selectionArea.x(), selectionArea.y(), selectionArea.width(), - selectionArea.height() ); + m_pcSelectedFrame = std::make_shared( *m_pcFrame, selectionArea.x(), + selectionArea.y(), + selectionArea.width(), + selectionArea.height() ); } updateDataHistogram(); selectionImageButton->click(); @@ -413,7 +415,11 @@ void FramePropertiesDock::updateDataHistogram() { if( m_cSelectionArea.isValid() ) { - m_cSelectedFrame = CalypFrame( m_cFrame, m_cSelectionArea.x(), m_cSelectionArea.y(), m_cSelectionArea.width(), m_cSelectionArea.height() ); + m_pcSelectedFrame = std::make_shared( *m_pcFrame, + m_cSelectionArea.x(), + m_cSelectionArea.y(), + m_cSelectionArea.width(), + m_cSelectionArea.height() ); fullImageButton->show(); selectionImageButton->show(); } @@ -422,7 +428,7 @@ void FramePropertiesDock::updateDataHistogram() fullImageButton->hide(); selectionImageButton->hide(); } - histogramWidget->updateData( &m_cFrame, m_cSelectionArea.isValid() ? &m_cSelectedFrame : nullptr ); + histogramWidget->updateData( m_pcFrame, m_cSelectionArea.isValid() ? m_pcSelectedFrame : nullptr ); } else { @@ -448,7 +454,7 @@ void FramePropertiesDock::updateStatistiques() if( channel == CalypFrame::HIST_ALL_CHANNELS ) channel = colorsCB->itemData( colorsCB->currentIndex() ).toInt(); - CalypFrame* frame; + std::shared_ptr frame; if( histogramWidget->m_renderingType == HistogramWidget::FullImageHistogram ) frame = histogramWidget->m_fullImage; diff --git a/app/docks/FramePropertiesDock.h b/app/docks/FramePropertiesDock.h index 64cfc72..cde3496 100644 --- a/app/docks/FramePropertiesDock.h +++ b/app/docks/FramePropertiesDock.h @@ -49,8 +49,8 @@ public: void stopHistogram(); private: - CalypFrame m_cFrame; - CalypFrame m_cSelectedFrame; + std::shared_ptr m_pcFrame; + std::shared_ptr m_pcSelectedFrame; int m_iLastFrameType; bool m_bIsPlaying; bool m_bHasFrame; diff --git a/app/widgets/HistogramWidget.cpp b/app/widgets/HistogramWidget.cpp index 4813350..eb21767 100644 --- a/app/widgets/HistogramWidget.cpp +++ b/app/widgets/HistogramWidget.cpp @@ -41,24 +41,23 @@ class HistogramWorker : public QThread { private: QObject* m_parent; - CalypFrame* m_pcFrame; + std::shared_ptr m_pcFrame; public: HistogramWorker( QObject* parent ) { - m_pcFrame = NULL; m_parent = parent; } - void setup( CalypFrame* frame ) + void setup( std::shared_ptr frame ) { m_pcFrame = frame; - //run(); - start(); + run(); + //start(); } void run() { - if( m_pcFrame && m_parent ) + if( m_pcFrame != nullptr && m_parent != nullptr ) { EventData* eventData = new EventData(); eventData->starting = true; @@ -86,7 +85,7 @@ public: bool starting; bool success; - CalypFrame* frame; + std::shared_ptr frame; }; }; @@ -371,7 +370,7 @@ void HistogramWidget::stopHistogramComputation() // Update Data Methods //////////////////////////////////////////////////////////////////////////////// -void HistogramWidget::updateData( CalypFrame* pcFrame, CalypFrame* pcFrameSelection ) +void HistogramWidget::updateData( std::shared_ptr pcFrame, std::shared_ptr pcFrameSelection ) { d->imageBits = pcFrame->getBitsPel(); switch( pcFrame->getColorSpace() ) @@ -489,7 +488,7 @@ void HistogramWidget::paintEvent( QPaintEvent* ) int wWidth = width() - 1; int wHeight = height() - 1; double max; - CalypFrame* frame; + std::shared_ptr frame; if( m_renderingType == ImageSelectionHistogram && m_selectionImage ) frame = m_selectionImage; diff --git a/app/widgets/HistogramWidget.h b/app/widgets/HistogramWidget.h index ff182de..4cefbb0 100644 --- a/app/widgets/HistogramWidget.h +++ b/app/widgets/HistogramWidget.h @@ -90,7 +90,7 @@ public: void stopHistogramComputation(); /** Update full image histogram data. */ - void updateData( CalypFrame* pcFrame, CalypFrame* pcFrameSelection ); + void updateData( std::shared_ptr pcFrame, std::shared_ptr pcFrameSelection ); /** @see @p HistogramOption */ void setOptions( HistogramOptions options = AllOptions ); @@ -113,12 +113,10 @@ public: /** Full image */ HistogramWorker* m_imageWorker; - // CalypFrameStats* m_imageHistogram; - CalypFrame* m_fullImage; + std::shared_ptr m_fullImage; /** Histogram area selection */ HistogramWorker* m_selectionWorker; - // CalypFrameStats* m_selectionHistogram; - CalypFrame* m_selectionImage; + std::shared_ptr m_selectionImage; Q_SIGNALS: void signalintervalChanged( int min, int max ); diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index cda50b1..118beba 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -258,12 +258,6 @@ public: /*! * \brief Constructors */ - -CalypFrame::CalypFrame() - : d{ std::make_unique() } -{ -} - CalypFrame::CalypFrame( unsigned int width, unsigned int height, int pelFormat, unsigned bitsPixel ) : d{ std::make_unique() } { @@ -300,15 +294,15 @@ CalypFrame::CalypFrame( const CalypFrame& other ) copyFrom( &other ); } -CalypFrame::CalypFrame( const CalypFrame* other ) - : d{ std::make_unique() } -{ - if( other ) - { - d->init( other->getWidth(), other->getHeight(), other->getPelFormat(), other->getBitsPel(), other->getHasNegativeValues() ); - copyFrom( other ); - } -} +// CalypFrame::CalypFrame( const CalypFrame* other ) +// : d{ std::make_unique() } +// { +// if( other ) +// { +// d->init( other->getWidth(), other->getHeight(), other->getPelFormat(), other->getBitsPel(), other->getHasNegativeValues() ); +// copyFrom( other ); +// } +// } CalypFrame& CalypFrame::operator=( const CalypFrame& other ) { @@ -621,7 +615,7 @@ void CalypFrame::copyFrom( const CalypFrame* other, unsigned x, unsigned y ) copyFrom( *other, x, y ); } -void CalypFrame::copyTo( const CalypFrame& other, unsigned x, unsigned y ) +void CalypFrame::copyTo( const CalypFrame& other, unsigned x, unsigned y ) const { if( !haveSameFmt( other, MATCH_COLOR_SPACE | MATCH_PEL_FMT | MATCH_BITS ) ) return; @@ -642,7 +636,7 @@ void CalypFrame::copyTo( const CalypFrame& other, unsigned x, unsigned y ) d->m_bHasHistogram = false; } -void CalypFrame::copyTo( const CalypFrame* other, unsigned x, unsigned y ) +void CalypFrame::copyTo( const CalypFrame* other, unsigned x, unsigned y ) const { if( other ) copyTo( *other, x, y ); @@ -709,7 +703,7 @@ void CalypFrame::frameFromBuffer( const std::vector& Buff, int iEndiann d->m_bHasHistogram = false; } -void CalypFrame::frameToBuffer( std::vector& output_buffer, int iEndianness ) +void CalypFrame::frameToBuffer( std::vector& output_buffer, int iEndianness ) const { unsigned int bytesPixel = ( d->m_uiBitsPel - 1 ) / 8 + 1; ClpByte* ppBuff[MAX_NUMBER_PLANES]; @@ -1230,7 +1224,7 @@ double CalypFrame::getEntropy( unsigned channel, unsigned int start, unsigned in ************************************************************** */ -bool CalypFrame::toMat( cv::Mat& cvMat, bool convertToGray, bool scale, unsigned channel ) +bool CalypFrame::toMat( cv::Mat& cvMat, bool convertToGray, bool scale, unsigned channel ) const { bool bRet = false; #ifdef USE_OPENCV diff --git a/lib/CalypFrame.h b/lib/CalypFrame.h index 1ba95f3..d221ad1 100644 --- a/lib/CalypFrame.h +++ b/lib/CalypFrame.h @@ -27,6 +27,7 @@ #define __CALYPFRAME_H__ #include +#include #include "CalypDefs.h" @@ -105,11 +106,6 @@ public: static int findPixelFormat( const ClpString& name ); static int pelformatColorSpace( const int idx ); - /** - * Default constructor. Frame is not valid - */ - CalypFrame(); - /** * Creates a new frame using the following configuration * @@ -152,7 +148,6 @@ public: * @param other existing frame to copy from */ CalypFrame( const CalypFrame& other ); - CalypFrame( const CalypFrame* other ); /** * Copy-assignement contructor @@ -369,12 +364,12 @@ public: * @param x x position on the current frame * @param y y position on the current frame */ - void copyTo( const CalypFrame& other, unsigned x, unsigned y ); - void copyTo( const CalypFrame* other, unsigned x, unsigned y ); + void copyTo( const CalypFrame& other, unsigned x, unsigned y ) const; + void copyTo( const CalypFrame* other, unsigned x, unsigned y ) const; void frameFromBuffer( const std::vector&, int, unsigned long ); void frameFromBuffer( const std::vector&, int ); - void frameToBuffer( std::vector&, int ); + void frameToBuffer( std::vector&, int ) const; void fillRGBBuffer(); @@ -415,7 +410,7 @@ public: /** * interface with OpenCV lib */ - bool toMat( cv::Mat& cvMat, bool convertToGray = false, bool scale = true, unsigned channel = 0 ); + bool toMat( cv::Mat& cvMat, bool convertToGray = false, bool scale = true, unsigned channel = 0 ) const; bool fromMat( cv::Mat& cvMat, int iChannel = -1 ); /** diff --git a/lib/CalypOptions.h b/lib/CalypOptions.h index ab2e151..5325d93 100644 --- a/lib/CalypOptions.h +++ b/lib/CalypOptions.h @@ -42,6 +42,7 @@ #include #include +#include #include "CalypDefs.h" diff --git a/lib/CalypStream.cpp b/lib/CalypStream.cpp index 467d65e..a2ff4e4 100644 --- a/lib/CalypStream.cpp +++ b/lib/CalypStream.cpp @@ -99,40 +99,38 @@ std::vector CalypStream::stdResolutionSizes() class CalypStreamBufferPrivate { private: - std::vector m_apcFrameBuffer; + std::vector m_apcFrameBuffer; unsigned int m_uiIndex; public: - CalypStreamBufferPrivate( unsigned int size, unsigned int width, unsigned int height, int pelFormat, int bitsPixel, bool hasNegative ) + CalypStreamBufferPrivate( unsigned int size, unsigned int width, unsigned int height, int pelFormat, unsigned int bitsPixel, bool hasNegative ) { for( unsigned int i = 0; i < size; i++ ) { - m_apcFrameBuffer.push_back( new CalypFrame( width, height, pelFormat, bitsPixel, hasNegative ) ); + m_apcFrameBuffer.push_back( CalypFrame{ width, height, pelFormat, bitsPixel, hasNegative } ); } m_uiIndex = 0; } - ~CalypStreamBufferPrivate() - { - while( !m_apcFrameBuffer.empty() ) - { - delete m_apcFrameBuffer.back(); - m_apcFrameBuffer.pop_back(); - } - } + ~CalypStreamBufferPrivate() = default; + void increase( unsigned int newSize ) { for( unsigned int i = m_apcFrameBuffer.size(); i < newSize; i++ ) { - m_apcFrameBuffer.push_back( new CalypFrame( m_apcFrameBuffer.at( 0 ) ) ); + m_apcFrameBuffer.push_back( CalypFrame{ m_apcFrameBuffer[0].getWidth(), + m_apcFrameBuffer[0].getHeight(), + m_apcFrameBuffer[0].getPelFormat(), + m_apcFrameBuffer[0].getBitsPel(), + m_apcFrameBuffer[0].getHasNegativeValues() } ); } } unsigned int size() { return m_apcFrameBuffer.size(); } void setIndex( unsigned int i ) { m_uiIndex = i; } - CalypFrame* frame( int i ) { return m_apcFrameBuffer.at( i ); } + CalypFrame& frame( int i ) { return m_apcFrameBuffer.at( i ); } - CalypFrame* current() { return m_apcFrameBuffer.at( m_uiIndex ); } - CalypFrame* next() { return m_apcFrameBuffer.at( nextIndex() ); } + CalypFrame& current() { return m_apcFrameBuffer.at( m_uiIndex ); } + CalypFrame& next() { return m_apcFrameBuffer.at( nextIndex() ); } void setNextFrame() { m_uiIndex = nextIndex(); } private: @@ -140,8 +138,9 @@ private: inline int prevIndex() { return m_uiIndex - 1 < 0 ? m_apcFrameBuffer.size() - 1 : m_uiIndex - 1; } }; -struct CalypStreamPrivate +class CalypStream::CalypStreamPrivate { +public: bool isInit; bool isInput; @@ -165,6 +164,26 @@ struct CalypStreamPrivate iCurrFrameNum = -1; cFilename = ""; } + ~CalypStreamPrivate() + { + close(); + } + void close() + { + if( !isInit ) + return; + + if( handler ) + { + handler->closeHandler(); + handler->Delete(); + } + if( frameBuffer ) + delete frameBuffer; + + bLoadAll = false; + isInit = false; + } }; std::vector CalypStreamFormat::getExts() @@ -219,15 +238,11 @@ CreateStreamHandlerFn CalypStream::findStreamHandler( ClpString strFilename, boo } CalypStream::CalypStream() - : d( new CalypStreamPrivate ) + : d{ std::make_unique() } { } -CalypStream::~CalypStream() -{ - close(); - delete d; -} +CalypStream::~CalypStream() = default; ClpString CalypStream::getFormatName() const { @@ -329,7 +344,7 @@ bool CalypStream::open( ClpString filename, unsigned int width, unsigned int hei return d->isInit; } - d->handler->m_uiNBytesPerFrame = d->frameBuffer->current()->getBytesPerFrame(); + d->handler->m_uiNBytesPerFrame = d->frameBuffer->current().getBytesPerFrame(); // Some handlers need to know how long is a frame to get frame number d->handler->calculateFrameNumber(); @@ -365,7 +380,7 @@ bool CalypStream::reload() throw CalypFailure( "CalypStream", "Cannot open stream " + d->cFilename + " with the " + ClpString( d->handler->m_pchHandlerName ) + " handler" ); } - d->handler->m_uiNBytesPerFrame = d->frameBuffer->current()->getBytesPerFrame(); + d->handler->m_uiNBytesPerFrame = d->frameBuffer->current().getBytesPerFrame(); d->handler->calculateFrameNumber(); d->handler->configureBuffer( d->frameBuffer->current() ); @@ -386,19 +401,7 @@ bool CalypStream::reload() void CalypStream::close() { - if( !d->isInit ) - return; - - if( d->handler ) - { - d->handler->closeHandler(); - d->handler->Delete(); - } - if( d->frameBuffer ) - delete d->frameBuffer; - - d->bLoadAll = false; - d->isInit = false; + d->close(); } ClpString CalypStream::getFileName() const @@ -488,7 +491,7 @@ void CalypStream::loadAll() d->iCurrFrameNum = 0; } -bool CalypStream::readFrame( CalypFrame* frame ) +bool CalypStream::readFrame( CalypFrame& frame ) { if( !d->isInit || !d->isInput || d->handler->m_uiCurrFrameFileIdx >= d->handler->m_uiTotalNumberFrames ) return false; @@ -509,7 +512,7 @@ void CalypStream::writeFrame() writeFrame( d->frameBuffer->current() ); } -void CalypStream::writeFrame( CalypFrame* pcFrame ) +void CalypStream::writeFrame( const CalypFrame& pcFrame ) { if( !d->handler->write( pcFrame ) ) { @@ -523,11 +526,11 @@ bool CalypStream::saveFrame( const ClpString& filename ) return saveFrame( filename, d->frameBuffer->current() ); } -bool CalypStream::saveFrame( const ClpString& filename, CalypFrame* saveFrame ) +bool CalypStream::saveFrame( const ClpString& filename, const CalypFrame& saveFrame ) { CalypStream auxSaveStream; - if( !auxSaveStream.open( filename, saveFrame->getWidth(), saveFrame->getHeight(), saveFrame->getPelFormat(), - saveFrame->getBitsPel(), CLP_LITTLE_ENDIAN, 1, false ) ) + if( !auxSaveStream.open( filename, saveFrame.getWidth(), saveFrame.getHeight(), saveFrame.getPelFormat(), + saveFrame.getBitsPel(), CLP_LITTLE_ENDIAN, 1, false ) ) { return false; } @@ -560,11 +563,11 @@ void CalypStream::readNextFrame() void CalypStream::readNextFrameFillRGBBuffer() { readNextFrame(); - d->frameBuffer->next()->fillRGBBuffer(); + d->frameBuffer->next().fillRGBBuffer(); return; } -CalypFrame* CalypStream::getCurrFrame( CalypFrame* pyuv_image ) const +CalypFrame* CalypStream::getCurrFrame( CalypFrame* pyuv_image ) { if( pyuv_image == NULL ) pyuv_image = new CalypFrame( d->frameBuffer->current() ); @@ -573,7 +576,12 @@ CalypFrame* CalypStream::getCurrFrame( CalypFrame* pyuv_image ) const return pyuv_image; } -CalypFrame* CalypStream::getCurrFrame() const +CalypFrame* CalypStream::getCurrFrame() +{ + return &d->frameBuffer->current(); +} + +const CalypFrame& CalypStream::getCurrFrameConst() const { return d->frameBuffer->current(); } diff --git a/lib/CalypStream.h b/lib/CalypStream.h index 76a2046..dd15a32 100644 --- a/lib/CalypStream.h +++ b/lib/CalypStream.h @@ -26,6 +26,8 @@ #ifndef __CALYPSTREAM_H__ #define __CALYPSTREAM_H__ +#include + #include "CalypDefs.h" class CalypFrame; @@ -33,21 +35,21 @@ class CalypStreamHandlerIf; typedef CalypStreamHandlerIf* ( *CreateStreamHandlerFn )( void ); -typedef struct +struct CalypStreamFormat { ClpString formatName; ClpString formatExt; std::vector getExts(); ClpString formatPattern; CreateStreamHandlerFn formatFct; -} CalypStreamFormat; +}; -typedef struct +struct CalypStandardResolution { ClpString shortName; unsigned int uiWidth; unsigned int uiHeight; -} CalypStandardResolution; +}; /** * \class CalypStream @@ -68,9 +70,7 @@ public: ~CalypStream(); ClpString getFormatName() const; - ; ClpString getCodecName() const; - ; bool open( ClpString filename, ClpString resolution, ClpString input_format, unsigned int bitsPel, int endianness, bool hasNegative, unsigned int frame_rate, bool bInput ); @@ -97,27 +97,29 @@ public: void loadAll(); void writeFrame(); - void writeFrame( CalypFrame* pcFrame ); + void writeFrame( const CalypFrame& pcFrame ); bool saveFrame( const ClpString& filename ); - static bool saveFrame( const ClpString& filename, CalypFrame* saveFrame ); + static bool saveFrame( const ClpString& filename, const CalypFrame& saveFrame ); - CalypFrame* getCurrFrame( CalypFrame* ) const; + CalypFrame* getCurrFrame( CalypFrame* ); // continuous read control bool setNextFrame(); void readNextFrame(); void readNextFrameFillRGBBuffer(); - CalypFrame* getCurrFrame() const; + CalypFrame* getCurrFrame(); + const CalypFrame& getCurrFrameConst() const; bool seekInputRelative( bool bIsFoward ); bool seekInput( unsigned long new_frame_num ); private: - bool readFrame( CalypFrame* frame ); + bool readFrame( CalypFrame& frame ); private: - struct CalypStreamPrivate* d; + class CalypStreamPrivate; + std::unique_ptr d; }; #endif // __CALYPSTREAM_H__ diff --git a/lib/CalypStreamHandlerIf.h b/lib/CalypStreamHandlerIf.h index 2aa2752..9207226 100644 --- a/lib/CalypStreamHandlerIf.h +++ b/lib/CalypStreamHandlerIf.h @@ -89,10 +89,10 @@ public: virtual bool openHandler( ClpString strFilename, bool bInput ) = 0; virtual void closeHandler() = 0; - virtual bool configureBuffer( CalypFrame* pcFrame ) = 0; + virtual bool configureBuffer( const CalypFrame& pcFrame ) = 0; virtual bool seek( ClpULong iFrameNum ) = 0; - virtual bool read( CalypFrame* pcFrame ) = 0; - virtual bool write( CalypFrame* pcFrame ) = 0; + virtual bool read( CalypFrame& pcFrame ) = 0; + virtual bool write( const CalypFrame& pcFrame ) = 0; virtual void calculateFrameNumber(){}; diff --git a/lib/StreamHandlerLibav.cpp b/lib/StreamHandlerLibav.cpp index 9f25050..d4a0c42 100644 --- a/lib/StreamHandlerLibav.cpp +++ b/lib/StreamHandlerLibav.cpp @@ -325,9 +325,9 @@ void StreamHandlerLibav::closeHandler() m_bHasStream = false; } -bool StreamHandlerLibav::configureBuffer( CalypFrame* pcFrame ) +bool StreamHandlerLibav::configureBuffer( const CalypFrame& pcFrame ) { - m_pStreamBuffer.resize( pcFrame->getBytesPerFrame() ); + m_pStreamBuffer.resize( pcFrame.getBytesPerFrame() ); return true; } @@ -354,7 +354,7 @@ void StreamHandlerLibav::calculateFrameNumber() m_uiTotalNumberFrames = num_frames; } -bool StreamHandlerLibav::read( CalypFrame* pcFrame ) +bool StreamHandlerLibav::read( CalypFrame& pcFrame ) { int bGotFrame = 0; bool bErrors = false; @@ -428,14 +428,14 @@ bool StreamHandlerLibav::read( CalypFrame* pcFrame ) 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 ); + pcFrame.frameFromBuffer( m_pStreamBuffer, m_iEndianness ); m_uiCurrFrameFileIdx++; return true; } return false; } -bool StreamHandlerLibav::write( CalypFrame* pcFrame ) +bool StreamHandlerLibav::write( const CalypFrame& pcFrame ) { return false; } diff --git a/lib/StreamHandlerLibav.h b/lib/StreamHandlerLibav.h index cb23073..afa5599 100644 --- a/lib/StreamHandlerLibav.h +++ b/lib/StreamHandlerLibav.h @@ -65,11 +65,11 @@ public: ~StreamHandlerLibav() {} bool openHandler( ClpString strFilename, bool bInput ); void closeHandler(); - bool configureBuffer( CalypFrame* pcFrame ); + bool configureBuffer( const CalypFrame& pcFrame ); void calculateFrameNumber(); bool seek( ClpULong iFrameNum ); - bool read( CalypFrame* pcFrame ); - bool write( CalypFrame* pcFrame ); + bool read( CalypFrame& pcFrame ); + bool write( const CalypFrame& pcFrame ); unsigned int getStreamDuration() { return m_uiSecs; } unsigned char* m_pchFrameBuffer; diff --git a/lib/StreamHandlerOpenCV.cpp b/lib/StreamHandlerOpenCV.cpp index e7752cf..c50822e 100644 --- a/lib/StreamHandlerOpenCV.cpp +++ b/lib/StreamHandlerOpenCV.cpp @@ -126,7 +126,7 @@ void StreamHandlerOpenCV::closeHandler() } } -bool StreamHandlerOpenCV::configureBuffer( CalypFrame* pcFrame ) +bool StreamHandlerOpenCV::configureBuffer( const CalypFrame& pcFrame ) { return true; } @@ -137,7 +137,7 @@ bool StreamHandlerOpenCV::seek( ClpULong iFrameNum ) return true; } -bool StreamHandlerOpenCV::read( CalypFrame* pcFrame ) +bool StreamHandlerOpenCV::read( CalypFrame& pcFrame ) { bool bRet = false; if( pcVideoCapture ) @@ -145,23 +145,23 @@ bool StreamHandlerOpenCV::read( CalypFrame* pcFrame ) Mat cvMat; bRet = pcVideoCapture->read( cvMat ); if( bRet ) - bRet = pcFrame->fromMat( cvMat ); + bRet = pcFrame.fromMat( cvMat ); } else { Mat cvMat = cv::imread( m_cFilename ); - bRet = pcFrame->fromMat( cvMat ); + bRet = pcFrame.fromMat( cvMat ); } if( bRet ) m_uiCurrFrameFileIdx++; return bRet; } -bool StreamHandlerOpenCV::write( CalypFrame* pcFrame ) +bool StreamHandlerOpenCV::write( const CalypFrame& pcFrame ) { bool bRet = false; Mat cvFrame; - bRet = pcFrame->toMat( cvFrame, false, true ); + bRet = pcFrame.toMat( cvFrame, false, true ); if( !bRet ) return bRet; bRet = cv::imwrite( m_cFilename, cvFrame ); diff --git a/lib/StreamHandlerOpenCV.h b/lib/StreamHandlerOpenCV.h index 690c626..e1e083c 100644 --- a/lib/StreamHandlerOpenCV.h +++ b/lib/StreamHandlerOpenCV.h @@ -42,10 +42,10 @@ public: ~StreamHandlerOpenCV() {} bool openHandler( ClpString strFilename, bool bInput ); void closeHandler(); - bool configureBuffer( CalypFrame* pcFrame ); + bool configureBuffer( const CalypFrame& pcFrame ); bool seek( ClpULong iFrameNum ); - bool read( CalypFrame* pcFrame ); - bool write( CalypFrame* pcFrame ); + bool read( CalypFrame& pcFrame ); + bool write( const CalypFrame& pcFrame ); private: cv::VideoCapture* pcVideoCapture; diff --git a/lib/StreamHandlerPortableMap.cpp b/lib/StreamHandlerPortableMap.cpp index cf06750..376d6f0 100644 --- a/lib/StreamHandlerPortableMap.cpp +++ b/lib/StreamHandlerPortableMap.cpp @@ -126,9 +126,9 @@ void StreamHandlerPortableMap::closeHandler() fclose( m_pFile ); } -bool StreamHandlerPortableMap::configureBuffer( CalypFrame* pcFrame ) +bool StreamHandlerPortableMap::configureBuffer( const CalypFrame& pcFrame ) { - m_pStreamBuffer.resize( pcFrame->getBytesPerFrame() ); + m_pStreamBuffer.resize( pcFrame.getBytesPerFrame() ); return true; } @@ -138,20 +138,20 @@ bool StreamHandlerPortableMap::seek( ClpULong iFrameNum ) return true; } -bool StreamHandlerPortableMap::read( CalypFrame* pcFrame ) +bool StreamHandlerPortableMap::read( CalypFrame& pcFrame ) { 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 ); + pcFrame.frameFromBuffer( m_pStreamBuffer, CLP_BIG_ENDIAN ); m_uiCurrFrameFileIdx++; return true; } -bool StreamHandlerPortableMap::write( CalypFrame* pcFrame ) +bool StreamHandlerPortableMap::write( const CalypFrame& pcFrame ) { - CalypFrame pcRGBFrame( pcFrame->getWidth(), pcFrame->getHeight(), - m_iPixelFormat, pcFrame->getBitsPel() ); + CalypFrame pcRGBFrame( pcFrame.getWidth(), pcFrame.getHeight(), + m_iPixelFormat, pcFrame.getBitsPel() ); pcRGBFrame.copyFrom( pcFrame ); fseek( m_pFile, 0, SEEK_SET ); fprintf( m_pFile, "P%d\n%d %d\n", m_iMagicNumber, m_uiWidth, m_uiHeight ); diff --git a/lib/StreamHandlerPortableMap.h b/lib/StreamHandlerPortableMap.h index 87b50b5..007ec36 100644 --- a/lib/StreamHandlerPortableMap.h +++ b/lib/StreamHandlerPortableMap.h @@ -37,10 +37,10 @@ public: ~StreamHandlerPortableMap() {} bool openHandler( ClpString strFilename, bool bInput ); void closeHandler(); - bool configureBuffer( CalypFrame* pcFrame ); + bool configureBuffer( const CalypFrame& pcFrame ); bool seek( ClpULong iFrameNum ); - bool read( CalypFrame* pcFrame ); - bool write( CalypFrame* pcFrame ); + bool read( CalypFrame& pcFrame ); + bool write( const CalypFrame& pcFrame ); private: FILE* m_pFile; /**< The input file pointer >*/ diff --git a/lib/StreamHandlerRaw.cpp b/lib/StreamHandlerRaw.cpp index 026a3de..b9f4b13 100644 --- a/lib/StreamHandlerRaw.cpp +++ b/lib/StreamHandlerRaw.cpp @@ -66,9 +66,9 @@ void StreamHandlerRaw::closeHandler() fclose( m_pFile ); } -bool StreamHandlerRaw::configureBuffer( CalypFrame* pcFrame ) +bool StreamHandlerRaw::configureBuffer( const CalypFrame& pcFrame ) { - m_pStreamBuffer.resize( pcFrame->getBytesPerFrame() ); + m_pStreamBuffer.resize( pcFrame.getBytesPerFrame() ); return true; } @@ -94,7 +94,7 @@ bool StreamHandlerRaw::seek( ClpULong iFrameNum ) return false; } -bool StreamHandlerRaw::read( CalypFrame* pcFrame ) +bool StreamHandlerRaw::read( CalypFrame& pcFrame ) { if( !m_pFile || m_pStreamBuffer.empty() || m_uiNBytesPerFrame == 0 ) return false; @@ -102,13 +102,13 @@ bool StreamHandlerRaw::read( CalypFrame* pcFrame ) if( processed_bytes != m_uiNBytesPerFrame ) return false; m_uiCurrFrameFileIdx++; - pcFrame->frameFromBuffer( m_pStreamBuffer, m_iEndianness ); + pcFrame.frameFromBuffer( m_pStreamBuffer, m_iEndianness ); return true; } -bool StreamHandlerRaw::write( CalypFrame* pcFrame ) +bool StreamHandlerRaw::write( const CalypFrame& pcFrame ) { - pcFrame->frameToBuffer( m_pStreamBuffer, m_iEndianness ); + pcFrame.frameToBuffer( m_pStreamBuffer, m_iEndianness ); unsigned long long int processed_bytes = fwrite( m_pStreamBuffer.data(), sizeof( ClpByte ), m_uiNBytesPerFrame, m_pFile ); if( processed_bytes != m_uiNBytesPerFrame ) return false; diff --git a/lib/StreamHandlerRaw.h b/lib/StreamHandlerRaw.h index 6db2835..095a5bb 100644 --- a/lib/StreamHandlerRaw.h +++ b/lib/StreamHandlerRaw.h @@ -44,11 +44,11 @@ public: ~StreamHandlerRaw() {} bool openHandler( ClpString strFilename, bool bInput ); void closeHandler(); - bool configureBuffer( CalypFrame* pcFrame ); + bool configureBuffer( const CalypFrame& pcFrame ); void calculateFrameNumber(); bool seek( ClpULong iFrameNum ); - bool read( CalypFrame* pcFrame ); - bool write( CalypFrame* pcFrame ); + bool read( CalypFrame& pcFrame ); + bool write( const CalypFrame& pcFrame ); }; #endif // __STREAMHANDLERRAW_H__ diff --git a/modules/FrameDifference.cpp b/modules/FrameDifference.cpp index fc5fa24..d62fa2b 100644 --- a/modules/FrameDifference.cpp +++ b/modules/FrameDifference.cpp @@ -82,8 +82,8 @@ bool FrameDifference::create( std::vector apcFrameList ) CalypFrame* FrameDifference::process( std::vector apcFrameList ) { - const CalypFrame& frame1 = apcFrameList[0]; - const CalypFrame& frame2 = apcFrameList[1]; + const CalypFrame& frame1 = *apcFrameList[0]; + const CalypFrame& frame2 = *apcFrameList[1]; ClpPel* pOutputPelYUV = m_pcFrameDifference->getPelBufferYUV()[0][0]; short aux_pel_1, aux_pel_2; short diff = 0; diff --git a/modules/FrameShift.cpp b/modules/FrameShift.cpp index d4f67e3..2b06aaa 100644 --- a/modules/FrameShift.cpp +++ b/modules/FrameShift.cpp @@ -24,6 +24,8 @@ #include "FrameShift.h" +#include + FrameShift::FrameShift() { /* Module Definition */ @@ -48,7 +50,11 @@ FrameShift::FrameShift() bool FrameShift::create( std::vector apcFrameList ) { _BASIC_MODULE_API_2_CHECK_ - m_pcProcessedFrame = new CalypFrame( apcFrameList[0] ); + m_pcProcessedFrame = new CalypFrame{ apcFrameList[0]->getWidth(), + apcFrameList[0]->getHeight(), + apcFrameList[0]->getPelFormat(), + apcFrameList[0]->getBitsPel(), + apcFrameList[0]->getHasNegativeValues() }; return true; } diff --git a/modules/OptimiseDisplay.cpp b/modules/OptimiseDisplay.cpp index 1129763..6dbbca2 100644 --- a/modules/OptimiseDisplay.cpp +++ b/modules/OptimiseDisplay.cpp @@ -53,7 +53,11 @@ bool OptimiseDisplay::create( std::vector apcFrameList ) { _BASIC_MODULE_API_2_CHECK_ - m_pcOptimisedFrame = new CalypFrame( apcFrameList[0] ); + m_pcOptimisedFrame = new CalypFrame{ apcFrameList[0]->getWidth(), + apcFrameList[0]->getHeight(), + apcFrameList[0]->getPelFormat(), + apcFrameList[0]->getBitsPel(), + apcFrameList[0]->getHasNegativeValues() }; m_pcOptimisedFrame->reset(); return true; diff --git a/modules/ThreeSixtyDownsampling.cpp b/modules/ThreeSixtyDownsampling.cpp index 14d31c3..06d052c 100644 --- a/modules/ThreeSixtyDownsampling.cpp +++ b/modules/ThreeSixtyDownsampling.cpp @@ -595,8 +595,11 @@ bool ThreeSixtyDownsampling::createDownsamplingMask( CalypFrame* pcInputFrame ) m_pcOutputFrame = new CalypFrame( m_cvReshapePoints[0]->cols, m_cvReshapePoints[0]->rows, pcInputFrame->getPelFormat(), pcInputFrame->getBitsPel() ); break; case 2: - m_pcOutputFrame = new CalypFrame( pcInputFrame ); - m_pcOutputFrame->reset(); + m_pcOutputFrame = new CalypFrame{ pcInputFrame->getWidth(), + pcInputFrame->getHeight(), + pcInputFrame->getPelFormat(), + pcInputFrame->getBitsPel(), + pcInputFrame->getHasNegativeValues() }; break; } return true; diff --git a/tools/CalypTools.cpp b/tools/CalypTools.cpp index 128929e..2408f5f 100644 --- a/tools/CalypTools.cpp +++ b/tools/CalypTools.cpp @@ -479,7 +479,7 @@ int CalypTools::RateReductionOperation() if( ( frame % m_iRateReductionFactor ) == 0 ) { log( CLP_LOG_INFO, "Writing", frame ); - m_apcOutputStreams[0]->writeFrame( m_apcInputStreams[0]->getCurrFrame() ); + m_apcOutputStreams[0]->writeFrame( m_apcInputStreams[0]->getCurrFrameConst() ); } abEOF = m_apcInputStreams[0]->setNextFrame(); if( !abEOF ) @@ -640,7 +640,7 @@ int CalypTools::ModuleOperation() if( pcProcessedFrame ) { - m_apcOutputStreams[0]->writeFrame( pcProcessedFrame ); + m_apcOutputStreams[0]->writeFrame( *pcProcessedFrame ); } } else if( m_pcCurrModuleIf->m_iModuleType == CLP_FRAME_MEASUREMENT_MODULE ) @@ -675,7 +675,7 @@ int CalypTools::ModuleOperation() pcProcessedFrame = m_pcCurrModuleIf->process( apcFrameList ); if( !pcProcessedFrame ) break; - m_apcOutputStreams[0]->writeFrame( pcProcessedFrame ); + m_apcOutputStreams[0]->writeFrame( *pcProcessedFrame ); } } }