From e42f0d02bb116f985f3d38fcd70a8163d40ea056 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Wed, 3 Apr 2019 16:37:32 +0100 Subject: [PATCH] Major changes in OpenCV handling CalypFrame to Mat conversion Remove custom modules --- lib/CalypFrame.cpp | 178 +++++++++++++++--------- lib/CalypFrame.h | 4 +- modules/CMakeLists.txt | 7 +- modules/DisparityStereoBM.cpp | 2 +- modules/ThreeSixtyDownsampling.cpp | 149 -------------------- modules/ThreeSixtyDownsampling.h | 47 ------- modules/ThreeSixtySpatialtoTemporal.cpp | 114 --------------- modules/ThreeSixtySpatialtoTemporal.h | 52 ------- modules/ThreeSixtyTemporaltoSpatial.cpp | 101 -------------- modules/ThreeSixtyTemporaltoSpatial.h | 52 ------- 10 files changed, 121 insertions(+), 585 deletions(-) delete mode 100644 modules/ThreeSixtyDownsampling.cpp delete mode 100644 modules/ThreeSixtyDownsampling.h delete mode 100644 modules/ThreeSixtySpatialtoTemporal.cpp delete mode 100644 modules/ThreeSixtySpatialtoTemporal.h delete mode 100644 modules/ThreeSixtyTemporaltoSpatial.cpp delete mode 100644 modules/ThreeSixtyTemporaltoSpatial.h diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index f7008d7..287fc73 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -33,6 +33,7 @@ #ifdef USE_OPENCV #include +#include #endif std::vector CalypFrame::supportedColorSpacesListNames() @@ -117,13 +118,13 @@ public: unsigned int m_uiHistoSegments; /** - * Common constructor function of a frame - * - * @param width width of the frame - * @param height height of the frame - * @param pel_format pixel format index (always use PixelFormats enum) - * - */ + * Common constructor function of a frame + * + * @param width width of the frame + * @param height height of the frame + * @param pel_format pixel format index (always use PixelFormats enum) + * + */ void init( unsigned int width, unsigned int height, int pel_format, unsigned bitsPixel ) { m_bInit = false; @@ -535,7 +536,7 @@ void CalypFrame::copyFrom( const CalypFrame& other ) return; d->m_bHasRGBPel = false; d->m_bHasHistogram = false; - memcpy( &( d->m_pppcInputPel[0][0][0]), &(other.getPelBufferYUV()[0][0][0]), getTotalNumberOfPixels() * sizeof( ClpPel ) ); + memcpy( &( d->m_pppcInputPel[0][0][0] ), &( other.getPelBufferYUV()[0][0][0] ), getTotalNumberOfPixels() * sizeof( ClpPel ) ); } void CalypFrame::copyFrom( const CalypFrame* other ) @@ -549,23 +550,23 @@ void CalypFrame::copyFrom( const CalypFrame& other, unsigned int xPos, unsigned if( !haveSameFmt( other, MATCH_COLOR_SPACE | MATCH_BYTES_PER_FRAME | MATCH_BITS ) ) return; // TODO: Protect width and height - ClpPel*** pInput = other.getPelBufferYUV(); -// ClpPel* pInput; -// ClpPel* pOutput; + ClpPel*** pInput = other.getPelBufferYUV(); + // ClpPel* pInput; + // ClpPel* pOutput; for( unsigned int ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ ) { int ratioH = ch > 0 ? d->m_pcPelFormat->log2ChromaWidth : 0; int ratioW = ch > 0 ? d->m_pcPelFormat->log2ChromaHeight : 0; for( unsigned int i = 0; i < CHROMASHIFT( d->m_uiHeight, ratioH ); i++ ) { - memcpy( &(d->m_pppcInputPel[ch][i][0]), &( pInput[ch][( yPos >> ratioH ) + i][( xPos >> ratioW )] ), + memcpy( &( d->m_pppcInputPel[ch][i][0] ), &( pInput[ch][( yPos >> ratioH ) + i][( xPos >> ratioW )] ), ( d->m_uiWidth >> ratioW ) * sizeof( ClpPel ) ); -// pOutput = d->m_pppcInputPel[ch][i]; -// pInput = other.getPelBufferYUV()[ch][( yPos >> ratioH ) + i] + ( xPos >> ratioW ); -// for( unsigned int j = 0; j < CHROMASHIFT( d->m_uiWidth, ratioW ); j++ ) -// { -// *pOutput++ = *pInput++; -// } + // pOutput = d->m_pppcInputPel[ch][i]; + // pInput = other.getPelBufferYUV()[ch][( yPos >> ratioH ) + i] + ( xPos >> ratioW ); + // for( unsigned int j = 0; j < CHROMASHIFT( d->m_uiWidth, ratioW ); j++ ) + // { + // *pOutput++ = *pInput++; + // } } } d->m_bHasRGBPel = false; @@ -1057,14 +1058,14 @@ double CalypFrame::getStdDev( int channel, unsigned int start, unsigned int end /*------------ original - for ( i = start ; i <= end ; i++ ) - { - dev += ( i - mean ) * ( i - mean ) * d->m_puiHistogram[indexStart +i]; - } + for ( i = start ; i <= end ; i++ ) + { + dev += ( i - mean ) * ( i - mean ) * d->m_puiHistogram[indexStart +i]; + } - return sqrt( dev / count ); + return sqrt( dev / count ); - -----------------------*/ + -----------------------*/ for( unsigned int i = start; i <= end; i++ ) { @@ -1095,7 +1096,7 @@ double CalypFrame::getHistogramValue( int channel, unsigned int bin ) ************************************************************** */ -bool CalypFrame::toMat( cv::Mat& cvMat, bool convertToGray ) +bool CalypFrame::toMat( cv::Mat& cvMat, bool convertToGray, unsigned channel ) { bool bRet = false; #ifdef USE_OPENCV @@ -1104,46 +1105,69 @@ bool CalypFrame::toMat( cv::Mat& cvMat, bool convertToGray ) { return bRet; } - int cvType = CV_MAKETYPE( CV_8U, convertToGray ? 1 : d->m_pcPelFormat->numberChannels ); - cvMat.create( d->m_uiHeight, d->m_uiWidth, cvType ); - unsigned char* pCvPel = cvMat.data; - if( !convertToGray && ( d->m_pcPelFormat->colorSpace == CLP_COLOR_YUV || - d->m_pcPelFormat->colorSpace == CLP_COLOR_RGB ) ) + unsigned int cvPrecision = getBitsPel() > 8 ? CV_16U : CV_8U; + unsigned numBytes = getBitsPel() > 8 ? 2 : 1; + unsigned numChannels = getNumberChannels(); + if( convertToGray ) { - fillRGBBuffer(); - unsigned char* pARGB = d->m_pcARGB32; - for( unsigned int i = 0; i < d->m_uiWidth * d->m_uiHeight; i++ ) - { - *pCvPel++ = *pARGB++; - *pCvPel++ = *pARGB++; - *pCvPel++ = *pARGB++; - pARGB++; - } - bRet = true; + channel = channel >= numChannels ? 0 : channel; + numChannels = 1; } - else if( convertToGray || d->m_pcPelFormat->colorSpace == CLP_COLOR_GRAY ) + + unsigned imgWidth = getWidth( channel ); + unsigned imgHeight = getHeight( channel ); + + cvMat.create( imgHeight, imgWidth, CV_MAKETYPE( cvPrecision, numChannels ) ); + cv::Mat tmpMat( imgHeight, imgWidth, CV_MAKETYPE( cvPrecision, numChannels ) ); + + unsigned char* cv_data = tmpMat.data; + unsigned int cv_step = tmpMat.step; + CalypPixel currPel; + for( unsigned int y = 0; y < imgHeight; y++ ) { - ClpPel* pPel = d->m_pppcInputPel[CLP_LUMA][0]; - for( unsigned int i = 0; i < d->m_uiWidth * d->m_uiHeight; i++ ) + for( unsigned int x = 0; x < imgWidth; x++ ) { - *pCvPel++ = *pPel++; + currPel = getPixel( x, y ); + for( unsigned int ch = 0; ch < numChannels; ch++ ) + { + for( unsigned b = 0; b < numBytes; b++ ) + { + *( cv_data + y * cv_step + x * numChannels * numBytes + ch + b ) = currPel[ch] >> ( 8 * b ); + } + } + } + } + + if( !convertToGray && getNumberChannels() >= 1 ) + { + // TODO: check for other formats + switch( getColorSpace() ) + { + case CLP_COLOR_YUV: + cv::cvtColor( tmpMat, cvMat, cv::COLOR_YCrCb2RGB ); + break; } - bRet = true; } else { - return false; + tmpMat.copyTo( cvMat ); } + bRet = true; + #endif return bRet; } -bool CalypFrame::fromMat( cv::Mat& cvMat ) +bool CalypFrame::fromMat( cv::Mat& cvMat, int channel ) { bool bRet = false; #ifdef USE_OPENCV + unsigned numBytes = getBitsPel() > 8 ? 2 : 1; + unsigned numChannels = getNumberChannels(); + unsigned int cvPrecision = getBitsPel() > 8 ? CV_16U : CV_8U; if( !d->m_bInit ) { + uchar depth = cvMat.type() & CV_MAT_DEPTH_MASK; if( d->m_iPixelFormat == CLP_INVALID_FMT ) { switch( cvMat.channels() ) @@ -1158,35 +1182,61 @@ bool CalypFrame::fromMat( cv::Mat& cvMat ) return false; } } - d->init( cvMat.cols, cvMat.rows, d->m_iPixelFormat, 8 ); + d->m_uiBitsPel = depth == CV_8U ? 8 : 16; + d->init( cvMat.cols, cvMat.rows, d->m_iPixelFormat, d->m_uiBitsPel ); } d->m_bHasRGBPel = false; d->m_bHasHistogram = false; - unsigned char* pCvPel = cvMat.data; - if( d->m_iPixelFormat != CLP_GRAY ) + if( channel >= 0 ) + numChannels = 1; + else + channel = 0; + + if( cvMat.channels() != numChannels ) { - ClpPel* pInputPelR = d->m_pppcInputPel[CLP_COLOR_R][0]; - ClpPel* pInputPelG = d->m_pppcInputPel[CLP_COLOR_G][0]; - ClpPel* pInputPelB = d->m_pppcInputPel[CLP_COLOR_B][0]; - for( unsigned int i = 0; i < d->m_uiHeight * d->m_uiWidth; i++ ) + return false; + } + + unsigned imgWidth = getWidth( channel ); + unsigned imgHeight = getHeight( channel ); + + cv::Mat tmpMat( imgHeight, imgWidth, CV_MAKETYPE( cvPrecision, numChannels ) ); + if( numChannels > 0 ) + { + unsigned color_space = getColorSpace(); + switch( getColorSpace() ) { - *pInputPelB++ = *pCvPel++; - *pInputPelG++ = *pCvPel++; - *pInputPelR++ = *pCvPel++; + case CLP_COLOR_YUV: + cv::cvtColor( tmpMat, cvMat, cv::COLOR_RGB2YCrCb ); + break; } - bRet = true; } else { - ClpPel* pPel = d->m_pppcInputPel[CLP_LUMA][0]; - for( unsigned int i = 0; i < d->m_uiWidth * d->m_uiHeight; i++ ) - { - *pPel++ = *pCvPel++; - } - bRet = true; + cvMat.copyTo( tmpMat ); } + + unsigned char* cv_data = tmpMat.data; + unsigned int cv_step = tmpMat.step; + CalypPixel currPel; + for( unsigned int y = 0; y < imgHeight; y++ ) + { + for( unsigned int x = 0; x < imgWidth; x++ ) + { + for( unsigned int ch = 0; ch < numChannels; ch++ ) + { + currPel[ch] = 0; + for( unsigned b = 0; b < numBytes; b++ ) + { + currPel[ch] = currPel[ch] + ( *( cv_data + y * cv_step + x * numChannels * numBytes + ch + b ) << ( 8 * b ) ); + } + } + setPixel( x, y, currPel ); + } + } + bRet = true; #endif return bRet; } diff --git a/lib/CalypFrame.h b/lib/CalypFrame.h index 7036f19..d8f1327 100644 --- a/lib/CalypFrame.h +++ b/lib/CalypFrame.h @@ -347,8 +347,8 @@ public: /** * interface with OpenCV lib */ - bool toMat( cv::Mat& cvMat, bool convertToGray = false ); - bool fromMat( cv::Mat& cvMat ); + bool toMat( cv::Mat& cvMat, bool convertToGray = false, unsigned channel = 0 ); + bool fromMat( cv::Mat& cvMat, int iChannel = -1 ); /** * \ingroup CalypFrameGrp diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index bd6a46f..07ae411 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -3,6 +3,7 @@ ### OPTION( CALYP_THREADED_MODULES "Use threads for modules" OFF ) +SET( CALYP_EXTRA_MODULES "CALYP_EXTRA_MODULES" CACHE PATH "Location of extra Calyp modules") INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) @@ -42,9 +43,9 @@ ADD_MODULE_USE_OPENCV( SaliencyDetectionSpectral "SaliencyDetection" VERSION 3.3 ADD_MODULE_USE_OPENCV( SaliencyDetectionFineGrained "SaliencyDetection" VERSION 3.3.0 MODULES saliency ) ADD_MODULE_USE_OPENCV( SaliencyDetectionBinWangApr2014 "SaliencyDetection" VERSION 3.3.0 MODULES saliency ) -ADD_MODULE_USE_OPENCV( ThreeSixtyDownsampling "ThreeSixtyDownsampling" VERSION 3.1.0 MODULES core ) -ADD_MODULE_USE_OPENCV( ThreeSixtySpatialtoTemporal "ThreeSixtySpatialtoTemporal" VERSION 3.1.0 MODULES core ) -ADD_MODULE_USE_OPENCV( ThreeSixtyTemporaltoSpatial "ThreeSixtyTemporaltoSpatial" VERSION 3.1.0 MODULES core ) +IF(EXISTS ${CALYP_EXTRA_MODULES}) + ADD_SUBDIRECTORY( ${CALYP_EXTRA_MODULES} ) +ENDIF() # # Create header and auxiliar files diff --git a/modules/DisparityStereoBM.cpp b/modules/DisparityStereoBM.cpp index 064deb1..83c0785 100644 --- a/modules/DisparityStereoBM.cpp +++ b/modules/DisparityStereoBM.cpp @@ -90,6 +90,7 @@ CalypFrame* DisparityStereoBM::process( std::vector apcFrameList ) { return m_pcDisparityFrame; } + cv::Mat disparityImage, disparityImage8; #if( CV_MAJOR_VERSION == 2 ) @@ -99,7 +100,6 @@ CalypFrame* DisparityStereoBM::process( std::vector apcFrameList ) #endif disparityImage.convertTo( disparityImage8, CV_8U ); - m_pcDisparityFrame->fromMat( disparityImage8 ); return m_pcDisparityFrame; } diff --git a/modules/ThreeSixtyDownsampling.cpp b/modules/ThreeSixtyDownsampling.cpp deleted file mode 100644 index a79a207..0000000 --- a/modules/ThreeSixtyDownsampling.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* This file is a part of Calyp project - * Copyright (C) 2014-2019 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 ThreeSixtyDownsampling.cpp - * \brief Downsampling ERP to NxN - */ - -#include "ThreeSixtyDownsampling.h" - -#include -#include - -using cv::InputArray; -using cv::Mat; -using cv::OutputArray; -using cv::Size; - -ThreeSixtyDownsampling::ThreeSixtyDownsampling() -{ - /* Module Definition */ - m_iModuleAPI = CLP_MODULE_API_2; - m_iModuleType = CLP_FRAME_PROCESSING_MODULE; - m_pchModuleCategory = "360Video"; - m_pchModuleName = "ThreeSixtyDownsampling"; - m_pchModuleLongName = "ERP to NxN"; - m_pchModuleTooltip = "Downsampling ERP to NxN"; - m_uiNumberOfFrames = 1; - m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY | CLP_MODULE_REQUIRES_OPTIONS; - - m_cModuleOptions.addOptions() /**/ - ( "Downsampling", m_bDownsampling, "ERP to NxN [true]" ) /**/ - ( "Interpolation", m_iInterpolation, "Interpolation method (1-5) [1]" ); - - // INTER_NEAREST - a nearest-neighbor interpolation - // INTER_LINEAR - a bilinear interpolation (used by default) - // INTER_AREA - resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire’-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method. - // INTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhood - // INTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhood - m_bDownsampling = true; - m_iInterpolation = 1; - - m_pcOutputFrame = NULL; -} - -bool ThreeSixtyDownsampling::create( std::vector apcFrameList ) -{ - _BASIC_MODULE_API_2_CHECK_ - m_pcOutputFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY ); - m_isOdd = !( m_pcOutputFrame->getHeight() % 2 ); - - switch( m_iInterpolation ) - { - case 2: - m_iInterpolation = cv::INTER_LINEAR; - break; - case 3: - m_iInterpolation = cv::INTER_AREA; - break; - case 4: - m_iInterpolation = cv::INTER_CUBIC; - break; - case 5: - m_iInterpolation = cv::INTER_LANCZOS4; - break; - default: - m_iInterpolation = cv::INTER_NEAREST; - } - return true; -} - -CalypFrame* ThreeSixtyDownsampling::process( std::vector apcFrameList ) -{ - Mat cvIn; - apcFrameList[0]->toMat( cvIn, true ); - m_pcOutputFrame->reset(); - - memcpy( &m_pcOutputFrame->getPelBufferYUV()[0][m_pcOutputFrame->getHeight() / 2][0], - &apcFrameList[0]->getPelBufferYUV()[0][m_pcOutputFrame->getHeight() / 2][0], - m_pcOutputFrame->getWidth() * sizeof( ClpPel ) ); - if( m_isOdd ) - { - memcpy( &m_pcOutputFrame->getPelBufferYUV()[0][m_pcOutputFrame->getHeight() / 2 - 1][0], - &apcFrameList[0]->getPelBufferYUV()[0][m_pcOutputFrame->getHeight() / 2 - 1][0], - m_pcOutputFrame->getWidth() * sizeof( ClpPel ) ); - } - - for( int line = 1; line < m_pcOutputFrame->getHeight() / 2; line++ ) - { - for( int hemisfer = -1; hemisfer < 2; hemisfer += 2 ) - { - Mat cvOutput; - - // calculate destination sizes - unsigned int ypos = m_pcOutputFrame->getHeight() / 2 + line * hemisfer + ( hemisfer == -1 ? ( m_isOdd ? -1 : 0 ) : 0 ); - unsigned int lineWidth = ( m_pcOutputFrame->getHeight() / 2 - line ) * 4 + 2; - unsigned int xpos = ( m_pcOutputFrame->getWidth() - lineWidth ) / 2; - - Mat cvDownsample( 1, lineWidth, CV_8UC1 ); - Mat cvUpsample( 1, m_pcOutputFrame->getWidth(), CV_8UC1 ); - - // resize - if( m_bDownsampling ) - { - cv::resize( cvIn.row( ypos ), cvDownsample, cvDownsample.size(), 0, 0, m_iInterpolation ); - cvOutput = cvDownsample; - } - else - { - Mat cvauxin = cvIn.row( ypos ).colRange( xpos, xpos + lineWidth ); - cvauxin.copyTo( cvDownsample ); - cv::resize( cvDownsample, cvUpsample, cvUpsample.size(), 0, 0, m_iInterpolation ); - cvOutput = cvUpsample; - } - - // copy to output - ClpPel* outpel = &m_pcOutputFrame->getPelBufferYUV()[0][ypos][xpos * m_bDownsampling]; - unsigned char* pchar = cvOutput.data; - for( unsigned int i = 0; i < cvOutput.cols; i++ ) - { - *outpel++ = *pchar++; - } - } - } - return m_pcOutputFrame; -} - -void ThreeSixtyDownsampling::destroy() -{ - if( m_pcOutputFrame ) - delete m_pcOutputFrame; - m_pcOutputFrame = NULL; -} diff --git a/modules/ThreeSixtyDownsampling.h b/modules/ThreeSixtyDownsampling.h deleted file mode 100644 index c7d838e..0000000 --- a/modules/ThreeSixtyDownsampling.h +++ /dev/null @@ -1,47 +0,0 @@ -/* This file is a part of Calyp project - * Copyright (C) 2014-2019 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 ThreeSixtyDownsampling.h - * \brief Downsampling ERP to NxN - */ - -#ifndef __THREESIXTYDOWNSAMPLING_H__ -#define __THREESIXTYDOWNSAMPLING_H__ - -// CalypLib -#include "lib/CalypModuleIf.h" - -class ThreeSixtyDownsampling : public CalypModuleIf -{ - REGISTER_CLASS_FACTORY( ThreeSixtyDownsampling ) -private: - bool m_isOdd; - bool m_bDownsampling; - int m_iInterpolation; - -public: - ThreeSixtyDownsampling(); - virtual ~ThreeSixtyDownsampling() {} - bool create( std::vector apcFrameList ); - CalypFrame* process( std::vector apcFrameList ); - void destroy(); -}; - -#endif // __THREESIXTYDOWNSAMPLING_H__ diff --git a/modules/ThreeSixtySpatialtoTemporal.cpp b/modules/ThreeSixtySpatialtoTemporal.cpp deleted file mode 100644 index 76b9d76..0000000 --- a/modules/ThreeSixtySpatialtoTemporal.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* This file is a part of Calyp project - * Copyright (C) 2014-2019 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 ThreeSixtySpatialtoTemporal.cpp - * \brief Convert 360 videos from spatial to temporal - */ - -#include "ThreeSixtySpatialtoTemporal.h" - -ThreeSixtySpatialtoTemporal::ThreeSixtySpatialtoTemporal() -{ - /* Module Definition */ - m_iModuleAPI = CLP_MODULE_API_3; - m_iModuleType = CLP_FRAME_PROCESSING_MODULE; - m_pchModuleCategory = "360Video"; - m_pchModuleLongName = "Spatial to Temporal"; - m_pchModuleName = "SpatialtoTemporal"; - m_pchModuleTooltip = "Convert 360 video from Cube Map Projection to temporal frames"; - m_uiNumberOfFrames = 1; - m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY; - - m_uiFacesX = 3; - m_uiFacesY = 2; - - flush(); -} - -bool ThreeSixtySpatialtoTemporal::flush() -{ - CalypModuleIf::flush(); - m_uiCopyX = 0; - m_uiCopyY = 0; - return true; -}; - -bool ThreeSixtySpatialtoTemporal::needFrame() -{ - if( m_iFrameBufferCount <= 0 ) - { - return true; - } - return false; -}; - -bool ThreeSixtySpatialtoTemporal::create( std::vector apcFrameList ) -{ - _BASIC_MODULE_API_2_CHECK_ - - unsigned int iWidth; - unsigned int iHeight; - - iWidth = apcFrameList[0]->getWidth() / m_uiFacesX; - iHeight = apcFrameList[0]->getHeight() / m_uiFacesY; - - m_pcOutputFrame = new CalypFrame( iWidth, iHeight, apcFrameList[0]->getPelFormat(), - apcFrameList[0]->getBitsPel() ); - - m_pcTmpFrame = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(), - apcFrameList[0]->getBitsPel() ); - return true; -} - -CalypFrame* ThreeSixtySpatialtoTemporal::process( std::vector apcFrameList ) -{ - _BASIC_MODULE_API_3_BREAK_CONDITION_ - - if( m_iFrameBufferCount == 0 ) - { - m_pcTmpFrame->copyFrom( apcFrameList[0], 0, 0 ); - m_uiCopyX = 0; - m_uiCopyY = 0; - - m_iFrameBufferCount = m_uiFacesX * m_uiFacesY; - } - - m_pcOutputFrame->copyFrom( m_pcTmpFrame, m_uiCopyX, m_uiCopyY ); - m_iFrameBufferCount--; - - m_uiCopyX += m_pcOutputFrame->getWidth(); - if( m_uiCopyX >= m_pcTmpFrame->getWidth() ) - { - m_uiCopyX = 0; - m_uiCopyY += m_pcOutputFrame->getHeight(); - } - - return m_pcOutputFrame; -} - -void ThreeSixtySpatialtoTemporal::destroy() -{ - if( m_pcOutputFrame ) - delete m_pcOutputFrame; - m_pcOutputFrame = NULL; - if( m_pcTmpFrame ) - delete m_pcTmpFrame; - m_pcTmpFrame = NULL; -} diff --git a/modules/ThreeSixtySpatialtoTemporal.h b/modules/ThreeSixtySpatialtoTemporal.h deleted file mode 100644 index c38fdee..0000000 --- a/modules/ThreeSixtySpatialtoTemporal.h +++ /dev/null @@ -1,52 +0,0 @@ -/* This file is a part of Calyp project - * Copyright (C) 2014-2019 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 ThreeSixtySpatialtoTemporal.h - * \brief Convert 360 videos from spatial to temporal - */ - -#ifndef __THREESIXTYSPATIALTOTEMPORAL_H__ -#define __THREESIXTYSPATIALTOTEMPORAL_H__ - -// CalypLib -#include "lib/CalypModuleIf.h" - -class ThreeSixtySpatialtoTemporal : public CalypModuleIf -{ - REGISTER_CLASS_FACTORY( ThreeSixtySpatialtoTemporal ) - -private: - CalypFrame* m_pcTmpFrame; - unsigned int m_uiFacesX; - unsigned int m_uiFacesY; - unsigned int m_uiCopyX; - unsigned int m_uiCopyY; - -public: - ThreeSixtySpatialtoTemporal(); - virtual ~ThreeSixtySpatialtoTemporal() {} - bool create( std::vector apcFrameList ); - bool needFrame(); - CalypFrame* process( std::vector apcFrameList ); - bool flush(); - void destroy(); -}; - -#endif // __THREESIXTYSPATIALTOTEMPORAL_H__ diff --git a/modules/ThreeSixtyTemporaltoSpatial.cpp b/modules/ThreeSixtyTemporaltoSpatial.cpp deleted file mode 100644 index e192701..0000000 --- a/modules/ThreeSixtyTemporaltoSpatial.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* This file is a part of Calyp project - * Copyright (C) 2014-2019 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 ThreeSixtyTemporaltoSpatial.cpp - * \brief Convert 360 videos from temporal to spatial - */ - -#include "ThreeSixtyTemporaltoSpatial.h" - -ThreeSixtyTemporaltoSpatial::ThreeSixtyTemporaltoSpatial() -{ - /* Module Definition */ - m_iModuleAPI = CLP_MODULE_API_3; - m_iModuleType = CLP_FRAME_PROCESSING_MODULE; - m_pchModuleCategory = "360Video"; - m_pchModuleLongName = "Temporal to Spatial"; - m_pchModuleName = "TemporaltoSpatial"; - m_pchModuleTooltip = "Convert 360 video from temporal frames to Cube Map Projection"; - m_uiNumberOfFrames = 1; - m_uiModuleRequirements = CLP_MODULE_REQUIRES_SKIP_WHILE_PLAY; - - m_uiFacesX = 3; - m_uiFacesY = 2; - - flush(); -} - -bool ThreeSixtyTemporaltoSpatial::flush() -{ - CalypModuleIf::flush(); - m_uiCopyX = 0; - m_uiCopyY = 0; - m_uiFacesCount = 0; - return true; -}; - -bool ThreeSixtyTemporaltoSpatial::needFrame() -{ - return CalypModuleIf::needFrame(); -}; - -bool ThreeSixtyTemporaltoSpatial::create( std::vector apcFrameList ) -{ - _BASIC_MODULE_API_2_CHECK_ - - unsigned int iWidth; - unsigned int iHeight; - - iWidth = apcFrameList[0]->getWidth() * m_uiFacesX; - iHeight = apcFrameList[0]->getHeight() * m_uiFacesY; - - m_pcOutputFrame = new CalypFrame( iWidth, iHeight, apcFrameList[0]->getPelFormat(), - apcFrameList[0]->getBitsPel() ); - return true; -} - -CalypFrame* ThreeSixtyTemporaltoSpatial::process( std::vector apcFrameList ) -{ - _BASIC_MODULE_API_3_BREAK_CONDITION_ - - m_pcOutputFrame->copyTo( apcFrameList[0], m_uiCopyX, m_uiCopyY ); - - m_uiCopyX += apcFrameList[0]->getWidth(); - if( m_uiCopyX >= m_pcOutputFrame->getWidth() ) - { - m_uiCopyX = 0; - m_uiCopyY += apcFrameList[0]->getHeight(); - } - if( ++m_uiFacesCount < (m_uiFacesX * m_uiFacesY) ) - { - return NULL; - } - m_uiCopyX = 0; - m_uiCopyY = 0; - m_uiFacesCount = 0; - return m_pcOutputFrame; -} - -void ThreeSixtyTemporaltoSpatial::destroy() -{ - if( m_pcOutputFrame ) - delete m_pcOutputFrame; - m_pcOutputFrame = NULL; -} diff --git a/modules/ThreeSixtyTemporaltoSpatial.h b/modules/ThreeSixtyTemporaltoSpatial.h deleted file mode 100644 index be48d4c..0000000 --- a/modules/ThreeSixtyTemporaltoSpatial.h +++ /dev/null @@ -1,52 +0,0 @@ -/* This file is a part of Calyp project - * Copyright (C) 2014-2019 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 ThreeSixtyTemporaltoSpatial.h - * \brief Convert 360 videos from temporal to spatial - */ - -#ifndef __THREESIXTYTEMPORALTOSPATIAL_H__ -#define __THREESIXTYTEMPORALTOSPATIAL_H__ - -// CalypLib -#include "lib/CalypModuleIf.h" - -class ThreeSixtyTemporaltoSpatial : public CalypModuleIf -{ - REGISTER_CLASS_FACTORY( ThreeSixtyTemporaltoSpatial ) - -private: - unsigned int m_uiFacesX; - unsigned int m_uiFacesY; - unsigned int m_uiCopyX; - unsigned int m_uiCopyY; - unsigned int m_uiFacesCount; - -public: - ThreeSixtyTemporaltoSpatial(); - virtual ~ThreeSixtyTemporaltoSpatial() {} - bool create( std::vector apcFrameList ); - bool needFrame(); - CalypFrame* process( std::vector apcFrameList ); - bool flush(); - void destroy(); -}; - -#endif // __THREESIXTYTEMPORALTOSPATIAL_H__