From 805cee6fbcf91e6415073c5c48d76a6478733d2c Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Thu, 28 Feb 2019 18:04:47 +0000 Subject: [PATCH] Improve frame difference to support multiple channels --- modules/AbsoluteFrameDifference.cpp | 23 ++++++++++++---------- modules/FrameDifference.cpp | 30 ++++++++++++++--------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/modules/AbsoluteFrameDifference.cpp b/modules/AbsoluteFrameDifference.cpp index daa71bb..41c4f85 100644 --- a/modules/AbsoluteFrameDifference.cpp +++ b/modules/AbsoluteFrameDifference.cpp @@ -49,13 +49,11 @@ bool AbsoluteFrameDifference::create( std::vector apcFrameList ) _BASIC_MODULE_API_2_CHECK_ for( unsigned int i = 1; i < apcFrameList.size(); i++ ) - if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_COLOR_SPACE | - CalypFrame::MATCH_RESOLUTION | - CalypFrame::MATCH_BITS ) ) + if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_COLOR_SPACE_IGNORE_GRAY + | CalypFrame::MATCH_COLOR_SPACE | CalypFrame::MATCH_RESOLUTION | CalypFrame::MATCH_BITS ) ) return false; - m_pcFrameDifference = - new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY ); + m_pcFrameDifference = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY, apcFrameList[0]->getBitsPel() ); return true; } @@ -68,13 +66,18 @@ CalypFrame* AbsoluteFrameDifference::process( std::vector apcFrameL ClpPel* pOutputPelYUV = m_pcFrameDifference->getPelBufferYUV()[0][0]; int aux_pel_1, aux_pel_2; - for( unsigned int y = 0; y < m_pcFrameDifference->getHeight(); y++ ) - for( unsigned int x = 0; x < m_pcFrameDifference->getWidth(); x++ ) + for( unsigned int ch = 0; ch < m_pcFrameDifference->getNumberChannels(); ch++ ) + { + for( unsigned int y = 0; y < m_pcFrameDifference->getHeight(); y++ ) { - aux_pel_1 = *pInput1PelYUV++; - aux_pel_2 = *pInput2PelYUV++; - *pOutputPelYUV++ = abs( aux_pel_1 - aux_pel_2 ); + for( unsigned int x = 0; x < m_pcFrameDifference->getWidth(); x++ ) + { + aux_pel_1 = *pInput1PelYUV++; + aux_pel_2 = *pInput2PelYUV++; + *pOutputPelYUV++ = abs( aux_pel_1 - aux_pel_2 ); + } } + } return m_pcFrameDifference; } diff --git a/modules/FrameDifference.cpp b/modules/FrameDifference.cpp index f98dcf4..2acb61a 100644 --- a/modules/FrameDifference.cpp +++ b/modules/FrameDifference.cpp @@ -52,8 +52,7 @@ bool FrameDifference::create( std::vector apcFrameList ) unsigned int uiMaxBitsPixel = 0; for( unsigned int i = 0; i < apcFrameList.size(); i++ ) { - if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], - CalypFrame::MATCH_COLOR_SPACE | CalypFrame::MATCH_RESOLUTION ) ) + if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_PEL_FMT | CalypFrame::MATCH_COLOR_SPACE | CalypFrame::MATCH_RESOLUTION ) ) return false; if( apcFrameList[i]->getBitsPel() > uiMaxBitsPixel ) { @@ -70,7 +69,7 @@ bool FrameDifference::create( std::vector apcFrameList ) m_iMaxDiffValue = ( 1 << ( m_uiBitsPixel - 1 ) ); m_pcFrameDifference = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), - CLP_GRAY, m_uiBitsPixel ); + apcFrameList[0]->getPelFormat(), m_uiBitsPixel ); return true; } @@ -82,19 +81,20 @@ CalypFrame* FrameDifference::process( std::vector apcFrameList ) int aux_pel_1, aux_pel_2; int diff = 0; - for( unsigned int y = 0; y < m_pcFrameDifference->getHeight(); y++ ) - for( unsigned int x = 0; x < m_pcFrameDifference->getWidth(); x++ ) - { - aux_pel_1 = *pInput1PelYUV++; - aux_pel_2 = *pInput2PelYUV++; - diff = aux_pel_1 - aux_pel_2; - diff = m_iDiffBitShift > 0 ? diff >> m_iDiffBitShift : diff << m_iDiffBitShift; - diff = std::min( diff, m_iMaxDiffValue - 1 ); - diff = std::max( diff, -m_iMaxDiffValue ); + for( unsigned int ch = 0; ch < m_pcFrameDifference->getNumberChannels(); ch++ ) + for( unsigned int y = 0; y < m_pcFrameDifference->getHeight(); y++ ) + for( unsigned int x = 0; x < m_pcFrameDifference->getWidth(); x++ ) + { + aux_pel_1 = *pInput1PelYUV++; + aux_pel_2 = *pInput2PelYUV++; + diff = aux_pel_1 - aux_pel_2; + diff = m_iDiffBitShift > 0 ? diff >> m_iDiffBitShift : diff << m_iDiffBitShift; + diff = std::min( diff, m_iMaxDiffValue - 1 ); + diff = std::max( diff, -m_iMaxDiffValue ); - diff += m_iMaxDiffValue; - *pOutputPelYUV++ = diff; - } + diff += m_iMaxDiffValue; + *pOutputPelYUV++ = diff; + } return m_pcFrameDifference; }