Improve frame difference to support multiple channels

This commit is contained in:
2019-02-28 18:04:47 +00:00
parent b3340bb13b
commit 805cee6fbc
2 changed files with 28 additions and 25 deletions
+13 -10
View File
@@ -49,13 +49,11 @@ bool AbsoluteFrameDifference::create( std::vector<CalypFrame*> apcFrameList )
_BASIC_MODULE_API_2_CHECK_ _BASIC_MODULE_API_2_CHECK_
for( unsigned int i = 1; i < apcFrameList.size(); i++ ) for( unsigned int i = 1; i < apcFrameList.size(); i++ )
if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_COLOR_SPACE | if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_COLOR_SPACE_IGNORE_GRAY
CalypFrame::MATCH_RESOLUTION | | CalypFrame::MATCH_COLOR_SPACE | CalypFrame::MATCH_RESOLUTION | CalypFrame::MATCH_BITS ) )
CalypFrame::MATCH_BITS ) )
return false; return false;
m_pcFrameDifference = m_pcFrameDifference = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY, apcFrameList[0]->getBitsPel() );
new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), CLP_GRAY );
return true; return true;
} }
@@ -68,13 +66,18 @@ CalypFrame* AbsoluteFrameDifference::process( std::vector<CalypFrame*> apcFrameL
ClpPel* pOutputPelYUV = m_pcFrameDifference->getPelBufferYUV()[0][0]; ClpPel* pOutputPelYUV = m_pcFrameDifference->getPelBufferYUV()[0][0];
int aux_pel_1, aux_pel_2; int aux_pel_1, aux_pel_2;
for( unsigned int y = 0; y < m_pcFrameDifference->getHeight(); y++ ) for( unsigned int ch = 0; ch < m_pcFrameDifference->getNumberChannels(); ch++ )
for( unsigned int x = 0; x < m_pcFrameDifference->getWidth(); x++ ) {
for( unsigned int y = 0; y < m_pcFrameDifference->getHeight(); y++ )
{ {
aux_pel_1 = *pInput1PelYUV++; for( unsigned int x = 0; x < m_pcFrameDifference->getWidth(); x++ )
aux_pel_2 = *pInput2PelYUV++; {
*pOutputPelYUV++ = abs( aux_pel_1 - aux_pel_2 ); aux_pel_1 = *pInput1PelYUV++;
aux_pel_2 = *pInput2PelYUV++;
*pOutputPelYUV++ = abs( aux_pel_1 - aux_pel_2 );
}
} }
}
return m_pcFrameDifference; return m_pcFrameDifference;
} }
+15 -15
View File
@@ -52,8 +52,7 @@ bool FrameDifference::create( std::vector<CalypFrame*> apcFrameList )
unsigned int uiMaxBitsPixel = 0; unsigned int uiMaxBitsPixel = 0;
for( unsigned int i = 0; i < apcFrameList.size(); i++ ) for( unsigned int i = 0; i < apcFrameList.size(); i++ )
{ {
if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], if( !apcFrameList[i]->haveSameFmt( apcFrameList[0], CalypFrame::MATCH_PEL_FMT | CalypFrame::MATCH_COLOR_SPACE | CalypFrame::MATCH_RESOLUTION ) )
CalypFrame::MATCH_COLOR_SPACE | CalypFrame::MATCH_RESOLUTION ) )
return false; return false;
if( apcFrameList[i]->getBitsPel() > uiMaxBitsPixel ) if( apcFrameList[i]->getBitsPel() > uiMaxBitsPixel )
{ {
@@ -70,7 +69,7 @@ bool FrameDifference::create( std::vector<CalypFrame*> apcFrameList )
m_iMaxDiffValue = ( 1 << ( m_uiBitsPixel - 1 ) ); m_iMaxDiffValue = ( 1 << ( m_uiBitsPixel - 1 ) );
m_pcFrameDifference = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), m_pcFrameDifference = new CalypFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(),
CLP_GRAY, m_uiBitsPixel ); apcFrameList[0]->getPelFormat(), m_uiBitsPixel );
return true; return true;
} }
@@ -82,19 +81,20 @@ CalypFrame* FrameDifference::process( std::vector<CalypFrame*> apcFrameList )
int aux_pel_1, aux_pel_2; int aux_pel_1, aux_pel_2;
int diff = 0; int diff = 0;
for( unsigned int y = 0; y < m_pcFrameDifference->getHeight(); y++ ) for( unsigned int ch = 0; ch < m_pcFrameDifference->getNumberChannels(); ch++ )
for( unsigned int x = 0; x < m_pcFrameDifference->getWidth(); x++ ) 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++; aux_pel_1 = *pInput1PelYUV++;
diff = aux_pel_1 - aux_pel_2; aux_pel_2 = *pInput2PelYUV++;
diff = m_iDiffBitShift > 0 ? diff >> m_iDiffBitShift : diff << m_iDiffBitShift; diff = aux_pel_1 - aux_pel_2;
diff = std::min( diff, m_iMaxDiffValue - 1 ); diff = m_iDiffBitShift > 0 ? diff >> m_iDiffBitShift : diff << m_iDiffBitShift;
diff = std::max( diff, -m_iMaxDiffValue ); diff = std::min( diff, m_iMaxDiffValue - 1 );
diff = std::max( diff, -m_iMaxDiffValue );
diff += m_iMaxDiffValue; diff += m_iMaxDiffValue;
*pOutputPelYUV++ = diff; *pOutputPelYUV++ = diff;
} }
return m_pcFrameDifference; return m_pcFrameDifference;
} }