From 95c35373f4f7d11dece6ffda79eb98c716764206 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 6 Apr 2015 00:34:40 +0100 Subject: [PATCH] Add full frame difference with plus 1 bit precision --- app/PlaYUVerAppModuleIf.cpp | 20 ++------------------ lib/PlaYUVerFrame.cpp | 11 +++++++---- modules/FrameDifference.cpp | 20 ++++++++++++-------- modules/FrameDifference.h | 7 ++++--- modules/PlaYUVerModuleIf.h | 10 +--------- tools/PlaYUVerTools.cpp | 20 ++------------------ 6 files changed, 28 insertions(+), 60 deletions(-) diff --git a/app/PlaYUVerAppModuleIf.cpp b/app/PlaYUVerAppModuleIf.cpp index 37ab439..9428850 100644 --- a/app/PlaYUVerAppModuleIf.cpp +++ b/app/PlaYUVerAppModuleIf.cpp @@ -65,15 +65,7 @@ void PlaYUVerAppModuleIf::run() } else { - switch( m_pcModule->m_uiNumberOfFrames ) - { - case MODULE_REQUIRES_ONE_FRAME: - m_pcProcessedFrame = m_pcModule->process( m_pcSubWindow[0]->getCurrFrame() ); - break; - case MODULE_REQUIRES_TWO_FRAMES: - m_pcProcessedFrame = m_pcModule->process( m_pcSubWindow[0]->getCurrFrame(), m_pcSubWindow[1]->getCurrFrame() ); - break; - } + m_pcProcessedFrame = m_pcModule->process( m_pcSubWindow[0]->getCurrFrame() ); } } else if( m_pcModule->m_iModuleType == FRAME_MEASUREMENT_MODULE ) @@ -84,15 +76,7 @@ void PlaYUVerAppModuleIf::run() } else { - switch( m_pcModule->m_uiNumberOfFrames ) - { - case MODULE_REQUIRES_ONE_FRAME: - m_dMeasurementResult = m_pcModule->measure( m_pcSubWindow[0]->getCurrFrame() ); - break; - case MODULE_REQUIRES_TWO_FRAMES: - m_dMeasurementResult = m_pcModule->measure( m_pcSubWindow[0]->getCurrFrame(), m_pcSubWindow[1]->getCurrFrame() ); - break; - } + m_dMeasurementResult = m_pcModule->measure( m_pcSubWindow[0]->getCurrFrame() ); } } else diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index 25f7a9f..4a85f15 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -345,15 +345,19 @@ Void PlaYUVerFrame::fillRGBBuffer() if( m_bHasRGBPel ) return; Int iR, iG, iB; + Int shiftBits = m_iBitsPel - 8; UInt* pARGB = ( UInt* )m_pcARGB32; if( m_pcPelFormat->colorSpace == COLOR_GRAY ) { Pel* pY = m_pppcInputPel[LUMA][0]; + Int iY; for( UInt i = 0; i < m_uiHeight * m_uiWidth; i++ ) { - iR = *pY; - iG = *pY; - iB = *pY++; + iY = *pY++; + iY >>= shiftBits; + iR = iY; + iG = iY; + iB = iY; *pARGB++ = PEL_RGB( iR, iG, iB ); } } @@ -373,7 +377,6 @@ Void PlaYUVerFrame::fillRGBBuffer() } else if( m_pcPelFormat->colorSpace == COLOR_YUV ) { - Int shiftBits = m_iBitsPel - 8; Pel* pLineY = m_pppcInputPel[LUMA][0]; Pel* pLineU = m_pppcInputPel[CHROMA_U][0]; Pel* pLineV = m_pppcInputPel[CHROMA_V][0]; diff --git a/modules/FrameDifference.cpp b/modules/FrameDifference.cpp index 719b173..f11ebe3 100644 --- a/modules/FrameDifference.cpp +++ b/modules/FrameDifference.cpp @@ -31,6 +31,7 @@ namespace plaYUVer FrameDifference::FrameDifference() { /* Module Definition */ + m_iModuleAPI = MODULE_API_2; m_iModuleType = FRAME_PROCESSING_MODULE; m_pchModuleCategory = "Measurements"; m_pchModuleName = "FrameDifference"; @@ -41,15 +42,18 @@ FrameDifference::FrameDifference() m_pcFrameDifference = NULL; } -Void FrameDifference::create( PlaYUVerFrame* Input ) +Bool FrameDifference::create( std::vector apcFrameList ) { - m_pcFrameDifference = new PlaYUVerFrame( Input->getWidth(), Input->getHeight(), PlaYUVerFrame::GRAY, Input->getBitsPel() ); + UInt bitsPixel = ( apcFrameList[0]->getBitsPel() + 1 ) & 0x0F; + m_iMaxDiffValue = ( 1 << ( bitsPixel - 1 ) ); + m_pcFrameDifference = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), PlaYUVerFrame::GRAY, bitsPixel ); + return true; } -PlaYUVerFrame* FrameDifference::process( PlaYUVerFrame* Input1, PlaYUVerFrame* Input2 ) +PlaYUVerFrame* FrameDifference::process( std::vector apcFrameList ) { - Pel* pInput1PelYUV = Input1->getPelBufferYUV()[0][0]; - Pel* pInput2PelYUV = Input2->getPelBufferYUV()[0][0]; + Pel* pInput1PelYUV = apcFrameList[0]->getPelBufferYUV()[0][0]; + Pel* pInput2PelYUV = apcFrameList[1]->getPelBufferYUV()[0][0]; Pel* pOutputPelYUV = m_pcFrameDifference->getPelBufferYUV()[0][0]; Int aux_pel_1, aux_pel_2; Int diff = 0; @@ -60,9 +64,9 @@ PlaYUVerFrame* FrameDifference::process( PlaYUVerFrame* Input1, PlaYUVerFrame* I aux_pel_1 = *pInput1PelYUV++; aux_pel_2 = *pInput2PelYUV++; diff = aux_pel_1 - aux_pel_2; - diff = std::min( diff, 127 ); - diff = std::max( diff, -128 ); - diff += 128; + diff = std::min( diff, m_iMaxDiffValue ); + diff = std::max( diff, -m_iMaxDiffValue ); + diff += m_iMaxDiffValue + 1; *pOutputPelYUV++ = diff; } return m_pcFrameDifference; diff --git a/modules/FrameDifference.h b/modules/FrameDifference.h index 93bf9c8..9b01b0c 100644 --- a/modules/FrameDifference.h +++ b/modules/FrameDifference.h @@ -34,9 +34,10 @@ namespace plaYUVer class FrameDifference: public PlaYUVerModuleIf { - REGISTER_CLASS_FACTORY( FrameDifference ) +REGISTER_CLASS_FACTORY( FrameDifference ) private: + Int m_iMaxDiffValue; PlaYUVerFrame* m_pcFrameDifference; public: @@ -44,8 +45,8 @@ public: virtual ~FrameDifference() { } - Void create( PlaYUVerFrame* Input ); - PlaYUVerFrame* process( PlaYUVerFrame* Input1, PlaYUVerFrame* Input2 ); + Bool create( std::vector apcFrameList ); + PlaYUVerFrame* process( std::vector apcFrameList ); Void destroy(); }; diff --git a/modules/PlaYUVerModuleIf.h b/modules/PlaYUVerModuleIf.h index b6e31d1..81b4dcd 100644 --- a/modules/PlaYUVerModuleIf.h +++ b/modules/PlaYUVerModuleIf.h @@ -101,28 +101,20 @@ public: } virtual Bool create( std::vector apcFrameList ) { + return false; } virtual PlaYUVerFrame* process( PlaYUVerFrame* ) { return NULL; } - virtual PlaYUVerFrame* process( PlaYUVerFrame*, PlaYUVerFrame* ) - { - return NULL; - } virtual PlaYUVerFrame* process( std::vector ) { return NULL; } - virtual Double measure( PlaYUVerFrame* ) { return 0; } - virtual Double measure( PlaYUVerFrame*, PlaYUVerFrame* ) - { - return 0; - } virtual Double measure( std::vector ) { return 0; diff --git a/tools/PlaYUVerTools.cpp b/tools/PlaYUVerTools.cpp index 906aad4..64110a4 100644 --- a/tools/PlaYUVerTools.cpp +++ b/tools/PlaYUVerTools.cpp @@ -316,15 +316,7 @@ PlaYUVerFrame* PlaYUVerTools::applyFrameModule() PlaYUVerFrame* pcProcessedFrame = NULL; if( m_pcCurrModuleIf->m_iModuleType == FRAME_PROCESSING_MODULE ) { - switch( m_pcCurrModuleIf->m_uiNumberOfFrames ) - { - case MODULE_REQUIRES_ONE_FRAME: - pcProcessedFrame = m_pcCurrModuleIf->process( m_apcInputStreams[0]->getCurrFrame() ); - break; - case MODULE_REQUIRES_TWO_FRAMES: - pcProcessedFrame = m_pcCurrModuleIf->process( m_apcInputStreams[0]->getCurrFrame(), m_apcInputStreams[1]->getCurrFrame() ); - break; - } + pcProcessedFrame = m_pcCurrModuleIf->process( m_apcInputStreams[0]->getCurrFrame() ); } return pcProcessedFrame; } @@ -371,15 +363,7 @@ Int PlaYUVerTools::ModuleOperation() } else { - switch( m_pcCurrModuleIf->m_uiNumberOfFrames ) - { - case MODULE_REQUIRES_ONE_FRAME: - dMeasurementResult = m_pcCurrModuleIf->measure( m_apcInputStreams[0]->getCurrFrame() ); - break; - case MODULE_REQUIRES_TWO_FRAMES: - dMeasurementResult = m_pcCurrModuleIf->measure( m_apcInputStreams[0]->getCurrFrame(), m_apcInputStreams[1]->getCurrFrame() ); - break; - } + dMeasurementResult = m_pcCurrModuleIf->measure( m_apcInputStreams[0]->getCurrFrame() ); } m_cCmdLineHandler.log( CommandLineHandle::INFO, " %3d", frame ); m_cCmdLineHandler.log( CommandLineHandle::RESULT, " %8.3f \n", dMeasurementResult );