From 987a95f73b66019c7bee41b02cd7498cc43956ec Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sun, 29 Jun 2014 01:07:47 +0100 Subject: [PATCH] Complete PSNR measurement side bar --- source/app/QualityMeasurementSidebar.cpp | 53 +++++++++++++----------- source/app/plaYUVerApp.cpp | 30 ++++++++++---- source/app/plaYUVerApp.h | 5 ++- source/lib/PlaYUVerFrame.cpp | 12 +++++- source/lib/PlaYUVerFrame.h | 4 ++ 5 files changed, 68 insertions(+), 36 deletions(-) diff --git a/source/app/QualityMeasurementSidebar.cpp b/source/app/QualityMeasurementSidebar.cpp index 2c165e0..0797662 100644 --- a/source/app/QualityMeasurementSidebar.cpp +++ b/source/app/QualityMeasurementSidebar.cpp @@ -46,27 +46,23 @@ QualityMeasurementSidebar::QualityMeasurementSidebar( QWidget* parent, QMdiArea m_comboBoxRef = new QComboBox; - m_comboBoxRec = new QComboBox; - updateSubWindowList(); QGridLayout *mainLayout = new QGridLayout; mainLayout->addWidget( RefLabel, 0, 0, Qt::AlignLeft ); mainLayout->addWidget( m_comboBoxRef, 0, 1, Qt::AlignLeft ); - //mainLayout->addWidget( RecLabel, 1, 0, Qt::AlignLeft ); - //mainLayout->addWidget( m_comboBoxRec, 1, 1, Qt::AlignLeft ); - m_ppcLabelQualityLabel[LUMA] = new QLabel( tr( "PSNR Y:" ) ); + m_ppcLabelQualityLabel[LUMA] = new QLabel( "PSNR Y:" ); m_ppcLabelQualityLabel[LUMA]->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); m_ppcLabelQualityValue[LUMA] = new QLabel; m_ppcLabelQualityValue[LUMA]->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); - m_ppcLabelQualityLabel[CHROMA_U] = new QLabel( tr( "PSNR U:" ) ); + m_ppcLabelQualityLabel[CHROMA_U] = new QLabel( "PSNR U:" ); m_ppcLabelQualityLabel[CHROMA_U]->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); m_ppcLabelQualityValue[CHROMA_U] = new QLabel; m_ppcLabelQualityValue[CHROMA_U]->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); - m_ppcLabelQualityLabel[CHROMA_V] = new QLabel( tr( "PSNR V:" ) ); + m_ppcLabelQualityLabel[CHROMA_V] = new QLabel( "PSNR V:" ); m_ppcLabelQualityLabel[CHROMA_V]->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); m_ppcLabelQualityValue[CHROMA_V] = new QLabel; m_ppcLabelQualityValue[CHROMA_V]->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); @@ -86,7 +82,7 @@ QualityMeasurementSidebar::QualityMeasurementSidebar( QWidget* parent, QMdiArea mainLayout->addWidget( statisticsGroup, 4, 0, 3, 3 ); - mainLayout->setRowStretch( 8, 10 ); + //mainLayout->setRowStretch( 8, 10 ); setLayout( mainLayout ); connect( m_comboBoxRef, SIGNAL( activated(int) ), this, SLOT( slotReferenceChanged(int) ) ); @@ -134,27 +130,27 @@ Void QualityMeasurementSidebar::updateCurrentWindow( SubWindowHandle *subWindow Void QualityMeasurementSidebar::updateSidebarData() { QString value( "0.00" ); - SubWindowHandle* refSubWindow = m_pcCurrentSubWindow->getRefSubWindow(); - - if( refSubWindow ) + if( m_pcCurrentSubWindow ) { - PlaYUVerFrame* currFrame = m_pcCurrentSubWindow->getCurrFrame(); - PlaYUVerFrame* refFrame = refSubWindow->getCurrFrame(); - Double quality; - - for( Int component = 0; component < 3; component++ ) + if( SubWindowHandle* refSubWindow = m_pcCurrentSubWindow->getRefSubWindow() ) { - quality = currFrame->getPSNR( refFrame, component ); - m_ppcLabelQualityLabel[component]->setText( value.setNum( quality, 'f', 2 ) ); + PlaYUVerFrame* currFrame = m_pcCurrentSubWindow->getCurrFrame(); + PlaYUVerFrame* refFrame = refSubWindow->getCurrFrame(); + Double quality; + + for( Int component = 0; component < 3; component++ ) + { + quality = currFrame->getPSNR( refFrame, component ); + m_ppcLabelQualityValue[component]->setText( value.setNum( quality, 'f', 2 ) ); + } + return; } } - else + for( Int component = 0; component < 3; component++ ) { - for( Int component = 0; component < 3; component++ ) - { - m_ppcLabelQualityLabel[component]->setText( value ); - } + m_ppcLabelQualityValue[component]->setText( value ); } + } Void QualityMeasurementSidebar::slotReferenceChanged( Int index ) @@ -164,9 +160,16 @@ Void QualityMeasurementSidebar::slotReferenceChanged( Int index ) { subWindow = qobject_cast( m_pcMainWindowMdiArea->subWindowList().at( index ) ); if( subWindow ) - m_pcCurrentSubWindow->setRefSubWindow( subWindow ); + { + if( m_pcCurrentSubWindow->getCurrFrame()->haveSameFmt( subWindow->getCurrFrame() ) ) + { + m_pcCurrentSubWindow->setRefSubWindow( subWindow ); + updateSidebarData(); + return; + } + } } - // updateSidebarData(); + m_comboBoxRef->setCurrentIndex( -1 ); } } // NAMESPACE diff --git a/source/app/plaYUVerApp.cpp b/source/app/plaYUVerApp.cpp index 5030d9e..7810d00 100644 --- a/source/app/plaYUVerApp.cpp +++ b/source/app/plaYUVerApp.cpp @@ -155,14 +155,14 @@ Void plaYUVerApp::closeEvent( QCloseEvent *event ) Void plaYUVerApp::loadFile( QString fileName ) { - QMdiSubWindow *existing = findSubWindow( fileName ); - if( existing ) + SubWindowHandle *interfaceChild = plaYUVerApp::findSubWindow( mdiArea, fileName ); + if( interfaceChild ) { - mdiArea->setActiveSubWindow( existing ); + mdiArea->setActiveSubWindow( interfaceChild ); return; } - SubWindowHandle *interfaceChild = new SubWindowHandle( this ); //createSubWindow(); + interfaceChild = new SubWindowHandle( this ); //createSubWindow(); if( interfaceChild->loadFile( fileName ) ) { statusBar()->showMessage( tr( "Loading file..." ) ); @@ -559,9 +559,6 @@ Void plaYUVerApp::playEvent() if( !m_arrayActions[VIDEO_LOOP_ACT]->isChecked() ) { stop(); - updateCurrFrameNum(); - updateFrameProperties(); - return; } else { @@ -584,6 +581,7 @@ Void plaYUVerApp::playEvent() } updateCurrFrameNum(); updateFrameProperties(); + m_pcQualityMeasurement->updateSidebarData(); m_uiAveragePlayInterval = ( m_uiAveragePlayInterval + time ) / 2; } @@ -799,6 +797,10 @@ Void plaYUVerApp::chageSubWindowSelection() if( activeSubWindow() ) { m_pcCurrentSubWindow = new_window; + if( !plaYUVerApp::findSubWindow( mdiArea, m_pcCurrentSubWindow->getRefSubWindow() ) ) + { + m_pcCurrentSubWindow->setRefSubWindow( NULL ); + } updateCurrFrameNum(); updateTotalFrameNum(); updateStreamProperties(); @@ -871,18 +873,28 @@ SubWindowHandle *plaYUVerApp::activeSubWindow() return 0; } -QMdiSubWindow *plaYUVerApp::findSubWindow( const QString &fileName ) +SubWindowHandle* plaYUVerApp::findSubWindow( const QMdiArea* mdiArea, const QString& fileName ) { QString canonicalFilePath = QFileInfo( fileName ).canonicalFilePath(); foreach( QMdiSubWindow * window, mdiArea->subWindowList() ){ SubWindowHandle *mdiChild = qobject_cast( window); if( mdiChild->currentFile() == canonicalFilePath ) - return window; + return mdiChild; } return 0; } +SubWindowHandle* plaYUVerApp::findSubWindow( const QMdiArea* mdiArea, const SubWindowHandle* subWindow ) +{ + foreach( QMdiSubWindow * window, mdiArea->subWindowList() ){ + SubWindowHandle *mdiChild = qobject_cast( window); + if( mdiChild == subWindow ) + return mdiChild; +} +return 0; +} + Void plaYUVerApp::setNavigationTool() { m_appTool = NavigationTool; diff --git a/source/app/plaYUVerApp.h b/source/app/plaYUVerApp.h index 7474e79..845da77 100644 --- a/source/app/plaYUVerApp.h +++ b/source/app/plaYUVerApp.h @@ -148,7 +148,10 @@ private: Void writeSettings(); SubWindowHandle *activeSubWindow(); - QMdiSubWindow *findSubWindow( const QString &fileName ); + + static SubWindowHandle* findSubWindow( const QMdiArea* mdiArea, const QString& fileName ); + static SubWindowHandle* findSubWindow( const QMdiArea* mdiArea, const SubWindowHandle* subWindow ); + QVector m_acPlayingSubWindows; QSlider *m_pcFrameSlider; diff --git a/source/lib/PlaYUVerFrame.cpp b/source/lib/PlaYUVerFrame.cpp index 1ce5a1a..021bd05 100644 --- a/source/lib/PlaYUVerFrame.cpp +++ b/source/lib/PlaYUVerFrame.cpp @@ -489,7 +489,17 @@ Double PlaYUVerFrame::getMSE( PlaYUVerFrame* Org, Int component ) Int diff = 0; Double ssd = 0; - for( UInt i = 0; i < Org->getHeight() * Org->getWidth(); i++ ) + Int 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 --git a/source/lib/PlaYUVerFrame.h b/source/lib/PlaYUVerFrame.h index d936d1c..a182bc5 100644 --- a/source/lib/PlaYUVerFrame.h +++ b/source/lib/PlaYUVerFrame.h @@ -170,6 +170,10 @@ 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() ); + } private: UInt m_uiWidth;