From fdf8989337ba9c449893f3ea0472ccbdd1985b7b Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 28 Jun 2014 18:09:15 +0100 Subject: [PATCH] Add functions to get MSE and PSNR in PlaYUVerFrame --- source/lib/PlaYUVerFrame.cpp | 31 +++++++++++++++++++++++++++++++ source/lib/PlaYUVerFrame.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/source/lib/PlaYUVerFrame.cpp b/source/lib/PlaYUVerFrame.cpp index d651205..1ce5a1a 100644 --- a/source/lib/PlaYUVerFrame.cpp +++ b/source/lib/PlaYUVerFrame.cpp @@ -478,7 +478,38 @@ Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame, UInt xPos, UInt yPos ) default: Q_ASSERT( 0 ); } +} +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; + + for( UInt i = 0; i < Org->getHeight() * Org->getWidth(); 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() diff --git a/source/lib/PlaYUVerFrame.h b/source/lib/PlaYUVerFrame.h index 2d23d52..d936d1c 100644 --- a/source/lib/PlaYUVerFrame.h +++ b/source/lib/PlaYUVerFrame.h @@ -114,6 +114,9 @@ public: Void copyFrom( PlaYUVerFrame* ); Void copyFrom( PlaYUVerFrame*, UInt, UInt); + Double getMSE( PlaYUVerFrame* Org, Int component ); + Double getPSNR( PlaYUVerFrame* Org, Int component ); + UInt64 getBytesPerFrame(); UInt getChromaLength() const;