Improve histogram measurement and display.

Now it is possible to show histogram of luminance in RGB frames
This commit is contained in:
jfmcarreira committed 2018-02-06 01:10:16 +00:00
1 parent 2d6ba03d4a
commit 8ba512f4d0
13 files changed
+463 -600

No files matched your search

+1 -1
View File
@@ -91,7 +91,7 @@ SortIncludes: true
SpacesInParentheses: true
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
TabWidth: 2
UseTab: Never
...
+31 -72
View File
@@ -42,8 +42,8 @@ FramePropertiesDock::FramePropertiesDock( QWidget* parent, Bool* pbMainPlaySwitc
channelLabel->setAlignment( Qt::AlignVCenter | Qt::AlignRight );
channelCB = new QComboBox;
channelCB->addItem( tr( "Luminance" ) );
channelCB->setItemIcon( 0, QIcon( ":/images/channel-luma.png" ) );
//channelCB->addItem( tr( "Luminance" ) );
//channelCB->setItemIcon( 0, QIcon( ":/images/channel-luma.png" ) );
channelCB->setWhatsThis( tr( "<p>Select here the histogram channel to display:<p>"
"<b>Luminance</b>: Display luminance (perceived brightness).<p>"
@@ -218,8 +218,6 @@ FramePropertiesDock::FramePropertiesDock( QWidget* parent, Bool* pbMainPlaySwitc
statisticsLayout->addWidget( labelStdDevValue, gridRow++, 1 );
statisticsLayout->addWidget( medianLabel, gridRow, 0 );
statisticsLayout->addWidget( labelMedianValue, gridRow++, 1 );
// statisticsLayout->addWidget( percentileLabel, 5, 0 );
// statisticsLayout->addWidget( labelPercentileValue, 5, 1 );
QGroupBox* statisticsGroup = new QGroupBox( tr( "Statistics" ) );
statisticsGroup->setLayout( statisticsLayout );
@@ -298,21 +296,20 @@ Void FramePropertiesDock::setFrame( PlaYUVerFrame* pcFrame )
if( colorSpace == PlaYUVerPixel::COLOR_RGB || colorSpace == PlaYUVerPixel::COLOR_RGBA )
{
channelCB->clear();
channelCB->clear();
channelCB->insertItem( LuminosityChannel, QIcon( ":/images/channel-luma.png" ), "Luminance" );
channelCB->insertItem( FirstChannel, QIcon( ":/images/channel-red.png" ), "Red" );
channelCB->insertItem( SecondChannel, QIcon( ":/images/channel-green.png" ), "Green" );
channelCB->insertItem( ThirdChannel, QIcon( ":/images/channel-blue.png" ), "Blue" );
channelCB->addItem( QIcon( ":/images/channel-luma.png" ), "Luminance", PlaYUVerFrame::HIST_LUMA );
channelCB->addItem( QIcon( ":/images/channel-red.png" ), "Red", PlaYUVerFrame::HIST_COLOR_R );
channelCB->addItem( QIcon( ":/images/channel-green.png" ), "Green", PlaYUVerFrame::HIST_COLOR_G );
channelCB->addItem( QIcon( ":/images/channel-blue.png" ), "Blue", PlaYUVerFrame::HIST_COLOR_B );
if( colorSpace == PlaYUVerPixel::COLOR_RGBA )
{
channelCB->insertItem( AlphaChannel, QIcon( ":/images/channel-alpha.png" ), "Alpha" );
channelCB->addItem( QIcon( ":/images/channel-alpha.png" ), "Alpha", PlaYUVerFrame::HIST_COLOR_A );
}
channelCB->insertItem( ColorChannels, QIcon( ":/images/channel-all.png" ), "Colors" );
channelCB->addItem( QIcon( ":/images/channel-all.png" ), "Colors", PlaYUVerFrame::HIST_ALL_CHANNELS );
colorsCB->clear();
colorsCB->addItem( "Red" );
colorsCB->addItem( "Green" );
colorsCB->addItem( "Blue" );
colorsCB->addItem( "Red", PlaYUVerFrame::HIST_COLOR_R );
colorsCB->addItem( "Green", PlaYUVerFrame::HIST_COLOR_G );
colorsCB->addItem( "Blue", PlaYUVerFrame::HIST_COLOR_B );
colorsCB->setEnabled( false );
colorsCB->setWhatsThis( tr( "<p>Select here the main color displayed with Colors Channel mode:"
"<p><b>Red</b>: Draw the Red image channel in the foreground.<p>"
@@ -324,15 +321,15 @@ Void FramePropertiesDock::setFrame( PlaYUVerFrame* pcFrame )
else if( colorSpace == PlaYUVerPixel::COLOR_YUV )
{
channelCB->clear();
channelCB->insertItem( FirstChannel, QIcon( ":/images/channel-luma.png" ), "Luminance" );
channelCB->insertItem( SecondChannel, QIcon( ":/images/channel-red.png" ), "Chroma U" );
channelCB->insertItem( ThirdChannel, QIcon( ":/images/channel-green.png" ), "Chroma V" );
channelCB->insertItem( ColorChannels, QIcon( ":/images/channel-all.png" ), "All Channels" );
channelCB->addItem( QIcon( ":/images/channel-luma.png" ), "Luminance", PlaYUVerFrame::HIST_LUMA );
channelCB->addItem( QIcon( ":/images/channel-red.png" ), "Chroma U", PlaYUVerFrame::HIST_CHROMA_U );
channelCB->addItem( QIcon( ":/images/channel-green.png" ), "Chroma V", PlaYUVerFrame::HIST_CHROMA_V );
channelCB->addItem( QIcon( ":/images/channel-all.png" ), "All Channels", PlaYUVerFrame::HIST_ALL_CHANNELS );
colorsCB->clear();
colorsCB->addItem( "Luminance" );
colorsCB->addItem( "Chroma U" );
colorsCB->addItem( "Chroma V" );
colorsCB->addItem( "Luminance", PlaYUVerFrame::HIST_LUMA );
colorsCB->addItem( "Chroma U", PlaYUVerFrame::HIST_CHROMA_U );
colorsCB->addItem( "Chroma V", PlaYUVerFrame::HIST_CHROMA_V );
colorsCB->setEnabled( false );
colorsCB->setWhatsThis( tr( "<p>Select here the main color displayed with Colors Channel mode:"
"<p><b>Luminance</b>: DraupdateDataw the Luminance channel in the "
@@ -346,8 +343,7 @@ Void FramePropertiesDock::setFrame( PlaYUVerFrame* pcFrame )
else
{
channelCB->clear();
channelCB->addItem( tr( "Luminance" ) );
channelCB->setItemIcon( 0, QIcon( ":/images/channel-luma.png" ) );
channelCB->addItem( QIcon( ":/images/channel-luma.png" ), "Luminance", PlaYUVerFrame::HIST_LUMA );
colorsCB->hide();
colorsLabel->hide();
}
@@ -436,8 +432,8 @@ Void FramePropertiesDock::updateStatistiques()
Int max = maxInterv->value();
Int channel = histogramWidget->m_channelType;
if( channel == HistogramWidget::ColorChannelsHistogram )
channel = colorsCB->currentIndex();
if( channel == PlaYUVerFrame::HIST_ALL_CHANNELS )
channel = colorsCB->itemData( colorsCB->currentIndex() ).toInt();
PlaYUVerFrame* frame;
@@ -449,7 +445,7 @@ Void FramePropertiesDock::updateStatistiques()
if( frame )
{
QString rangeText =
"[" + QString::number( frame->getMin( channel ) ) + ":" + QString::number( frame->getMax( channel ) ) + "]";
"[" + QString::number( frame->getMinimumPelValue( channel ) ) + ":" + QString::number( frame->getMaximumPelValue( channel ) ) + "]";
labelRangeValue->setText( rangeText );
double mean = frame->getMean( channel, min, max );
@@ -461,7 +457,7 @@ Void FramePropertiesDock::updateStatistiques()
double stddev = frame->getStdDev( channel, min, max );
labelStdDevValue->setText( value.setNum( stddev, 'f', 1 ) );
double counts = frame->getCount( channel, min, max );
double counts = frame->getNumPixelsRange( channel, min, max );
labelCountValue->setText( value.setNum( (float)counts, 'f', 0 ) );
double median = frame->getMedian( channel, min, max );
@@ -509,41 +505,15 @@ Void FramePropertiesDock::slotHistogramComputationFailed()
m_pcFrame = NULL;
}
Void FramePropertiesDock::slotChannelChanged( Int channel )
Void FramePropertiesDock::slotChannelChanged( Int index )
{
if( m_pcFrame->getColorSpace() == PlaYUVerPixel::COLOR_YUV )
channel += 1;
if( channel == AlphaChannel && m_pcFrame->getColorSpace() != PlaYUVerPixel::COLOR_RGBA )
channel = ColorChannels;
Int channel = channelCB->itemData( index ).toInt();
switch( channel )
{
case FirstChannel:
histogramWidget->m_channelType = HistogramWidget::FirstChannelHistogram;
colorsCB->setEnabled( false );
break;
case SecondChannel:
histogramWidget->m_channelType = HistogramWidget::SecondChannelHistogram;
colorsCB->setEnabled( false );
break;
case ThirdChannel:
histogramWidget->m_channelType = HistogramWidget::ThirdChannelHistogram;
colorsCB->setEnabled( false );
break;
case AlphaChannel:
histogramWidget->m_channelType = HistogramWidget::AlphaChannelHistogram;
colorsCB->setEnabled( false );
break;
case ColorChannels:
histogramWidget->m_channelType = HistogramWidget::ColorChannelsHistogram;
histogramWidget->m_channelType = channel;
if( channel == PlaYUVerFrame::HIST_ALL_CHANNELS )
colorsCB->setEnabled( true );
break;
default: // Luminance.
// histogramWidget->m_channelType = HistogramWidget::LumaHistogram;
histogramWidget->m_channelType = HistogramWidget::FirstChannelHistogram;
else
colorsCB->setEnabled( false );
break;
}
histogramWidget->update();
updateStatistiques();
}
@@ -554,21 +524,10 @@ Void FramePropertiesDock::slotScaleChanged( Int scale )
histogramWidget->update();
}
Void FramePropertiesDock::slotColorsChanged( Int color )
Void FramePropertiesDock::slotColorsChanged( Int index )
{
switch( color )
{
case AllColorsGreen:
histogramWidget->m_colorType = HistogramWidget::SecondChannelColor;
break;
case AllColorsBlue:
histogramWidget->m_colorType = HistogramWidget::ThirdChannelColor;
break;
default: // Red.
histogramWidget->m_colorType = HistogramWidget::FirstChannelColor;
break;
}
Int color = colorsCB->itemData( index ).toInt();
histogramWidget->m_colorType = color;
histogramWidget->update();
updateStatistiques();
}
+2 -19
View File
@@ -48,23 +48,6 @@ public:
Void stopHistogram();
private:
enum ColorChannel
{
LuminosityChannel = 0,
FirstChannel = 1,
SecondChannel = 2,
ThirdChannel = 3,
ColorChannels = 4,
AlphaChannel = 5,
};
enum AllColorsColorType
{
AllColorsRed = 0,
AllColorsGreen,
AllColorsBlue
};
PlaYUVerFrame* m_pcFrame;
PlaYUVerFrame* m_pcSelectedFrame;
Int m_iLastFrameType;
@@ -106,9 +89,9 @@ private:
private Q_SLOTS:
void slotRefreshOptions( int range );
void slotHistogramComputationFailed( void );
void slotChannelChanged( int channel );
void slotChannelChanged( int index );
void slotScaleChanged( int scale );
void slotColorsChanged( int color );
void slotColorsChanged( int index );
void slotRenderingChanged( int rendering );
void slotMinValueChanged( int );
void slotMaxValueChanged( int );
+105 -146
View File
@@ -79,8 +79,8 @@ public:
}
/**
* Custom Event
*/
* Custom Event
*/
class EventData : public QEvent
{
public:
@@ -154,13 +154,13 @@ public:
bool statisticsVisible; // Display tooltip histogram statistics.
bool inSelected;
bool selectMode; // If true, a part of the histogram can be
// selected !
// selected !
bool blinkFlag;
bool blinkComputation; // If true, a message will be displayed during
// histogram computation, else nothing (limit
// flicker effect in widget especially for small
// image/computation time).
bool lumaChannel; // Compute luminance channel if true.
// histogram computation, else nothing (limit
// flicker effect in widget especially for small
// image/computation time).
bool lumaChannel; // Compute luminance channel if true.
bool inInitialRepaintWait;
QTimer* blinkTimer;
@@ -180,10 +180,9 @@ HistogramWidget::HistogramWidget( Int width, Int height, QWidget* parent )
d = new HistogramWidgetPrivate;
// m_channelType = LumaHistogram;
m_channelType = FirstChannelHistogram;
m_channelType = PlaYUVerFrame::HIST_LUMA;
m_scaleType = LogScaleHistogram;
m_colorType = FirstChannelColor;
m_colorType = -1;
m_renderingType = FullImageHistogram;
setOptions( HistogramWidget::BlinkComputation | HistogramWidget::SelectMode | HistogramWidget::ShowLumaChannel );
@@ -211,12 +210,6 @@ HistogramWidget::~HistogramWidget()
{
d->blinkTimer->stop();
// if( m_imageHistogram )
// delete m_imageHistogram;
//
// if( m_selectionHistogram )
// delete m_selectionHistogram;
delete m_imageWorker;
delete m_selectionWorker;
@@ -327,16 +320,6 @@ Void HistogramWidget::customEvent( QEvent* event )
// Remove old histogram data from memory.
m_fullImage = NULL;
m_selectionImage = NULL;
// if( m_imageHistogram )
// {
// delete m_imageHistogram;
// m_imageHistogram = 0;
// }
// if( m_selectionHistogram )
// {
// delete m_selectionHistogram;
// m_selectionHistogram = 0;
// }
emit signalHistogramComputationFailed();
}
}
@@ -519,34 +502,12 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
yb = 0;
max = 0.0;
switch( m_channelType )
{
case HistogramWidget::FirstChannelHistogram: // Y channel.
max = frame->getMaximum( LUMA );
break;
case HistogramWidget::SecondChannelHistogram: // Cb channel.
max = frame->getMaximum( CHROMA_U );
break;
case HistogramWidget::ThirdChannelHistogram: // Cr channel.
max = frame->getMaximum( CHROMA_V );
break;
case HistogramWidget::AlphaChannelHistogram: // Alpha channel.
max = frame->getMaximum( COLOR_A );
break;
case HistogramWidget::ColorChannelsHistogram: // All color channels.
max = qMax( qMax( frame->getMaximum( LUMA ), frame->getMaximum( CHROMA_U ) ), frame->getMaximum( CHROMA_V ) );
break;
// case HistogramWidget::LumaHistogram: // Luminance.
// max = frame->getMaximum( LUMA );
// break;
}
max = frame->getMaximum( m_channelType );
switch( m_scaleType )
{
case HistogramWidget::LinScaleHistogram:
break;
case HistogramWidget::LogScaleHistogram:
if( max > 0.0 )
max = log( max );
@@ -569,8 +530,8 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
double value_r = 0.0, value_g = 0.0, value_b = 0.0; // For all channels.
int i, j;
i = ( x * frame->getHistogramSegment() ) / wWidth;
j = ( ( x + 1 ) * frame->getHistogramSegment() ) / wWidth;
i = ( x * frame->getNumHistogramSegment() ) / wWidth;
j = ( ( x + 1 ) * frame->getNumHistogramSegment() ) / wWidth;
do
{
@@ -582,37 +543,12 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
vg = 0.0;
vb = 0.0;
switch( m_channelType )
if( m_channelType == PlaYUVerFrame::HIST_ALL_CHANNELS )
{
case HistogramWidget::FirstChannelHistogram: // Y channel.
v = frame->getHistogramValue( LUMA, i++ );
break;
case HistogramWidget::SecondChannelHistogram: // Cb channel.
v = frame->getHistogramValue( CHROMA_U, i++ );
break;
case HistogramWidget::ThirdChannelHistogram: // Cr channel.
v = frame->getHistogramValue( CHROMA_V, i++ );
break;
case HistogramWidget::AlphaChannelHistogram: // Alpha channel.
v = frame->getHistogramValue( COLOR_A, i++ );
break;
case HistogramWidget::ColorChannelsHistogram: // All color.
vr = frame->getHistogramValue( LUMA, i );
vg = frame->getHistogramValue( CHROMA_U, i );
vb = frame->getHistogramValue( CHROMA_V, i++ );
break;
// case HistogramWidget::LumaHistogram: // Luminance.
// v = frame->getHistogramValue( LUMA, i++ );
// break;
}
vr = frame->getHistogramValue( PlaYUVerFrame::HIST_CHAN_ONE, i );
vg = frame->getHistogramValue( PlaYUVerFrame::HIST_CHAN_TWO, i );
vb = frame->getHistogramValue( PlaYUVerFrame::HIST_CHAN_THREE, i );
if( m_channelType != HistogramWidget::ColorChannelsHistogram )
{
if( v > value )
value = v;
}
else
{
if( vr > value_r )
value_r = vr;
if( vg > value_g )
@@ -620,9 +556,16 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
if( vb > value_b )
value_b = vb;
}
else
{
v = frame->getHistogramValue( m_channelType, i );
if( v > value )
value = v;
}
i++;
} while( i < j );
if( m_channelType != HistogramWidget::ColorChannelsHistogram )
if( m_channelType != PlaYUVerFrame::HIST_ALL_CHANNELS )
{
switch( m_scaleType )
{
@@ -673,7 +616,7 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
// Drawing the histogram + selection or only the histogram.
if( m_channelType != HistogramWidget::ColorChannelsHistogram )
if( m_channelType != PlaYUVerFrame::HIST_ALL_CHANNELS )
{
if( d->selectMode == true ) // Selection mode enable ?
{
@@ -726,17 +669,23 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
// colors channel mode?
switch( m_colorType )
{
case HistogramWidget::FirstChannelColor:
case PlaYUVerFrame::HIST_LUMA:
case PlaYUVerFrame::HIST_COLOR_R:
p1.drawLine( x, wHeight, x, wHeight - yr );
break;
case HistogramWidget::SecondChannelColor:
case PlaYUVerFrame::HIST_CHROMA_U:
case PlaYUVerFrame::HIST_COLOR_G:
p1.drawLine( x, wHeight, x, wHeight - yg );
break;
default:
case PlaYUVerFrame::HIST_CHROMA_V:
case PlaYUVerFrame::HIST_COLOR_B:
p1.drawLine( x, wHeight, x, wHeight - yb );
break;
default:
Q_ASSERT( 0 );
}
}
else
@@ -745,12 +694,13 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
// colors channel mode?
switch( m_colorType )
{
case HistogramWidget::FirstChannelColor:
p1.setPen( QPen( g_eColorPallet[pallet][SecondChannelColor], 1, Qt::SolidLine ) );
case PlaYUVerFrame::HIST_LUMA:
case PlaYUVerFrame::HIST_COLOR_R:
p1.setPen( QPen( g_eColorPallet[pallet][1], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yg );
p1.setPen( QPen( g_eColorPallet[pallet][ThirdChannelColor], 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][2], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yb );
p1.setPen( QPen( g_eColorPallet[pallet][FirstChannelColor], 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][0], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yr );
p1.setPen( QPen( Qt::white, 1, Qt::SolidLine ) );
@@ -762,12 +712,13 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
break;
case HistogramWidget::SecondChannelColor:
p1.setPen( QPen( g_eColorPallet[pallet][ThirdChannelColor], 1, Qt::SolidLine ) );
case PlaYUVerFrame::HIST_CHROMA_U:
case PlaYUVerFrame::HIST_COLOR_G:
p1.setPen( QPen( g_eColorPallet[pallet][2], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yb );
p1.setPen( QPen( g_eColorPallet[pallet][FirstChannelColor], 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][0], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yr );
p1.setPen( QPen( g_eColorPallet[pallet][SecondChannelColor], 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][1], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yg );
p1.setPen( QPen( Qt::white, 1, Qt::SolidLine ) );
@@ -778,23 +729,25 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
p1.drawLine( x, wHeight - yg - 1, x, wHeight - yg );
break;
case PlaYUVerFrame::HIST_CHROMA_V:
case PlaYUVerFrame::HIST_COLOR_B:
p1.setPen( QPen( g_eColorPallet[pallet][0], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yr );
p1.setPen( QPen( g_eColorPallet[pallet][1], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yg );
p1.setPen( QPen( g_eColorPallet[pallet][2], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yb );
p1.setPen( QPen( Qt::white, 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight - qMax( qMax( yr, yg ), yb ), x, 0 );
p1.setPen( QPen( Qt::gray, 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight - yr - 1, x, wHeight - yr );
p1.drawLine( x, wHeight - yg - 1, x, wHeight - yg );
p1.drawLine( x, wHeight - yb - 1, x, wHeight - yb );
break;
default:
p1.setPen( QPen( g_eColorPallet[pallet][FirstChannelColor], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yr );
p1.setPen( QPen( g_eColorPallet[pallet][SecondChannelColor], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yg );
p1.setPen( QPen( g_eColorPallet[pallet][ThirdChannelColor], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yb );
p1.setPen( QPen( Qt::white, 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight - qMax( qMax( yr, yg ), yb ), x, 0 );
p1.setPen( QPen( Qt::gray, 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight - yr - 1, x, wHeight - yr );
p1.drawLine( x, wHeight - yg - 1, x, wHeight - yg );
p1.drawLine( x, wHeight - yb - 1, x, wHeight - yb );
break;
Q_ASSERT( 0 );
}
if( x == wWidth / 4 || x == wWidth / 2 || x == 3 * wWidth / 4 )
@@ -810,15 +763,16 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
// colors channel mode?
switch( m_colorType )
{
case HistogramWidget::FirstChannelColor:
case PlaYUVerFrame::HIST_LUMA:
case PlaYUVerFrame::HIST_COLOR_R:
p1.setPen( QPen( Qt::green, 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][SecondChannelColor], 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][1], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yg );
p1.setPen( QPen( Qt::blue, 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][ThirdChannelColor], 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][2], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yb );
p1.setPen( QPen( Qt::red, 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][FirstChannelColor], 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][0], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yr );
p1.setPen( QPen( Qt::white, 1, Qt::SolidLine ) );
@@ -830,15 +784,16 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
break;
case HistogramWidget::SecondChannelColor:
case PlaYUVerFrame::HIST_CHROMA_U:
case PlaYUVerFrame::HIST_COLOR_G:
p1.setPen( QPen( Qt::blue, 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][ThirdChannelColor], 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][2], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yb );
p1.setPen( QPen( Qt::red, 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][FirstChannelColor], 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][0], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yr );
p1.setPen( QPen( Qt::green, 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][SecondChannelColor], 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][1], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yg );
p1.setPen( QPen( Qt::white, 1, Qt::SolidLine ) );
@@ -850,25 +805,28 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
break;
case PlaYUVerFrame::HIST_CHROMA_V:
case PlaYUVerFrame::HIST_COLOR_B:
p1.setPen( QPen( Qt::red, 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][0], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yr );
p1.setPen( QPen( Qt::green, 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][1], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yg );
p1.setPen( QPen( Qt::blue, 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][2], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yb );
p1.setPen( QPen( Qt::white, 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight - qMax( qMax( yr, yg ), yb ), x, 0 );
p1.setPen( QPen( Qt::gray, 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight - yr - 1, x, wHeight - yr );
p1.drawLine( x, wHeight - yg - 1, x, wHeight - yg );
p1.drawLine( x, wHeight - yb - 1, x, wHeight - yb );
break;
default:
p1.setPen( QPen( Qt::red, 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][FirstChannelColor], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yr );
p1.setPen( QPen( Qt::green, 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][SecondChannelColor], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yg );
p1.setPen( QPen( Qt::blue, 1, Qt::SolidLine ) );
p1.setPen( QPen( g_eColorPallet[pallet][ThirdChannelColor], 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight, x, wHeight - yb );
p1.setPen( QPen( Qt::white, 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight - qMax( qMax( yr, yg ), yb ), x, 0 );
p1.setPen( QPen( Qt::gray, 1, Qt::SolidLine ) );
p1.drawLine( x, wHeight - yr - 1, x, wHeight - yr );
p1.drawLine( x, wHeight - yg - 1, x, wHeight - yg );
p1.drawLine( x, wHeight - yb - 1, x, wHeight - yb );
break;
Q_ASSERT( 0 );
}
if( x == wWidth / 4 || x == wWidth / 2 || x == 3 * wWidth / 4 )
@@ -889,22 +847,23 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
{
switch( m_channelType )
{
case HistogramWidget::FirstChannelHistogram:
case PlaYUVerFrame::HIST_CHROMA_V:
case PlaYUVerFrame::HIST_COLOR_R:
guidePos = d->colorGuide.red();
break;
case HistogramWidget::SecondChannelHistogram:
case PlaYUVerFrame::HIST_COLOR_G:
guidePos = d->colorGuide.green();
break;
case HistogramWidget::ThirdChannelHistogram:
case PlaYUVerFrame::HIST_CHROMA_U:
case PlaYUVerFrame::HIST_COLOR_B:
guidePos = d->colorGuide.blue();
break;
// case HistogramWidget::LumaHistogram:
// guidePos = qMax( qMax( d->colorGuide.red(), d->colorGuide.green()
// ), d->colorGuide.blue() );
// break;
case PlaYUVerFrame::HIST_LUMA:
guidePos = qMax( qMax( d->colorGuide.red(), d->colorGuide.green() ), d->colorGuide.blue() );
break;
default: // Alpha.
guidePos = -1;
@@ -913,7 +872,7 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
if( guidePos != -1 )
{
int xGuide = ( guidePos * wWidth ) / frame->getHistogramSegment();
int xGuide = ( guidePos * wWidth ) / frame->getNumHistogramSegment();
p1.drawLine( xGuide, 0, xGuide, wHeight );
QString string = tr( "x:%1" ).arg( guidePos );
@@ -950,7 +909,7 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
tipText = "<table cellspacing=0 cellpadding=0>";
tipText += cellBeg + tr( "Mean:" ) + cellMid;
double mean = frame->getMean( m_channelType, 0, frame->getHistogramSegment() - 1 );
double mean = frame->getMean( m_channelType, 0, frame->getNumHistogramSegment() - 1 );
tipText += value.setNum( mean, 'f', 1 ) + cellEnd;
tipText += cellBeg + tr( "Pixels:" ) + cellMid;
@@ -958,15 +917,15 @@ Void HistogramWidget::paintEvent( QPaintEvent* )
tipText += value.setNum( (float)pixels, 'f', 0 ) + cellEnd;
tipText += cellBeg + tr( "Std dev.:" ) + cellMid;
double stddev = frame->getStdDev( m_channelType, 0, frame->getHistogramSegment() - 1 );
double stddev = frame->getStdDev( m_channelType, 0, frame->getNumHistogramSegment() - 1 );
tipText += value.setNum( stddev, 'f', 1 ) + cellEnd;
tipText += cellBeg + tr( "Selected:" ) + cellMid;
double counts = frame->getCount( m_channelType, 0, frame->getHistogramSegment() - 1 );
double counts = frame->getNumPixelsRange( m_channelType, 0, frame->getNumHistogramSegment() - 1 );
tipText += value.setNum( (float)counts, 'f', 0 ) + cellEnd;
tipText += cellBeg + tr( "Median:" ) + cellMid;
double median = frame->getMedian( m_channelType, 0, frame->getHistogramSegment() - 1 );
double median = frame->getMedian( m_channelType, 0, frame->getNumHistogramSegment() - 1 );
tipText += value.setNum( median, 'f', 1 ) + cellEnd;
tipText += cellBeg + tr( "Percent:" ) + cellMid;
-22
View File
@@ -43,20 +43,6 @@ class HistogramWidget : public QWidget
Q_OBJECT
public:
enum HistogramChannel
{
/** Luminance */
// LumaHistogram = 0,
/** Channels */
FirstChannelHistogram = 0,
SecondChannelHistogram,
ThirdChannelHistogram,
/** Alpha channel */
AlphaChannelHistogram,
/** All color channels */
ColorChannelsHistogram,
};
enum HistogramScale
{
/** Linear scale */
@@ -65,14 +51,6 @@ public:
LogScaleHistogram
};
enum HistogramAllColorMode
{
// Select wich component is shown in foreground
FirstChannelColor,
SecondChannelColor,
ThirdChannelColor,
};
enum HistogramRendering
{
/** Full image histogram rendering */
+1 -1
View File
@@ -990,7 +990,7 @@ Void VideoSubWindow::updatePixelValueStatusBar( const QPoint& pos )
strStatus = QString( "(%1,%2) " ).arg( posX ).arg( posY );
Int colorSpace = m_pcCurrFrame->getColorSpace();
PlaYUVerPixel pixelValue = m_pcCurrFrame->getPixelValue( pos.x(), pos.y() );
PlaYUVerPixel pixelValue = m_pcCurrFrame->getPixel( pos.x(), pos.y() );
switch( colorSpace )
{
case PlaYUVerPixel::COLOR_GRAY:
+22 -15
View File
@@ -487,7 +487,7 @@ Void ViewArea::paintEvent( QPaintEvent* event )
{
Int imageWidth = m_pixmap.width();
Int imageHeight = m_pixmap.height();
PlaYUVerPixel sPixelValue;
PlaYUVerPixel pixelValue;
QFont font( "Helvetica" );
font.setPixelSize( 12 );
@@ -508,51 +508,58 @@ Void ViewArea::paintEvent( QPaintEvent* event )
if( frFormat == PlaYUVerPixel::COLOR_YUV )
{
sPixelValue = m_pcCurrFrame->getPixelValue( pixelTopLeft.x(), pixelTopLeft.y() );
pixelValue = m_pcCurrFrame->getPixel( pixelTopLeft.x(), pixelTopLeft.y() );
if( sPixelValue.Y() < m_uiPixelHalfScale )
if( pixelValue.Y() < m_uiPixelHalfScale )
paInter.setPen( QColor( Qt::white ) );
else
paInter.setPen( QColor( Qt::black ) );
paInter.drawText( pixelRect, Qt::AlignCenter,
"Y: " + QString::number( sPixelValue.Y() ) + "\n" +
"U: " + QString::number( sPixelValue.Cb() ) + "\n" +
"V: " + QString::number( sPixelValue.Cr() ) );
"Y: " + QString::number( pixelValue.Y() ) + "\n" +
"U: " + QString::number( pixelValue.Cb() ) + "\n" +
"V: " + QString::number( pixelValue.Cr() ) );
}
if( frFormat == PlaYUVerPixel::COLOR_GRAY )
{
sPixelValue = m_pcCurrFrame->getPixelValue( pixelTopLeft.x(), pixelTopLeft.y() );
pixelValue = m_pcCurrFrame->getPixel( pixelTopLeft.x(), pixelTopLeft.y() );
if( sPixelValue.Y() < m_uiPixelHalfScale )
if( pixelValue.Y() < m_uiPixelHalfScale )
paInter.setPen( QColor( Qt::white ) );
else
paInter.setPen( QColor( Qt::black ) );
paInter.drawText( pixelRect, Qt::AlignCenter, "Y: " + QString::number( sPixelValue.Y() ) );
paInter.drawText( pixelRect, Qt::AlignCenter, "Y: " + QString::number( pixelValue.Y() ) );
}
if( ( frFormat == PlaYUVerPixel::COLOR_RGB ) )
{
sPixelValue = m_pcCurrFrame->getPixelValue( pixelTopLeft.x(), pixelTopLeft.y() );
pixelValue = m_pcCurrFrame->getPixel( pixelTopLeft.x(), pixelTopLeft.y() );
if( ( sPixelValue.R() + sPixelValue.G() + sPixelValue.B() ) < ( m_uiPixelHalfScale * 3 ) )
if( ( pixelValue.R() + pixelValue.G() + pixelValue.B() ) < ( m_uiPixelHalfScale * 3 ) )
paInter.setPen( QColor( Qt::white ) );
else
paInter.setPen( QColor( Qt::black ) );
paInter.drawText( pixelRect, Qt::AlignCenter, "R: " + QString::number( sPixelValue.R() ) + "\nG: " + QString::number( sPixelValue.G() ) + "\nB: " + QString::number( sPixelValue.B() ) );
paInter.drawText( pixelRect, Qt::AlignCenter,
"R: " + QString::number( pixelValue.R() ) +
"\nG: " + QString::number( pixelValue.G() ) +
"\nB: " + QString::number( pixelValue.B() ) );
}
if( ( frFormat == PlaYUVerPixel::COLOR_RGBA ) )
{
sPixelValue = m_pcCurrFrame->getPixelValue( pixelTopLeft.x(), pixelTopLeft.y() );
pixelValue = m_pcCurrFrame->getPixel( pixelTopLeft.x(), pixelTopLeft.y() );
if( ( sPixelValue.R() + sPixelValue.G() + sPixelValue.B() ) < ( m_uiPixelHalfScale * 3 ) )
if( ( pixelValue.R() + pixelValue.G() + pixelValue.B() ) < ( m_uiPixelHalfScale * 3 ) )
paInter.setPen( QColor( Qt::white ) );
else
paInter.setPen( QColor( Qt::black ) );
paInter.drawText( pixelRect, Qt::AlignCenter, "R: " + QString::number( sPixelValue.R() ) + "\nG: " + QString::number( sPixelValue.G() ) + "\nB: " + QString::number( sPixelValue.B() ) + "\nA: " + QString::number( sPixelValue.A() ) );
paInter.drawText( pixelRect, Qt::AlignCenter,
"R: " + QString::number( pixelValue.R() ) +
"\nG: " + QString::number( pixelValue.G() ) +
"\nB: " + QString::number( pixelValue.B() ) +
"\nA: " + QString::number( pixelValue.A() ) );
}
}
}
+189 -251
View File
@@ -293,27 +293,46 @@ PlaYUVerPixel PlaYUVerPixel::operator*( const Double& op )
PlaYUVerPixel PlaYUVerPixel::ConvertPixel( ColorSpace eOutputSpace )
{
Int outA, outB, outC;
PlaYUVerPixel outPixel( COLOR_INVALID, 0, 0, 0 );
if( ColorSpace() == eOutputSpace || eOutputSpace == COLOR_RGBA || eOutputSpace == COLOR_GRAY )
if( d->iColorSpace == eOutputSpace )
return *this;
if( eOutputSpace == COLOR_RGB )
Int outA = 0;
Int outB = 0;
Int outC = 0;
Int outD = 0;
if( d->iColorSpace == COLOR_YUV )
{
yuvToRgb( Y(), Cb(), Cr(), outA, outB, outC );
outPixel.R() = outA;
outPixel.G() = outB;
outPixel.B() = outC;
switch( eOutputSpace )
{
case COLOR_GRAY:
outA = Y();
break;
case COLOR_RGBA:
outD = 255;
case COLOR_RGB:
yuvToRgb( Y(), Cb(), Cr(), outA, outB, outC );
break;
default:
break;
}
}
if( eOutputSpace == COLOR_YUV )
if( d->iColorSpace == COLOR_RGB )
{
rgbToYuv( R(), G(), B(), outA, outB, outC );
outPixel.Y() = outA;
outPixel.Cb() = outB;
outPixel.Cr() = outC;
switch( eOutputSpace )
{
case COLOR_GRAY:
rgbToYuv( R(), G(), B(), outA, outB, outC );
case COLOR_YUV:
rgbToYuv( R(), G(), B(), outA, outB, outC );
break;
case COLOR_RGBA:
outD = 255;
break;
default:
break;
}
}
return outPixel;
return PlaYUVerPixel( eOutputSpace, outA, outB, outC, outD );
}
struct PlaYUVerFramePrivate
@@ -425,6 +444,38 @@ struct PlaYUVerFramePrivate
m_bInit = true;
}
Int getRealHistogramChannel( Int channel )
{
Int realChannel = -1;
if( channel == PlaYUVerFrame::HIST_ALL_CHANNELS )
{
realChannel = channel;
}
else if( channel >= 0 && channel < 4 )
{
realChannel = channel;
}
else if( m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_YUV )
{
if( channel >= 10 && channel < 13 )
{
realChannel = channel - 10;
}
}
else if( m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_RGB || m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_RGBA )
{
if( channel == PlaYUVerFrame::HIST_LUMA )
{
realChannel = m_uiHistoChannels - 1;
}
if( channel >= 20 && channel < 24 )
{
realChannel = channel - 20;
}
}
return realChannel;
}
~PlaYUVerFramePrivate()
{
while( m_bHistogramRunning )
@@ -685,7 +736,7 @@ UChar* PlaYUVerFrame::getRGBBuffer()
return d->m_pcARGB32;
}
PlaYUVerPixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos )
PlaYUVerPixel PlaYUVerFrame::getPixel( Int xPos, Int yPos )
{
PlaYUVerPixel PixelValue( d->m_pcPelFormat->colorSpace );
for( UInt ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ )
@@ -697,7 +748,7 @@ PlaYUVerPixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos )
return PixelValue;
}
PlaYUVerPixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos, PlaYUVerPixel::ColorSpace eColorSpace )
PlaYUVerPixel PlaYUVerFrame::getPixel( Int xPos, Int yPos, PlaYUVerPixel::ColorSpace eColorSpace )
{
PlaYUVerPixel PixelValue( d->m_pcPelFormat->colorSpace );
for( UInt ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ )
@@ -710,7 +761,7 @@ PlaYUVerPixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos, PlaYUVerPixel::C
return PixelValue;
}
Void PlaYUVerFrame::setPixelValue( Int xPos, Int yPos, PlaYUVerPixel pixel )
Void PlaYUVerFrame::setPixel( Int xPos, Int yPos, PlaYUVerPixel pixel )
{
for( UInt ch = 0; ch < d->m_pcPelFormat->numberChannels; ch++ )
{
@@ -982,207 +1033,152 @@ Void PlaYUVerFrame::calcHistogram()
xMemSet( UInt, d->m_uiHistoSegments * d->m_uiHistoChannels, d->m_puiHistogram );
UInt i, j;
UInt numberChannels = d->m_pcPelFormat->numberChannels;
Int colorSpace = d->m_pcPelFormat->colorSpace;
if( colorSpace == PlaYUVerPixel::COLOR_YUV )
for( UInt ch = 0; ch < numberChannels; ch++ )
{
const Pel* data[3];
data[LUMA] = d->m_pppcInputPel[LUMA][0];
data[CHROMA_U] = d->m_pppcInputPel[CHROMA_U][0];
data[CHROMA_V] = d->m_pppcInputPel[CHROMA_V][0];
for( i = 0; i < d->m_uiHeight * d->m_uiWidth; i++ )
UInt size = CHROMASHIFT( d->m_uiWidth, ch > 0 ? d->m_pcPelFormat->log2ChromaWidth : 0 ) *
CHROMASHIFT( d->m_uiHeight, ch > 0 ? d->m_pcPelFormat->log2ChromaHeight : 0 );
Pel* chPel = &( d->m_pppcInputPel[ch][0][0] );
for( UInt i = 0; i < size; i++ )
{
d->m_puiHistogram[*( data[LUMA] ) + LUMA * d->m_uiHistoSegments]++;
data[LUMA] += 1;
}
for( i = 0; ( i < getChromaLength() ); i++ )
{
for( j = 1; j < numberChannels; j++ )
{
d->m_puiHistogram[*( data[j] ) + j * d->m_uiHistoSegments]++;
data[j] += 1;
}
d->m_puiHistogram[*chPel + ch * d->m_uiHistoSegments]++;
chPel++;
}
}
else
{
const Pel* data[3];
Pel luma;
data[COLOR_R] = d->m_pppcInputPel[COLOR_R][0];
data[COLOR_G] = d->m_pppcInputPel[COLOR_G][0];
data[COLOR_B] = d->m_pppcInputPel[COLOR_B][0];
for( i = 0; ( i < d->m_uiHeight * d->m_uiWidth ); i++ )
{
for( j = 0; j < numberChannels; j++ )
if( d->m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_RGB ||
d->m_pcPelFormat->colorSpace == PlaYUVerPixel::COLOR_RGBA )
{
for( UInt y = 0; y < d->m_uiHeight; y++ )
for( UInt x = 0; x < d->m_uiWidth; x++ )
{
d->m_puiHistogram[*( data[j] ) + j * d->m_uiHistoSegments]++;
Pel luma = getPixel( x, y ).ConvertPixel( PlaYUVerPixel::COLOR_YUV ).Y();
d->m_puiHistogram[luma + ( d->m_uiHistoChannels - 1 ) * d->m_uiHistoSegments]++;
}
if( ( colorSpace == PlaYUVerPixel::COLOR_RGB || colorSpace == PlaYUVerPixel::COLOR_RGBA ) )
{
PlaYUVerPixel currPixel( colorSpace, *( data[COLOR_R] ), *( data[COLOR_G] ), *( data[COLOR_B] ) );
luma = currPixel.ConvertPixel( PlaYUVerPixel::COLOR_YUV ).Y();
d->m_puiHistogram[luma + j * d->m_uiHistoSegments]++;
}
for( j = 0; j < numberChannels; j++ )
data[j] += 1;
}
}
d->m_bHasHistogram = true;
d->m_bHistogramRunning = false;
}
Int PlaYUVerFrame::getHistogramSegment()
Int PlaYUVerFrame::getNumHistogramSegment()
{
return d->m_uiHistoSegments;
}
Int getRealHistoChannel( Int colorSpace, Int channel )
UInt PlaYUVerFrame::getMinimumPelValue( Int channel )
{
Int histoChannel;
switch( colorSpace )
{
case PlaYUVerPixel::COLOR_GRAY:
if( channel != LUMA )
{
return -1;
}
histoChannel = 0;
break;
case PlaYUVerPixel::COLOR_RGB:
if( channel != COLOR_R && channel != COLOR_G && channel != COLOR_B && channel != LUMA )
{
return -1;
}
else
{
// if( channel == LUMA )
// {
// histoChannel = 3;
// }
// else
{
histoChannel = channel;
}
}
break;
case PlaYUVerPixel::COLOR_RGBA:
if( channel != COLOR_R && channel != COLOR_G && channel != COLOR_B && channel != COLOR_A && channel != LUMA )
{
return -1;
}
else
{
if( channel == LUMA )
{
histoChannel = 4;
}
else
{
histoChannel = channel;
}
}
break;
case PlaYUVerPixel::COLOR_YUV:
if( channel != LUMA && channel != CHROMA_U && channel != CHROMA_V )
{
return -1;
}
else
{
histoChannel = channel;
}
break;
default:
histoChannel = -1;
}
return histoChannel;
}
UInt PlaYUVerFrame::getMin( Int channel )
{
UInt value;
Int histoChannel;
Int indexStart;
if( !d->m_bHasHistogram )
{
return 0;
channel = d->getRealHistogramChannel( channel );
if( channel < 0 )
return 0;
Int indexStart;
Int indexEnd;
if( channel == HIST_ALL_CHANNELS )
{
indexStart = 0;
indexEnd = d->m_uiHistoChannels * d->m_uiHistoSegments;
}
else
{
indexStart = channel * d->m_uiHistoSegments;
indexEnd = indexStart + d->m_uiHistoSegments;
}
histoChannel = getRealHistoChannel( getColorSpace(), channel );
if( histoChannel == -1 )
for( Int i = indexStart; i < indexEnd; i++ )
{
return 0;
}
indexStart = histoChannel * d->m_uiHistoSegments;
for( value = 0; value <= d->m_uiHistoSegments; value++ )
{
if( d->m_puiHistogram[indexStart + value] > 0 )
if( d->m_puiHistogram[i] > 0 )
{
break;
return i - indexStart;
}
}
return value;
return 0;
}
UInt PlaYUVerFrame::getMax( Int channel )
UInt PlaYUVerFrame::getMaximumPelValue( Int channel )
{
Int value;
Int histoChannel;
Int indexStart;
if( !d->m_bHasHistogram )
{
return 0;
channel = d->getRealHistogramChannel( channel );
if( channel < 0 )
return 0;
Int indexStart;
Int indexEnd;
if( channel == HIST_ALL_CHANNELS )
{
indexStart = d->m_uiHistoChannels * d->m_uiHistoSegments;
indexEnd = 0;
}
else
{
indexStart = ( channel + 1 ) * d->m_uiHistoSegments - 1;
indexEnd = indexStart - d->m_uiHistoSegments;
}
histoChannel = getRealHistoChannel( getColorSpace(), channel );
if( histoChannel == -1 )
for( Int i = indexStart; i > indexEnd; i-- )
{
return 0;
}
indexStart = histoChannel * d->m_uiHistoSegments;
for( value = d->m_uiHistoSegments - 1; value >= 0; value-- )
{
if( d->m_puiHistogram[indexStart + value] > 0 )
if( d->m_puiHistogram[i] > 0 )
{
break;
return i - indexEnd + 1;
}
}
return value;
return 0;
}
UInt PlaYUVerFrame::getCount( Int channel, UInt start, UInt end )
UInt PlaYUVerFrame::getMaximum( Int channel )
{
UInt i;
Int histoChannel;
Int indexStart;
UInt count = 0;
if( !d->m_bHasHistogram )
return 0;
channel = d->getRealHistogramChannel( channel );
if( channel < 0 )
return 0;
UInt maxValue = 0;
Int indexStart;
Int indexEnd;
if( channel == HIST_ALL_CHANNELS )
{
indexStart = 0;
indexEnd = d->m_uiHistoChannels * d->m_uiHistoSegments;
}
else
{
indexStart = channel * d->m_uiHistoSegments;
indexEnd = indexStart + d->m_uiHistoSegments;
}
for( Int x = indexStart; x < indexEnd; x++ )
{
if( d->m_puiHistogram[x] > maxValue )
{
maxValue = d->m_puiHistogram[x];
}
}
return maxValue;
}
UInt PlaYUVerFrame::getNumPixelsRange( Int channel, UInt start, UInt end )
{
if( !d->m_bHasHistogram || start < 0 || end > d->m_uiHistoSegments - 1 || start > end )
{
return 0.0;
return 0;
}
histoChannel = getRealHistoChannel( getColorSpace(), channel );
if( histoChannel == -1 )
channel = d->getRealHistogramChannel( channel );
if( channel < 0 )
{
return 0;
}
indexStart = histoChannel * d->m_uiHistoSegments;
for( i = start; i <= end; i++ )
UInt count = 0;
Int indexStart;
indexStart = channel * d->m_uiHistoSegments;
for( UInt i = start; i <= end; i++ )
{
count += d->m_puiHistogram[indexStart + i];
}
@@ -1191,31 +1187,25 @@ UInt PlaYUVerFrame::getCount( Int channel, UInt start, UInt end )
Double PlaYUVerFrame::getMean( Int channel, UInt start, UInt end )
{
Int indexStart;
Int histoChannel;
Double mean = 0.0;
Double count;
if( !d->m_bHasHistogram || start < 0 || end > d->m_uiHistoSegments - 1 || start > end )
{
return 0.0;
}
histoChannel = getRealHistoChannel( getColorSpace(), channel );
if( histoChannel == -1 )
channel = d->getRealHistogramChannel( channel );
if( channel < 0 )
{
return 0.0;
}
indexStart = histoChannel * d->m_uiHistoSegments;
Double mean = 0.0;
Double count;
Int indexStart = channel * d->m_uiHistoSegments;
for( UInt i = start; i <= end; i++ )
{
mean += i * d->m_puiHistogram[indexStart + i];
}
count = getCount( channel, start, end );
count = getNumPixelsRange( channel, start, end );
if( count > 0.0 )
{
@@ -1227,27 +1217,20 @@ Double PlaYUVerFrame::getMean( Int channel, UInt start, UInt end )
Int PlaYUVerFrame::getMedian( Int channel, UInt start, UInt end )
{
Int histoChannel;
Int indexStart;
Double sum = 0.0;
Double count;
if( !d->m_bHasHistogram || start < 0 || end > d->m_uiHistoSegments - 1 || start > end )
{
return 0;
}
histoChannel = getRealHistoChannel( getColorSpace(), channel );
if( histoChannel == -1 )
channel = d->getRealHistogramChannel( channel );
if( channel < 0 )
{
return 0;
}
indexStart = histoChannel * d->m_uiHistoSegments;
count = getCount( channel, start, end );
Double sum = 0.0;
Int indexStart = channel * d->m_uiHistoSegments;
Double count = getNumPixelsRange( channel, start, end );
for( UInt i = start; i <= end; i++ )
{
sum += d->m_puiHistogram[indexStart + i];
@@ -1260,28 +1243,21 @@ Int PlaYUVerFrame::getMedian( Int channel, UInt start, UInt end )
Double PlaYUVerFrame::getStdDev( Int channel, UInt start, UInt end )
{
Int histoChannel;
Int indexStart;
Double dev = 0.0;
Double count;
Double mean;
if( !d->m_bHasHistogram || start < 0 || end > d->m_uiHistoSegments - 1 || start > end )
{
return 0.0;
}
histoChannel = getRealHistoChannel( getColorSpace(), channel );
if( histoChannel == -1 )
channel = d->getRealHistogramChannel( channel );
if( channel < 0 )
{
return 0.0;
}
indexStart = histoChannel * d->m_uiHistoSegments;
mean = getMean( channel, start, end );
count = getCount( channel, start, end );
Int indexStart = channel * d->m_uiHistoSegments;
Double mean = getMean( channel, start, end );
Double count = getNumPixelsRange( channel, start, end );
Double dev = 0.0;
if( count == 0.0 )
count = 1.0;
@@ -1306,55 +1282,17 @@ Double PlaYUVerFrame::getStdDev( Int channel, UInt start, UInt end )
Double PlaYUVerFrame::getHistogramValue( Int channel, UInt bin )
{
Double value;
Int histoChannel;
Int indexStart;
if( !d->m_bHasHistogram || bin < 0 || bin > d->m_uiHistoSegments - 1 )
return 0.0;
histoChannel = getRealHistoChannel( getColorSpace(), channel );
if( histoChannel == -1 )
channel = d->getRealHistogramChannel( channel );
if( channel < 0 )
{
return 0.0;
return 0;
}
indexStart = histoChannel * d->m_uiHistoSegments;
value = d->m_puiHistogram[indexStart + bin];
return value;
}
Double PlaYUVerFrame::getMaximum( Int channel )
{
Double max = 0.0;
Int histoChannel;
Int indexStart;
if( !d->m_bHasHistogram )
return 0.0;
histoChannel = getRealHistoChannel( getColorSpace(), channel );
if( histoChannel == -1 )
{
return 0.0;
}
indexStart = histoChannel * d->m_uiHistoSegments;
for( UInt x = 0; x < d->m_uiHistoSegments; x++ )
{
if( d->m_puiHistogram[indexStart + x] > max )
{
max = d->m_puiHistogram[indexStart + x];
}
}
return max;
Int indexStart = channel * d->m_uiHistoSegments;
return d->m_puiHistogram[indexStart + bin];
}
/*
+26 -9
View File
@@ -117,7 +117,7 @@ class PlaYUVerFrame
{
public:
/** ColorSpace Enum
* List of supported pixel formats - do not change order
* List of supported pixel formats
*/
enum PixelFormats
{
@@ -288,9 +288,9 @@ public:
UChar* getRGBBuffer() const;
UChar* getRGBBuffer();
PlaYUVerPixel getPixelValue( Int xPos, Int yPos );
PlaYUVerPixel getPixelValue( Int xPos, Int yPos, PlaYUVerPixel::ColorSpace eColorSpace );
Void setPixelValue( Int xPos, Int yPos, PlaYUVerPixel pixel );
PlaYUVerPixel getPixel( Int xPos, Int yPos );
PlaYUVerPixel getPixel( Int xPos, Int yPos, PlaYUVerPixel::ColorSpace eColorSpace );
Void setPixel( Int xPos, Int yPos, PlaYUVerPixel pixel );
Void copyFrom( const PlaYUVerFrame& );
Void copyFrom( const PlaYUVerFrame* );
@@ -306,18 +306,35 @@ public:
/**
* Histogram
*/
enum HistogramChannels
{
HIST_CHAN_ONE = 0,
HIST_CHAN_TWO,
HIST_CHAN_THREE,
HIST_CHAN_FOUR,
HIST_LUMA = 10,
HIST_CHROMA_U,
HIST_CHROMA_V,
HIST_COLOR_R = 20,
HIST_COLOR_G,
HIST_COLOR_B,
HIST_COLOR_A,
HIST_ALL_CHANNELS = 254,
HISTOGRAM_MAX = 255,
};
Void calcHistogram();
UInt getMin( Int channel );
UInt getMax( Int channel );
UInt getMinimumPelValue( Int channel );
UInt getMaximumPelValue( Int channel );
UInt getCount( Int channel, UInt start, UInt end );
UInt getMaximum( Int channel );
UInt getNumPixelsRange( Int channel, UInt start, UInt end );
Double getMean( Int channel, UInt start, UInt end );
Int getMedian( Int channel, UInt start, UInt end );
Double getStdDev( Int channel, UInt start, UInt end );
Double getHistogramValue( Int channel, UInt bin );
Double getMaximum( Int channel );
Int getHistogramSegment();
Int getNumHistogramSegment();
/**
* Interface with OpenCV lib
+55 -55
View File
@@ -40,6 +40,59 @@
#include <cstdio>
std::vector<PlaYUVerSupportedFormat> PlaYUVerStream::supportedReadFormats()
{
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerRaw, Read );
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerPortableMap, Read );
//#ifdef USE_OPENCV
// APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerOpenCV, Read );
//#endif
#ifdef USE_FFMPEG
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerLibav, Read );
#endif
END_REGIST_PLAYUVER_SUPPORTED_FMT;
}
std::vector<PlaYUVerSupportedFormat> PlaYUVerStream::supportedWriteFormats()
{
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerRaw, Write );
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerPortableMap, Write );
#ifdef USE_FFMPEG
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerLibav, Write );
#endif
#ifdef USE_OPENCV
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerOpenCV, Write );
#endif
END_REGIST_PLAYUVER_SUPPORTED_FMT;
}
std::vector<PlaYUVerStdResolution> PlaYUVerStream::stdResolutionSizes()
{
#define REGIST_PLAYUVER_STANDARD_RESOLUTION( name, width, height ) \
stdResElement.shortName = name; \
stdResElement.uiWidth = width; \
stdResElement.uiHeight = height; \
stdResList.push_back( stdResElement );
std::vector<PlaYUVerStdResolution> stdResList;
PlaYUVerStdResolution stdResElement;
REGIST_PLAYUVER_STANDARD_RESOLUTION( "CIF", 352, 288 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "VGA", 640, 480 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "WVGA", 832, 480 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "XVGA", 1024, 768 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "HD", 1280, 720 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "SXGA-", 1280, 900 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "SXGA", 1280, 1024 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "WSXGA", 1440, 900 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "FullHD", 1920, 1080 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "WQXGA", 2560, 1600 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "UltraHD", 3840, 2160 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "8K", 8192, 4608 );
return stdResList;
}
class PlaYUVerStreamBufferPrivate
{
private:
@@ -112,34 +165,6 @@ struct PlaYUVerStreamPrivate
}
};
std::vector<PlaYUVerSupportedFormat> PlaYUVerStream::supportedReadFormats()
{
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerRaw, Read );
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerPortableMap, Read );
#ifdef USE_FFMPEG
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerLibav, Read );
#endif
#ifdef USE_OPENCV
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerOpenCV, Read );
#endif
END_REGIST_PLAYUVER_SUPPORTED_FMT;
}
std::vector<PlaYUVerSupportedFormat> PlaYUVerStream::supportedWriteFormats()
{
INI_REGIST_PLAYUVER_SUPPORTED_FMT;
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerRaw, Write );
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerPortableMap, Write );
#ifdef USE_FFMPEG
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerLibav, Write );
#endif
#ifdef USE_OPENCV
APPEND_PLAYUVER_SUPPORTED_FMT( StreamHandlerOpenCV, Write );
#endif
END_REGIST_PLAYUVER_SUPPORTED_FMT;
}
std::vector<String> PlaYUVerSupportedFormat::getExts()
{
std::vector<String> arrayExt;
@@ -154,31 +179,6 @@ std::vector<String> PlaYUVerSupportedFormat::getExts()
return arrayExt;
}
std::vector<PlaYUVerStdResolution> PlaYUVerStream::stdResolutionSizes()
{
#define REGIST_PLAYUVER_STANDARD_RESOLUTION( name, width, height ) \
stdResElement.shortName = name; \
stdResElement.uiWidth = width; \
stdResElement.uiHeight = height; \
stdResList.push_back( stdResElement );
std::vector<PlaYUVerStdResolution> stdResList;
PlaYUVerStdResolution stdResElement;
REGIST_PLAYUVER_STANDARD_RESOLUTION( "CIF", 352, 288 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "VGA", 640, 480 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "WVGA", 832, 480 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "XVGA", 1024, 768 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "HD", 1280, 720 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "SXGA-", 1280, 900 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "SXGA", 1280, 1024 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "WSXGA", 1440, 900 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "FullHD", 1920, 1080 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "WQXGA", 2560, 1600 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "UltraHD", 3840, 2160 );
REGIST_PLAYUVER_STANDARD_RESOLUTION( "8K", 8192, 4608 );
return stdResList;
}
CreateStreamHandlerFn PlaYUVerStream::findStreamHandler( String strFilename, bool bRead )
{
String currExt = strFilename.substr( strFilename.find_last_of( "." ) + 1 );
@@ -208,7 +208,7 @@ CreateStreamHandlerFn PlaYUVerStream::findStreamHandler( String strFilename, boo
}
}
}
return &StreamHandlerRaw::Create;
return &StreamHandlerLibav::Create;
}
PlaYUVerStream::PlaYUVerStream()
@@ -298,7 +298,7 @@ Bool PlaYUVerStream::open( String filename, UInt width, UInt height, Int input_f
if( d->handler->m_uiWidth <= 0 || d->handler->m_uiHeight <= 0 || d->handler->m_iPixelFormat < 0 )
{
close();
throw PlaYUVerFailure( "PlaYUVerStream", "Incorrect configuration: width, height or pixel format" );
//throw PlaYUVerFailure( "PlaYUVerStream", "Incorrect configuration: width, height or pixel format" );
return d->isInit;
}
+26 -4
View File
@@ -43,7 +43,7 @@ std::vector<PlaYUVerSupportedFormat> StreamHandlerLibav::supportedReadFormats()
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "Joint Photographic Experts Group", "jpg,jpeg" );
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "Windows Bitmap", "bmp" );
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "Tagged Image File Format", "tiff" );
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, " Graphics Interchange Format", "gif" );
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "Graphics Interchange Format", "gif" );
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "Audio video interleaved", "avi" );
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "Windows media video", "wmv" );
REGIST_PLAYUVER_SUPPORTED_FMT( &StreamHandlerLibav::Create, "MPEG-4", "mp4" );
@@ -209,8 +209,6 @@ Bool StreamHandlerLibav::openHandler( String strFilename, Bool bInput )
}
if( m_iPixelFormat == PlaYUVerFrame::NO_FMT )
{
Int newPelFmt = PlaYUVerFrame::findPixelFormat( "YUV444p" );
m_iPixelFormat = newPelFmt;
m_bNative = false;
//throw PlaYUVerFailure( "StreamHandlerLibav", "Cannot open file using FFmpeg libs - unsupported pixel format" );
//return false;
@@ -252,6 +250,30 @@ Bool StreamHandlerLibav::openHandler( String strFilename, Bool bInput )
if( !m_bNative )
{
Int newPelFmt = -1;
const AVPixFmtDescriptor* ffPelDesc = av_pix_fmt_desc_get( AVPixelFormat( m_ffPixFmt ) );
if( ffPelDesc->flags & AV_PIX_FMT_FLAG_PAL )
{
newPelFmt = PlaYUVerFrame::RGB24;
}
else if( ffPelDesc->flags & AV_PIX_FMT_FLAG_ALPHA )
{
newPelFmt = PlaYUVerFrame::RGBA;
}
else if( ffPelDesc->flags & AV_PIX_FMT_FLAG_RGB )
{
newPelFmt = PlaYUVerFrame::RGB24;
}
else if( ffPelDesc->nb_components == 1 )
{
newPelFmt = PlaYUVerFrame::GRAY;
}
else
{
newPelFmt = PlaYUVerFrame::YUV444p;
}
m_iPixelFormat = newPelFmt;
AVPixelFormat newAvFmt = AVPixelFormat( g_PlaYUVerPixFmtDescriptorsMap.at( m_iPixelFormat ).ffmpegPelFormat );
/* create scaling context */
@@ -267,7 +289,7 @@ Bool StreamHandlerLibav::openHandler( String strFilename, Bool bInput )
}
if( av_image_alloc( m_cConvertedFrame->data, m_cConvertedFrame->linesize,
m_uiWidth, m_uiHeight, newAvFmt, 1 ) < 0 )
m_uiWidth, m_uiHeight, newAvFmt, 16 ) < 0 )
{
closeHandler();
return false;
+3 -3
View File
@@ -97,11 +97,11 @@ PlaYUVerFrame* FrameMask::process( std::vector<PlaYUVerFrame*> apcFrameList )
{
for( UInt x = 0; x < m_pcFrameProcessed->getWidth(); x++ )
{
pixelImg = InputFrame->getPixelValue( x, y );
pixelMask = MaskFrame->getPixelValue( x, y );
pixelImg = InputFrame->getPixel( x, y );
pixelMask = MaskFrame->getPixel( x, y );
pixelOut = pixelImg * ( 10 - m_iWeight ) + pixelMask * m_iWeight;
pixelOut = pixelOut * 0.1;
m_pcFrameProcessed->setPixelValue( x, y, pixelOut );
m_pcFrameProcessed->setPixel( x, y, pixelOut );
}
}
return m_pcFrameProcessed;
+2 -2
View File
@@ -102,8 +102,8 @@ PlaYUVerFrame* FrameRotate::process( std::vector<PlaYUVerFrame*> apcFrameList )
inY = x;
break;
}
pixel = InputFrame->getPixelValue( inX, inY );
m_pcFrameProcessed->setPixelValue( x, y, pixel );
pixel = InputFrame->getPixel( inX, inY );
m_pcFrameProcessed->setPixel( x, y, pixel );
}
}
return m_pcFrameProcessed;