From e0695f9cdc05d32551325a6414f92a27f65ef746 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 5 Apr 2014 14:35:42 +0100 Subject: [PATCH] Bugfix in HistogramWidget and PlaYUVerFrameStatistics Conditions were not proper checking if frame exists Change on some variables name Still incomplete the code and some variable must be renamed to include code style --- source/app/HistogramWidget.cpp | 15 ++++++++------- source/app/HistogramWidget.h | 2 +- source/app/PropertiesSidebar.cpp | 13 +++++++++---- source/lib/PlaYUVerFrameStatistics.cpp | 24 ++++++++++++------------ source/lib/PlaYUVerFrameStatistics.h | 4 ++-- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/source/app/HistogramWidget.cpp b/source/app/HistogramWidget.cpp index a34054d..41ddbfc 100755 --- a/source/app/HistogramWidget.cpp +++ b/source/app/HistogramWidget.cpp @@ -362,11 +362,12 @@ void HistogramWidget::updateData( uchar *imageData, uint imageWidth, uint imageH m_selectionHistogram = 0L; } -void HistogramWidget::updateData( const PlaYUVerFrame &image, const PlaYUVerFrame &selection ) +void HistogramWidget::updateData( const PlaYUVerFrame &playuver_frame, const PlaYUVerFrame &playuver_selection ) { d->sixteenBits = false; - d->imageColorSpace = image.getPelFormat(); - d->imageChannels = image.getNumberChannels(); + //d->imageColorSpace = image.getPelFormat(); + d->imageColorSpace = PlaYUVerFrame::RGB8; + d->imageChannels = playuver_frame.getNumberChannels(); // We are deleting the histogram data, // so we must not use it to draw any more. @@ -386,12 +387,12 @@ void HistogramWidget::updateData( const PlaYUVerFrame &image, const PlaYUVerFram delete m_selectionHistogram; // Calc new histogram data - m_imageHistogram = new PlaYUVerFrameStatistics( image, this ); + m_imageHistogram = new PlaYUVerFrameStatistics( playuver_frame, this ); - if( !selection.isValid() ) - m_selectionHistogram = new PlaYUVerFrameStatistics( selection, this ); + if( playuver_selection.isValid() ) + m_selectionHistogram = new PlaYUVerFrameStatistics( playuver_selection, this ); else - m_selectionHistogram = 0L; + m_selectionHistogram = NULL; } diff --git a/source/app/HistogramWidget.h b/source/app/HistogramWidget.h index ab21bf6..1e2b35d 100755 --- a/source/app/HistogramWidget.h +++ b/source/app/HistogramWidget.h @@ -126,7 +126,7 @@ public : uchar *selData = 0, uint selWidth = 0, uint selHeight = 0); /** Update full image histogram data from SImage.*/ - void updateData( const PlaYUVerFrame &image, const PlaYUVerFrame &selection ); + void updateData( const PlaYUVerFrame &playuver_frame, const PlaYUVerFrame &playuver_selection ); /** Update image selection histogram data methods.*/ void updateSelectionData( uchar *selData, uint selWidth, uint selHeight, diff --git a/source/app/PropertiesSidebar.cpp b/source/app/PropertiesSidebar.cpp index ba81f3b..166aa52 100755 --- a/source/app/PropertiesSidebar.cpp +++ b/source/app/PropertiesSidebar.cpp @@ -120,6 +120,9 @@ Void StreamPropertiesSideBar::setData( InputStream* pcStream ) { // Clear information. labelFormatValue->clear(); + labelCodecValue->clear(); + labelDurationValueTime->clear(); + labelDurationValueFrames->clear(); labelSizeValue->clear(); labelColorSpaceValue->clear(); @@ -409,8 +412,10 @@ Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame ) } else { - if( ( PlaYUVerFrame::isRGBorYUVorGray( pcFrame->getPelFormat() ) == PlaYUVerFrame::COLOR_RGB - || PlaYUVerFrame::isRGBorYUVorGray( pcFrame->getPelFormat() ) == PlaYUVerFrame::COLOR_ARGB ) && ( channelCB->count() == 1 ) ) + Int pel_fmt = pcFrame->getPelFormat(); + pel_fmt = PlaYUVerFrame::RGB8; + if( ( PlaYUVerFrame::isRGBorYUVorGray( pel_fmt ) == PlaYUVerFrame::COLOR_RGB + || PlaYUVerFrame::isRGBorYUVorGray( pel_fmt ) == PlaYUVerFrame::COLOR_ARGB ) && ( channelCB->count() == 1 ) ) { channelCB->addItem( tr( "Red" ) ); channelCB->setItemIcon( 1, QIcon( ":/images/channel-red.png" ) ); @@ -419,7 +424,7 @@ Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame ) channelCB->addItem( tr( "Blue" ) ); channelCB->setItemIcon( 3, QIcon( ":/images/channel-blue.png" ) ); - if( PlaYUVerFrame::isRGBorYUVorGray( pcFrame->getPelFormat() ) == PlaYUVerFrame::COLOR_ARGB ) + if( PlaYUVerFrame::isRGBorYUVorGray( pel_fmt ) == PlaYUVerFrame::COLOR_ARGB ) { channelCB->addItem( tr( "Alpha" ) ); channelCB->setItemIcon( 4, QIcon( ":/images/channel-alpha.png" ) ); @@ -442,7 +447,7 @@ Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame ) m_pcFrame = pcFrame; - if( !m_pcFrame->isValid() ) + if( m_pcFrame->isValid() ) { // 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 diff --git a/source/lib/PlaYUVerFrameStatistics.cpp b/source/lib/PlaYUVerFrameStatistics.cpp index 763e8aa..b45f124 100755 --- a/source/lib/PlaYUVerFrameStatistics.cpp +++ b/source/lib/PlaYUVerFrameStatistics.cpp @@ -29,6 +29,7 @@ #include #include "PlaYUVerFrameStatistics.h" +#include "LibMemory.h" namespace plaYUVer { @@ -64,7 +65,7 @@ public: } /** The histogram data.*/ - double *histogram; + Double *histogram; /** If true, calc the luminosity channel histogram when the image is RGB */ bool calcLuma; @@ -93,16 +94,18 @@ public: // Constructors and Destructor //////////////////////////////////////////////////////////////////////////////// -PlaYUVerFrameStatistics::PlaYUVerFrameStatistics( const PlaYUVerFrame& image, QObject *parent, Options options ) : +PlaYUVerFrameStatistics::PlaYUVerFrameStatistics( const PlaYUVerFrame& playuver_frame, QObject *parent, Options options ) : QThread() { - setup( image.getQImageBuffer(), image.getWidth(), image.getHeight(), image.getBitsChannel(), image.getPelFormat(), parent, options ); + // TODO: check the correct pel_format + setup( playuver_frame.getQImageBuffer(), playuver_frame.getWidth(), playuver_frame.getHeight(), playuver_frame.getBitsChannel(), PlaYUVerFrame::RGB8, parent, options ); } -PlaYUVerFrameStatistics::PlaYUVerFrameStatistics( uchar *data, uint width, uint height, int bitsPerChannel, Int pixel_format, QObject *parent, Options options ) : +PlaYUVerFrameStatistics::PlaYUVerFrameStatistics( Pel *data, uint width, uint height, int bitsPerChannel, Int pixel_format, QObject *parent, Options options ) : QThread() { - setup( data, width, height, bitsPerChannel, pixel_format, parent, options ); + // TODO: check the correct pel_format + setup( data, width, height, bitsPerChannel, PlaYUVerFrame::RGB8, parent, options ); } PlaYUVerFrameStatistics::~PlaYUVerFrameStatistics() @@ -118,7 +121,7 @@ PlaYUVerFrameStatistics::~PlaYUVerFrameStatistics() //////////////////////////////////////////////////////////////////////////////// // Setup Function //////////////////////////////////////////////////////////////////////////////// -void PlaYUVerFrameStatistics::setup( uchar *data, uint width, uint height, int bitsPerChannel, Int pixel_format, QObject *parent, Options options ) +void PlaYUVerFrameStatistics::setup( Pel *data, uint width, uint height, int bitsPerChannel, Int pixel_format, QObject *parent, Options options ) { d = new PlaYUVerFrameStatisticsPrivate; d->imageData = data; @@ -287,10 +290,7 @@ void PlaYUVerFrameStatistics::calcHistogramValues() if( d->parent ) postProgress( true, false ); - d->histogram = new double[d->histoSegments * d->histoChannels]; - -// Initialize the histogram - memset( d->histogram, 0, d->histoSegments * d->histoChannels * sizeof(double) ); + getMem1D( &(d->histogram ), d->histoSegments * d->histoChannels); if( !d->histogram ) { @@ -335,8 +335,8 @@ void PlaYUVerFrameStatistics::calcHistogramValues() // 8 bits images. else { - uchar *data = d->imageData; - uchar luma; + Pel *data = d->imageData; + Pel luma; for( i = 0; ( i < d->imageHeight * d->imageWidth ) && d->runningFlag; i++ ) { for( j = 0; j < d->imageChannels; j++ ) diff --git a/source/lib/PlaYUVerFrameStatistics.h b/source/lib/PlaYUVerFrameStatistics.h index 71c8afe..b736282 100755 --- a/source/lib/PlaYUVerFrameStatistics.h +++ b/source/lib/PlaYUVerFrameStatistics.h @@ -87,11 +87,11 @@ public: PlaYUVerFrameStatistics( uchar *data, uint width, uint height, int bitsPerChannel, Int pixel_format, QObject *parent = 0, Options options = CalcLumaWhenRGB ); - PlaYUVerFrameStatistics( const PlaYUVerFrame& image, QObject *parent = 0, Options options = CalcLumaWhenRGB ); + PlaYUVerFrameStatistics( const PlaYUVerFrame& playuver_frame, QObject *parent = 0, Options options = CalcLumaWhenRGB ); ~PlaYUVerFrameStatistics(); - void setup( uchar *data, uint width, uint height, int bitsPerChannel, Int pixel_format, QObject *parent = 0, Options options = CalcLumaWhenRGB ); + void setup( Pel *data, uint width, uint height, int bitsPerChannel, Int pixel_format, QObject *parent = 0, Options options = CalcLumaWhenRGB ); /** Method to stop threaded computations.*/ void stopCalcHistogramValues( void );