Add a variable to control the number of bits per pixel

This commit is contained in:
2015-04-02 17:34:43 +01:00
parent 32c224a49d
commit d8952ce953
11 changed files with 84 additions and 52 deletions
+19 -1
View File
@@ -174,6 +174,21 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) :
pixelGridLayout->addItem( new QSpacerItem( 10, 10, QSizePolicy::Expanding, QSizePolicy::Minimum ), 1, 1 );
pixelGridLayout->addWidget( m_comboBoxPixelFormat, 1, 2 );
/*
* Frame rate format
*/
QHBoxLayout* bitsPerPelLayout = new QHBoxLayout();
QLabel* bitsPerPelLabel = new QLabel();
bitsPerPelLabel->setFont( menusFont );
bitsPerPelLabel->setText( "Frame Rate" );
m_spinBoxBits = new QSpinBox();
m_spinBoxBits->setMinimumWidth( 30 );
m_spinBoxBits->setRange( 0, 16 );
m_spinBoxBits->setValue( 8 );
bitsPerPelLayout->addWidget( bitsPerPelLabel );
bitsPerPelLayout->addItem( new QSpacerItem( 20, 10, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
bitsPerPelLayout->addWidget( m_spinBoxBits );
/*
* Frame rate format
*/
@@ -204,6 +219,7 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) :
MainLayout->addWidget( resolutionGroup );
MainLayout->addItem( new QSpacerItem( 10, 5, QSizePolicy::Minimum ) );
MainLayout->addWidget( pixelGroup );
MainLayout->addLayout( bitsPerPelLayout );
MainLayout->addItem( new QSpacerItem( 10, 5, QSizePolicy::Minimum ) );
MainLayout->addLayout( framerateFormatLayout );
MainLayout->addItem( new QSpacerItem( 10, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
@@ -218,7 +234,7 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) :
}
Int ConfigureFormatDialog::runConfigureFormatDialog( QString Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate )
Int ConfigureFormatDialog::runConfigureFormatDialog( QString Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBits, UInt& rFrameRate )
{
// Set default values
//setWindowTitle( "Configure resolution for " + Filename );
@@ -246,6 +262,7 @@ Int ConfigureFormatDialog::runConfigureFormatDialog( QString Filename, UInt& rWi
}
m_comboBoxColorSpace->setCurrentIndex( colorSpace );
m_comboBoxPixelFormat->setCurrentIndex( sampling );
m_spinBoxBits->setValue( rBits );
m_spinBoxFrameRate->setValue( rFrameRate );
for( Int i = 0; i < standardResolutionSizes.size(); i++ )
{
@@ -270,6 +287,7 @@ Int ConfigureFormatDialog::runConfigureFormatDialog( QString Filename, UInt& rWi
rInputFormat = i;
}
}
rBits = m_spinBoxBits->value();
rFrameRate = m_spinBoxFrameRate->value();
return QDialog::Accepted;
}
+2 -3
View File
@@ -34,8 +34,6 @@
#endif
#include <QtCore>
class QPixmap;
class QColor;
@@ -52,7 +50,7 @@ Q_OBJECT
public:
ConfigureFormatDialog( QWidget *parent = 0 );
Int runConfigureFormatDialog ( QString Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate );
Int runConfigureFormatDialog( QString Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBits, UInt& rFrameRate );
private Q_SLOTS:
void StandardResolutionSelection();
@@ -68,6 +66,7 @@ private:
QSpinBox *m_spinBoxheight;
QComboBox *m_comboBoxColorSpace;
QComboBox *m_comboBoxPixelFormat;
QSpinBox *m_spinBoxBits;
QSpinBox *m_spinBoxFrameRate;
};
+9 -6
View File
@@ -44,6 +44,7 @@ QDataStream& operator<<( QDataStream& out, const PlaYUVerStreamInfoVector& array
<< d.m_uiHeight
<< d.m_iPelFormat
<< d.m_uiFrameRate
<< d.m_uiBitsPelPixel
<< d.m_uiFileSize;
}
return out;
@@ -60,6 +61,7 @@ QDataStream& operator>>( QDataStream& in, PlaYUVerStreamInfoVector& array )
in >> d.m_uiWidth;
in >> d.m_uiHeight;
in >> d.m_iPelFormat;
in >> d.m_uiBitsPelPixel;
in >> d.m_uiFrameRate;
in >> d.m_uiFileSize;
array.append( d );
@@ -141,16 +143,16 @@ Void VideoSubWindow::refreshSubWindow()
Bool VideoSubWindow::loadFile( QString cFilename, Bool bForceDialog )
{
UInt Width = 0, Height = 0, FrameRate = 30;
UInt Width = 0, Height = 0, BitsPel = 8, FrameRate = 30;
Int InputFormat = PlaYUVerFrame::YUV420p;
if( m_pCurrStream )
m_pCurrStream->getFormat( Width, Height, InputFormat, FrameRate );
m_pCurrStream->getFormat( Width, Height, InputFormat, BitsPel, FrameRate );
if( guessFormat( cFilename, Width, Height, InputFormat, FrameRate ) || bForceDialog )
{
ConfigureFormatDialog formatDialog( this );
if( formatDialog.runConfigureFormatDialog( QFileInfo( cFilename ).fileName(), Width, Height, InputFormat, FrameRate ) == QDialog::Rejected )
if( formatDialog.runConfigureFormatDialog( QFileInfo( cFilename ).fileName(), Width, Height, InputFormat, BitsPel, FrameRate ) == QDialog::Rejected )
{
return false;
}
@@ -166,12 +168,13 @@ Bool VideoSubWindow::loadFile( QString cFilename, Bool bForceDialog )
m_pCurrStream = new PlaYUVerStream;
}
m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, FrameRate );
m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, BitsPel, FrameRate );
m_sStreamInfo.m_cFilename = cFilename;
m_sStreamInfo.m_uiWidth = Width;
m_sStreamInfo.m_uiHeight = Height;
m_sStreamInfo.m_iPelFormat = InputFormat;
m_sStreamInfo.m_uiBitsPelPixel = BitsPel;
m_sStreamInfo.m_uiFrameRate = FrameRate;
m_sStreamInfo.m_uiFileSize = QFileInfo( cFilename ).size();
@@ -198,7 +201,7 @@ Bool VideoSubWindow::loadFile( PlaYUVerStreamInfo* streamInfo )
}
if( !m_pCurrStream->open( streamInfo->m_cFilename.toStdString(), streamInfo->m_uiWidth, streamInfo->m_uiHeight, streamInfo->m_iPelFormat,
streamInfo->m_uiFrameRate ) )
streamInfo->m_uiBitsPelPixel, streamInfo->m_uiFrameRate ) )
{
return false;
}
@@ -317,7 +320,7 @@ Bool VideoSubWindow::guessFormat( QString filename, UInt& rWidth, UInt& rHeight,
Int count = 0, module, frame_bytes, match;
for( UInt i = 0; i < stdResList.size(); i++ )
{
frame_bytes = PlaYUVerFrame::getBytesPerFrame( stdResList[i].uiWidth, stdResList[i].uiHeight, rInputFormat );
frame_bytes = PlaYUVerFrame::getBytesPerFrame( stdResList[i].uiWidth, stdResList[i].uiHeight, rInputFormat, 8 );
module = uiFileSize % frame_bytes;
if( module == 0 )
{
+1
View File
@@ -49,6 +49,7 @@ typedef struct
UInt m_uiWidth;
UInt m_uiHeight;
Int m_iPelFormat;
UInt m_uiBitsPelPixel;
UInt m_uiFrameRate;
UInt64 m_uiFileSize;
} PlaYUVerStreamInfo;
+1
View File
@@ -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
View File
@@ -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
View File
@@ -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();
+1 -1
View File
@@ -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
View File
@@ -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();
+4 -3
View File
@@ -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();
+7 -7
View File
@@ -79,7 +79,7 @@ Int PlaYUVerTools::openInputs()
pcStream = new PlaYUVerStream;
try
{
if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, 1 ) )
if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, 8, 1 ) )
{
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Cannot open input stream %s! ", inputFileNames[i].c_str() );
return 2;
@@ -132,11 +132,11 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
if( m_cCmdLineHandler.Opts()["quality"]->count() )
{
std::string qualityMetric = m_cCmdLineHandler.m_strQualityMetric;
if( m_apcInputStreams.size() != 2 )
{
m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Invalid number of inputs! " );
return 2;
}
// if( m_apcInputStreams.size() != 2 )
// {
// m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Invalid number of inputs! " );
// return 2;
// }
for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ )
{
if( lowercase( PlaYUVerFrame::supportedQualityMetricsList()[i] ) == lowercase( qualityMetric ) )
@@ -193,7 +193,7 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] )
{
PlaYUVerFrame* pcModFrame = applyFrameModule();
PlaYUVerStream* pcModStream = new PlaYUVerStream;
if( !pcModStream->open( outputFileNames[0], pcModFrame->getWidth(), pcModFrame->getHeight(), pcModFrame->getPelFormat(), 1, false ) )
if( !pcModStream->open( outputFileNames[0], pcModFrame->getWidth(), pcModFrame->getHeight(), pcModFrame->getPelFormat(), 8, 1, false ) )
{
delete pcModStream;
pcModStream = NULL;