Improve histogram measurement and display.
Now it is possible to show histogram of luminance in RGB frames
This commit is contained in:
13 files changed
+463
-600
No files matched your search
+189
-251
@@ -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
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user