Improve Properties side bar

Significantly improve the histogram to support both YUV and RGB
Still needs to confirmation and code arrangements
This commit is contained in:
jfmcarreira committed 2014-04-05 19:52:15 +01:00
1 parent a2d51d18f1
commit 2542958f03
6 files changed
+135 -133

No files matched your search

+21 -29
View File
@@ -314,8 +314,8 @@ void HistogramWidget::stopHistogramComputation( void )
// Update Data Methods
////////////////////////////////////////////////////////////////////////////////
void HistogramWidget::updateData( uchar *imageData, uint imageWidth, uint imageHeight, int bitsPerChannel, Int pixel_format, uchar *selData, uint selWidth,
uint selHeight )
void HistogramWidget::updateData( Pel ***imageData, UInt imageWidth, UInt imageHeight, Int bitsPerChannel, Int pixel_format, UInt chroma_size, Pel ***selData,
UInt selWidth, UInt selHeight )
{
Int colorSpace = PlaYUVerFrame::isRGBorYUVorGray( pixel_format );
d->sixteenBits = ( bool )( bitsPerChannel == 16 );
@@ -323,10 +323,10 @@ void HistogramWidget::updateData( uchar *imageData, uint imageWidth, uint imageH
switch( colorSpace )
{
case PlaYUVerFrame::COLOR_YUV:
case PlaYUVerFrame::COLOR_GRAY:
d->imageChannels = 1;
break;
case PlaYUVerFrame::COLOR_YUV:
case PlaYUVerFrame::COLOR_RGB:
d->imageChannels = 3;
break;
@@ -354,10 +354,10 @@ void HistogramWidget::updateData( uchar *imageData, uint imageWidth, uint imageH
delete m_selectionHistogram;
// Calc new histogram data
m_imageHistogram = new PlaYUVerFrameStatistics( imageData, imageWidth, imageHeight, bitsPerChannel, colorSpace, this );
m_imageHistogram = new PlaYUVerFrameStatistics( imageData, imageWidth, imageHeight, bitsPerChannel, pixel_format, chroma_size, this );
if( selData && selWidth && selHeight )
m_selectionHistogram = new PlaYUVerFrameStatistics( selData, selWidth, selHeight, bitsPerChannel, colorSpace, this );
m_selectionHistogram = new PlaYUVerFrameStatistics( selData, selWidth, selHeight, bitsPerChannel, pixel_format, chroma_size, this );
else
m_selectionHistogram = 0L;
}
@@ -366,7 +366,7 @@ void HistogramWidget::updateData( const PlaYUVerFrame &playuver_frame, const Pla
{
d->sixteenBits = false;
//d->imageColorSpace = image.getPelFormat();
d->imageColorSpace = PlaYUVerFrame::RGB8;
d->imageColorSpace = PlaYUVerFrame::isRGBorYUVorGray( playuver_frame.getPelFormat() );
d->imageChannels = playuver_frame.getNumberChannels();
// We are deleting the histogram data,
@@ -396,7 +396,7 @@ void HistogramWidget::updateData( const PlaYUVerFrame &playuver_frame, const Pla
}
void HistogramWidget::updateSelectionData( uchar *selData, uint selWidth, uint selHeight, int bitsPerChannel, Int colorSpace )
void HistogramWidget::updateSelectionData( Pel ***selData, UInt selWidth, UInt selHeight, Int bitsPerChannel, Int pixel_format, UInt chroma_size )
{
// Remove old histogram data from memory.
@@ -404,7 +404,7 @@ void HistogramWidget::updateSelectionData( uchar *selData, uint selWidth, uint s
delete m_selectionHistogram;
// Calc new histogram data
m_selectionHistogram = new PlaYUVerFrameStatistics( selData, selWidth, selHeight, bitsPerChannel, colorSpace, this );
m_selectionHistogram = new PlaYUVerFrameStatistics( selData, selWidth, selHeight, bitsPerChannel, pixel_format, chroma_size, this );
}
void HistogramWidget::updateSelectionData( const PlaYUVerFrame &selection )
@@ -507,18 +507,15 @@ void HistogramWidget::paintEvent( QPaintEvent * )
switch( m_channelType )
{
case HistogramWidget::GreenChannelHistogram: // Green channel.
max = histogram->getMaximum( PlaYUVerFrameStatistics::GreenChannel );
break;
case HistogramWidget::BlueChannelHistogram: // Blue channel.
max = histogram->getMaximum( PlaYUVerFrameStatistics::BlueChannel );
break;
case HistogramWidget::RedChannelHistogram: // Red channel.
max = histogram->getMaximum( PlaYUVerFrameStatistics::RedChannel );
break;
case HistogramWidget::GreenChannelHistogram: // Green channel.
max = histogram->getMaximum( PlaYUVerFrameStatistics::GreenChannel );
break;
case HistogramWidget::BlueChannelHistogram: // Blue channel.
max = histogram->getMaximum( PlaYUVerFrameStatistics::BlueChannel );
break;
case HistogramWidget::AlphaChannelHistogram: // Alpha channel.
max = histogram->getMaximum( PlaYUVerFrameStatistics::AlphaChannel );
break;
@@ -527,7 +524,6 @@ void HistogramWidget::paintEvent( QPaintEvent * )
max = qMax( qMax( histogram->getMaximum( PlaYUVerFrameStatistics::RedChannel ), histogram->getMaximum( PlaYUVerFrameStatistics::GreenChannel ) ),
histogram->getMaximum( PlaYUVerFrameStatistics::BlueChannel ) );
break;
case HistogramWidget::LumaHistogram: // Luminance.
max = histogram->getMaximum( PlaYUVerFrameStatistics::LumaChannel );
break;
@@ -574,31 +570,27 @@ void HistogramWidget::paintEvent( QPaintEvent * )
switch( m_channelType )
{
case HistogramWidget::GreenChannelHistogram: // Green channel.
v = histogram->getValue( PlaYUVerFrameStatistics::GreenChannel, i++ );
break;
case HistogramWidget::BlueChannelHistogram: // Blue channel.
v = histogram->getValue( PlaYUVerFrameStatistics::BlueChannel, i++ );
break;
case HistogramWidget::RedChannelHistogram: // Red channel.
v = histogram->getValue( PlaYUVerFrameStatistics::RedChannel, i++ );
break;
case HistogramWidget::GreenChannelHistogram: // Green channel.
v = histogram->getValue( PlaYUVerFrameStatistics::GreenChannel, i++ );
break;
case HistogramWidget::BlueChannelHistogram: // Blue channel.
v = histogram->getValue( PlaYUVerFrameStatistics::BlueChannel, i++ );
break;
case HistogramWidget::AlphaChannelHistogram: // Alpha channel.
v = histogram->getValue( PlaYUVerFrameStatistics::AlphaChannel, i++ );
break;
case HistogramWidget::ColorChannelsHistogram: // All color.
vr = histogram->getValue( PlaYUVerFrameStatistics::RedChannel, i );
vg = histogram->getValue( PlaYUVerFrameStatistics::GreenChannel, i );
vb = histogram->getValue( PlaYUVerFrameStatistics::BlueChannel, i++ );
break;
case HistogramWidget::LumaHistogram: // Luminance.
v = histogram->getValue( PlaYUVerFrameStatistics::LumaChannel, i++ );
break;
}
if( m_channelType != HistogramWidget::ColorChannelsHistogram )
+7 -9
View File
@@ -49,16 +49,14 @@ public:
{
/** Luminance */
LumaHistogram = 0,
/** Red channel */
/** RGB channels */
RedChannelHistogram,
/** Green channel */
GreenChannelHistogram,
/** Blue channel */
BlueChannelHistogram,
/** Alpha channel */
AlphaChannelHistogram,
/** All color channels */
ColorChannelsHistogram
ColorChannelsHistogram,
};
enum HistogramScale
@@ -121,16 +119,16 @@ public :
void stopHistogramComputation( void );
/** Update full image histogram data methods.*/
void updateData( uchar *imageData, uint imageWidth, uint imageHeight,
int bitsPerChannel, Int pixel_format,
uchar *selData = 0, uint selWidth = 0, uint selHeight = 0);
void updateData( Pel ***imageData, UInt imageWidth, UInt imageHeight,
Int bitsPerChannel, Int pixel_format, 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( uchar *selData, uint selWidth, uint selHeight,
int bitsPerChannel, Int colorSpace );
void updateSelectionData( Pel ***selData, uint selWidth, uint selHeight,
Int bitsPerChannel, Int pixel_format, UInt chroma_size );
/** Update image selection histogram data from SImage.*/
void updateSelectionData( const PlaYUVerFrame &imageSelection );
+27 -16
View File
@@ -413,28 +413,33 @@ Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame )
else
{
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 ) )
if( ( PlaYUVerFrame::isRGBorYUVorGray( pel_fmt ) == PlaYUVerFrame::COLOR_RGB || PlaYUVerFrame::isRGBorYUVorGray( pel_fmt ) == PlaYUVerFrame::COLOR_ARGB ) )
{
channelCB->addItem( tr( "Red" ) );
channelCB->setItemIcon( 1, QIcon( ":/images/channel-red.png" ) );
channelCB->addItem( tr( "Green" ) );
channelCB->setItemIcon( 2, QIcon( ":/images/channel-green.png" ) );
channelCB->addItem( tr( "Blue" ) );
channelCB->setItemIcon( 3, QIcon( ":/images/channel-blue.png" ) );
channelCB->clear();
channelCB->clear();
channelCB->insertItem( LuminosityChannel, QIcon( ":/images/channel-luma.png" ), "Luminance" );
channelCB->insertItem( RedChannel, QIcon( ":/images/channel-red.png" ), "Red" );
channelCB->insertItem( GreenChannel, QIcon( ":/images/channel-green.png" ), "Green" );
channelCB->insertItem( BlueChannel, QIcon( ":/images/channel-blue.png" ), "Blue" );
if( PlaYUVerFrame::isRGBorYUVorGray( pel_fmt ) == PlaYUVerFrame::COLOR_ARGB )
{
channelCB->addItem( tr( "Alpha" ) );
channelCB->setItemIcon( 4, QIcon( ":/images/channel-alpha.png" ) );
channelCB->insertItem( AlphaChannel, QIcon( ":/images/channel-alpha.png" ), "Alpha" );
}
channelCB->addItem( QIcon( ":/images/channel-all.png" ), tr( "Colors" ) );
channelCB->insertItem( ColorChannels, QIcon( ":/images/channel-all.png" ), "Colors" );
colorsCB->show();
colorsLabel->show();
}
else if( channelCB->count() != 1 )
else if( PlaYUVerFrame::isRGBorYUVorGray( pel_fmt ) == PlaYUVerFrame::COLOR_YUV )
{
channelCB->clear();
channelCB->insertItem( LuminosityChannel, QIcon( ":/images/channel-luma.png" ), "Luminance" );
channelCB->insertItem( ChromaUhannel, QIcon( ":/images/channel-red.png" ), "Chroma U" );
channelCB->insertItem( ChromaVhannel, QIcon( ":/images/channel-green.png" ), "Chroma V" );
channelCB->insertItem( ColorChannels, QIcon( ":/images/channel-all.png" ), "All Channels" );
colorsCB->show();
colorsLabel->show();
}
else
{
channelCB->clear();
channelCB->addItem( tr( "Luminance" ) );
@@ -532,6 +537,11 @@ void FramePropertiesSideBar::slotHistogramComputationFailed()
void FramePropertiesSideBar::slotChannelChanged( int channel )
{
if( PlaYUVerFrame::isRGBorYUVorGray( m_pcFrame->getPelFormat() ) == PlaYUVerFrame::COLOR_YUV )
channel += 1;
if( channel == AlphaChannel && PlaYUVerFrame::isRGBorYUVorGray( m_pcFrame->getPelFormat() ) != PlaYUVerFrame::COLOR_ARGB )
channel = ColorChannels;
switch( channel )
{
case RedChannel:
@@ -679,7 +689,8 @@ void FramePropertiesSideBar::updateStatistiques()
int min = minInterv->value();
int max = maxInterv->value();
int channel = channelCB->currentIndex();
int channel = histogramWidget->m_channelType;
//int channel = channelCB->currentIndex();
if( channel == HistogramWidget::ColorChannelsHistogram )
channel = colorsCB->currentIndex() + 1;
+23 -21
View File
@@ -75,19 +75,21 @@ public:
private:
enum ColorChannel
{
LuminosityChannel=0,
RedChannel,
GreenChannel,
BlueChannel,
AlphaChannel,
ColorChannels
LuminosityChannel = 0,
RedChannel = 1,
ChromaUhannel = 1,
GreenChannel = 2,
ChromaVhannel = 2,
BlueChannel = 3,
AlphaChannel = 5,
ColorChannels = 4,
};
enum AllColorsColorType
{
AllColorsRed=0,
AllColorsGreen,
AllColorsBlue
AllColorsRed = 0,
AllColorsGreen,
AllColorsBlue
};
PlaYUVerFrame *m_pcFrame;
@@ -128,21 +130,21 @@ private:
HistogramWidget *histogramWidget;
private:
void updateInformations();
void updateStatistiques();
void updateInformations();
void updateStatistiques();
private Q_SLOTS:
void slotRefreshOptions( bool sixteenBit );
void slotHistogramComputationFailed( void );
void slotChannelChanged( int channel );
void slotScaleChanged( int scale );
void slotColorsChanged( int color );
void slotRenderingChanged( int rendering );
void slotMinValueChanged( int );
void slotMaxValueChanged( int );
void slotRefreshOptions( bool sixteenBit );
void slotHistogramComputationFailed( void );
void slotChannelChanged( int channel );
void slotScaleChanged( int scale );
void slotColorsChanged( int color );
void slotRenderingChanged( int rendering );
void slotMinValueChanged( int );
void slotMaxValueChanged( int );
void slotUpdateInterval( int min, int max );
void slotUpdateIntervRange( int range );
void slotUpdateInterval( int min, int max );
void slotUpdateIntervRange( int range );
};
+51 -53
View File
@@ -68,26 +68,27 @@ public:
Double *histogram;
/** If true, calc the luminosity channel histogram when the image is RGB */
bool calcLuma;
Bool calcLuma;
/** If the image is RGB and calcLuma is true, we have 1 more channel */
int histoChannels;
Int histoChannels;
/** Image information.*/
uchar *imageData;
uint imageWidth;
uint imageHeight;
int imageChannels;
Pel ***imageData;
UInt imageWidth;
UInt imageHeight;
Int imageChannels;
Int imageColorSpace;
UInt imageChromaSize;
/** Numbers of histogram segments dependaing of image bytes depth*/
int histoSegments;
Int histoSegments;
/** To post event from thread to parent.*/
QObject *parent;
/** Used to stop thread during calculations.*/
bool runningFlag;
Bool runningFlag;
};
////////////////////////////////////////////////////////////////////////////////
@@ -97,15 +98,15 @@ public:
PlaYUVerFrameStatistics::PlaYUVerFrameStatistics( const PlaYUVerFrame& playuver_frame, QObject *parent, Options options ) :
QThread()
{
// TODO: check the correct pel_format
setup( playuver_frame.getQImageBuffer(), playuver_frame.getWidth(), playuver_frame.getHeight(), playuver_frame.getBitsChannel(), PlaYUVerFrame::RGB8, parent, options );
setup( playuver_frame.getPelBufferYUV(), playuver_frame.getWidth(), playuver_frame.getHeight(), playuver_frame.getBitsChannel(),
playuver_frame.getPelFormat(), playuver_frame.getChromaLength(), parent, options );
}
PlaYUVerFrameStatistics::PlaYUVerFrameStatistics( Pel *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, UInt chroma_size, QObject *parent,
Options options ) :
QThread()
{
// TODO: check the correct pel_format
setup( data, width, height, bitsPerChannel, PlaYUVerFrame::RGB8, parent, options );
setup( data, width, height, bitsPerChannel, pixel_format, chroma_size, parent, options );
}
PlaYUVerFrameStatistics::~PlaYUVerFrameStatistics()
@@ -121,7 +122,8 @@ PlaYUVerFrameStatistics::~PlaYUVerFrameStatistics()
////////////////////////////////////////////////////////////////////////////////
// Setup Function
////////////////////////////////////////////////////////////////////////////////
void PlaYUVerFrameStatistics::setup( Pel *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, UInt chroma_size, QObject *parent,
Options options )
{
d = new PlaYUVerFrameStatisticsPrivate;
d->imageData = data;
@@ -130,6 +132,7 @@ void PlaYUVerFrameStatistics::setup( Pel *data, uint width, uint height, int bit
d->parent = parent;
d->histoSegments = ( bitsPerChannel == 16 ) ? 65536 : 256;
d->imageColorSpace = PlaYUVerFrame::isRGBorYUVorGray( pixel_format );
d->imageChromaSize = chroma_size;
if( options == CalcLumaWhenRGB )
d->calcLuma = true;
@@ -235,13 +238,13 @@ int PlaYUVerFrameStatistics::getRealHistoChannel( int channel )
}
break;
case PlaYUVerFrame::COLOR_YUV:
if( channel != YChannel && channel != CbChannel && channel != CrChannel )
if( channel != LumaChannel && channel != YChannel && channel != CbChannel && channel != CrChannel )
{
return -1;
}
else
{
if( channel == YChannel )
if( channel == YChannel || channel == LumaChannel)
histoChannel = 0;
if( channel == CbChannel )
@@ -290,7 +293,7 @@ void PlaYUVerFrameStatistics::calcHistogramValues()
if( d->parent )
postProgress( true, false );
getMem1D<Double>( &(d->histogram ), d->histoSegments * d->histoChannels);
getMem1D<Double>( &( d->histogram ), d->histoSegments * d->histoChannels );
if( !d->histogram )
{
@@ -304,64 +307,59 @@ void PlaYUVerFrameStatistics::calcHistogramValues()
return;
}
// 16 bits image.
if( d->histoSegments == 65536 )
if( d->imageColorSpace == PlaYUVerFrame::COLOR_YUV )
{
unsigned short *data = ( unsigned short* )d->imageData;
unsigned short luma;
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++ )
{
for( j = 0; j < d->imageChannels; j++ )
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]++;
d->histogram[*( data[j] ) + j * d->histoSegments]++;
}
// Calc the luminosity when it's applicable
if( d->calcLuma && d->imageColorSpace == PlaYUVerFrame::COLOR_RGB )
{
luma = ( unsigned short )( 0.299 * data[0] + 0.587 * data[1] + 0.114 * data[2] );
d->histogram[luma + j * d->histoSegments]++;
}
if( d->calcLuma && d->imageColorSpace == PlaYUVerFrame::COLOR_ARGB )
{
luma = ( unsigned short )( 0.299 * data[1] + 0.587 * data[2] + 0.114 * data[3] );
d->histogram[luma + j * d->histoSegments]++;
}
data += d->imageChannels;
for( j = 1; j < d->imageChannels; j++ )
data[j] += 1;
}
}
// 8 bits images.
else
{
Pel *data = d->imageData;
Pel luma;
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]++;
d->histogram[*( data[j] ) + j * d->histoSegments]++;
}
// Calc the luminosity when it's applicable
if( d->calcLuma && d->imageColorSpace == PlaYUVerFrame::COLOR_RGB )
if( d->calcLuma && ( d->imageColorSpace == PlaYUVerFrame::COLOR_RGB || d->imageColorSpace == PlaYUVerFrame::COLOR_ARGB ) )
{
luma = ( uchar )( 0.299 * data[0] + 0.587 * data[1] + 0.114 * data[2] );
Pixel pixel_value =
{
d->imageColorSpace,
*( data[COLOR_R] ),
*( data[COLOR_G] ),
*( data[COLOR_B] ) };
luma = PlaYUVerFrame::ConvertPixel( pixel_value, PlaYUVerFrame::COLOR_YUV ).Luma;
d->histogram[luma + j * d->histoSegments]++;
}
if( d->calcLuma && d->imageColorSpace == PlaYUVerFrame::COLOR_ARGB )
{
luma = ( uchar )( 0.299 * data[1] + 0.587 * data[2] + 0.114 * data[3] );
d->histogram[luma + j * d->histoSegments]++;
}
data += d->imageChannels;
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 )
+6 -5
View File
@@ -52,9 +52,9 @@ public:
GreenChannel,
BlueChannel,
AlphaChannel,
YChannel,
CbChannel,
CrChannel
YChannel = 1,
CbChannel = 2,
CrChannel = 3
};
enum Options
@@ -85,13 +85,14 @@ public:
public:
PlaYUVerFrameStatistics( uchar *data, uint width, uint height, int bitsPerChannel, Int pixel_format, QObject *parent = 0, Options options = CalcLumaWhenRGB );
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 pixel_format, QObject *parent = 0, Options options = CalcLumaWhenRGB );
void setup( Pel ***data, UInt width, UInt height, Int bitsPerChannel, Int pixel_format, UInt chroma_size, QObject *parent = 0, Options options = CalcLumaWhenRGB );
/** Method to stop threaded computations.*/
void stopCalcHistogramValues( void );