Update histogram. now it is based on the PlaYUVerStats

This commit is contained in:
jfmcarreira committed 2015-01-12 00:57:19 +00:00
1 parent 013eb9610c
commit 7f45d3c858
10 files changed
+135 -1016

No files matched your search

-1
View File
@@ -26,7 +26,6 @@ set(plaYUver_App_SRCS
# Docks / Sidebars
ModuleHandleDock.cpp
PropertiesSidebar.cpp
PlaYUVerFrameStatistics.cpp
QualityMeasurementSidebar.cpp
# Widgets
HistogramWidget.cpp
+111 -126
View File
@@ -25,29 +25,88 @@
//TODO:
// - Optimizar paintEvent. Parece haver codigo redundante !!
#include "config.h"
#include <cmath>
#include <QtGui>
#include <QtDebug>
#include "HistogramWidget.h"
#include "PlaYUVerFrameStatistics.h"
namespace plaYUVer
{
class HistogramWorker: public QThread
{
private:
QObject* m_parent;
PlaYUVerFrameStats* m_histogram;
public:
HistogramWorker( QObject* parent )
{
m_histogram = NULL;
m_parent = parent;
}
Void setup( PlaYUVerFrameStats* hist )
{
m_histogram = hist;
run();
}
Void run()
{
if( m_histogram && m_parent )
{
EventData *eventData = new EventData();
// eventData->starting = true;
// eventData->success = false;
// eventData->histogram = m_histogram;
// QCoreApplication::postEvent( m_parent, eventData );
m_histogram->calcHistogram();
eventData->starting = false;
eventData->success = m_histogram->getHasHistogram();
eventData->histogram = m_histogram;
QCoreApplication::postEvent( m_parent, eventData );
}
}
/**
* Custom Event
*/
class EventData: public QEvent
{
public:
EventData() :
QEvent( QEvent::User )
{
starting = false;
success = false;
histogram = 0;
}
bool starting;
bool success;
PlaYUVerFrameStats *histogram;
};
};
const QBrush g_eColorPallet[][3] =
{
{
Qt::darkGray, // Luma
Qt::blue, // Cb
Qt::red, // Cr
},
{
Qt::red, // Channel Red
Qt::green, // Channel Green
Qt::blue, // Channel Blue
}, };
{
Qt::darkGray, // Luma
Qt::blue, // Cb
Qt::red, // Cr
},
{
Qt::red, // Channel Red
Qt::green, // Channel Green
Qt::blue, // Channel Blue
}, };
class HistogramWidgetPrivate
{
@@ -123,6 +182,9 @@ HistogramWidget::HistogramWidget( Int width, Int height, QWidget *parent ) :
m_imageHistogram = 0;
m_selectionHistogram = 0;
m_imageWorker = new HistogramWorker( this );
m_selectionWorker = new HistogramWorker( this );
update();
}
@@ -139,6 +201,9 @@ HistogramWidget::~HistogramWidget()
if( m_selectionHistogram )
delete m_selectionHistogram;
delete m_imageWorker;
delete m_selectionWorker;
delete d;
}
////////////////////////////////////////////////////////////////////////////////
@@ -182,16 +247,8 @@ Void HistogramWidget::reset()
d->guideVisible = false;
d->clearFlag = HistogramWidgetPrivate::HistogramNone;
// Remove histogram data from memory.
if( m_imageHistogram )
{
delete m_imageHistogram;
m_imageHistogram = 0;
}
if( m_selectionHistogram )
{
delete m_selectionHistogram;
m_selectionHistogram = 0;
}
m_imageHistogram = NULL;
m_selectionHistogram = NULL;
update();
}
@@ -206,7 +263,7 @@ Void HistogramWidget::customEvent( QEvent *event )
return;
}
PlaYUVerFrameStatistics::EventData *ed = ( PlaYUVerFrameStatistics::EventData* )event;
HistogramWorker::EventData *ed = ( HistogramWorker::EventData* )event;
if( !ed )
{
@@ -325,11 +382,11 @@ Void HistogramWidget::setLoadingFailed()
Void HistogramWidget::stopHistogramComputation()
{
if( m_imageHistogram )
m_imageHistogram->stopCalcHistogramValues();
if( m_selectionHistogram )
m_selectionHistogram->stopCalcHistogramValues();
// if( m_imageHistogram )
// m_imageHistogram->setRunningFlag( false );
//
// if( m_selectionHistogram )
// m_selectionHistogram->setRunningFlag( false );
d->blinkTimer->stop();
}
@@ -338,59 +395,12 @@ Void HistogramWidget::stopHistogramComputation()
// Update Data Methods
////////////////////////////////////////////////////////////////////////////////
Void HistogramWidget::updateData( Pel ***imageData, UInt imageWidth, UInt imageHeight, Int bitsPerChannel, Int colorSpace, UInt chroma_size, Pel ***selData,
UInt selWidth, UInt selHeight )
{
d->sixteenBits = ( bool )( bitsPerChannel == 16 );
d->imageColorSpace = colorSpace;
switch( colorSpace )
{
case PlaYUVerFrame::COLOR_GRAY:
d->imageChannels = 1;
break;
case PlaYUVerFrame::COLOR_YUV:
case PlaYUVerFrame::COLOR_RGB:
d->imageChannels = 3;
break;
case PlaYUVerFrame::COLOR_ARGB:
d->imageChannels = 4;
break;
default:
d->imageChannels = 1;
}
// We are deleting the histogram data,
// so we must not use it to draw any more.
d->clearFlag = HistogramWidgetPrivate::HistogramNone;
// Do not using PlaYUVerFrameStatistics::getHistogramSegment()
// method here because histogram hasn't yet been computed.
d->range = d->sixteenBits ? 65535 : 255;
emit signalMaximumValueChanged( d->range );
// Remove old histogram data from memory.
if( m_imageHistogram )
delete m_imageHistogram;
if( m_selectionHistogram )
delete m_selectionHistogram;
// Calc new histogram data
m_imageHistogram = new PlaYUVerFrameStatistics( imageData, imageWidth, imageHeight, bitsPerChannel, colorSpace, chroma_size, this );
if( selData && selWidth && selHeight )
m_selectionHistogram = new PlaYUVerFrameStatistics( selData, selWidth, selHeight, bitsPerChannel, colorSpace, chroma_size, this );
else
m_selectionHistogram = 0L;
}
Void HistogramWidget::updateData( const PlaYUVerFrame *playuver_frame, const PlaYUVerFrame *playuver_selection )
Void HistogramWidget::updateData( const PlaYUVerFrame *pcFrame, const PlaYUVerFrame *pcFrameSelection )
{
d->sixteenBits = false;
//d->imageColorSpace = image.getPelFormat();
d->imageColorSpace = playuver_frame->getColorSpace();
d->imageChannels = playuver_frame->getNumberChannels();
d->imageColorSpace = pcFrame->getColorSpace();
d->imageChannels = pcFrame->getNumberChannels();
// We are deleting the histogram data,
// so we must not use it to draw any more.
@@ -402,43 +412,18 @@ Void HistogramWidget::updateData( const PlaYUVerFrame *playuver_frame, const Pla
d->range = d->sixteenBits ? 65535 : 255;
emit signalMaximumValueChanged( d->range );
// Remove old histogram data from memory.
if( m_imageHistogram )
delete m_imageHistogram;
m_imageHistogram = ( PlaYUVerFrameStats* )pcFrame;
m_imageWorker->setup( m_imageHistogram );
if( m_selectionHistogram )
delete m_selectionHistogram;
// Calc new histogram data
m_imageHistogram = new PlaYUVerFrameStatistics( playuver_frame, this );
if( playuver_selection )
m_selectionHistogram = new PlaYUVerFrameStatistics( playuver_selection, this );
else
m_selectionHistogram = NULL;
m_selectionHistogram = ( PlaYUVerFrameStats* )pcFrameSelection;
m_selectionWorker->setup( m_selectionHistogram );
}
Void HistogramWidget::updateSelectionData( Pel ***selData, UInt selWidth, UInt selHeight, Int bitsPerChannel, Int colorSpace, UInt chroma_size )
Void HistogramWidget::updateSelectionData( const PlaYUVerFrame *pcFrameSelection )
{
// Remove old histogram data from memory.
if( m_selectionHistogram )
delete m_selectionHistogram;
// Calc new histogram data
m_selectionHistogram = new PlaYUVerFrameStatistics( selData, selWidth, selHeight, bitsPerChannel, colorSpace, chroma_size, this );
}
Void HistogramWidget::updateSelectionData( const PlaYUVerFrame *selection )
{
// Remove old histogram data from memory.
if( m_selectionHistogram )
delete m_selectionHistogram;
m_selectionHistogram = new PlaYUVerFrameStatistics( selection, this );
m_selectionHistogram = ( PlaYUVerFrame* )pcFrameSelection;
m_selectionWorker->setup( m_selectionHistogram );
}
////////////////////////////////////////////////////////////////////////////////
@@ -522,7 +507,7 @@ Void HistogramWidget::paintEvent( QPaintEvent * )
int wWidth = width() - 1;
int wHeight = height() - 1;
double max;
class PlaYUVerFrameStatistics *histogram;
PlaYUVerFrameStats *histogram;
if( m_renderingType == ImageSelectionHistogram && m_selectionHistogram )
histogram = m_selectionHistogram;
@@ -542,24 +527,24 @@ Void HistogramWidget::paintEvent( QPaintEvent * )
switch( m_channelType )
{
case HistogramWidget::FirstChannelHistogram: // Y channel.
max = histogram->getMaximum( PlaYUVerFrameStatistics::YChannel );
max = histogram->getMaximum( PlaYUVerFrameStats::YChannel );
break;
case HistogramWidget::SecondChannelHistogram: // Cb channel.
max = histogram->getMaximum( PlaYUVerFrameStatistics::CbChannel );
max = histogram->getMaximum( PlaYUVerFrameStats::CbChannel );
break;
case HistogramWidget::ThirdChannelHistogram: // Cr channel.
max = histogram->getMaximum( PlaYUVerFrameStatistics::CrChannel );
max = histogram->getMaximum( PlaYUVerFrameStats::CrChannel );
break;
case HistogramWidget::AlphaChannelHistogram: // Alpha channel.
max = histogram->getMaximum( PlaYUVerFrameStatistics::AlphaChannel );
max = histogram->getMaximum( PlaYUVerFrameStats::AlphaChannel );
break;
case HistogramWidget::ColorChannelsHistogram: // All color channels.
max = qMax( qMax( histogram->getMaximum( PlaYUVerFrameStatistics::YChannel ), histogram->getMaximum( PlaYUVerFrameStatistics::CbChannel ) ),
histogram->getMaximum( PlaYUVerFrameStatistics::CrChannel ) );
max = qMax( qMax( histogram->getMaximum( PlaYUVerFrameStats::YChannel ), histogram->getMaximum( PlaYUVerFrameStats::CbChannel ) ),
histogram->getMaximum( PlaYUVerFrameStats::CrChannel ) );
break;
case HistogramWidget::LumaHistogram: // Luminance.
max = histogram->getMaximum( PlaYUVerFrameStatistics::LumaChannel );
max = histogram->getMaximum( PlaYUVerFrameStats::LumaChannel );
break;
}
@@ -606,24 +591,24 @@ Void HistogramWidget::paintEvent( QPaintEvent * )
switch( m_channelType )
{
case HistogramWidget::FirstChannelHistogram: // Y channel.
v = histogram->getValue( PlaYUVerFrameStatistics::YChannel, i++ );
v = histogram->getHistogramValue( PlaYUVerFrameStats::YChannel, i++ );
break;
case HistogramWidget::SecondChannelHistogram: // Cb channel.
v = histogram->getValue( PlaYUVerFrameStatistics::CbChannel, i++ );
v = histogram->getHistogramValue( PlaYUVerFrameStats::CbChannel, i++ );
break;
case HistogramWidget::ThirdChannelHistogram: // Cr channel.
v = histogram->getValue( PlaYUVerFrameStatistics::CrChannel, i++ );
v = histogram->getHistogramValue( PlaYUVerFrameStats::CrChannel, i++ );
break;
case HistogramWidget::AlphaChannelHistogram: // Alpha channel.
v = histogram->getValue( PlaYUVerFrameStatistics::AlphaChannel, i++ );
v = histogram->getHistogramValue( PlaYUVerFrameStats::AlphaChannel, i++ );
break;
case HistogramWidget::ColorChannelsHistogram: // All color.
vr = histogram->getValue( PlaYUVerFrameStatistics::YChannel, i );
vg = histogram->getValue( PlaYUVerFrameStatistics::CbChannel, i );
vb = histogram->getValue( PlaYUVerFrameStatistics::CrChannel, i++ );
vr = histogram->getHistogramValue( PlaYUVerFrameStats::YChannel, i );
vg = histogram->getHistogramValue( PlaYUVerFrameStats::CbChannel, i );
vb = histogram->getHistogramValue( PlaYUVerFrameStats::CrChannel, i++ );
break;
case HistogramWidget::LumaHistogram: // Luminance.
v = histogram->getValue( PlaYUVerFrameStatistics::LumaChannel, i++ );
v = histogram->getHistogramValue( PlaYUVerFrameStats::LumaChannel, i++ );
break;
}
+7 -15
View File
@@ -31,14 +31,13 @@
#include <QWidget>
#include <QColor>
#include "lib/PlaYUVerFrame.h"
#include "PlaYUVerFrameStatistics.h"
class QEvent;
namespace plaYUVer
{
class PlaYUVerFrameStatistics;
class HistogramWorker;
class HistogramWidgetPrivate;
class HistogramWidget: public QWidget
@@ -118,20 +117,11 @@ public :
/** Stop current histogram computations.*/
Void stopHistogramComputation();
/** Update full image histogram data methods.*/
Void updateData( Pel ***imageData, UInt imageWidth, UInt imageHeight,
Int bitsPerChannel, Int colorSpace, UInt chroma_size,
Pel ***selData = 0, UInt selWidth = 0, UInt selHeight = 0);
/** Update full image histogram data from SImage.*/
Void updateData( const PlaYUVerFrame *playuver_frame, const PlaYUVerFrame *playuver_selection );
/** Update image selection histogram data methods.*/
Void updateSelectionData( Pel ***selData, uint selWidth, uint selHeight,
Int bitsPerChannel, Int colorSpace, UInt chroma_size );
Void updateData( const PlaYUVerFrame *pcFrame, const PlaYUVerFrame *pcFrameSelection );
/** Update image selection histogram data from SImage.*/
Void updateSelectionData( const PlaYUVerFrame *imageSelection );
Void updateSelectionData( const PlaYUVerFrame *pcFrameSelection );
/** @see @p HistogramOption */
Void setOptions( HistogramOptions options = AllOptions );
@@ -153,9 +143,11 @@ public:
Int m_renderingType;
/** Full image */
PlaYUVerFrameStatistics *m_imageHistogram;
HistogramWorker* m_imageWorker;
PlaYUVerFrameStats* m_imageHistogram;
/** Histogram area selection */
PlaYUVerFrameStatistics *m_selectionHistogram;
HistogramWorker* m_selectionWorker;
PlaYUVerFrameStats* m_selectionHistogram;
Q_SIGNALS:
void signalIntervalChanged( int min, int max );
-571
View File
@@ -1,571 +0,0 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file PlaYUVerFrameStatistics.cpp
* \brief Measure PlaYUVerFrame statistics
* Based on the work of Ricardo N. Rocha Sardo in SCode project
*/
#include <cstdio>
#include <cmath>
#include <cstring>
#include <QtGui>
#include "PlaYUVerFrameStatistics.h"
#include "lib/LibMemory.h"
namespace plaYUVer
{
////////////////////////////////////////////////////////////////////////////////
// Private Data Class
////////////////////////////////////////////////////////////////////////////////
class PlaYUVerFrameStatisticsPrivate
{
public:
/*
// Using a structure instead a class is more fast
// (access with memset() and bytes manipulation).
struct double_packet
{
double luma;
double red;
double green;
double blue;
double alpha;
};
*/
public:
PlaYUVerFrameStatisticsPrivate()
{
parent = 0;
imageData = 0;
histogram = 0;
runningFlag = true;
}
/** The histogram data.*/
Double *histogram;
/** If true, calc the luminosity channel histogram when the image is RGB */
Bool calcLuma;
/** If the image is RGB and calcLuma is true, we have 1 more channel */
Int histoChannels;
/** Image information.*/
Pel ***imageData;
UInt imageWidth;
UInt imageHeight;
Int imageChannels;
Int imageColorSpace;
UInt imageChromaSize;
/** Numbers of histogram segments dependaing of image bytes depth*/
Int histoSegments;
/** To post event from thread to parent.*/
QObject *parent;
/** Used to stop thread during calculations.*/
Bool runningFlag;
};
////////////////////////////////////////////////////////////////////////////////
// Constructors and Destructor
////////////////////////////////////////////////////////////////////////////////
PlaYUVerFrameStatistics::PlaYUVerFrameStatistics( const PlaYUVerFrame *playuver_frame, QObject *parent, Options options ) :
QThread()
{
setup( playuver_frame->getPelBufferYUV(), playuver_frame->getWidth(), playuver_frame->getHeight(), playuver_frame->getBitsChannel(),
playuver_frame->getColorSpace(), playuver_frame->getChromaLength(), parent, options );
}
PlaYUVerFrameStatistics::PlaYUVerFrameStatistics( Pel ***data, UInt width, UInt height, Int bitsPerChannel, Int colorSpace, UInt chroma_size, QObject *parent,
Options options ) :
QThread()
{
setup( data, width, height, bitsPerChannel, colorSpace, chroma_size, parent, options );
}
PlaYUVerFrameStatistics::~PlaYUVerFrameStatistics()
{
stopCalcHistogramValues();
if( d->histogram )
delete[] d->histogram;
delete d;
}
////////////////////////////////////////////////////////////////////////////////
// Setup Function
////////////////////////////////////////////////////////////////////////////////
void PlaYUVerFrameStatistics::setup( Pel ***data, UInt width, UInt height, Int bitsPerChannel, Int colorSpace, UInt chroma_size, QObject *parent,
Options options )
{
d = new PlaYUVerFrameStatisticsPrivate;
d->imageData = data;
d->imageWidth = width;
d->imageHeight = height;
d->parent = parent;
d->histoSegments = ( bitsPerChannel == 16 ) ? 65536 : 256;
d->imageColorSpace = colorSpace;
d->imageChromaSize = chroma_size;
if( options == CalcLumaWhenRGB )
d->calcLuma = true;
else
d->calcLuma = false;
switch( d->imageColorSpace )
{
case PlaYUVerFrame::COLOR_GRAY:
d->imageChannels = 1;
break;
case PlaYUVerFrame::COLOR_RGB:
case PlaYUVerFrame::COLOR_YUV:
d->imageChannels = 3;
break;
case PlaYUVerFrame::COLOR_ARGB:
d->imageChannels = 4;
break;
default:
d->imageChannels = 1;
}
if( d->calcLuma && ( d->imageColorSpace == PlaYUVerFrame::COLOR_RGB ) )
d->histoChannels = d->imageChannels + 1;
else
d->histoChannels = d->imageChannels;
if( d->imageData && d->imageWidth && d->imageHeight )
{
if( d->parent )
start();
else
run(); //Lukas - substitui calcHistogramValues por run()
}
else
{
if( d->parent )
postProgress( false, false );
}
}
////////////////////////////////////////////////////////////////////////////////
// Accessing Properties
////////////////////////////////////////////////////////////////////////////////
int PlaYUVerFrameStatistics::getHistogramSegment( void )
{
return d->histoSegments;
}
int PlaYUVerFrameStatistics::getRealHistoChannel( int channel )
{
int histoChannel;
switch( d->imageColorSpace )
{
case PlaYUVerFrame::COLOR_GRAY:
if( channel != LumaChannel )
{
return -1;
}
histoChannel = 0;
break;
case PlaYUVerFrame::COLOR_RGB:
if( channel != RedChannel && channel != GreenChannel && channel != BlueChannel && ( channel != LumaChannel && d->calcLuma ) )
{
return -1;
}
else
{
if( channel == RedChannel )
histoChannel = 0;
if( channel == GreenChannel )
histoChannel = 1;
if( channel == BlueChannel )
histoChannel = 2;
if( channel == LumaChannel )
histoChannel = 3;
}
break;
case PlaYUVerFrame::COLOR_ARGB:
if( channel != RedChannel && channel != GreenChannel && channel != BlueChannel && channel != AlphaChannel && ( channel != LumaChannel && d->calcLuma ) )
{
return -1;
}
else
{
if( channel == AlphaChannel )
histoChannel = 0;
if( channel == RedChannel )
histoChannel = 1;
if( channel == GreenChannel )
histoChannel = 2;
if( channel == BlueChannel )
histoChannel = 3;
if( channel == LumaChannel )
histoChannel = 4;
}
break;
case PlaYUVerFrame::COLOR_YUV:
if( channel != LumaChannel && channel != YChannel && channel != CbChannel && channel != CrChannel )
{
return -1;
}
else
{
if( channel == YChannel || channel == LumaChannel)
histoChannel = 0;
if( channel == CbChannel )
histoChannel = 1;
if( channel == CrChannel )
histoChannel = 2;
}
break;
default:
histoChannel = -1;
}
return histoChannel;
}
////////////////////////////////////////////////////////////////////////////////
// Progress Indicators
////////////////////////////////////////////////////////////////////////////////
void PlaYUVerFrameStatistics::postProgress( bool starting, bool success )
{
EventData *eventData = new EventData();
eventData->starting = starting;
eventData->success = success;
eventData->histogram = this;
QCoreApplication::postEvent( d->parent, eventData );
}
void PlaYUVerFrameStatistics::stopCalcHistogramValues( void )
{
d->runningFlag = false;
wait();
}
////////////////////////////////////////////////////////////////////////////////
// List of threaded operations
////////////////////////////////////////////////////////////////////////////////
void PlaYUVerFrameStatistics::run()
{
calcHistogramValues();
}
void PlaYUVerFrameStatistics::calcHistogramValues()
{
register uint i;
register int j;
if( d->parent )
postProgress( true, false );
getMem1D<Double>( &( d->histogram ), d->histoSegments * d->histoChannels );
if( !d->histogram )
{
qWarning( ) << "PlaYUVerFrameStatistics::calcHistogramValuess: "
"Unable to allocate memory!"
<< endl;
if( d->parent )
postProgress( false, false );
return;
}
if( d->imageColorSpace == PlaYUVerFrame::COLOR_YUV )
{
Pel *data[3];
data[LUMA] = d->imageData[LUMA][0];
data[CHROMA_U] = d->imageData[CHROMA_U][0];
data[CHROMA_V] = d->imageData[CHROMA_V][0];
for( i = 0; ( i < d->imageHeight * d->imageWidth ) && d->runningFlag; i++ )
{
d->histogram[*( data[LUMA] ) + LUMA * d->histoSegments]++;
data[LUMA] += 1;
}
for( i = 0; ( i < d->imageChromaSize ) && d->runningFlag; i++ )
{
for( j = 1; j < d->imageChannels; j++ )
{
d->histogram[*( data[j] ) + j * d->histoSegments]++;
}
for( j = 1; j < d->imageChannels; j++ )
data[j] += 1;
}
}
else
{
Pel *data[3], luma;
data[COLOR_R] = d->imageData[COLOR_R][0];
data[COLOR_G] = d->imageData[COLOR_G][0];
data[COLOR_B] = d->imageData[COLOR_B][0];
for( i = 0; ( i < d->imageHeight * d->imageWidth ) && d->runningFlag; i++ )
{
for( j = 0; j < d->imageChannels; j++ )
{
d->histogram[*( data[j] ) + j * d->histoSegments]++;
}
if( d->calcLuma && ( d->imageColorSpace == PlaYUVerFrame::COLOR_RGB || d->imageColorSpace == PlaYUVerFrame::COLOR_ARGB ) )
{
PlaYUVerFrame::Pixel currPixel( d->imageColorSpace, *( data[COLOR_R] ), *( data[COLOR_G] ), *( data[COLOR_B] ) );
luma = PlaYUVerFrame::ConvertPixel( currPixel, PlaYUVerFrame::COLOR_YUV ).Y();
d->histogram[luma + j * d->histoSegments]++;
}
for( j = 0; j < d->imageChannels; j++ )
data[j] += 1;
}
}
if( d->parent && d->runningFlag )
postProgress( false, true );
}
double PlaYUVerFrameStatistics::getCount( int channel, int start, int end )
{
int i;
int histoChannel;
int indexStart;
double count = 0.0;
if( !d->histogram || start < 0 || end > d->histoSegments - 1 || start > end )
{
return 0.0;
}
histoChannel = getRealHistoChannel( channel );
if( histoChannel == -1 )
{
return 0.0;
}
indexStart = histoChannel * d->histoSegments;
for( i = start; i <= end; i++ )
{
count += d->histogram[indexStart + i];
}
return count;
}
double PlaYUVerFrameStatistics::getPixels()
{
if( !d->histogram )
{
return 0.0;
}
return ( d->imageWidth * d->imageHeight );
}
double PlaYUVerFrameStatistics::getMean( int channel, int start, int end )
{
int i;
int indexStart;
int histoChannel;
double mean = 0.0;
double count;
if( !d->histogram || start < 0 || end > d->histoSegments - 1 || start > end )
{
return 0.0;
}
histoChannel = getRealHistoChannel( channel );
if( histoChannel == -1 )
{
return 0.0;
}
indexStart = histoChannel * d->histoSegments;
for( i = start; i <= end; i++ )
{
mean += i * d->histogram[indexStart + i];
}
count = getCount( channel, start, end );
if( count > 0.0 )
{
return mean / count;
}
return mean;
}
int PlaYUVerFrameStatistics::getMedian( int channel, int start, int end )
{
int i;
int histoChannel;
int indexStart;
double sum = 0.0;
double count;
if( !d->histogram || start < 0 || end > d->histoSegments - 1 || start > end )
{
return 0;
}
histoChannel = getRealHistoChannel( channel );
if( histoChannel == -1 )
{
return 0;
}
indexStart = histoChannel * d->histoSegments;
count = getCount( channel, start, end );
for( i = start; i <= end; i++ )
{
sum += d->histogram[indexStart + i];
if( sum * 2 > count )
return i;
}
return 0;
}
double PlaYUVerFrameStatistics::getStdDev( int channel, int start, int end )
{
int i;
int histoChannel;
int indexStart;
double dev = 0.0;
double count;
double mean;
if( !d->histogram || start < 0 || end > d->histoSegments - 1 || start > end )
{
return 0.0;
}
histoChannel = getRealHistoChannel( channel );
if( histoChannel == -1 )
{
return 0.0;
}
indexStart = histoChannel * d->histoSegments;
mean = getMean( channel, start, end );
count = getCount( channel, start, end );
if( count == 0.0 )
count = 1.0;
/*------------ original
for ( i = start ; i <= end ; i++ )
{
dev += ( i - mean ) * ( i - mean ) * d->histogram[indexStart +i];
}
return sqrt( dev / count );
-----------------------*/
for( i = start; i <= end; i++ )
{
dev += ( i * i ) * d->histogram[indexStart + i];
}
return sqrt( ( dev - count * mean * mean ) / ( count - 1 ) );
}
double PlaYUVerFrameStatistics::getValue( int channel, int bin )
{
double value;
int histoChannel;
int indexStart;
if( !d->histogram || bin < 0 || bin > d->histoSegments - 1 )
return 0.0;
histoChannel = getRealHistoChannel( channel );
if( histoChannel == -1 )
{
return 0.0;
}
indexStart = histoChannel * d->histoSegments;
value = d->histogram[indexStart + bin];
return value;
}
double PlaYUVerFrameStatistics::getMaximum( int channel )
{
double max = 0.0;
int x;
int histoChannel;
int indexStart;
if( !d->histogram )
return 0.0;
histoChannel = getRealHistoChannel( channel );
if( histoChannel == -1 )
{
return 0.0;
}
indexStart = histoChannel * d->histoSegments;
for( x = 0; x < d->histoSegments; x++ )
{
if( d->histogram[indexStart + x] > max )
{
max = d->histogram[indexStart + x];
}
}
return max;
}
} // NAMESPACE
-137
View File
@@ -1,137 +0,0 @@
/* This file is a part of plaYUVer project
* Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com)
* Joao Carreira (jfmcarreira@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file PlaYUVerFrameStatistics.h
* \brief Measure PlaYUVerFrame statistics
* Based on the work of Ricardo N. Rocha Sardo in SCode project
*/
#ifndef __PLAYUVERFRAMESTATISTICS_H_
#define __PLAYUVERFRAMESTATISTICS_H_
#include <QThread>
#include "lib/PlaYUVerFrame.h"
#include "lib/PlaYUVerDefs.h"
class QObject;
namespace plaYUVer
{
class PlaYUVerFrameStatisticsPrivate;
/**
* Esta classe permite obter o histograma de uma imagem assim como algumas
* estatísticas.
*/
class PlaYUVerFrameStatistics: public QThread
{
public:
enum StatisticsChannel
{
LumaChannel = 0,
RedChannel = 1,
GreenChannel = 2,
BlueChannel = 3,
AlphaChannel = 4,
YChannel = 1,
CbChannel = 2,
CrChannel = 3
};
enum Options
{
CalcLumaWhenRGB = 0
};
/**
* Custom Event
*/
class EventData: public QEvent
{
public:
EventData() :
QEvent( QEvent::User )
{
starting = false;
success = false;
histogram = 0;
}
bool starting;
bool success;
PlaYUVerFrameStatistics *histogram;
};
public:
PlaYUVerFrameStatistics( Pel ***data, UInt width, UInt height, Int bitsPerChannel, Int pixel_format, UInt chroma_size,
QObject *parent = 0, Options options = CalcLumaWhenRGB );
PlaYUVerFrameStatistics( const PlaYUVerFrame *playuver_frame, QObject *parent = 0, Options options = CalcLumaWhenRGB );
~PlaYUVerFrameStatistics();
void setup( Pel ***data, UInt width, UInt height, Int bitsPerChannel, Int colorSpace, UInt chroma_size, QObject *parent = 0, Options options = CalcLumaWhenRGB );
/** Method to stop threaded computations.*/
void stopCalcHistogramValues( void );
// Methods for to manipulate the histogram data.
double getCount( int channel, int start, int end );
double getMean( int channel, int start, int end );
/**
* @return Number of image pixels
*/
double getPixels();
double getStdDev( int channel, int start, int end );
double getValue( int channel, int bin );
double getMaximum( int channel );
/**
* @return Number of histogram segments: 256 or 65536 for 8 or 16 bits per
* sample.
*/
int getHistogramSegment( void );
int getMedian( int channel, int start, int end );
private:
PlaYUVerFrameStatisticsPrivate *d;
private:
int getRealHistoChannel( int channel );
void calcHistogramValues();
void postProgress( bool starting, bool success );
protected:
virtual void run();
};
} // NAMESPACE
#endif // __PLAYUVERFRAMESTATISTICS_H_
+1 -138
View File
@@ -39,143 +39,6 @@ static inline QSize bestSize( QSize currSize )
return currSize;
}
////////////////////////////////////////////////////////////////////////////////
// StreamPropertiesSideBar
////////////////////////////////////////////////////////////////////////////////
StreamPropertiesSideBar::StreamPropertiesSideBar( QWidget* parent ) :
QWidget( parent )
{
// -------------- Variables definition --------------
m_pcStream = NULL;
// ----------------- GUI definition -----------------
QLabel *streamNameLabel = new QLabel( tr( "Name:" ) );
streamNameLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
labelNameValue = new QLabel;
labelNameValue->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
labelNameValue->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
QLabel *formatLabel = new QLabel( tr( "File Format:" ) );
formatLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
labelFormatValue = new QLabel;
labelFormatValue->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
QLabel *codecLabel = new QLabel( tr( "Codec:" ) );
codecLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
labelCodecValue = new QLabel;
labelCodecValue->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
QLabel *durationLabel = new QLabel( tr( "Duration:" ) );
durationLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
labelDurationValueTime = new QLabel;
labelDurationValueTime->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
labelDurationValueFrames = new QLabel;
labelDurationValueFrames->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
QLabel *sizeLabel = new QLabel( tr( "Resolution:" ) );
sizeLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
labelSizeValue = new QLabel;
labelSizeValue->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
QLabel *colorSpaceLabel = new QLabel( tr( "Color Space:" ) );
colorSpaceLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
labelColorSpaceValue = new QLabel;
labelColorSpaceValue->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
QGridLayout *propertiesLayout = new QGridLayout;
Int layout_line = 0;
// propertiesLayout->addWidget( streamNameLabel, layout_line, 0 );
// propertiesLayout->addWidget( labelNameValue, layout_line, 1 );
// layout_line++;
propertiesLayout->addWidget( formatLabel, layout_line, 0 );
propertiesLayout->addWidget( labelFormatValue, layout_line, 1 );
layout_line++;
propertiesLayout->addWidget( codecLabel, layout_line, 0 );
propertiesLayout->addWidget( labelCodecValue, layout_line, 1 );
layout_line++;
propertiesLayout->addWidget( durationLabel, layout_line, 0 );
propertiesLayout->addWidget( labelDurationValueTime, layout_line, 1 );
layout_line++;
propertiesLayout->addWidget( labelDurationValueFrames, layout_line, 1 );
layout_line++;
propertiesLayout->addWidget( sizeLabel, layout_line, 0 );
propertiesLayout->addWidget( labelSizeValue, layout_line, 1 );
layout_line++;
propertiesLayout->addWidget( colorSpaceLabel, layout_line, 0 );
propertiesLayout->addWidget( labelColorSpaceValue, layout_line, 1 );
propertiesLayout->setRowStretch( 8, 10 );
setLayout( propertiesLayout );
//QGroupBox *propertiesGroup = new QGroupBox;
//propertiesGroup->setLayout( propertiesLayout );
//QGridLayout *mainLayout = new QGridLayout;
//mainLayout->addWidget( propertiesGroup );
//mainLayout->setRowStretch( 8, 10 );
//setLayout( mainLayout );
setEnabled( false );
}
StreamPropertiesSideBar::~StreamPropertiesSideBar()
{
}
QSize StreamPropertiesSideBar::sizeHint() const
{
return bestSize( size() );
}
Void StreamPropertiesSideBar::setData( PlaYUVerStream* pcStream )
{
// Clear information.
labelNameValue->clear();
labelFormatValue->clear();
labelCodecValue->clear();
labelDurationValueTime->clear();
labelDurationValueFrames->clear();
labelSizeValue->clear();
labelColorSpaceValue->clear();
if( !pcStream || !pcStream->getCurrFrame() )
{
setEnabled( false );
return;
}
else
{
m_pcStream = pcStream;
setEnabled( true );
labelNameValue->setText( QFileInfo( m_pcStream->getFileName() ).fileName() );
labelFormatValue->setText( m_pcStream->getFormatName() );
labelCodecValue->setText( m_pcStream->getCodecName() );
Int duration[3];
m_pcStream->getDuration( duration );
QString value;
value = QString( tr( "%1h:%2m:%3s" ) ).arg( duration[0] ).arg( duration[1] ).arg( duration[2] );
labelDurationValueTime->setText( value );
value = QString( tr( "%1 frms" ) ).arg( m_pcStream->getFrameNum() );
labelDurationValueFrames->setText( value );
UInt width = m_pcStream->getWidth();
UInt height = m_pcStream->getHeight();
UInt fps = m_pcStream->getFrameRate();
value = QString( tr( "%1 x %2 @ %3 Hz" ) ).arg( width ).arg( height ).arg( fps );
labelSizeValue->setText( value );
value = QString( PlaYUVerFrame::supportedPixelFormatListNames().at( m_pcStream->getCurrFrame()->getPelFormat() ) );
labelColorSpaceValue->setText( value );
}
}
////////////////////////////////////////////////////////////////////////////////
// FramePropertiesSideBar
////////////////////////////////////////////////////////////////////////////////
FramePropertiesSideBar::FramePropertiesSideBar( QWidget* parent, Bool* pbMainPlaySwitch ) :
QWidget( parent ),
pbMainPlaySwitch( pbMainPlaySwitch )
@@ -558,7 +421,7 @@ Void FramePropertiesSideBar::updateStatistiques()
if( channel == HistogramWidget::ColorChannelsHistogram )
channel = colorsCB->currentIndex() + 1;
PlaYUVerFrameStatistics *histogram;
PlaYUVerFrameStats* histogram;
if( histogramWidget->m_renderingType == HistogramWidget::FullImageHistogram )
histogram = histogramWidget->m_imageHistogram;
-24
View File
@@ -40,30 +40,6 @@
namespace plaYUVer
{
class StreamPropertiesSideBar: public QWidget
{
Q_OBJECT
public:
StreamPropertiesSideBar( QWidget* parent );
~StreamPropertiesSideBar();
QSize sizeHint() const;
Void setData( PlaYUVerStream* m_pcStream );
private:
PlaYUVerStream* m_pcStream;
Bool m_bIsVisible;
QLabel* labelNameValue;
QLabel* labelFormatValue;
QLabel* labelCodecValue;
QLabel* labelDurationValueTime;
QLabel* labelDurationValueFrames;
QLabel* labelSizeValue;
QLabel* labelColorSpaceValue;
};
class FramePropertiesSideBar: public QWidget
{
Q_OBJECT
+1 -1
View File
@@ -458,11 +458,11 @@ Void plaYUVerApp::update()
//if( activeSubWindow() != m_pcCurrentSubWindow )
{
m_pcCurrentSubWindow = NULL;
m_pcCurrentVideoSubWindow = NULL;
if( activeSubWindow() )
{
m_pcCurrentSubWindow = new_window;
m_pcCurrentVideoSubWindow = NULL;
switch( m_pcCurrentSubWindow->getCategory() )
{
case SubWindowHandle::VIDEO_SUBWINDOW:
+3 -2
View File
@@ -72,6 +72,7 @@ Void PlaYUVerFrameStats::xSetupStatistics( const PlaYUVerFrame *pcFrame, UInt op
Void PlaYUVerFrameStats::calcHistogram()
{
m_bRunningFlag = true;
m_bHasHistogram = false;
getMem1D<Double>( &( m_pdHistogram ), m_uiHistoSegments * histoChannels );
@@ -97,7 +98,7 @@ Void PlaYUVerFrameStats::calcHistogram()
m_pdHistogram[*( data[LUMA] ) + LUMA * m_uiHistoSegments]++;
data[LUMA] += 1;
}
for( i = 0; ( i < imageChromaSize ) && runningFlag; i++ )
for( i = 0; ( i < imageChromaSize ) && m_bRunningFlag; i++ )
{
for( j = 1; j < m_uiChannels; j++ )
{
@@ -115,7 +116,7 @@ Void PlaYUVerFrameStats::calcHistogram()
data[COLOR_G] = m_pppImageData[COLOR_G][0];
data[COLOR_B] = m_pppImageData[COLOR_B][0];
for( i = 0; ( i < m_uiImageHeight * m_uiImageWidth ) && runningFlag; i++ )
for( i = 0; ( i < m_uiImageHeight * m_uiImageWidth ) && m_bRunningFlag; i++ )
{
for( j = 0; j < m_uiChannels; j++ )
{
+12 -1
View File
@@ -80,6 +80,17 @@ public:
*/
Int getHistogramSegment();
/**
* Control calculation
*/
Void setRunningFlag( Bool bFlag )
{
m_bRunningFlag = bFlag;
}
Bool getHasHistogram()
{
return m_bHasHistogram;
}
private:
/** The histogram data.*/
@@ -103,7 +114,7 @@ private:
UInt m_uiHistoSegments;
/** Used to stop thread during calculations.*/
Bool runningFlag;
Bool m_bRunningFlag;
Int getRealHistoChannel( Int channel );