diff --git a/.clang-tidy b/.clang-tidy index 1658e98..dc6a817 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay' +Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic' WarningsAsErrors: '' HeaderFilterRegex: '' AnalyzeTemporaryDtors: false diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ea75ab0..0f45fee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=OFF + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON - name: Build # Build your program with the given configuration diff --git a/CMakeLists.txt b/CMakeLists.txt index 63fdecd..705684f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -243,7 +243,7 @@ IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") IF(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wlogical-op") ENDIF() - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") + # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") ENDIF() IF(USE_WERROR) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 3ddcb1f..2769980 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -53,7 +53,6 @@ SET(Calyp_App_SRCS # Module Quality QualityHandle.cpp PlotSubWindow.cpp - external/qcustomplot/qcustomplot.cpp # Module Plugins ModulesHandle.cpp CalypAppModuleIf.cpp @@ -127,6 +126,8 @@ QT5_ADD_RESOURCES(Calyp_App_RCC ${Calyp_App_RCC}) # Instruct CMake to run moc automatically when needed. SET(CMAKE_AUTOMOC ON) +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-enum-enum-conversion") + # Windows application icon IF(WIN32) SET(WINDOWS_RES_FILE ${CMAKE_CURRENT_BINARY_DIR}/resources.obj) diff --git a/app/MainWindow.cpp b/app/MainWindow.cpp index 0216402..e87b96a 100644 --- a/app/MainWindow.cpp +++ b/app/MainWindow.cpp @@ -81,7 +81,7 @@ MainWindow::MainWindow() setUnifiedTitleAndToolBarOnMac( true ); setCentralWidget( m_pcWindowHandle ); setAcceptDrops( true ); - setBackgroundRole( QPalette::Background ); + setBackgroundRole( QPalette::Window ); connect( m_pcWindowHandle, &SubWindowHandle::windowActivated, this, &MainWindow::update ); connect( m_pcWindowHandle, &SubWindowHandle::changed, this, &MainWindow::update, Qt::QueuedConnection ); diff --git a/app/MdiSubWindow.cpp b/app/MdiSubWindow.cpp index f012407..7de76d9 100644 --- a/app/MdiSubWindow.cpp +++ b/app/MdiSubWindow.cpp @@ -32,7 +32,7 @@ MdiSubWindow::MdiSubWindow( QWidget* parent ) : QMdiSubWindow( parent ) { setAttribute( Qt::WA_DeleteOnClose ); - setBackgroundRole( QPalette::Background ); + setBackgroundRole( QPalette::Window ); } QSize MdiSubWindow::sizeHint() const diff --git a/app/PlotSubWindow.cpp b/app/PlotSubWindow.cpp index 2d540b2..1991026 100644 --- a/app/PlotSubWindow.cpp +++ b/app/PlotSubWindow.cpp @@ -29,7 +29,6 @@ #include #include "qcustomplot.h" -//#include "external/qcustomplot/qcustomplot.h" void PlotSubWindow::definePlotColors() { diff --git a/app/QualityHandle.cpp b/app/QualityHandle.cpp index 5450906..5ec7828 100644 --- a/app/QualityHandle.cpp +++ b/app/QualityHandle.cpp @@ -32,7 +32,6 @@ #include "SubWindowHandle.h" #include "SubWindowSelectorDialog.h" #include "VideoSubWindow.h" -#include "lib/LibMemory.h" QualityHandle::QualityHandle( QWidget* parent, SubWindowHandle* windowManager ) : m_pcParet( parent ), m_pcMainWindowManager( windowManager ) diff --git a/app/QualityHandle.h b/app/QualityHandle.h index d41f5c3..8c03722 100644 --- a/app/QualityHandle.h +++ b/app/QualityHandle.h @@ -25,11 +25,11 @@ #ifndef __QUALITYMEASUREMENT_H__ #define __QUALITYMEASUREMENT_H__ +#include #include #include #include "CommonDefs.h" -#include "QFuture" #include "QualityMeasurementSidebar.h" #include "config.h" diff --git a/app/SubWindowAbstract.cpp b/app/SubWindowAbstract.cpp index 2184078..3a6d859 100644 --- a/app/SubWindowAbstract.cpp +++ b/app/SubWindowAbstract.cpp @@ -40,7 +40,7 @@ SubWindowAbstract::SubWindowAbstract( QWidget* parent, unsigned int category ) // setFocusPolicy( Qt::WheelFocus ); setFocusPolicy( Qt::StrongFocus ); setAttribute( Qt::WA_DeleteOnClose ); - setBackgroundRole( QPalette::Background ); + setBackgroundRole( QPalette::Window ); setWindowIcon( QIcon( ":/logos/calyp-icon.png" ) ); diff --git a/app/SubWindowHandle.cpp b/app/SubWindowHandle.cpp index b6c6ad8..bd2b919 100644 --- a/app/SubWindowHandle.cpp +++ b/app/SubWindowHandle.cpp @@ -49,7 +49,7 @@ public: MdiArea( QWidget* parent = 0 ) : QMdiArea( parent ), m_pixmapLogo( ":/logos/calyp-logo.png" ) { - setBackgroundRole( QPalette::Background ); + setBackgroundRole( QPalette::Window ); } void appendLogMessage( const QString& msg ) diff --git a/app/VideoHandle.cpp b/app/VideoHandle.cpp index 0e9adcd..592dd80 100644 --- a/app/VideoHandle.cpp +++ b/app/VideoHandle.cpp @@ -675,7 +675,7 @@ void VideoHandle::calculateRealFrameRate() void VideoHandle::playEvent() { - auto start = std::chrono::steady_clock::now(); + // auto start = std::chrono::steady_clock::now(); // This value should only be true if it is really needed to refresh the UI after this play event // Lets assume the current window is not playing. Nothing changes in the UI expect the playing windows diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index 734d582..6599c42 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -518,10 +518,10 @@ bool VideoSubWindow::guessFormat( QString filename, unsigned int& rWidth, unsign { bGuessed = false; // Guess pixel format - QVector formats_list = QVector::fromStdVector( CalypFrame::supportedPixelFormatListNames() ); - for( int i = 0; i < formats_list.size(); i++ ) + auto formats_list = CalypFrame::supportedPixelFormatListNames(); + for( std::size_t i = 0; i < formats_list.size(); i++ ) { - if( FilenameShort.contains( formats_list.at( i ).c_str(), Qt::CaseInsensitive ) ) + if( FilenameShort.contains( formats_list[i].c_str(), Qt::CaseInsensitive ) ) { rInputFormat = i; break; @@ -779,7 +779,7 @@ bool VideoSubWindow::disableAllModules() bool VideoSubWindow::hasRunningModule() { bool bRet = false; - for( int i = 0; i < m_associatedModules.size() && !bRet; i++ ) + for( std::size_t i = 0; i < m_associatedModules.size() && !bRet; i++ ) { bRet |= m_associatedModules.at( i )->isRunning(); } diff --git a/app/ViewArea.cpp b/app/ViewArea.cpp index 1cfc97c..0b14d59 100644 --- a/app/ViewArea.cpp +++ b/app/ViewArea.cpp @@ -25,6 +25,8 @@ #include "ViewArea.h" +#include + #include #include #include @@ -729,10 +731,10 @@ void ViewArea::wheelEvent( QWheelEvent* event ) QWidget* p = parentWidget(); QSize minimumSize = QSize( p->size().width() - 5, p->size().height() - 5 ); - usedScale = scaleZoomFactor( scale, event->pos(), minimumSize ); + usedScale = scaleZoomFactor( scale, event->position().toPoint(), minimumSize ); if( usedScale != 1.0 ) { - emit zoomFactorChanged_byWheel( usedScale, event->pos() ); + emit zoomFactorChanged_byWheel( usedScale, event->position().toPoint() ); } } } @@ -743,7 +745,7 @@ void ViewArea::mousePressEvent( QMouseEvent* event ) QPoint vpos = windowToView( event->pos() ); - if( event->button() == Qt::MidButton ) + if( event->button() == Qt::MiddleButton ) { } if( event->button() == Qt::LeftButton ) diff --git a/app/external/qcustomplot/CMakeLists.txt b/app/external/qcustomplot/CMakeLists.txt index ff308d3..00fa408 100644 --- a/app/external/qcustomplot/CMakeLists.txt +++ b/app/external/qcustomplot/CMakeLists.txt @@ -6,7 +6,10 @@ FIND_PACKAGE(Qt5 REQUIRED COMPONENTS Core Gui Widgets PrintSupport) SET(qcustomplot_SRCS qcustomplot.cpp qcustomplot.h) +SET(CMAKE_AUTOMOC ON) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-deprecated-enum-enum-conversion") + ADD_LIBRARY(QCustomPlotLib STATIC ${qcustomplot_SRCS}) TARGET_LINK_LIBRARIES(QCustomPlotLib Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport) - TARGET_INCLUDE_DIRECTORIES(QCustomPlotLib PUBLIC .) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 3a0ceb6..06557bb 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -6,7 +6,7 @@ INCLUDE(GNUInstallDirs) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) -SET(Calyp_Lib_Frame_SRCS CalypPixel.cpp PixelFormats.h PixelFormats.cpp CalypFrame.h CalypFrame.cpp) +SET(Calyp_Lib_Frame_SRCS CalypPixel.cpp PixelFormats.h PixelFormats.cpp CalypFrame.h CalypFrame.cpp CalypPlane.h) SET(Calyp_Lib_Stream_SRCS CalypStream.h @@ -22,15 +22,7 @@ SET(Calyp_Lib_OptionParser_SRCS CalypOptions.h CalypOptions.cpp) SET(Calyp_Lib_Modules_SRCS CalypOptions.h CalypOptions.cpp) -SET(Calyp_Lib_SRCS - LibMemory.h - CalypLib.h - CalypDefs.h - ${Calyp_Lib_Frame_SRCS} - ${Calyp_Lib_Stream_SRCS} - ${Calyp_Lib_OptionParser_SRCS} - ${Calyp_Lib_Modules_SRCS} -) +SET(Calyp_Lib_SRCS CalypLib.h CalypDefs.h ${Calyp_Lib_Frame_SRCS} ${Calyp_Lib_Stream_SRCS} ${Calyp_Lib_OptionParser_SRCS} ${Calyp_Lib_Modules_SRCS}) LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${PROJECT_LIBRARY}) LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index 71dd06d..c39f070 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -27,11 +27,10 @@ #include #include #include +#include #include #include -#include "LibMemory.h" -#include "PixelFormats.h" #include "config.h" #ifdef USE_OPENCV @@ -40,6 +39,18 @@ #include #endif +#include "PixelFormats.h" +#include "config.h" + +#define DATA_ALIGN 1 ///< use 32-bit aligned malloc/free +#if DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 ) +#define xMalloc( len ) _aligned_malloc( len, 32 ) +#define xFreeMem( ptr ) _aligned_free( ptr ) +#else +#define xMalloc( len ) malloc( len ) +#define xFreeMem( ptr ) free( ptr ) +#endif + constexpr auto kMinBitsPerPixel = 8; constexpr auto kMaxBitsPerPixel = 16; @@ -166,7 +177,7 @@ public: } mem_size += num_of_ptrs * sizeof( ClpPel* ) + sizeof( ClpPel** ) * iNumberChannels; - m_pppcInputPel = (ClpPel***)xMallocMem( mem_size ); + m_pppcInputPel = (ClpPel***)xMalloc( mem_size ); ClpPel** pelPtrMem = (ClpPel**)( m_pppcInputPel + iNumberChannels ); ClpPel* pelMem = (ClpPel*)( pelPtrMem + num_of_ptrs ); @@ -675,7 +686,7 @@ void CalypFrame::frameFromBuffer( const std::vector& Buff, int iEndiann ppBuff[i] = ppBuff[i - 1] + CHROMASHIFT( d->m_uiHeight, ratioH ) * CHROMASHIFT( d->m_uiWidth, ratioW ) * bytesPixel; } - xMemSet( ClpPel, getTotalNumberOfPixels(), d->m_pppcInputPel[0][0] ); + memset( d->m_pppcInputPel[0][0], 0, getTotalNumberOfPixels() * sizeof( ClpPel ) ); for( unsigned ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ ) { @@ -850,7 +861,7 @@ void CalypFrame::fillRGBBuffer() const uint32_t* pARGBLine = pARGB; uint32_t* pARGBAux; - for( int y = 0; y < CHROMASHIFT( d->m_uiHeight, d->m_pcPelFormat->log2ChromaHeight ); y++ ) + for( unsigned y = 0; y < CHROMASHIFT( d->m_uiHeight, d->m_pcPelFormat->log2ChromaHeight ); y++ ) { for( int i = 0; i < 1 << d->m_pcPelFormat->log2ChromaHeight; i++ ) { @@ -858,7 +869,7 @@ void CalypFrame::fillRGBBuffer() const ClpPel* pU = pLineU; ClpPel* pV = pLineV; pARGBAux = pARGBLine; - for( int x = 0; x < CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth ); x++ ) + for( unsigned x = 0; x < CHROMASHIFT( d->m_uiWidth, d->m_pcPelFormat->log2ChromaWidth ); x++ ) { int iU = *pU++; iU >>= shiftBits; diff --git a/lib/CalypModuleIf.h b/lib/CalypModuleIf.h index f9b1f9c..b115b56 100644 --- a/lib/CalypModuleIf.h +++ b/lib/CalypModuleIf.h @@ -42,9 +42,16 @@ #define REGISTER_CLASS_MAKER( X ) \ extern "C" CalypModulePtr Maker() { return std::make_unique(); } -#define REGISTER_CLASS_FACTORY( X ) \ -public: \ +#define REGISTER_CLASS_FACTORY( X ) \ +public: \ + X( const X& buffer ) \ + noexcept = delete; \ + X( X&& buffer ) \ + noexcept = delete; \ + auto operator=( const X& buffer )->X& = delete; \ + auto operator=( X&& buffer ) noexcept->X& = delete; \ static CalypModulePtr Create() { return std::make_unique(); } + #define _BASIC_MODULE_API_2_CHECK_ \ if( apcFrameList.size() != m_uiNumberOfFrames ) \ return false; \ @@ -76,8 +83,9 @@ enum Module_API_Version */ enum Module_Type { - CLP_FRAME_PROCESSING_MODULE, - CLP_FRAME_MEASUREMENT_MODULE, + CLP_INVALID_MODULE = -1, + CLP_FRAME_PROCESSING_MODULE = 0, + CLP_FRAME_MEASUREMENT_MODULE = 1, CLP_MODULE_TYPE_MAX = 255, }; @@ -114,31 +122,24 @@ enum Module_Key_Supported class CalypModuleIf { public: - int m_iModuleAPI; - int m_iModuleType; - const char* m_pchModuleCategory; - const char* m_pchModuleName; - const char* m_pchModuleTooltip; - const char* m_pchModuleLongName; + int m_iModuleAPI{ CLP_MODULE_API_1 }; + int m_iModuleType{ CLP_INVALID_MODULE }; + const char* m_pchModuleCategory{ "" }; + const char* m_pchModuleName{ "" }; + const char* m_pchModuleTooltip{ "" }; + const char* m_pchModuleLongName{ "" }; //! Number of frames - unsigned int m_uiNumberOfFrames; + unsigned int m_uiNumberOfFrames{ 1 }; //! Features/Requirements - unsigned int m_uiModuleRequirements; + unsigned int m_uiModuleRequirements{ CLP_MODULE_REQUIRES_NOTHING }; - unsigned int m_iFrameBufferCount; - CalypFrame* m_pcOutputFrame; + unsigned int m_iFrameBufferCount{ 0 }; + //CalypFrame* m_pcOutputFrame; CalypOptions m_cModuleOptions; - CalypModuleIf() - { - m_iModuleAPI = CLP_MODULE_API_1; - m_uiModuleRequirements = CLP_MODULE_REQUIRES_NOTHING; - m_pchModuleLongName = NULL; - m_pcOutputFrame = NULL; - m_iFrameBufferCount = 0; - } + CalypModuleIf() = default; virtual ~CalypModuleIf() {} virtual void destroy() = 0; @@ -164,7 +165,7 @@ public: /** * Module API version 3 */ - virtual CalypFrame* getProcessedFrame() { return m_pcOutputFrame; } + virtual CalypFrame* getProcessedFrame() { return nullptr; } virtual bool needFrame() { return m_iFrameBufferCount == 0 ? true : false; }; virtual bool flush() { diff --git a/lib/CalypOpenCVModuleIf.cpp b/lib/CalypOpenCVModuleIf.cpp index 7a346f2..ea07d76 100644 --- a/lib/CalypOpenCVModuleIf.cpp +++ b/lib/CalypOpenCVModuleIf.cpp @@ -25,59 +25,45 @@ #include "CalypOpenCVModuleIf.h" // OpenCV +#include #include -using cv::Mat; - bool CalypOpenCVModuleIf::create( std::vector apcFrameList ) { _BASIC_MODULE_API_2_CHECK_ bool bRet = false; - std::vector acMatList( apcFrameList.size() ); + std::vector acMatList( apcFrameList.size() ); for( unsigned i = 0; i < apcFrameList.size(); i++ ) { - acMatList[i] = new Mat; - apcFrameList[i]->toMat( *acMatList[i], m_bConvertToGray ); + apcFrameList[i]->toMat( acMatList[i], m_bConvertToGray ); } Mat* outputMat = create_using_opencv( acMatList ); if( outputMat ) { unsigned pelFormat = m_bConvertToGray ? CalypFrame::findPixelFormat( "GRAY" ) : apcFrameList[0]->getPelFormat(); - m_pcOutputFrame = new CalypFrame( outputMat->cols, outputMat->rows, pelFormat, apcFrameList[0]->getBitsPel() ); + m_pcOutputFrame = std::make_unique( outputMat->cols, outputMat->rows, pelFormat, apcFrameList[0]->getBitsPel() ); bRet = true; } else { return false; } - for( unsigned i = 0; i < apcFrameList.size(); i++ ) - { - delete acMatList[i]; - } return bRet; } CalypFrame* CalypOpenCVModuleIf::process( std::vector apcFrameList ) { m_pcOutputFrame->reset(); - std::vector acMatList( apcFrameList.size() ); + std::vector acMatList( apcFrameList.size() ); for( unsigned i = 0; i < apcFrameList.size(); i++ ) { - acMatList[i] = new Mat; - apcFrameList[i]->toMat( *acMatList[i], m_bConvertToGray ); + apcFrameList[i]->toMat( acMatList[i], m_bConvertToGray ); } Mat* cvOutput = process_using_opencv( acMatList ); m_pcOutputFrame->fromMat( *cvOutput ); - for( unsigned i = 0; i < apcFrameList.size(); i++ ) - { - delete acMatList[i]; - } - return m_pcOutputFrame; + return m_pcOutputFrame.get(); } void CalypOpenCVModuleIf::destroy() { - if( m_pcOutputFrame ) - delete m_pcOutputFrame; - m_pcOutputFrame = NULL; } diff --git a/lib/CalypOpenCVModuleIf.h b/lib/CalypOpenCVModuleIf.h index bad4445..6ecf17b 100644 --- a/lib/CalypOpenCVModuleIf.h +++ b/lib/CalypOpenCVModuleIf.h @@ -26,6 +26,8 @@ #ifndef __CALYPOPENCVMODULEIF_H__ #define __CALYPOPENCVMODULEIF_H__ +#include + #include "CalypModuleIf.h" namespace cv @@ -40,8 +42,11 @@ class Mat; */ class CalypOpenCVModuleIf : public CalypModuleIf { + using Mat = cv::Mat; + protected: - const char* m_pchPythonFunctionName; + //const char* m_pchPythonFunctionName; + std::unique_ptr m_pcOutputFrame; bool m_bConvertToGray; public: @@ -57,8 +62,8 @@ public: void destroy(); // API using OpenCV - virtual cv::Mat* create_using_opencv( std::vector apcFrameList ) { return NULL; }; - virtual cv::Mat* process_using_opencv( std::vector apcFrameList ) = 0; + virtual cv::Mat* create_using_opencv( const std::vector& apcFrameList ) { return nullptr; }; + virtual Mat* process_using_opencv( const std::vector& apcFrameList ) = 0; virtual void destroy_using_opencv(){}; }; diff --git a/lib/CalypPlane.h b/lib/CalypPlane.h new file mode 100644 index 0000000..898a4ce --- /dev/null +++ b/lib/CalypPlane.h @@ -0,0 +1,76 @@ +/* This file is a part of Calyp project + * Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com) + * Luis Lucas (luisfrlucas@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 CalypPlane.h + * \ingroup CalypFrameGrp + * \brief Video Frame Plane handling + */ + +#ifndef __CALYPPLANE_H__ +#define __CALYPPLANE_H__ + +#include +#include + +#include "CalypDefs.h" + +/** + * \class CalypPlane + * \ingroup CalypLibGrp CalypPlaneGrp + * \brief Frame handling class + */ +template +class CalypPlane +{ +public: + CalypPlane() noexcept = default; + CalypPlane( std::size_t width, std::size_t height ) noexcept { resize( width, height ); } + + ~CalypPlane() noexcept = default; + CalypPlane( const CalypPlane& buffer ) noexcept = default; + CalypPlane( CalypPlane&& buffer ) noexcept = default; + auto operator=( const CalypPlane& buffer ) -> CalypPlane& = default; + auto operator=( CalypPlane&& buffer ) noexcept -> CalypPlane& = default; + + auto operator[]( std::size_t row ) const& noexcept -> const std::span& { return m_rows[row]; } + auto operator[]( std::size_t row ) & noexcept -> std::span& { return m_rows[row]; } + + auto operator[]( std::size_t row ) const&& noexcept { return m_rows[row]; } + auto operator[]( std::size_t row ) && noexcept { return m_rows[row]; } + + auto data() noexcept { return std::span( m_data ); } + auto data() const noexcept { return std::span( m_data ); } + + void resize( std::size_t width, std::size_t height ) noexcept + { + m_data.resize( width * height ); + m_rows.resize( height ); + for( std::size_t y = 0; y < height; y++ ) + { + m_rows[y] = std::span( m_data ).subspan( y * width, width ); + } + } + +private: + std::vector m_data; + std::vector> m_rows; +}; + +#endif // __CALYPPLANE_H__ diff --git a/lib/CalypStream.cpp b/lib/CalypStream.cpp index 17a562a..cd3efd4 100644 --- a/lib/CalypStream.cpp +++ b/lib/CalypStream.cpp @@ -33,7 +33,6 @@ #include "CalypFrame.h" #include "CalypStreamHandlerIf.h" -#include "LibMemory.h" #include "StreamHandlerPortableMap.h" #include "StreamHandlerRaw.h" #include "config.h" diff --git a/lib/LibMemory.h b/lib/LibMemory.h deleted file mode 100644 index 235db0b..0000000 --- a/lib/LibMemory.h +++ /dev/null @@ -1,117 +0,0 @@ -/* This file is a part of Calyp project - * Copyright (C) 2014-2021 by Joao Carreira (jfmcarreira@gmail.com) - * Luis Lucas (luisfrlucas@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 LibMemory.cpp - * \ingroup CalypLib - * \brief Memory allocation functions - */ - -#ifndef __LIBMEMORY_H__ -#define __LIBMEMORY_H__ - -#include -#include -#include - -#define DATA_ALIGN 1 ///< use 32-bit aligned malloc/free -#if DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 ) -#define xMalloc( len ) _aligned_malloc( len, 32 ) -#define xFreeMem( ptr ) _aligned_free( ptr ) -#else -#define xMalloc( len ) malloc( len ) -#define xFreeMem( ptr ) free( ptr ) -#endif -#define xMemSet( type, len, ptr ) memset( ptr, 0, ( len ) * sizeof( type ) ) - -[[deprecated]] static inline void* xMallocMem( size_t nitems ) -{ - void* d; - if( ( d = xMalloc( nitems ) ) == NULL ) - { - printf( "malloc failed.\n" ); - return NULL; - } - return d; -} - -[[deprecated]] static inline void* xCallocMem( size_t nitems, size_t size ) -{ - size_t padded_size = nitems * size; - void* d = xMallocMem( padded_size ); - if( d ) - memset( d, 0, (int)padded_size ); - return d; -} - -template -[[deprecated]] int getMem1D( T** array1D, int dim0 ) -{ - if( ( *array1D = (T*)xCallocMem( dim0, sizeof( T ) ) ) == NULL ) - return 0; - - 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 ) -{ - int i; - - if( ( *array2D = (T**)xMallocMem( dim0 * sizeof( T* ) ) ) == NULL ) - printf( "get_mem2Dint: array2D" ); - if( ( *( *array2D ) = (T*)xCallocMem( dim0 * dim1, sizeof( T ) ) ) == NULL ) - printf( "get_mem2Dint: array2D" ); - - for( i = 1; i < dim0; i++ ) - ( *array2D )[i] = ( *array2D )[i - 1] + dim1; - - return dim0 * ( sizeof( T* ) + dim1 * sizeof( T ) ); -} - -template -void freeMem2D( T**& array2D ) -{ - if( *array2D ) - { - if( *array2D ) - xFreeMem( *array2D ); - else - printf( "free_mem2Dint: trying to free unused memory" ); - - xFreeMem( array2D ); - array2D = NULL; - } - else - { - printf( "free_mem2Dint: trying to free unused memory" ); - } -} - -#endif // __LIBMEMORY_H__ diff --git a/lib/PixelFormats.cpp b/lib/PixelFormats.cpp index 1cf6fdc..cb25174 100644 --- a/lib/PixelFormats.cpp +++ b/lib/PixelFormats.cpp @@ -25,7 +25,6 @@ #include "PixelFormats.h" #include "CalypFrame.h" -#include "LibMemory.h" #include "config.h" #ifdef USE_FFMPEG #include "StreamHandlerLibav.h" diff --git a/lib/StreamHandlerLibav.cpp b/lib/StreamHandlerLibav.cpp index d4a0c42..bc1e0bb 100644 --- a/lib/StreamHandlerLibav.cpp +++ b/lib/StreamHandlerLibav.cpp @@ -28,7 +28,6 @@ #include #include "CalypFrame.h" -#include "LibMemory.h" #include "PixelFormats.h" #if( ( LIBAVCODEC_VERSION_MAJOR > 57 ) || ( LIBAVCODEC_VERSION_MAJOR == 57 ) && ( LIBAVCODEC_VERSION_MINOR >= 37 ) ) diff --git a/lib/StreamHandlerOpenCV.cpp b/lib/StreamHandlerOpenCV.cpp index c50822e..3565484 100644 --- a/lib/StreamHandlerOpenCV.cpp +++ b/lib/StreamHandlerOpenCV.cpp @@ -28,7 +28,6 @@ #include #include "CalypFrame.h" -#include "LibMemory.h" #if CV_MAJOR_VERSION >= 3 #include #endif diff --git a/lib/StreamHandlerPortableMap.cpp b/lib/StreamHandlerPortableMap.cpp index 376d6f0..4ecb345 100644 --- a/lib/StreamHandlerPortableMap.cpp +++ b/lib/StreamHandlerPortableMap.cpp @@ -28,7 +28,6 @@ #include #include "CalypFrame.h" -#include "LibMemory.h" std::vector StreamHandlerPortableMap::supportedReadFormats() { diff --git a/lib/StreamHandlerRaw.cpp b/lib/StreamHandlerRaw.cpp index b9f4b13..5f7262d 100644 --- a/lib/StreamHandlerRaw.cpp +++ b/lib/StreamHandlerRaw.cpp @@ -27,7 +27,6 @@ #include #include "CalypFrame.h" -#include "LibMemory.h" std::vector StreamHandlerRaw::supportedReadFormats() { diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 735dfe3..c504681 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -70,6 +70,7 @@ ADD_MODULE_USE_OPENCV(SaliencyDetectionFineGrained "SaliencyDetection" VERSION 3 ADD_MODULE_USE_OPENCV(SaliencyDetectionBinWangApr2014 "SaliencyDetection" VERSION 3.3.0 MODULES saliency) ADD_MODULE_USE_OPENCV(FrameResampling "FrameResampling" VERSION 3.3.0 MODULES core) +ADD_MODULE_USE_OPENCV(SaliencyBasedFiltering "SaliencyBasedFiltering" VERSION 3.1.0 MODULES core) ADD_MODULE_USE_OPENCV(ThreeSixtySpatialtoTemporal "ThreeSixtySpatialtoTemporal" VERSION 3.1.0 MODULES core) ADD_MODULE_USE_OPENCV(ThreeSixtyFaceExtraction "ThreeSixtyFaceExtraction" VERSION 3.1.0 MODULES core) diff --git a/modules/FrameResampling.cpp b/modules/FrameResampling.cpp index ef22f20..c203b64 100644 --- a/modules/FrameResampling.cpp +++ b/modules/FrameResampling.cpp @@ -80,26 +80,24 @@ bool FrameResampling::create( std::vector apcFrameList ) { m_iHeight = apcFrameList[0]->getHeight() * double( m_iWidth ) / double( apcFrameList[0]->getWidth() ); } - m_pcOutputFrame = new CalypFrame( m_iWidth, m_iHeight, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); - return m_pcOutputFrame; + m_resamplingFrame = std::make_unique( m_iWidth, m_iHeight, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); + return true; } CalypFrame* FrameResampling::process( std::vector apcFrameList ) { - m_pcOutputFrame->reset(); + m_resamplingFrame->reset(); for( unsigned ch = 0; ch < apcFrameList[0]->getNumberChannels(); ch++ ) { Mat inputFrame, outputFrame; - cv::Size outSize( m_pcOutputFrame->getWidth( ch ), m_pcOutputFrame->getHeight( ch ) ); + cv::Size outSize( m_resamplingFrame->getWidth( ch ), m_resamplingFrame->getHeight( ch ) ); apcFrameList[0]->toMat( inputFrame, true, false, ch ); cv::resize( inputFrame, outputFrame, outSize, 0, 0, m_iInterpolation ); - m_pcOutputFrame->fromMat( outputFrame, ch ); + m_resamplingFrame->fromMat( outputFrame, ch ); } - return m_pcOutputFrame; + return m_resamplingFrame.get(); } void FrameResampling::destroy() { - if( m_pcOutputFrame ) - delete m_pcOutputFrame; } diff --git a/modules/FrameResampling.h b/modules/FrameResampling.h index fd10ed8..a66c1d0 100644 --- a/modules/FrameResampling.h +++ b/modules/FrameResampling.h @@ -43,6 +43,7 @@ private: int m_iWidth; int m_iHeight; int m_iInterpolation; + std::unique_ptr m_resamplingFrame; public: FrameResampling(); diff --git a/modules/HEVCIntraPrediction.cpp b/modules/HEVCIntraPrediction.cpp index c7d00a5..00c8ee1 100644 --- a/modules/HEVCIntraPrediction.cpp +++ b/modules/HEVCIntraPrediction.cpp @@ -26,8 +26,6 @@ #include -#include "lib/LibMemory.h" - HEVCIntraPrediction::HEVCIntraPrediction() { /* Module Definition */ diff --git a/modules/InterFrameVariance.cpp b/modules/InterFrameVariance.cpp index 4aa58c5..a1ff162 100644 --- a/modules/InterFrameVariance.cpp +++ b/modules/InterFrameVariance.cpp @@ -24,8 +24,6 @@ #include "InterFrameVariance.h" -#include "lib/LibMemory.h" - InterFrameVariance::InterFrameVariance() { /* Module Definition */ @@ -56,7 +54,8 @@ bool InterFrameVariance::create( std::vector apcFrameList ) m_pcFrameVariance = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY, 8 ); - getMem2D( &m_pVariance, apcFrameList[0]->getHeight(), apcFrameList[0]->getWidth() ); + + m_pVariance = CalypPlane{ apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight() }; return true; } @@ -105,9 +104,6 @@ CalypFrame* InterFrameVariance::process( std::vector apcFrameList ) void InterFrameVariance::destroy() { - if( m_pVariance ) - freeMem2D( m_pVariance ); - m_pVariance = NULL; if( m_pcFrameVariance ) delete m_pcFrameVariance; m_pcFrameVariance = NULL; diff --git a/modules/InterFrameVariance.h b/modules/InterFrameVariance.h index a4fc4cf..ecbbe20 100644 --- a/modules/InterFrameVariance.h +++ b/modules/InterFrameVariance.h @@ -27,6 +27,7 @@ // CalypLib #include "lib/CalypModuleIf.h" +#include "lib/CalypPlane.h" class InterFrameVariance : public CalypModuleIf { @@ -34,7 +35,7 @@ class InterFrameVariance : public CalypModuleIf private: CalypFrame* m_pcFrameVariance; - double** m_pVariance; + CalypPlane m_pVariance; public: InterFrameVariance(); diff --git a/modules/OptimiseDisplay.cpp b/modules/OptimiseDisplay.cpp index 6dbbca2..f44039c 100644 --- a/modules/OptimiseDisplay.cpp +++ b/modules/OptimiseDisplay.cpp @@ -27,8 +27,6 @@ #include -#include "lib/LibMemory.h" - OptimiseDisplay::OptimiseDisplay() { /* Module Definition */ @@ -53,11 +51,11 @@ bool OptimiseDisplay::create( std::vector apcFrameList ) { _BASIC_MODULE_API_2_CHECK_ - m_pcOptimisedFrame = new CalypFrame{ apcFrameList[0]->getWidth(), - apcFrameList[0]->getHeight(), - apcFrameList[0]->getPelFormat(), - apcFrameList[0]->getBitsPel(), - apcFrameList[0]->getHasNegativeValues() }; + m_pcOptimisedFrame = std::make_unique( apcFrameList[0]->getWidth(), + apcFrameList[0]->getHeight(), + apcFrameList[0]->getPelFormat(), + apcFrameList[0]->getBitsPel(), + apcFrameList[0]->getHasNegativeValues() ); m_pcOptimisedFrame->reset(); return true; @@ -95,11 +93,9 @@ CalypFrame* OptimiseDisplay::process( std::vector apcFrameList ) } } } - return m_pcOptimisedFrame; + return m_pcOptimisedFrame.get(); } void OptimiseDisplay::destroy() { - delete m_pcOptimisedFrame; - m_pcOptimisedFrame = nullptr; } diff --git a/modules/OptimiseDisplay.h b/modules/OptimiseDisplay.h index 45898d1..b0d18e1 100644 --- a/modules/OptimiseDisplay.h +++ b/modules/OptimiseDisplay.h @@ -34,14 +34,14 @@ class OptimiseDisplay : public CalypModuleIf REGISTER_CLASS_FACTORY( OptimiseDisplay ) private: - CalypFrame* m_pcOptimisedFrame; + std::unique_ptr m_pcOptimisedFrame; public: OptimiseDisplay(); virtual ~OptimiseDisplay() {} - bool create( std::vector apcFrameList ); - CalypFrame* process( std::vector apcFrameList ); - void destroy(); + bool create( std::vector apcFrameList ) final; + CalypFrame* process( std::vector apcFrameList ) final; + void destroy() final; }; #endif // __OPTIMISEDISPLAY_H__ diff --git a/modules/SaliencyBasedFiltering.cpp b/modules/SaliencyBasedFiltering.cpp index 8879389..1b8ede1 100644 --- a/modules/SaliencyBasedFiltering.cpp +++ b/modules/SaliencyBasedFiltering.cpp @@ -32,55 +32,61 @@ SaliencyBasedFiltering::SaliencyBasedFiltering() { /* Module Definition */ - m_iModuleAPI = MODULE_API_2; - m_iModuleType = FRAME_PROCESSING_MODULE; + m_iModuleAPI = CLP_MODULE_API_2; + m_iModuleType = CLP_FRAME_PROCESSING_MODULE; m_pchModuleCategory = "Quality"; m_pchModuleName = "SaliencyBasedFiltering"; m_pchModuleTooltip = "Image filter based on a map"; - m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; - m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES; + m_uiModuleRequirements = CLP_MODULE_REQUIRES_NOTHING; + m_uiNumberOfFrames = 2; m_pcProcessedFrame = NULL; } -Bool SaliencyBasedFiltering::create( std::vector apcFrameList ) +bool SaliencyBasedFiltering::create( std::vector apcFrameList ) { _BASIC_MODULE_API_2_CHECK_ - for( UInt i = 0; i < apcFrameList.size(); i++ ) + for( unsigned i = 0; i < apcFrameList.size(); i++ ) { - if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], PlaYUVerFrame::MATCH_RESOLUTION ) ) + if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_RESOLUTION ) ) return false; } if( apcFrameList[1]->getNumberChannels() != 1 ) { return false; } - m_pcProcessedFrame = new PlaYUVerFrame( apcFrameList[0] ); + + m_pcProcessedFrame = std::make_unique( apcFrameList[0]->getWidth(), + apcFrameList[0]->getHeight(), + apcFrameList[0]->getPelFormat(), + apcFrameList[0]->getBitsPel(), + apcFrameList[0]->getHasNegativeValues() ); + return true; } -static cv::Mat* getCvFrame( Pel* pInputPel, UInt uiWidth, UInt uiHeight ) +static cv::Mat* getCvFrame( ClpPel* pInputPel, unsigned uiWidth, unsigned uiHeight ) { cv::Mat* cvInput = new cv::Mat( uiHeight, uiWidth, CV_MAKETYPE( CV_8U, 1 ) ); - UChar* pCvPel = cvInput->data; - for( UInt i = 0; i < uiWidth * uiHeight; i++ ) + unsigned char* pCvPel = cvInput->data; + for( unsigned i = 0; i < uiWidth * uiHeight; i++ ) { *pCvPel++ = *pInputPel++; } return cvInput; } -static cv::Mat* filterframe( cv::Mat* cvFrame, UInt kernelSize ) +static cv::Mat* filterframe( cv::Mat* cvFrame, unsigned kernelSize ) { cv::Mat* cvFiltered = new cv::Mat( cvFrame->rows, cvFrame->cols, CV_MAKETYPE( CV_8U, 1 ) ); /// Initialize arguments for the filter cv::Point anchor = cv::Point( -1, -1 ); - Double delta = 0; - Int ddepth = -1; + double delta = 0; + int ddepth = -1; /// Update kernel size for a normalized box filter - cv::Mat kernel = cv::Mat::ones( kernelSize, kernelSize, CV_32F ) / (Double)( kernelSize * kernelSize ); + cv::Mat kernel = cv::Mat::ones( kernelSize, kernelSize, CV_32F ) / static_cast( kernelSize * kernelSize ); /// Apply filter cv::filter2D( *cvFrame, *cvFiltered, ddepth, kernel, anchor, delta, cv::BORDER_DEFAULT ); @@ -88,44 +94,42 @@ static cv::Mat* filterframe( cv::Mat* cvFrame, UInt kernelSize ) return cvFiltered; } -static void filterComponent( PlaYUVerFrame* pInput, PlaYUVerFrame* pOutput, PlaYUVerFrame* Map, UInt uiComp ) +static void filterComponent( CalypFrame* pInput, CalypFrame* pOutput, CalypFrame* Map, unsigned uiComp ) { - Pel* pMapPel = Map->getPelBufferYUV()[0][0]; - Int iMapStep = 1; - Pel* pInputPel = pInput->getPelBufferYUV()[uiComp][0]; - Pel* pOutputPel = pOutput->getPelBufferYUV()[uiComp][0]; - Int iHeight = pInput->getHeight(); - Int iWidth = pInput->getWidth(); + ClpPel* pMapPel = Map->getPelBufferYUV()[0][0]; + int iMapStep = 1; + ClpPel* pInputPel = pInput->getPelBufferYUV()[uiComp][0]; + ClpPel* pOutputPel = pOutput->getPelBufferYUV()[uiComp][0]; + std::int64_t iHeight = pInput->getHeight( uiComp ); + std::int64_t iWidth = pInput->getWidth( uiComp ); if( uiComp > 0 ) { - iHeight = pInput->getChromaHeight(); - iWidth = pInput->getChromaWidth(); iMapStep = 2; } cv::Mat* cvInput = getCvFrame( pInputPel, iWidth, iHeight ); - UInt numberFilters = 1; - UChar* pCvPel[3]; + unsigned numberFilters = 1; + unsigned char* pCvPel[3]; cv::Mat* cvOutput[3]; - for( UInt i = 0; i < numberFilters; i++ ) + for( unsigned i = 0; i < numberFilters; i++ ) { cvOutput[i] = filterframe( cvInput, ( 1 << ( 2 * i + 7 ) ) + 1 ); pCvPel[i] = cvOutput[i]->data; } - Int iCheckNeighbour = 8; - UInt uiRelevance = 0; - for( Int y = 0; y < iHeight; y++ ) + int iCheckNeighbour = 8; + unsigned uiRelevance = 0; + for( int y = 0; y < iHeight; y++ ) { - for( Int x = 0; x < iWidth; x++ ) + for( int x = 0; x < iWidth; x++ ) { uiRelevance = 0; // uiRelevance = *pMapPel; - for( Int j = CLAMP_RANGE( y - iCheckNeighbour, 0, iHeight ); j < CLAMP_RANGE( y + iCheckNeighbour + 1, 0, iHeight ); j++ ) + for( std::int64_t j = CLAMP_RANGE( y - iCheckNeighbour, 0, iHeight ); j < CLAMP_RANGE( y + iCheckNeighbour + 1, 0, iHeight ); j++ ) { - for( Int i = CLAMP_RANGE( x - iCheckNeighbour, 0, iWidth ); i < CLAMP_RANGE( x + iCheckNeighbour + 1, 0, iWidth ); i++ ) + for( std::int64_t i = CLAMP_RANGE( x - iCheckNeighbour, 0, iWidth ); i < CLAMP_RANGE( x + iCheckNeighbour + 1, 0, iWidth ); i++ ) { uiRelevance += *( pMapPel + ( ( j - y ) * iWidth ) + ( i - x ) ); } @@ -141,7 +145,7 @@ static void filterComponent( PlaYUVerFrame* pInput, PlaYUVerFrame* pOutput, PlaY //*pOutputPel = 0; } - for( UInt i = 0; i < numberFilters; i++ ) + for( unsigned i = 0; i < numberFilters; i++ ) pCvPel[i]++; pInputPel++; pOutputPel++; @@ -151,16 +155,16 @@ static void filterComponent( PlaYUVerFrame* pInput, PlaYUVerFrame* pOutput, PlaY } } -PlaYUVerFrame* SaliencyBasedFiltering::process( std::vector apcFrameList ) +CalypFrame* SaliencyBasedFiltering::process( std::vector apcFrameList ) { - PlaYUVerFrame* pcInputFrame = apcFrameList[0]; + CalypFrame* pcInputFrame = apcFrameList[0]; - for( UInt c = 0; c < pcInputFrame->getNumberChannels(); c++ ) - filterComponent( pcInputFrame, m_pcProcessedFrame, apcFrameList[1], c ); + for( unsigned c = 0; c < pcInputFrame->getNumberChannels(); c++ ) + filterComponent( pcInputFrame, m_pcProcessedFrame.get(), apcFrameList[1], c ); - return m_pcProcessedFrame; + return m_pcProcessedFrame.get(); } -Void SaliencyBasedFiltering::destroy() +void SaliencyBasedFiltering::destroy() { } diff --git a/modules/SaliencyBasedFiltering.h b/modules/SaliencyBasedFiltering.h index e2f2964..470c075 100644 --- a/modules/SaliencyBasedFiltering.h +++ b/modules/SaliencyBasedFiltering.h @@ -24,25 +24,21 @@ #ifndef __SALIENCYBASEDFILTERING_H__ #define __SALIENCYBASEDFILTERING_H__ -#include +#include "lib/CalypModuleIf.h" -#include "lib/PlaYUVerModuleIf.h" - -class SaliencyBasedFiltering : public PlaYUVerModuleIf +class SaliencyBasedFiltering : public CalypModuleIf { REGISTER_CLASS_FACTORY( SaliencyBasedFiltering ) private: - PlaYUVerFrame* m_pcProcessedFrame; + std::unique_ptr m_pcProcessedFrame; public: SaliencyBasedFiltering(); - virtual ~SaliencyBasedFiltering() - { - } - Bool create( std::vector apcFrameList ); - PlaYUVerFrame* process( std::vector apcFrameList ); - Void destroy(); + virtual ~SaliencyBasedFiltering() {} + bool create( std::vector apcFrameList ); + CalypFrame* process( std::vector apcFrameList ); + void destroy(); }; #endif // __SALIENCYBASEDFILTERING_H__ diff --git a/modules/SaliencyDetection.cpp b/modules/SaliencyDetection.cpp index 0eddc8e..d04686f 100644 --- a/modules/SaliencyDetection.cpp +++ b/modules/SaliencyDetection.cpp @@ -45,7 +45,6 @@ SaliencyDetectionModule::SaliencyDetectionModule() void SaliencyDetectionModule::destroy_using_opencv() { - delete m_pcvSaliency; } SaliencyDetectionSpectral::SaliencyDetectionSpectral() @@ -63,17 +62,17 @@ SaliencyDetectionSpectral::SaliencyDetectionSpectral() m_bBinaryMap = false; } -cv::Mat* SaliencyDetectionSpectral::create_using_opencv( std::vector apcMatList ) +cv::Mat* SaliencyDetectionSpectral::create_using_opencv( const std::vector& apcMatList ) { m_ptrSaliencyAlgorithm = StaticSaliencySpectralResidual::create(); - m_pcvSaliency = new Mat( apcMatList[0]->rows, apcMatList[0]->cols, CV_8UC1 ); - return m_pcvSaliency; + m_pcvSaliency = std::make_unique( apcMatList[0].rows, apcMatList[0].cols, CV_8UC1 ); + return m_pcvSaliency.get(); } -Mat* SaliencyDetectionSpectral::process_using_opencv( std::vector apcMatList ) +Mat* SaliencyDetectionSpectral::process_using_opencv( const std::vector& apcMatList ) { Mat cvSaliency; - m_ptrSaliencyAlgorithm->computeSaliency( *apcMatList[0], cvSaliency ); + m_ptrSaliencyAlgorithm->computeSaliency( apcMatList[0], cvSaliency ); Mat cvBinaryMap; StaticSaliencySpectralResidual spec; spec.computeBinaryMap( cvSaliency, *m_pcvSaliency ); @@ -82,7 +81,7 @@ Mat* SaliencyDetectionSpectral::process_using_opencv( std::vector apcMatLi cvSaliency *= 255; cvSaliency.convertTo( *m_pcvSaliency, CV_8UC1 ); } - return m_pcvSaliency; + return m_pcvSaliency.get(); } SaliencyDetectionFineGrained::SaliencyDetectionFineGrained() @@ -93,17 +92,17 @@ SaliencyDetectionFineGrained::SaliencyDetectionFineGrained() m_pchModuleTooltip = "Measure saliency using fine grained method"; } -Mat* SaliencyDetectionFineGrained::create_using_opencv( std::vector apcMatList ) +Mat* SaliencyDetectionFineGrained::create_using_opencv( const std::vector& apcMatList ) { m_ptrSaliencyAlgorithm = cv::saliency::StaticSaliencyFineGrained::create(); - m_pcvSaliency = new Mat( apcMatList[0]->rows, apcMatList[0]->cols, CV_8UC1 ); - return m_pcvSaliency; + m_pcvSaliency = std::make_unique( apcMatList[0].rows, apcMatList[0].cols, CV_8UC1 ); + return m_pcvSaliency.get(); } -Mat* SaliencyDetectionFineGrained::process_using_opencv( std::vector apcMatList ) +Mat* SaliencyDetectionFineGrained::process_using_opencv( const std::vector& apcMatList ) { - m_ptrSaliencyAlgorithm->computeSaliency( *apcMatList[0], *m_pcvSaliency ); - return m_pcvSaliency; + m_ptrSaliencyAlgorithm->computeSaliency( apcMatList[0], *m_pcvSaliency ); + return m_pcvSaliency.get(); } SaliencyDetectionBinWangApr2014::SaliencyDetectionBinWangApr2014() @@ -114,22 +113,22 @@ SaliencyDetectionBinWangApr2014::SaliencyDetectionBinWangApr2014() m_pchModuleTooltip = "Measure saliency using a fast self-tuning background subtraction algorithm"; } -Mat* SaliencyDetectionBinWangApr2014::create_using_opencv( std::vector apcMatList ) +Mat* SaliencyDetectionBinWangApr2014::create_using_opencv( const std::vector& apcMatList ) { m_ptrSaliencyAlgorithm = MotionSaliencyBinWangApr2014::create(); - m_ptrSaliencyAlgorithm.dynamicCast()->setImagesize( apcMatList[0]->cols, apcMatList[0]->rows ); + m_ptrSaliencyAlgorithm.dynamicCast()->setImagesize( apcMatList[0].cols, apcMatList[0].rows ); m_ptrSaliencyAlgorithm.dynamicCast()->init(); - m_pcvSaliency = new Mat( apcMatList[0]->rows, apcMatList[0]->cols, CV_8UC1 ); - return m_pcvSaliency; + m_pcvSaliency = std::make_unique( apcMatList[0].rows, apcMatList[0].cols, CV_8UC1 ); + return m_pcvSaliency.get(); } -Mat* SaliencyDetectionBinWangApr2014::process_using_opencv( std::vector apcMatList ) +Mat* SaliencyDetectionBinWangApr2014::process_using_opencv( const std::vector& apcMatList ) { - if( m_ptrSaliencyAlgorithm->computeSaliency( *apcMatList[0], *m_pcvSaliency ) ) + if( m_ptrSaliencyAlgorithm->computeSaliency( apcMatList[0], *m_pcvSaliency ) ) { *m_pcvSaliency *= 255; m_pcvSaliency->convertTo( *m_pcvSaliency, CV_8UC1 ); //cv::cvtColor(m_matSaliency, m_matSaliency, cv::COLOR_BGR2GRAY); } - return m_pcvSaliency; + return m_pcvSaliency.get(); } diff --git a/modules/SaliencyDetection.h b/modules/SaliencyDetection.h index 8c9b854..50e3b02 100644 --- a/modules/SaliencyDetection.h +++ b/modules/SaliencyDetection.h @@ -32,8 +32,6 @@ #include #include -using cv::Mat; - /** * \ingroup Calyp_Modules * @defgroup Calyp_Modules_Saliency Saliency @@ -44,8 +42,10 @@ using cv::Mat; class SaliencyDetectionModule : public CalypOpenCVModuleIf { + using Mat = cv::Mat; + protected: - Mat* m_pcvSaliency; + std::unique_ptr m_pcvSaliency; cv::Ptr m_ptrSaliencyAlgorithm; public: @@ -68,6 +68,8 @@ public: */ class SaliencyDetectionSpectral : public SaliencyDetectionModule { + using Mat = cv::Mat; + REGISTER_CLASS_FACTORY( SaliencyDetectionSpectral ) private: bool m_bBinaryMap; @@ -75,8 +77,8 @@ private: public: SaliencyDetectionSpectral(); virtual ~SaliencyDetectionSpectral() {} - Mat* create_using_opencv( std::vector apcMatList ); - Mat* process_using_opencv( std::vector apcMatList ); + Mat* create_using_opencv( const std::vector& apcMatList ) override; + Mat* process_using_opencv( const std::vector& apcMatList ) override; }; /** @@ -91,12 +93,14 @@ public: */ class SaliencyDetectionFineGrained : public SaliencyDetectionModule { + using Mat = cv::Mat; + REGISTER_CLASS_FACTORY( SaliencyDetectionFineGrained ) public: SaliencyDetectionFineGrained(); virtual ~SaliencyDetectionFineGrained() {} - Mat* create_using_opencv( std::vector apcMatList ); - Mat* process_using_opencv( std::vector apcMatList ); + Mat* create_using_opencv( const std::vector& apcMatList ) override; + Mat* process_using_opencv( const std::vector& apcMatList ) override; }; /** @@ -108,12 +112,14 @@ public: */ class SaliencyDetectionBinWangApr2014 : public SaliencyDetectionModule { + using Mat = cv::Mat; + REGISTER_CLASS_FACTORY( SaliencyDetectionBinWangApr2014 ) public: SaliencyDetectionBinWangApr2014(); virtual ~SaliencyDetectionBinWangApr2014() {} - Mat* create_using_opencv( std::vector apcMatList ); - Mat* process_using_opencv( std::vector apcMatList ); + Mat* create_using_opencv( const std::vector& apcMatList ) override; + Mat* process_using_opencv( const std::vector& apcMatList ) override; }; #endif // __SALIENCYDETECTION_H__ diff --git a/modules/ThreeSixtyDownsampling.cpp b/modules/ThreeSixtyDownsampling.cpp index 06d052c..a64f67e 100644 --- a/modules/ThreeSixtyDownsampling.cpp +++ b/modules/ThreeSixtyDownsampling.cpp @@ -75,7 +75,7 @@ ThreeSixtyDownsampling::ThreeSixtyDownsampling() m_bForceIntSlope = 0; m_iRearrange = 0; m_iWidth = -1; - m_pcOutputFrame = NULL; + m_pcResultedFrame = NULL; m_pcDownsampled = NULL; m_dPixelRatio = 0; @@ -589,17 +589,17 @@ bool ThreeSixtyDownsampling::createDownsamplingMask( CalypFrame* pcInputFrame ) switch( m_uiDownsampling ) { case 0: - m_pcOutputFrame = new CalypFrame( m_pcDownsampled->getWidth(), m_pcDownsampled->getHeight(), pcInputFrame->getPelFormat(), pcInputFrame->getBitsPel() ); + m_pcResultedFrame = new CalypFrame( m_pcDownsampled->getWidth(), m_pcDownsampled->getHeight(), pcInputFrame->getPelFormat(), pcInputFrame->getBitsPel() ); break; case 1: - m_pcOutputFrame = new CalypFrame( m_cvReshapePoints[0]->cols, m_cvReshapePoints[0]->rows, pcInputFrame->getPelFormat(), pcInputFrame->getBitsPel() ); + m_pcResultedFrame = new CalypFrame( m_cvReshapePoints[0]->cols, m_cvReshapePoints[0]->rows, pcInputFrame->getPelFormat(), pcInputFrame->getBitsPel() ); break; case 2: - m_pcOutputFrame = new CalypFrame{ pcInputFrame->getWidth(), - pcInputFrame->getHeight(), - pcInputFrame->getPelFormat(), - pcInputFrame->getBitsPel(), - pcInputFrame->getHasNegativeValues() }; + m_pcResultedFrame = new CalypFrame{ pcInputFrame->getWidth(), + pcInputFrame->getHeight(), + pcInputFrame->getPelFormat(), + pcInputFrame->getBitsPel(), + pcInputFrame->getHasNegativeValues() }; break; } return true; @@ -609,7 +609,7 @@ void ThreeSixtyDownsampling::downsamplingOperation( CalypFrame* pcInputFrame ) { unsigned numBytes = m_pcDownsampled->getBitsPel() > 8 ? 2 : 1; m_pcDownsampled->reset(); - m_pcOutputFrame->reset(); + m_pcResultedFrame->reset(); for( unsigned ch = 0; ch < m_pcDownsampled->getNumberChannels(); ch++ ) { int imH = int( m_pcDownsampled->getHeight( ch ) ); @@ -640,12 +640,12 @@ void ThreeSixtyDownsampling::downsamplingOperation( CalypFrame* pcInputFrame ) } Mat_ reshapePoints = *( m_cvReshapePoints[ch] ); ClpPel** downSampPelBuff = m_pcDownsampled->getPelBufferYUV()[ch]; - ClpPel* pelOutputPtr = m_pcOutputFrame->getPelBufferYUV()[ch][0]; + ClpPel* pelOutputPtr = m_pcResultedFrame->getPelBufferYUV()[ch][0]; - Mat outputMask( m_pcOutputFrame->getHeight( ch ), m_pcOutputFrame->getWidth( ch ), CV_8UC1, Scalar( 1 ) ); - for( unsigned y = 0; y < m_pcOutputFrame->getHeight( ch ); y++ ) + Mat outputMask( m_pcResultedFrame->getHeight( ch ), m_pcResultedFrame->getWidth( ch ), CV_8UC1, Scalar( 1 ) ); + for( unsigned y = 0; y < m_pcResultedFrame->getHeight( ch ); y++ ) { - for( unsigned x = 0; x < m_pcOutputFrame->getWidth( ch ); x++ ) + for( unsigned x = 0; x < m_pcResultedFrame->getWidth( ch ); x++ ) { Point pt = reshapePoints.at( y, x ); if( pt.x > -1 ) @@ -659,9 +659,9 @@ void ThreeSixtyDownsampling::downsamplingOperation( CalypFrame* pcInputFrame ) if( m_iInpaintMethod ) { Mat outputFrameUnfilled, outputFrame; - m_pcOutputFrame->toMat( outputFrameUnfilled, true, false, ch ); + m_pcResultedFrame->toMat( outputFrameUnfilled, true, false, ch ); cv::inpaint( outputFrameUnfilled, outputMask, outputFrame, 16, m_iInpaintMethod ); - m_pcOutputFrame->fromMat( outputFrame, ch ); + m_pcResultedFrame->fromMat( outputFrame, ch ); } } } @@ -670,7 +670,7 @@ void ThreeSixtyDownsampling::upsamplingOperation( CalypFrame* pcInputFrame ) { unsigned numBytes = m_pcDownsampled->getBitsPel() > 8 ? 2 : 1; m_pcDownsampled->reset(); - m_pcOutputFrame->reset(); + m_pcResultedFrame->reset(); for( unsigned ch = 0; ch < m_pcDownsampled->getNumberChannels(); ch++ ) { Mat_ reshapePoints = *( m_cvReshapePoints[ch] ); @@ -689,7 +689,7 @@ void ThreeSixtyDownsampling::upsamplingOperation( CalypFrame* pcInputFrame ) Mat cvDownsampled; m_pcDownsampled->toMat( cvDownsampled, true, false, ch ); - int imH = m_pcOutputFrame->getHeight( ch ); + int imH = m_pcResultedFrame->getHeight( ch ); Mat cvUpsample( 1, 2 * imH, numBytes > 2 ? CV_16UC1 : CV_8UC1 ); for( int y = 0; y < imH; y++ ) { @@ -700,7 +700,7 @@ void ThreeSixtyDownsampling::upsamplingOperation( CalypFrame* pcInputFrame ) cv::resize( cvDownsampled.row( y ).colRange( xpos, xpos + lineWidth ), cvUpsample, cvUpsample.size(), 0, 0, m_iInterpolation ); // copy to output - ClpPel* outpel = &m_pcOutputFrame->getPelBufferYUV()[ch][y][0]; + ClpPel* outpel = &m_pcResultedFrame->getPelBufferYUV()[ch][y][0]; unsigned char* cv_data = cvUpsample.data; for( int i = 0; i < 2 * imH; i++ ) { @@ -713,7 +713,7 @@ void ThreeSixtyDownsampling::upsamplingOperation( CalypFrame* pcInputFrame ) } } } - //m_pcOutputFrame->copyFrom( m_pcDownsampled ); + //m_pcResultedFrame->copyFrom( m_pcDownsampled ); } CalypFrame* ThreeSixtyDownsampling::process( std::vector apcFrameList ) @@ -725,9 +725,9 @@ CalypFrame* ThreeSixtyDownsampling::process( std::vector apcFrameLi } if( m_uiDownsampling == 0 || m_uiDownsampling == 2 ) { - upsamplingOperation( m_uiDownsampling == 2 ? m_pcOutputFrame : apcFrameList[0] ); + upsamplingOperation( m_uiDownsampling == 2 ? m_pcResultedFrame : apcFrameList[0] ); } - return m_pcOutputFrame; + return m_pcResultedFrame; } bool ThreeSixtyDownsampling::keyPressed( enum Module_Key_Supported value ) @@ -761,7 +761,7 @@ void ThreeSixtyDownsampling::destroy() if( m_pcDownsampled ) delete m_pcDownsampled; m_pcDownsampled = NULL; - if( m_pcOutputFrame ) - delete m_pcOutputFrame; - m_pcOutputFrame = NULL; + if( m_pcResultedFrame ) + delete m_pcResultedFrame; + m_pcResultedFrame = NULL; } diff --git a/modules/ThreeSixtyDownsampling.h b/modules/ThreeSixtyDownsampling.h index fedf882..2948dc3 100644 --- a/modules/ThreeSixtyDownsampling.h +++ b/modules/ThreeSixtyDownsampling.h @@ -52,6 +52,7 @@ private: double m_dPixelRatio; + CalypFrame* m_pcResultedFrame; CalypFrame* m_pcDownsampled; // Values one per channel diff --git a/modules/ThreeSixtyDynamicDownsampling.h b/modules/ThreeSixtyDynamicDownsampling.h index 4a97aa1..a18a30d 100644 --- a/modules/ThreeSixtyDynamicDownsampling.h +++ b/modules/ThreeSixtyDynamicDownsampling.h @@ -55,6 +55,8 @@ private: unsigned m_uiFaceWidth; unsigned m_uiFaceHeight; + CalypFrame* m_pcOutputFrame; + public: ThreeSixtyDynamicDownsampling(); virtual ~ThreeSixtyDynamicDownsampling() {} diff --git a/modules/ThreeSixtyFaceConcatenation.cpp b/modules/ThreeSixtyFaceConcatenation.cpp index 3dd01d2..eabfc48 100644 --- a/modules/ThreeSixtyFaceConcatenation.cpp +++ b/modules/ThreeSixtyFaceConcatenation.cpp @@ -56,8 +56,6 @@ ThreeSixtyFaceConcatenation::ThreeSixtyFaceConcatenation() m_uiNumberOfPartitionsPerFace = 1; m_uiFacesX = 0; m_uiFacesY = 0; - - m_pcTmpFrame = NULL; } bool ThreeSixtyFaceConcatenation::create( std::vector apcFrameList ) @@ -90,14 +88,14 @@ bool ThreeSixtyFaceConcatenation::create( std::vector apcFrameList unsigned int width = apcFrameList[0]->getWidth() * m_uiFacesX; unsigned int height = apcFrameList[0]->getHeight() * m_uiFacesY; - m_pcOutputFrame = new CalypFrame( width, height, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); + m_pcConcatenatedFaces = std::make_unique( width, height, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); return true; } CalypFrame* ThreeSixtyFaceConcatenation::process( std::vector apcFrameList ) { - m_pcOutputFrame->reset(); + m_pcConcatenatedFaces->reset(); switch( m_uiProjectionType ) { @@ -107,19 +105,16 @@ CalypFrame* ThreeSixtyFaceConcatenation::process( std::vector apcFr CalypFrame* pcFrame = apcFrameList[i]; unsigned x = i % m_uiFacesX * pcFrame->getWidth(); unsigned y = i / m_uiFacesX * pcFrame->getHeight(); - m_pcOutputFrame->copyTo( pcFrame, x, y ); + m_pcConcatenatedFaces->copyTo( pcFrame, x, y ); } break; default: assert( 0 ); } - return m_pcOutputFrame; + return m_pcConcatenatedFaces.get(); } void ThreeSixtyFaceConcatenation::destroy() { - if( m_pcOutputFrame ) - delete m_pcOutputFrame; - m_pcOutputFrame = NULL; } diff --git a/modules/ThreeSixtyFaceConcatenation.h b/modules/ThreeSixtyFaceConcatenation.h index ff66c53..480e98f 100644 --- a/modules/ThreeSixtyFaceConcatenation.h +++ b/modules/ThreeSixtyFaceConcatenation.h @@ -32,7 +32,7 @@ class ThreeSixtyFaceConcatenation : public CalypModuleIf REGISTER_CLASS_FACTORY( ThreeSixtyFaceConcatenation ) private: - CalypFrame* m_pcTmpFrame; + std::unique_ptr m_pcConcatenatedFaces; unsigned m_uiProjectionType; unsigned m_uiNumberOfPartitionsPerFace; unsigned m_uiFacesX; diff --git a/modules/ThreeSixtyFaceExtraction.cpp b/modules/ThreeSixtyFaceExtraction.cpp index 163ec67..f84dd72 100644 --- a/modules/ThreeSixtyFaceExtraction.cpp +++ b/modules/ThreeSixtyFaceExtraction.cpp @@ -77,14 +77,14 @@ bool ThreeSixtyFaceExtraction::create( std::vector apcFrameList ) unsigned int width = apcFrameList[0]->getWidth() / m_uiFacesX; unsigned int height = apcFrameList[0]->getHeight() / m_uiFacesY; - m_pcOutputFrame = new CalypFrame( width, height, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); + m_pcFrameExtractionFrame = std::make_unique( width, height, apcFrameList[0]->getPelFormat(), apcFrameList[0]->getBitsPel() ); return true; } CalypFrame* ThreeSixtyFaceExtraction::process( std::vector apcFrameList ) { - m_pcOutputFrame->reset(); + m_pcFrameExtractionFrame->reset(); unsigned x = -1; unsigned y = -1; @@ -92,20 +92,17 @@ CalypFrame* ThreeSixtyFaceExtraction::process( std::vector apcFrame switch( m_uiProjectionType ) { case 1: // Cube-map - x = m_uiFaceNum % m_uiFacesX * m_pcOutputFrame->getWidth(); - y = ( m_uiFaceNum / m_uiFacesX ) * m_pcOutputFrame->getHeight(); + x = m_uiFaceNum % m_uiFacesX * m_pcFrameExtractionFrame->getWidth(); + y = ( m_uiFaceNum / m_uiFacesX ) * m_pcFrameExtractionFrame->getHeight(); break; default: assert( 0 ); } - m_pcOutputFrame->copyFrom( apcFrameList[0], x, y ); - return m_pcOutputFrame; + m_pcFrameExtractionFrame->copyFrom( apcFrameList[0], x, y ); + return m_pcFrameExtractionFrame.get(); } void ThreeSixtyFaceExtraction::destroy() { - if( m_pcOutputFrame ) - delete m_pcOutputFrame; - m_pcOutputFrame = NULL; } diff --git a/modules/ThreeSixtyFaceExtraction.h b/modules/ThreeSixtyFaceExtraction.h index fd4577b..9a40d44 100644 --- a/modules/ThreeSixtyFaceExtraction.h +++ b/modules/ThreeSixtyFaceExtraction.h @@ -32,7 +32,8 @@ class ThreeSixtyFaceExtraction : public CalypModuleIf REGISTER_CLASS_FACTORY( ThreeSixtyFaceExtraction ) private: - CalypFrame* m_pcTmpFrame; + std::unique_ptr m_pcFrameExtractionFrame; + std::unique_ptr m_pcTmpFrame; unsigned m_uiFaceNum; unsigned m_uiProjectionType; unsigned m_uiNumberOfPartitionsPerFace; diff --git a/modules/ThreeSixtyNxN.cpp b/modules/ThreeSixtyNxN.cpp index 66a1aca..5f72689 100644 --- a/modules/ThreeSixtyNxN.cpp +++ b/modules/ThreeSixtyNxN.cpp @@ -25,14 +25,10 @@ #include "ThreeSixtyNxN.h" #include - -#include "lib/LibMemory.h" -//#include #include #include +#include -//using cv::InputArray; -//using cv::OutputArray; using cv::Rect; using cv::Scalar; using cv::Size; @@ -147,7 +143,6 @@ void ThreeSixtyNxN::downsamplingOperation( const CalypFrame* pcInputFrame ) ClpPel* in = &pcInputFrame->getPelBufferYUV()[ch][0][0]; ClpPel* out = &m_pcOutputFrame->getPelBufferYUV()[ch][0][0]; - unsigned long nn = N * N; int n_2 = N / 2; int n1 = N - 1; double dist_y; @@ -175,7 +170,6 @@ void ThreeSixtyNxN::downsamplingOperation( const CalypFrame* pcInputFrame ) rx = x + y * N + out; *( rx ) = interpol_lanczos3( tx_y, tx_x, N * 2, max_value ); - //*( rx ) = interpol_cub( tx_y, tx_x, N * 2, max_value ); } } } @@ -202,9 +196,7 @@ void ThreeSixtyNxN::upsamplingOperation( const CalypFrame* pcInputFrame ) double Dj; double tx; ClpPel* rx; - ClpPel* linhaY; - - getMem1D( &linhaY, n2 ); + std::vector linhaY( n2, 0 ); for( y = 0; y < N; y++ ) { @@ -220,7 +212,7 @@ void ThreeSixtyNxN::upsamplingOperation( const CalypFrame* pcInputFrame ) novo_x = ( dist_x > dist_y ? dist_y : ( dist_x + 1 < -dist_y ? -dist_y - 1 : dist_x ) ) + N / 2; novo_y = abs( dist_x ) > dist_y ? ( y < N / 2 ? dist_Lj : N - dist_Lj - 1 ) : y; - *( linhaY + x ) = *( in + (int)novo_x + (int)novo_y * N ); + linhaY[x] = *( in + (int)novo_x + (int)novo_y * N ); } for( x = 0; x < n2; x++ ) @@ -228,10 +220,9 @@ void ThreeSixtyNxN::upsamplingOperation( const CalypFrame* pcInputFrame ) tx = ( x + 1 ) / Dj - 1; rx = x + y * n2 + out; - *( rx ) = interpol_lanczos3( linhaY, tx, Lj, max_value ); + *( rx ) = interpol_lanczos3( linhaY.data(), tx, Lj, max_value ); } } - freeMem1D( linhaY ); } } diff --git a/modules/ThreeSixtyNxN.h b/modules/ThreeSixtyNxN.h index e9a563c..204b369 100644 --- a/modules/ThreeSixtyNxN.h +++ b/modules/ThreeSixtyNxN.h @@ -39,6 +39,7 @@ class ThreeSixtyNxN : public CalypModuleIf REGISTER_CLASS_FACTORY( ThreeSixtyNxN ) private: unsigned m_uiDownsampling; + CalypFrame* m_pcOutputFrame; void downsamplingOperation( const CalypFrame* pcInputFrame ); void upsamplingOperation( const CalypFrame* pcInputFrame ); diff --git a/modules/ThreeSixtySpatialtoTemporal.cpp b/modules/ThreeSixtySpatialtoTemporal.cpp index bb624f1..fa00654 100644 --- a/modules/ThreeSixtySpatialtoTemporal.cpp +++ b/modules/ThreeSixtySpatialtoTemporal.cpp @@ -75,12 +75,17 @@ bool ThreeSixtySpatialtoTemporal::needFrame() return false; } +CalypFrame* ThreeSixtySpatialtoTemporal::getProcessedFrame() +{ + return m_pcTempSpatialFrame != nullptr ? m_pcTempSpatialFrame.get() : nullptr; +} + bool ThreeSixtySpatialtoTemporal::create( std::vector apcFrameList ) { _BASIC_MODULE_API_2_CHECK_ - unsigned int iWidth; - unsigned int iHeight; + unsigned int iWidth{ 0 }; + unsigned int iHeight{ 0 }; if( m_uiSpatial2Temporal ) { @@ -93,10 +98,10 @@ bool ThreeSixtySpatialtoTemporal::create( std::vector apcFrameList iWidth = apcFrameList[0]->getWidth() / m_uiFacesX; iHeight = apcFrameList[0]->getHeight() / m_uiFacesY; - m_pcTmpInputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(), - apcFrameList[0]->getBitsPel() ); - m_pcTmpFace = new CalypFrame( iWidth, iHeight, apcFrameList[0]->getPelFormat(), - apcFrameList[0]->getBitsPel() ); + m_pcTmpInputFrame = std::make_unique( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(), + apcFrameList[0]->getBitsPel() ); + m_pcTmpFace = std::make_unique( iWidth, iHeight, apcFrameList[0]->getPelFormat(), + apcFrameList[0]->getBitsPel() ); iWidth *= m_uiFacesPerFrame; } else @@ -104,8 +109,8 @@ bool ThreeSixtySpatialtoTemporal::create( std::vector apcFrameList iWidth = apcFrameList[0]->getWidth() * m_uiFacesX / m_uiFacesPerFrame; iHeight = apcFrameList[0]->getHeight() * m_uiFacesY; } - m_pcOutputFrame = new CalypFrame( iWidth, iHeight, apcFrameList[0]->getPelFormat(), - apcFrameList[0]->getBitsPel() ); + m_pcTempSpatialFrame = std::make_unique( iWidth, iHeight, apcFrameList[0]->getPelFormat(), + apcFrameList[0]->getBitsPel() ); return true; } @@ -125,8 +130,8 @@ CalypFrame* ThreeSixtySpatialtoTemporal::process( std::vector apcFr for( unsigned i = 0; i < m_uiFacesPerFrame; i++ ) { - m_pcTmpFace->copyFrom( m_pcTmpInputFrame, m_uiCopyX, m_uiCopyY ); - m_pcOutputFrame->copyTo( m_pcTmpFace, m_pcTmpFace->getWidth() * i, 0 ); + m_pcTmpFace->copyFrom( *m_pcTmpInputFrame, m_uiCopyX, m_uiCopyY ); + m_pcTempSpatialFrame->copyTo( *m_pcTmpFace, m_pcTmpFace->getWidth() * i, 0 ); m_iFrameBufferCount--; m_uiCopyX += m_pcTmpFace->getWidth(); if( m_uiCopyX >= m_pcTmpInputFrame->getWidth() ) @@ -138,40 +143,28 @@ CalypFrame* ThreeSixtySpatialtoTemporal::process( std::vector apcFr } else { - m_pcOutputFrame->copyTo( apcFrameList[0], m_uiCopyX, m_uiCopyY ); + m_pcTempSpatialFrame->copyTo( apcFrameList[0], m_uiCopyX, m_uiCopyY ); m_uiFacesCount += m_uiFacesPerFrame; m_uiCopyX += apcFrameList[0]->getWidth(); - if( m_uiCopyX >= m_pcOutputFrame->getWidth() ) + if( m_uiCopyX >= m_pcTempSpatialFrame->getWidth() ) { m_uiCopyX = 0; m_uiCopyY += apcFrameList[0]->getHeight(); } if( m_uiFacesCount < ( m_uiFacesX * m_uiFacesY ) ) { - return NULL; + return nullptr; } m_iFrameBufferCount = 0; m_uiCopyX = 0; m_uiCopyY = 0; m_uiFacesCount = 0; - return m_pcOutputFrame; } - return m_pcOutputFrame; + return m_pcTempSpatialFrame.get(); } void ThreeSixtySpatialtoTemporal::destroy() { - if( m_pcOutputFrame ) - delete m_pcOutputFrame; - m_pcOutputFrame = NULL; - - if( m_pcTmpInputFrame ) - delete m_pcTmpInputFrame; - m_pcTmpInputFrame = NULL; - - if( m_pcTmpFace ) - delete m_pcTmpFace; - m_pcTmpFace = NULL; } diff --git a/modules/ThreeSixtySpatialtoTemporal.h b/modules/ThreeSixtySpatialtoTemporal.h index 878713a..c83d455 100644 --- a/modules/ThreeSixtySpatialtoTemporal.h +++ b/modules/ThreeSixtySpatialtoTemporal.h @@ -33,8 +33,9 @@ class ThreeSixtySpatialtoTemporal : public CalypModuleIf REGISTER_CLASS_FACTORY( ThreeSixtySpatialtoTemporal ) private: - CalypFrame* m_pcTmpInputFrame; - CalypFrame* m_pcTmpFace; + std::unique_ptr m_pcTempSpatialFrame; + std::unique_ptr m_pcTmpInputFrame; + std::unique_ptr m_pcTmpFace; bool m_uiSpatial2Temporal; unsigned int m_uiFacesX; unsigned int m_uiFacesY; @@ -46,11 +47,12 @@ private: public: ThreeSixtySpatialtoTemporal(); virtual ~ThreeSixtySpatialtoTemporal() {} - bool create( std::vector apcFrameList ); - bool needFrame(); - CalypFrame* process( std::vector apcFrameList ); - bool flush(); - void destroy(); + bool create( std::vector apcFrameList ) override; + CalypFrame* getProcessedFrame() override; + bool needFrame() override; + CalypFrame* process( std::vector apcFrameList ) override; + bool flush() override; + void destroy() override; }; #endif // __THREESIXTYSPATIALTOTEMPORAL_H__