From dc1827946f16c267a8c4f9ca0b801bd4785537cf Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 13 May 2014 04:01:34 +0100 Subject: [PATCH] Change functions in PlaYUVerFrame and PropertiesSidebar Add new contructor to PlaYUVerFrame to improve the copy of frames Add support to stop histogram when frames are removed --- source/app/HistogramWidget.cpp | 2 +- source/app/InputStream.cpp | 6 +- source/app/PropertiesSidebar.cpp | 183 ++++++++++++------------------- source/app/PropertiesSidebar.h | 7 +- source/lib/PlaYUVerFrame.cpp | 35 ++++-- source/lib/PlaYUVerFrame.h | 4 +- 6 files changed, 107 insertions(+), 130 deletions(-) diff --git a/source/app/HistogramWidget.cpp b/source/app/HistogramWidget.cpp index 1a2ec76..69c695b 100755 --- a/source/app/HistogramWidget.cpp +++ b/source/app/HistogramWidget.cpp @@ -402,7 +402,7 @@ void HistogramWidget::updateData( const PlaYUVerFrame *playuver_frame, const Pla // Calc new histogram data m_imageHistogram = new PlaYUVerFrameStatistics( playuver_frame, this ); - if( playuver_selection->isValid() ) + if( playuver_selection ) m_selectionHistogram = new PlaYUVerFrameStatistics( playuver_selection, this ); else m_selectionHistogram = NULL; diff --git a/source/app/InputStream.cpp b/source/app/InputStream.cpp index 8c82f89..b00287d 100755 --- a/source/app/InputStream.cpp +++ b/source/app/InputStream.cpp @@ -376,9 +376,9 @@ Void InputStream::setNextFrame() PlaYUVerFrame* InputStream::getCurrFrame( PlaYUVerFrame *pyuv_image ) { if( pyuv_image == NULL ) - pyuv_image = new PlaYUVerFrame( m_pcCurrFrame->getWidth(), m_pcCurrFrame->getHeight(), m_pcCurrFrame->getPelFormat() ); - - pyuv_image->CopyFrom( m_pcCurrFrame ); + pyuv_image = new PlaYUVerFrame( m_pcCurrFrame ); + else + pyuv_image->copyFrom( m_pcCurrFrame ); return pyuv_image; } diff --git a/source/app/PropertiesSidebar.cpp b/source/app/PropertiesSidebar.cpp index 2c596b2..cb269bf 100755 --- a/source/app/PropertiesSidebar.cpp +++ b/source/app/PropertiesSidebar.cpp @@ -32,7 +32,14 @@ namespace plaYUVer { -static inline QSize bestSize( QSize currSize ); +static inline QSize bestSize( QSize currSize ) +{ + QSize bestSize( 180, currSize.height() ); + if( currSize.width() < bestSize.width() ) + return bestSize; + else + return currSize; +} //////////////////////////////////////////////////////////////////////////////// // StreamPropertiesSideBar @@ -164,6 +171,7 @@ FramePropertiesSideBar::FramePropertiesSideBar( QWidget* parent ) : { // -------------- Variables definition -------------- m_pcFrame = NULL; + m_pcFrameSelection = NULL; m_iLastFrameType = -1; // Histogram area ----------------------------------------------------- @@ -374,10 +382,8 @@ FramePropertiesSideBar::~FramePropertiesSideBar() // If there is a currently histogram computation when dialog is closed, // stop it before the image data are deleted automatically! histogramWidget->stopHistogramComputation(); - if( histogramWidget ) delete histogramWidget; - } QSize FramePropertiesSideBar::sizeHint() const @@ -385,25 +391,6 @@ QSize FramePropertiesSideBar::sizeHint() const return bestSize( size() ); } -void FramePropertiesSideBar::slotUpdateHistogram() -{ - if( m_pcFrame->isValid() && isVisible() ) - { - // If a selection area is done in Image Editor and if the current - // image is the same in Image Viewer, then compute too the histogram - // for this selection. - histogramWidget->updateData( m_pcFrame, new PlaYUVerFrame ); - fullImageButton->hide(); - selectionImageButton->hide(); - updateInformations(); - } - else - { - histogramWidget->setLoadingFailed(); - slotHistogramComputationFailed(); - } -} - Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame ) { if( !pcFrame ) @@ -483,14 +470,10 @@ Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame ) } setEnabled( true ); m_pcFrame = pcFrame; - slotUpdateHistogram(); + slotUpdateDataHistogram(); } } -//////////////////////////////////////////////////////////////////////////////// -// Set Selection -//////////////////////////////////////////////////////////////////////////////// - Void FramePropertiesSideBar::setSelection( const QRect &selectionArea ) { // This is necessary to stop computation because image.bits() is @@ -503,12 +486,7 @@ Void FramePropertiesSideBar::setSelection( const QRect &selectionArea ) histogramWidget->stopHistogramComputation(); - m_pcFrame->CopyFrom( m_pcFrameSelection ); -// histogramWidget->updateSelectionData( imageSelection.bits(), -// imageSelection.width(), -// imageSelection.height(), -// imageSelection.bitsPerChannel(), -// imageSelection.colorSpace() ); + m_pcFrameSelection->copyFrom( m_pcFrame ); histogramWidget->updateSelectionData( m_pcFrameSelection ); fullImageButton->show(); selectionImageButton->show(); @@ -521,10 +499,72 @@ Void FramePropertiesSideBar::setSelection( const QRect &selectionArea ) slotRenderingChanged( HistogramWidget::FullImageHistogram ); } } + +Void FramePropertiesSideBar::updateStatistiques() +{ + QString value; + + int min = minInterv->value(); + int max = maxInterv->value(); + int channel = histogramWidget->m_channelType; + //int channel = channelCB->currentIndex(); + + if( channel == HistogramWidget::ColorChannelsHistogram ) + channel = colorsCB->currentIndex() + 1; + + PlaYUVerFrameStatistics *histogram; + + if( histogramWidget->m_renderingType == HistogramWidget::FullImageHistogram ) + histogram = histogramWidget->m_imageHistogram; + else + histogram = histogramWidget->m_selectionHistogram; + + double mean = histogram->getMean( channel, min, max ); + labelMeanValue->setText( value.setNum( mean, 'f', 1 ) ); + + double pixels = histogram->getPixels(); + labelPixelsValue->setText( value.setNum( ( float )pixels, 'f', 0 ) ); + + double stddev = histogram->getStdDev( channel, min, max ); + labelStdDevValue->setText( value.setNum( stddev, 'f', 1 ) ); + + double counts = histogram->getCount( channel, min, max ); + labelCountValue->setText( value.setNum( ( float )counts, 'f', 0 ) ); + + double median = histogram->getMedian( channel, min, max ); + labelMedianValue->setText( value.setNum( median, 'f', 1 ) ); + + double percentile = ( pixels > 0 ? ( 100.0 * counts / pixels ) : 0.0 ); + labelPercentileValue->setText( value.setNum( percentile, 'f', 1 ) ); +} + +Void FramePropertiesSideBar::stopHistogram() +{ + histogramWidget->stopHistogramComputation(); +} + //////////////////////////////////////////////////////////////////////////////// // SLOTS //////////////////////////////////////////////////////////////////////////////// +void FramePropertiesSideBar::slotUpdateDataHistogram() +{ + if( m_pcFrame && isVisible() ) + { + // If a selection area is done in Image Editor and if the current + // image is the same in Image Viewer, then compute too the histogram + // for this selection. + histogramWidget->updateData( m_pcFrame, NULL ); + fullImageButton->hide(); + selectionImageButton->hide(); + } + else + { + histogramWidget->setLoadingFailed(); + slotHistogramComputationFailed(); + } +} + void FramePropertiesSideBar::slotRefreshOptions( bool /*depth*/) { if( !isVisible() ) @@ -545,7 +585,6 @@ void FramePropertiesSideBar::slotRefreshOptions( bool /*depth*/) slotRenderingChanged( HistogramWidget::FullImageHistogram ); else if( selectionImageButton->isChecked() ) slotRenderingChanged( HistogramWidget::ImageSelectionHistogram ); - } } @@ -673,82 +712,6 @@ void FramePropertiesSideBar::slotUpdateIntervRange( int range ) maxInterv->setMaximum( range ); maxInterv->blockSignals( false ); } -//////////////////////////////////////////////////////////////////////////////// -// Informations -//////////////////////////////////////////////////////////////////////////////// - -void FramePropertiesSideBar::updateInformations() -{ -#if 0 - QString value; - switch( image.colorMode() ) - { - case SImage::BlackWhite: - value = tr( "Black and White" ); - break; - case SImage::Gray: - value = tr( "Grayscale" ); - break; - default: - value = tr( "Color" ); - break; - } - colorModeValueLabel->setText( value ); - value = tr( "%n bit(s)", "", image.depth() ); - depthValueLabel->setText( value ); - alphaValueLabel->setText( image.hasAlpha() ? tr( "Yes" ) : tr( "No" ) ); -#endif -} -//////////////////////////////////////////////////////////////////////////////// -// Statistiques -//////////////////////////////////////////////////////////////////////////////// - -void FramePropertiesSideBar::updateStatistiques() -{ - QString value; - - int min = minInterv->value(); - int max = maxInterv->value(); - int channel = histogramWidget->m_channelType; - //int channel = channelCB->currentIndex(); - - if( channel == HistogramWidget::ColorChannelsHistogram ) - channel = colorsCB->currentIndex() + 1; - - PlaYUVerFrameStatistics *histogram; - - if( histogramWidget->m_renderingType == HistogramWidget::FullImageHistogram ) - histogram = histogramWidget->m_imageHistogram; - else - histogram = histogramWidget->m_selectionHistogram; - - double mean = histogram->getMean( channel, min, max ); - labelMeanValue->setText( value.setNum( mean, 'f', 1 ) ); - - double pixels = histogram->getPixels(); - labelPixelsValue->setText( value.setNum( ( float )pixels, 'f', 0 ) ); - - double stddev = histogram->getStdDev( channel, min, max ); - labelStdDevValue->setText( value.setNum( stddev, 'f', 1 ) ); - - double counts = histogram->getCount( channel, min, max ); - labelCountValue->setText( value.setNum( ( float )counts, 'f', 0 ) ); - - double median = histogram->getMedian( channel, min, max ); - labelMedianValue->setText( value.setNum( median, 'f', 1 ) ); - - double percentile = ( pixels > 0 ? ( 100.0 * counts / pixels ) : 0.0 ); - labelPercentileValue->setText( value.setNum( percentile, 'f', 1 ) ); -} - -static inline QSize bestSize( QSize currSize ) -{ - QSize bestSize( 180, currSize.height() ); - if( currSize.width() < bestSize.width() ) - return bestSize; - else - return currSize; -} } // NAMESPACE diff --git a/source/app/PropertiesSidebar.h b/source/app/PropertiesSidebar.h index f6beba1..aa8e334 100755 --- a/source/app/PropertiesSidebar.h +++ b/source/app/PropertiesSidebar.h @@ -73,6 +73,8 @@ public: Void setData( PlaYUVerFrame* m_pcStream ); Void setSelection( const QRect &selectionArea ); + Void stopHistogram(); + private: enum ColorChannel { @@ -132,11 +134,10 @@ private: HistogramWidget *histogramWidget; private: - void updateInformations(); - void updateStatistiques(); + Void updateStatistiques(); private Q_SLOTS: - void slotUpdateHistogram(); + void slotUpdateDataHistogram(); void slotRefreshOptions( bool sixteenBit ); void slotHistogramComputationFailed( void ); void slotChannelChanged( int channel ); diff --git a/source/lib/PlaYUVerFrame.cpp b/source/lib/PlaYUVerFrame.cpp index a9d1ac9..b039950 100755 --- a/source/lib/PlaYUVerFrame.cpp +++ b/source/lib/PlaYUVerFrame.cpp @@ -31,6 +31,28 @@ namespace plaYUVer { PlaYUVerFrame::PlaYUVerFrame( UInt width, UInt height, Int pel_format ) +{ + init( width, height, pel_format ); +} + +PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other ) +{ + init( other->getWidth(), other->getHeight(), other->getPelFormat() ); + copyFrom(other); +} + +PlaYUVerFrame::~PlaYUVerFrame() +{ + if( m_pppcInputPel ) + freeMem3ImageComponents( m_pppcInputPel ); + + if( m_pcRGBPelInterlaced ) + freeMem1D( m_pcRGBPelInterlaced ); + + closePixfc(); +} + +Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format ) { m_pppcInputPel = NULL; m_pcRGBPelInterlaced = NULL; @@ -74,17 +96,6 @@ PlaYUVerFrame::PlaYUVerFrame( UInt width, UInt height, Int pel_format ) openPixfc(); } -PlaYUVerFrame::~PlaYUVerFrame() -{ - if( m_pppcInputPel ) - freeMem3ImageComponents( m_pppcInputPel ); - - if( m_pcRGBPelInterlaced ) - freeMem1D( m_pcRGBPelInterlaced ); - - closePixfc(); -} - Void PlaYUVerFrame::openPixfc() { #ifdef USE_PIXFC @@ -345,7 +356,7 @@ Void PlaYUVerFrame::FrameFromBuffer( Pel *input_buffer, Int pel_format ) } } -Void PlaYUVerFrame::CopyFrom( PlaYUVerFrame* input_frame ) +Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame ) { if( m_iPixelFormat != input_frame->getPelFormat() ) return; diff --git a/source/lib/PlaYUVerFrame.h b/source/lib/PlaYUVerFrame.h index 542b829..0c3866f 100755 --- a/source/lib/PlaYUVerFrame.h +++ b/source/lib/PlaYUVerFrame.h @@ -54,6 +54,7 @@ class PlaYUVerFrame { public: PlaYUVerFrame( UInt width = 0, UInt height = 0, Int pel_format = 0 ); + PlaYUVerFrame( PlaYUVerFrame *other ); ~PlaYUVerFrame(); enum ColorSpace @@ -115,7 +116,7 @@ public: Void FrameFromBuffer( Pel *input_buffer, Int pel_format ); - Void CopyFrom( PlaYUVerFrame* ); + Void copyFrom( PlaYUVerFrame* ); UInt64 getBytesPerFrame(); UInt getChromaLength() const; @@ -179,6 +180,7 @@ private: Pel*** m_pppcInputPel; UChar* m_pcRGBPelInterlaced; + Void init( UInt width, UInt height, Int pel_format ); Void openPixfc(); Void closePixfc(); #ifdef USE_PIXFC