Save pixels in Short instead of UChar

This commit is contained in:
jfmcarreira committed 2015-04-03 13:04:20 +01:00
1 parent c8079e87cb
commit e2385a81c2
8 files changed
+63 -67

No files matched your search

+8 -4
View File
@@ -127,10 +127,9 @@ Bool LibOpenCVHandler::saveFrame( PlaYUVerFrame* pcFrame, std::string filename )
}
cv::Mat pcCvFrame( pcFrame->getHeight(), pcFrame->getWidth(), cvType );
UChar* pCvPel = pcCvFrame.data;
if( pcFrame->getColorSpace() != PlaYUVerFrame::COLOR_GRAY )
{
UChar* pCvPel = pcCvFrame.data;
UChar* pARGB = pcFrame->getRGBBuffer();
for( UInt i = 0; i < pcFrame->getHeight() * pcFrame->getWidth(); i++ )
{
@@ -140,9 +139,14 @@ Bool LibOpenCVHandler::saveFrame( PlaYUVerFrame* pcFrame, std::string filename )
pARGB++;
}
}
else
if( pcFrame->getColorSpace() == PlaYUVerFrame::COLOR_GRAY )
{
memcpy( pcCvFrame.data, pcFrame->getPelBufferYUV()[LUMA][0], pcFrame->getHeight() * pcFrame->getWidth() * sizeof(Pel) );
Pel* pPel = pcFrame->getPelBufferYUV()[LUMA][0];
for( UInt i = 0; i < pcFrame->getHeight() * pcFrame->getWidth(); i++ )
{
*pCvPel++ = *pPel++;
}
}
return cv::imwrite( filename, pcCvFrame );
}
+7 -7
View File
@@ -18,13 +18,13 @@
*/
/**
* \file TypeDef.h
* \file PlaYUVerDefs.h
* \ingroup PlaYUVerLib
* \brief Define basic types, new types and enumerations
*/
#ifndef __TYPEDEF_H__
#define __TYPEDEF_H__
#ifndef __PLAYUVERDEFS_H__
#define __PLAYUVERDEFS_H__
#include <string>
#include <algorithm>
@@ -75,9 +75,9 @@ typedef unsigned long long UInt64;
// Type definition
// ====================================================================================================================
typedef UChar Pel; ///< 8-bit pixel type
typedef UChar SBytePel; ///< 8-bit pixel type
//typedef Short Pel; ///< 16-bit pixel type
//typedef UChar Pel; ///< 8-bit pixel type
typedef Short Pel; ///< 16-bit pixel type
typedef UChar Byte;
// ====================================================================================================================
// Limits definition
@@ -131,4 +131,4 @@ inline std::string lowercase( const std::string& in )
} // NAMESPACE
#endif // __TYPEDEF_H__
#endif // __PLAYUVERDEFS_H__
+15 -13
View File
@@ -145,16 +145,16 @@ PlaYUVerFrame::~PlaYUVerFrame()
closePixfc();
}
static Int getMem3ImageComponents( SBytePel**** array3D, Int dim1, Int dim2, Int log2ChromaHeight, Int log2ChromaWidth )
static Int getMem3ImageComponents( Pel**** array3D, Int dim1, Int dim2, Int log2ChromaHeight, Int log2ChromaWidth )
{
Int dim0 = 3;
Int i;
UInt64 total_mem_size = 0;
UInt64 mem_size = ( dim1 * dim2 + CHROMASHIFT( dim1, log2ChromaHeight ) * CHROMASHIFT( dim2, log2ChromaWidth ) * 2 );
total_mem_size += getMem2D<SBytePel*>( array3D, dim0, dim1 );
total_mem_size += getMem2D<Pel*>( array3D, dim0, dim1 );
if( ( ( *array3D )[0][0] = ( SBytePel* )xCallocMem( mem_size, sizeof(Pel) ) ) == NULL )
if( ( ( *array3D )[0][0] = ( Pel* )xCallocMem( mem_size, sizeof(Pel) ) ) == NULL )
printf( "getMem3DImageComponents: array1D" );
total_mem_size += mem_size * sizeof(Pel);
@@ -197,7 +197,7 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel
m_pcPelFormat = &( g_PlaYUVerPixFmtDescriptorsList[pel_format] );
m_bHasRGBPel = false;
UInt m_uiWidthBytes = m_uiWidth * ( ( m_iBitsPel - 1 ) / 8 + 1 );
UInt m_uiWidthBytes = m_uiWidth; //* ( ( m_iBitsPel - 1 ) / 8 + 1 );
if( m_pcPelFormat->colorSpace == COLOR_GRAY )
{
getMem3ImageComponents( &m_pppcInputPel, m_uiHeight, m_uiWidthBytes, 1, 1 );
@@ -255,13 +255,14 @@ UInt PlaYUVerFrame::getChromaLength() const
return getChromaWidth() * getChromaHeight();
}
Void PlaYUVerFrame::frameFromBuffer( Pel *Buff, UInt64 uiBuffSize )
Void PlaYUVerFrame::frameFromBuffer( Byte *Buff, UInt64 uiBuffSize )
{
if( uiBuffSize != getBytesPerFrame() )
return;
Pel* ppBuff[MAX_NUMBER_PLANES];
Pel* pTmpPel, *pTmpBuff;
Byte* ppBuff[MAX_NUMBER_PLANES];
Byte* pTmpBuff;
Pel* pTmpPel;
UInt bytesPixel = ( m_iBitsPel - 1 ) / 8 + 1;
Int ratioH, ratioW, step;
UInt i, ch;
@@ -283,7 +284,7 @@ Void PlaYUVerFrame::frameFromBuffer( Pel *Buff, UInt64 uiBuffSize )
pTmpPel = m_pppcInputPel[ch][0];
pTmpBuff = ppBuff[m_pcPelFormat->comp[ch].plane] + ( m_pcPelFormat->comp[ch].offset_plus1 - 1 );
for( i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ) * bytesPixel; i++ )
for( i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ); i++ )
{
*pTmpPel++ = *pTmpBuff;
pTmpBuff += step;
@@ -294,11 +295,12 @@ Void PlaYUVerFrame::frameFromBuffer( Pel *Buff, UInt64 uiBuffSize )
m_bHasHistogram = false;
}
Void PlaYUVerFrame::frameToBuffer( Pel *output_buffer )
Void PlaYUVerFrame::frameToBuffer( Byte *output_buffer )
{
UInt bytesPixel = ( m_iBitsPel - 1 ) / 8 + 1;
Pel* ppBuff[MAX_NUMBER_PLANES];
Pel* pTmpPel, *pTmpBuff;
Byte* ppBuff[MAX_NUMBER_PLANES];
Byte* pTmpBuff;
Pel* pTmpPel;
Int ratioH, ratioW, step;
UInt i, ch;
@@ -319,7 +321,7 @@ Void PlaYUVerFrame::frameToBuffer( Pel *output_buffer )
pTmpPel = m_pppcInputPel[ch][0];
pTmpBuff = ppBuff[m_pcPelFormat->comp[ch].plane];
for( i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ) * bytesPixel; i++ )
for( i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ); i++ )
{
*pTmpBuff = *pTmpPel++;
pTmpBuff += step;
@@ -527,7 +529,7 @@ Void PlaYUVerFrame::fromCvMat( Void* voidFrame )
Pel* pInputPelY = m_pppcInputPel[LUMA][0];
Pel* pInputPelU = m_pppcInputPel[CHROMA_U][0];
Pel* pInputPelV = m_pppcInputPel[CHROMA_V][0];
Pel* pcRGBPelInterlaced = m_pcARGB32;
UChar* pcRGBPelInterlaced = m_pcARGB32;
memcpy( pcRGBPelInterlaced, opencvFrame->data, m_uiWidth * m_uiHeight * 4 * sizeof(Pel) );
UInt* buff = ( UInt* )pcRGBPelInterlaced;
for( UInt i = 0; i < m_uiHeight * m_uiWidth; i++ )
+2 -2
View File
@@ -214,8 +214,8 @@ public:
UInt getChromaHeight() const;
UInt getChromaLength() const;
Void frameFromBuffer( Pel*, UInt64 );
Void frameToBuffer( Pel* );
Void frameFromBuffer( Byte*, UInt64 );
Void frameToBuffer( Byte* );
Void fillRGBBuffer();
+24 -24
View File
@@ -36,15 +36,15 @@ namespace plaYUVer
{
PlaYUVerFrameStats::PlaYUVerFrameStats() :
m_pdHistogram( NULL ),
m_puiHistogram( NULL ),
m_bHasHistogram( false )
{
}
PlaYUVerFrameStats::~PlaYUVerFrameStats()
{
if( m_pdHistogram )
freeMem1D( m_pdHistogram );
if( m_puiHistogram )
freeMem1D( m_puiHistogram );
}
@@ -77,9 +77,9 @@ Void PlaYUVerFrameStats::calcHistogram()
//m_bHasHistogram = false;
if( m_bHasHistogram )
return;
getMem1D<Double>( &( m_pdHistogram ), m_uiHistoSegments * histoChannels );
getMem1D<UInt>( &( m_puiHistogram ), m_uiHistoSegments * histoChannels );
if( !m_pdHistogram )
if( !m_puiHistogram )
{
// qWarning( ) << "PlaYUVerFrameStats::calcHistogramValuess: "
// "Unable to allocate memory!"
@@ -97,14 +97,14 @@ Void PlaYUVerFrameStats::calcHistogram()
data[CHROMA_V] = m_pppImageData[CHROMA_V][0];
for( i = 0; i < m_uiImageHeight * m_uiImageWidth; i++ )
{
m_pdHistogram[*( data[LUMA] ) + LUMA * m_uiHistoSegments]++;
m_puiHistogram[*( data[LUMA] ) + LUMA * m_uiHistoSegments]++;
data[LUMA] += 1;
}
for( i = 0; ( i < imageChromaSize ) && m_bRunningFlag; i++ )
{
for( j = 1; j < m_uiChannels; j++ )
{
m_pdHistogram[*( data[j] ) + j * m_uiHistoSegments]++;
m_puiHistogram[*( data[j] ) + j * m_uiHistoSegments]++;
}
for( j = 1; j < m_uiChannels; j++ )
data[j] += 1;
@@ -122,13 +122,13 @@ Void PlaYUVerFrameStats::calcHistogram()
{
for( j = 0; j < m_uiChannels; j++ )
{
m_pdHistogram[*( data[j] ) + j * m_uiHistoSegments]++;
m_puiHistogram[*( data[j] ) + j * m_uiHistoSegments]++;
}
if( calcLuma && ( imageColorSpace == PlaYUVerFrame::COLOR_RGB || imageColorSpace == PlaYUVerFrame::COLOR_ARGB ) )
{
PlaYUVerFrame::Pixel currPixel( imageColorSpace, *( data[COLOR_R] ), *( data[COLOR_G] ), *( data[COLOR_B] ) );
luma = PlaYUVerFrame::ConvertPixel( currPixel, PlaYUVerFrame::COLOR_YUV ).Y();
m_pdHistogram[luma + j * m_uiHistoSegments]++;
m_puiHistogram[luma + j * m_uiHistoSegments]++;
}
for( j = 0; j < m_uiChannels; j++ )
data[j] += 1;
@@ -228,7 +228,7 @@ Double PlaYUVerFrameStats::getCount( Int channel, UInt start, UInt end )
Int indexStart;
Double count = 0.0;
if( !m_pdHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end )
if( !m_puiHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end )
{
return 0.0;
}
@@ -244,14 +244,14 @@ Double PlaYUVerFrameStats::getCount( Int channel, UInt start, UInt end )
for( i = start; i <= end; i++ )
{
count += m_pdHistogram[indexStart + i];
count += m_puiHistogram[indexStart + i];
}
return count;
}
Double PlaYUVerFrameStats::getPixels()
{
if( !m_pdHistogram )
if( !m_puiHistogram )
{
return 0.0;
}
@@ -266,7 +266,7 @@ Double PlaYUVerFrameStats::getMean( Int channel, UInt start, UInt end )
Double mean = 0.0;
Double count;
if( !m_pdHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end )
if( !m_puiHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end )
{
return 0.0;
}
@@ -282,7 +282,7 @@ Double PlaYUVerFrameStats::getMean( Int channel, UInt start, UInt end )
for( UInt i = start; i <= end; i++ )
{
mean += i * m_pdHistogram[indexStart + i];
mean += i * m_puiHistogram[indexStart + i];
}
count = getCount( channel, start, end );
@@ -302,7 +302,7 @@ Int PlaYUVerFrameStats::getMedian( Int channel, UInt start, UInt end )
Double sum = 0.0;
Double count;
if( !m_pdHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end )
if( !m_puiHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end )
{
return 0;
}
@@ -320,7 +320,7 @@ Int PlaYUVerFrameStats::getMedian( Int channel, UInt start, UInt end )
for( UInt i = start; i <= end; i++ )
{
sum += m_pdHistogram[indexStart + i];
sum += m_puiHistogram[indexStart + i];
if( sum * 2 > count )
return i;
}
@@ -336,7 +336,7 @@ Double PlaYUVerFrameStats::getStdDev( Int channel, UInt start, UInt end )
Double count;
Double mean;
if( !m_pdHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end )
if( !m_puiHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end )
{
return 0.0;
}
@@ -359,7 +359,7 @@ Double PlaYUVerFrameStats::getStdDev( Int channel, UInt start, UInt end )
for ( i = start ; i <= end ; i++ )
{
dev += ( i - mean ) * ( i - mean ) * m_pdHistogram[indexStart +i];
dev += ( i - mean ) * ( i - mean ) * m_puiHistogram[indexStart +i];
}
return sqrt( dev / count );
@@ -368,7 +368,7 @@ Double PlaYUVerFrameStats::getStdDev( Int channel, UInt start, UInt end )
for( UInt i = start; i <= end; i++ )
{
dev += ( i * i ) * m_pdHistogram[indexStart + i];
dev += ( i * i ) * m_puiHistogram[indexStart + i];
}
return sqrt( ( dev - count * mean * mean ) / ( count - 1 ) );
@@ -381,7 +381,7 @@ Double PlaYUVerFrameStats::getHistogramValue( Int channel, UInt bin )
Int histoChannel;
Int indexStart;
if( !m_pdHistogram || bin < 0 || bin > m_uiHistoSegments - 1 )
if( !m_puiHistogram || bin < 0 || bin > m_uiHistoSegments - 1 )
return 0.0;
histoChannel = getRealHistoChannel( channel );
@@ -393,7 +393,7 @@ Double PlaYUVerFrameStats::getHistogramValue( Int channel, UInt bin )
indexStart = histoChannel * m_uiHistoSegments;
value = m_pdHistogram[indexStart + bin];
value = m_puiHistogram[indexStart + bin];
return value;
}
@@ -405,7 +405,7 @@ Double PlaYUVerFrameStats::getMaximum( Int channel )
Int histoChannel;
Int indexStart;
if( !m_pdHistogram )
if( !m_puiHistogram )
return 0.0;
histoChannel = getRealHistoChannel( channel );
@@ -419,9 +419,9 @@ Double PlaYUVerFrameStats::getMaximum( Int channel )
for( UInt x = 0; x < m_uiHistoSegments; x++ )
{
if( m_pdHistogram[indexStart + x] > max )
if( m_puiHistogram[indexStart + x] > max )
{
max = m_pdHistogram[indexStart + x];
max = m_puiHistogram[indexStart + x];
}
}
+1 -1
View File
@@ -95,7 +95,7 @@ public:
private:
/** The histogram data.*/
Double* m_pdHistogram;
UInt* m_puiHistogram;
/** If true, calc the luminosity channel histogram when the image is RGB */
Bool calcLuma;
+5 -15
View File
@@ -364,7 +364,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
return m_bInit;
}
if( !getMem1D<Pel>( &m_pStreamBuffer, m_pcCurrFrame->getBytesPerFrame() ) )
if( !getMem1D<Byte>( &m_pStreamBuffer, m_pcCurrFrame->getBytesPerFrame() ) )
{
close();
throw "[PlaYUVerStream] Cannot allocated memory";
@@ -432,7 +432,7 @@ Void PlaYUVerStream::close()
}
if( m_pStreamBuffer )
freeMem1D<Pel>( m_pStreamBuffer );
freeMem1D<Byte>( m_pStreamBuffer );
if( m_pchFilename )
delete[] m_pchFilename;
@@ -563,7 +563,7 @@ Void PlaYUVerStream::readFrame()
if( m_uiStreamHandler == YUV_IO )
{
UInt64 frame_bytes_input = m_pcNextFrame->getBytesPerFrame();
UInt64 bytes_read = fread( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile );
UInt64 bytes_read = fread( m_pStreamBuffer, sizeof(Byte), frame_bytes_input, m_pFile );
if( bytes_read != frame_bytes_input )
{
throw "[PlaYUVerStream] Cannot read file";
@@ -577,17 +577,7 @@ Void PlaYUVerStream::readFrame()
Void PlaYUVerStream::writeFrame()
{
if( m_uiStreamHandler == YUV_IO )
{
UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame();
m_pcCurrFrame->frameToBuffer( m_pStreamBuffer );
UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile );
if( bytes_read != frame_bytes_input )
{
throw "[PlaYUVerStream] Cannot write into the file";
}
}
return;
writeFrame( m_pcCurrFrame );
}
Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame )
@@ -596,7 +586,7 @@ Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame )
{
UInt64 frame_bytes_input = pcFrame->getBytesPerFrame();
pcFrame->frameToBuffer( m_pStreamBuffer );
UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile );
UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Byte), frame_bytes_input, m_pFile );
if( bytes_read != frame_bytes_input )
{
throw "[PlaYUVerStream] Cannot write into the file";
+1 -1
View File
@@ -84,7 +84,7 @@ private:
Int m_iPixelFormat;
UInt m_uiBitsPerPixel;
Pel* m_pStreamBuffer;
Byte* m_pStreamBuffer;
UInt m_uiFrameBufferSize;
PlaYUVerFrame **m_ppcFrameBuffer;