diff --git a/source/lib/PlaYUVerFrame.cpp b/source/lib/PlaYUVerFrame.cpp index 5088777..f4a97fe 100644 --- a/source/lib/PlaYUVerFrame.cpp +++ b/source/lib/PlaYUVerFrame.cpp @@ -480,48 +480,6 @@ Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame, UInt xPos, UInt yPos ) } } -Double PlaYUVerFrame::getMSE( PlaYUVerFrame* Org, Int component ) -{ - Pel* pPelYUV = getPelBufferYUV()[component][0]; - Pel* pOrgPelYUV = Org->getPelBufferYUV()[component][0]; - - Int aux_pel_1, aux_pel_2; - Int diff = 0; - Double ssd = 0; - - UInt numberOfPixels = 0; - if( component == LUMA ) - { - numberOfPixels = Org->getHeight() * Org->getWidth(); - } - else - { - numberOfPixels = getChromaLength(); - } - - for( UInt i = 0; i < numberOfPixels; i++ ) - { - aux_pel_1 = *pPelYUV++; - aux_pel_2 = *pOrgPelYUV++; - diff = aux_pel_1 - aux_pel_2; - ssd += ( Double )( diff * diff ); - } - if( ssd == 0.0 ) - { - return 0.0; - } - return ssd / ( Org->getWidth() * Org->getHeight() ); -} - -Double PlaYUVerFrame::getPSNR( PlaYUVerFrame* Org, Int component ) -{ - Double dPSNR = 100; - Double dMSE = getMSE( Org, component ); - if( dMSE != 0 ) - dPSNR = 10 * log10( 65025 / dMSE ); - return dPSNR; -} - UInt64 PlaYUVerFrame::getBytesPerFrame() { return getBytesPerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat ); @@ -776,5 +734,73 @@ Void PlaYUVerFrame::copyFrom( cv::Mat* opencvFrame ) } } #endif + +/** + * Quality Related Function API + */ + +Double PlaYUVerFrame::getQuality( Int Metric, PlaYUVerFrame* Org, Int component ) +{ + switch( Metric ) + { + case PSNR_METRIC: + return getPSNR( Org, component ); + break; + case SSIM_METRIC: + return getSSIM( Org, component ); + break; + default: + assert( 0 ); + }; + return 0; } -// NAMESPACE + +Double PlaYUVerFrame::getMSE( PlaYUVerFrame* Org, Int component ) +{ + Pel* pPelYUV = getPelBufferYUV()[component][0]; + Pel* pOrgPelYUV = Org->getPelBufferYUV()[component][0]; + + Int aux_pel_1, aux_pel_2; + Int diff = 0; + Double ssd = 0; + + UInt numberOfPixels = 0; + if( component == LUMA ) + { + numberOfPixels = Org->getHeight() * Org->getWidth(); + } + else + { + numberOfPixels = getChromaLength(); + } + + for( UInt i = 0; i < numberOfPixels; i++ ) + { + aux_pel_1 = *pPelYUV++; + aux_pel_2 = *pOrgPelYUV++; + diff = aux_pel_1 - aux_pel_2; + ssd += ( Double )( diff * diff ); + } + if( ssd == 0.0 ) + { + return 0.0; + } + return ssd / ( Org->getWidth() * Org->getHeight() ); +} + +Double PlaYUVerFrame::getPSNR( PlaYUVerFrame* Org, Int component ) +{ + Double dPSNR = 100; + Double dMSE = getMSE( Org, component ); + if( dMSE != 0 ) + dPSNR = 10 * log10( 65025 / dMSE ); + return dPSNR; +} + +Double PlaYUVerFrame::getSSIM( PlaYUVerFrame* Org, Int component ) +{ + Double dSSIM = 1; + return dSSIM; +} + +} // NAMESPACE diff --git a/source/lib/PlaYUVerFrame.h b/source/lib/PlaYUVerFrame.h index 9e5ebe4..b57f323 100644 --- a/source/lib/PlaYUVerFrame.h +++ b/source/lib/PlaYUVerFrame.h @@ -112,10 +112,7 @@ public: Void FrameToBuffer( Pel* ); Void copyFrom( PlaYUVerFrame* ); - Void copyFrom( PlaYUVerFrame*, UInt, UInt); - - Double getMSE( PlaYUVerFrame* Org, Int component ); - Double getPSNR( PlaYUVerFrame* Org, Int component ); + Void copyFrom( PlaYUVerFrame*, UInt, UInt ); UInt64 getBytesPerFrame(); static UInt64 getBytesPerFrame( UInt uiWidth, UInt uiHeight, Int iPixelFormat ); @@ -149,6 +146,29 @@ public: Void copyFrom( cv::Mat* ); #endif + enum QualityMetrics + { + NO_METRIC = -1, + PSNR_METRIC = 0, + SSIM_METRIC, + NUMBER_METRICS, + }; + + static QStringList supportedQualityMetricsList() + { + QStringList metrics; + metrics << "PSNR" + << "SSIM" // SSIM + ; + assert( metrics.size() == NUMBER_METRICS ); + return metrics; + } + + Double getQuality( Int Metric, PlaYUVerFrame* Org, Int component ); + Double getMSE( PlaYUVerFrame* Org, Int component ); + Double getPSNR( PlaYUVerFrame* Org, Int component ); + Double getSSIM( PlaYUVerFrame* Org, Int component ); + UInt getWidth() const { return m_uiWidth; @@ -174,9 +194,9 @@ public: return ( m_uiWidth > 0 ) && ( m_uiHeight > 0 ) && ( m_iPixelFormat >= 0 ); } Bool haveSameFmt( PlaYUVerFrame* other ) const - { - return ( m_uiWidth == other->getWidth() ) && ( m_uiHeight == other->getHeight() ) && ( m_iPixelFormat == other->getPelFormat() ); - } + { + return ( m_uiWidth == other->getWidth() ) && ( m_uiHeight == other->getHeight() ) && ( m_iPixelFormat == other->getPelFormat() ); + } private: UInt m_uiWidth;