Add a variable to control the number of bits per pixel
This commit is contained in:
1 parent
32c224a49d
commit
d8952ce953
11 files changed
+84
-52
No files matched your search
@@ -76,6 +76,7 @@ typedef unsigned long long UInt64;
|
||||
// ====================================================================================================================
|
||||
|
||||
typedef UChar Pel; ///< 8-bit pixel type
|
||||
typedef UChar SBytePel; ///< 8-bit pixel type
|
||||
//typedef Short Pel; ///< 16-bit pixel type
|
||||
|
||||
// ====================================================================================================================
|
||||
|
||||
+16
-17
@@ -99,14 +99,14 @@ PlaYUVerFrame::Pixel PlaYUVerFrame::ConvertPixel( Pixel inputPixel, ColorSpace e
|
||||
return outPixel;
|
||||
}
|
||||
|
||||
PlaYUVerFrame::PlaYUVerFrame( UInt width, UInt height, Int pel_format )
|
||||
PlaYUVerFrame::PlaYUVerFrame( UInt width, UInt height, Int pelFormat, Int bitsPixel )
|
||||
{
|
||||
init( width, height, pel_format );
|
||||
init( width, height, pelFormat, bitsPixel );
|
||||
}
|
||||
|
||||
PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other )
|
||||
{
|
||||
init( other->getWidth(), other->getHeight(), other->getPelFormat() );
|
||||
init( other->getWidth(), other->getHeight(), other->getPelFormat(), other->getBitsPel() );
|
||||
copyFrom( other );
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other, UInt posX, UInt posY, UInt a
|
||||
areaHeight++;
|
||||
}
|
||||
|
||||
init( areaWidth, areaHeight, other->getPelFormat() );
|
||||
init( areaWidth, areaHeight, other->getPelFormat(), other->getBitsPel() );
|
||||
copyFrom( other, posX, posY );
|
||||
}
|
||||
|
||||
@@ -145,16 +145,16 @@ PlaYUVerFrame::~PlaYUVerFrame()
|
||||
closePixfc();
|
||||
}
|
||||
|
||||
static Int getMem3ImageComponents( Pel**** array3D, Int dim1, Int dim2, Int log2ChromaHeight, Int log2ChromaWidth )
|
||||
static Int getMem3ImageComponents( SBytePel**** 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<Pel*>( array3D, dim0, dim1 );
|
||||
total_mem_size += getMem2D<SBytePel*>( array3D, dim0, dim1 );
|
||||
|
||||
if( ( ( *array3D )[0][0] = ( Pel* )xCallocMem( mem_size, sizeof(Pel) ) ) == NULL )
|
||||
if( ( ( *array3D )[0][0] = ( SBytePel* )xCallocMem( mem_size, sizeof(Pel) ) ) == NULL )
|
||||
printf( "getMem3DImageComponents: array1D" );
|
||||
|
||||
total_mem_size += mem_size * sizeof(Pel);
|
||||
@@ -179,7 +179,7 @@ static Int getMem3ImageComponents( Pel**** array3D, Int dim1, Int dim2, Int log2
|
||||
return total_mem_size;
|
||||
}
|
||||
|
||||
Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format )
|
||||
Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel )
|
||||
{
|
||||
m_pppcInputPel = NULL;
|
||||
m_pcARGB32 = NULL;
|
||||
@@ -187,13 +187,11 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format )
|
||||
m_uiHeight = height;
|
||||
m_iPixelFormat = pel_format;
|
||||
m_iNumberChannels = 3;
|
||||
m_iBitsChannels = 8;
|
||||
m_iBitsPel = bitsPixel;
|
||||
|
||||
Int max_bits_per_pel = sizeof(Pel) * 8;
|
||||
|
||||
if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || m_iBitsChannels > max_bits_per_pel )
|
||||
if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > 16 )
|
||||
{
|
||||
return;
|
||||
throw "Cannot create a PlYUVerFrame of this type";
|
||||
}
|
||||
|
||||
m_pcPelFormat = &( g_PlaYUVerPixFmtDescriptorsList[pel_format] );
|
||||
@@ -225,19 +223,20 @@ UInt PlaYUVerFrame::getNumberChannels() const
|
||||
|
||||
UInt64 PlaYUVerFrame::getBytesPerFrame()
|
||||
{
|
||||
return getBytesPerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat );
|
||||
return getBytesPerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat, m_iBitsPel );
|
||||
}
|
||||
|
||||
UInt64 PlaYUVerFrame::getBytesPerFrame( UInt uiWidth, UInt uiHeight, Int iPixelFormat )
|
||||
UInt64 PlaYUVerFrame::getBytesPerFrame( UInt uiWidth, UInt uiHeight, Int iPixelFormat, Int bitsPixel )
|
||||
{
|
||||
PlaYUVerPixFmtDescriptor* pcPelFormat = &( g_PlaYUVerPixFmtDescriptorsList[iPixelFormat] );
|
||||
UInt bytesPerPixel = bitsPixel / 8;
|
||||
UInt64 numberBytes = uiWidth * uiHeight;
|
||||
if( pcPelFormat->numberChannels > 1 )
|
||||
{
|
||||
UInt64 numberBytesChroma = CHROMASHIFT( uiWidth, pcPelFormat->log2ChromaWidth ) * CHROMASHIFT( uiHeight, pcPelFormat->log2ChromaHeight );
|
||||
numberBytes += ( pcPelFormat->numberChannels - 1 ) * numberBytesChroma;
|
||||
}
|
||||
return numberBytes;
|
||||
return numberBytes * bytesPerPixel;
|
||||
}
|
||||
|
||||
UInt PlaYUVerFrame::getChromaWidth() const
|
||||
@@ -501,7 +500,7 @@ Void PlaYUVerFrame::fromCvMat( Void* voidFrame )
|
||||
|
||||
if( !isValid() )
|
||||
{
|
||||
init( opencvFrame->cols, opencvFrame->rows, m_iPixelFormat );
|
||||
init( opencvFrame->cols, opencvFrame->rows, m_iPixelFormat, 8 );
|
||||
}
|
||||
|
||||
m_bHasRGBPel = false;
|
||||
|
||||
+6
-6
@@ -158,7 +158,7 @@ public:
|
||||
* pixel format
|
||||
* @return number of bytes per frame
|
||||
*/
|
||||
static UInt64 getBytesPerFrame( UInt, UInt, Int );
|
||||
static UInt64 getBytesPerFrame( UInt uiWidth, UInt uiHeight, Int iPixelFormat, Int bitsPixel );
|
||||
|
||||
/**
|
||||
* Convert a Pixel to a new color space
|
||||
@@ -177,7 +177,7 @@ public:
|
||||
*
|
||||
* @note this function might misbehave if the pixel format enum is not correct
|
||||
*/
|
||||
PlaYUVerFrame( UInt width, UInt height, Int pel_format = 0 );
|
||||
PlaYUVerFrame( UInt width, UInt height, Int pelFormat = 0, Int bitsPixel = 8 );
|
||||
|
||||
/**
|
||||
* Creates and new frame with the configuration of an
|
||||
@@ -236,9 +236,9 @@ public:
|
||||
{
|
||||
return m_iPixelFormat;
|
||||
}
|
||||
Int getBitsChannel() const
|
||||
Int getBitsPel() const
|
||||
{
|
||||
return m_iBitsChannels;
|
||||
return m_iBitsPel;
|
||||
}
|
||||
Bool isValid() const
|
||||
{
|
||||
@@ -334,7 +334,7 @@ private:
|
||||
UInt m_uiHeight; //!< Height of the frame
|
||||
Int m_iPixelFormat; //!< Pixel format number (it follows the list of supported pixel formats)
|
||||
Int m_iNumberChannels; //!< Number of channels
|
||||
Int m_iBitsChannels; //!< Bits per pixel/channel
|
||||
Int m_iBitsPel; //!< Bits per pixel/channel
|
||||
|
||||
Pel*** m_pppcInputPel;
|
||||
|
||||
@@ -349,7 +349,7 @@ private:
|
||||
* @param pel_format pixel format index (always use PixelFormats enum)
|
||||
*
|
||||
*/
|
||||
Void init( UInt width, UInt height, Int pel_format );
|
||||
Void init( UInt width, UInt height, Int pel_format, Int bitsPixel );
|
||||
|
||||
Void openPixfc();
|
||||
Void closePixfc();
|
||||
|
||||
@@ -56,7 +56,7 @@ Void PlaYUVerFrameStats::xSetupStatistics( const PlaYUVerFrame *pcFrame, UInt op
|
||||
m_uiImageHeight = pcFrame->getHeight();
|
||||
m_uiChannels = pcFrame->getNumberChannels();
|
||||
|
||||
m_uiHistoSegments = ( pcFrame->getBitsChannel() == 16 ) ? 65536 : 256;
|
||||
m_uiHistoSegments = 1 << pcFrame->getBitsPel();
|
||||
imageColorSpace = pcFrame->getColorSpace();
|
||||
imageChromaSize = pcFrame->getChromaLength();
|
||||
|
||||
|
||||
+18
-8
@@ -163,7 +163,7 @@ PlaYUVerStream::~PlaYUVerStream()
|
||||
close();
|
||||
}
|
||||
|
||||
Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::string input_format_name, UInt frame_rate, Bool bInput )
|
||||
Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::string input_format_name, UInt bitsPel, UInt frame_rate, Bool bInput )
|
||||
{
|
||||
UInt width;
|
||||
UInt height;
|
||||
@@ -185,10 +185,10 @@ Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::st
|
||||
break;
|
||||
}
|
||||
}
|
||||
return open( filename, width, height, input_format, frame_rate, bInput );
|
||||
return open( filename, width, height, input_format, bitsPel, frame_rate, bInput );
|
||||
}
|
||||
|
||||
Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int input_format, UInt frame_rate, Bool bInput )
|
||||
Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int input_format, UInt bitsPel, UInt frame_rate, Bool bInput )
|
||||
{
|
||||
if( m_bInit )
|
||||
{
|
||||
@@ -200,6 +200,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
|
||||
m_uiWidth = width;
|
||||
m_uiHeight = height;
|
||||
m_iPixelFormat = input_format;
|
||||
m_uiBitsPerPixel = bitsPel;
|
||||
m_dFrameRate = frame_rate;
|
||||
|
||||
m_pchFilename = new Char[m_cFilename.size() + 1];
|
||||
@@ -254,6 +255,10 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if( m_uiBitsPerPixel != 8 )
|
||||
{
|
||||
m_uiStreamHandler = YUV_IO;
|
||||
}
|
||||
m_uiFrameBufferSize = 2;
|
||||
}
|
||||
else
|
||||
@@ -311,8 +316,11 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
|
||||
getMem1D<PlaYUVerFrame*>( &m_ppcFrameBuffer, m_uiFrameBufferSize );
|
||||
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
|
||||
{
|
||||
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat );
|
||||
if( !m_ppcFrameBuffer[i] )
|
||||
try
|
||||
{
|
||||
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel );
|
||||
}
|
||||
catch( const char *msg )
|
||||
{
|
||||
close();
|
||||
throw "[PlaYUVerStream] Cannot allocated frame buffer";
|
||||
@@ -384,7 +392,7 @@ Bool PlaYUVerStream::openFile()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( m_bIsInput )
|
||||
if( m_bIsInput )
|
||||
{
|
||||
fseek( m_pFile, m_iCurrFrameNum >= 0 ? m_iCurrFrameNum : 0, SEEK_SET );
|
||||
}
|
||||
@@ -433,13 +441,14 @@ Void PlaYUVerStream::close()
|
||||
m_bInit = false;
|
||||
}
|
||||
|
||||
Void PlaYUVerStream::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate )
|
||||
Void PlaYUVerStream::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, UInt& rFrameRate )
|
||||
{
|
||||
if( m_bInit )
|
||||
{
|
||||
rWidth = m_uiWidth;
|
||||
rHeight = m_uiHeight;
|
||||
rInputFormat = m_iPixelFormat;
|
||||
rBitsPerPel = m_uiBitsPerPixel;
|
||||
rFrameRate = m_dFrameRate;
|
||||
}
|
||||
else
|
||||
@@ -447,6 +456,7 @@ Void PlaYUVerStream::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat,
|
||||
rWidth = 0;
|
||||
rHeight = 0;
|
||||
rInputFormat = PlaYUVerFrame::YUV420p;
|
||||
rBitsPerPel = 8;
|
||||
rFrameRate = 30;
|
||||
}
|
||||
}
|
||||
@@ -471,7 +481,7 @@ Void PlaYUVerStream::loadAll()
|
||||
getMem1D<PlaYUVerFrame*>( &m_ppcFrameBuffer, m_uiFrameBufferSize );
|
||||
for( UInt i = 0; i < m_uiFrameBufferSize; i++ )
|
||||
{
|
||||
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat );
|
||||
m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel );
|
||||
if( !m_ppcFrameBuffer[i] )
|
||||
{
|
||||
close();
|
||||
|
||||
@@ -82,6 +82,7 @@ private:
|
||||
|
||||
Int m_iFileFormat;
|
||||
Int m_iPixelFormat;
|
||||
UInt m_uiBitsPerPixel;
|
||||
|
||||
Pel* m_pStreamBuffer;
|
||||
|
||||
@@ -121,14 +122,14 @@ public:
|
||||
END_OF_SEQ,
|
||||
};
|
||||
|
||||
Bool open( std::string filename, std::string resolution, std::string input_format, UInt frame_rate, Bool bInput = true );
|
||||
Bool open( std::string filename, UInt width, UInt height, Int input_format, UInt frame_rate, Bool bInput = true );
|
||||
Bool open( std::string filename, std::string resolution, std::string input_format, UInt bitsPel, UInt frame_rate, Bool bInput = true );
|
||||
Bool open( std::string filename, UInt width, UInt height, Int input_format, UInt bitsPel, UInt frame_rate, Bool bInput = true );
|
||||
Void close();
|
||||
|
||||
Bool openFile();
|
||||
Void closeFile();
|
||||
|
||||
Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate );
|
||||
Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, UInt& rFrameRate );
|
||||
|
||||
Void loadAll();
|
||||
|
||||
|
||||
Reference in new issue
Block a user