Add support for little and big endian with an option

This commit is contained in:
jfmcarreira committed 2016-03-31 00:52:11 +01:00
1 parent f596fda8dc
commit b68bbded34
14 files changed
+104 -35

No files matched your search

+38 -6
View File
@@ -174,7 +174,7 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) :
pixelGridLayout->addItem( new QSpacerItem( 10, 10, QSizePolicy::Expanding, QSizePolicy::Minimum ), 1, 1 );
pixelGridLayout->addWidget( m_comboBoxPixelFormat, 1, 2 );
QHBoxLayout* bitsPerPelLayout = new QHBoxLayout();
QLabel* bitsPerPelLabel = new QLabel();
bitsPerPelLabel->setFont( normalFont );
bitsPerPelLabel->setText( "Pixel bit depth" );
@@ -187,6 +187,27 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) :
pixelGridLayout->addItem( new QSpacerItem( 20, 10, QSizePolicy::Expanding, QSizePolicy::Minimum ), 2, 1 );
pixelGridLayout->addWidget( m_spinBoxBits, 2, 2 );
/*
* Endianess
*/
QHBoxLayout* endiannessLayout = new QHBoxLayout();
QLabel* endiannessLabel = new QLabel();
endiannessLabel->setFont( menusFont );
endiannessLabel->setText( "Endianness" );
QComboBox* endiannessComboBox = new QComboBox();
endiannessComboBox->setFont( normalFont );
endiannessComboBox->setSizePolicy( sizePolicy );
endiannessComboBox->clear();
endiannessComboBox->addItem( QStringLiteral("Big Endian") );
endiannessComboBox->addItem( QStringLiteral("Little Endian") );
endiannessComboBox->setCurrentIndex( 0 );
endiannessLayout->addWidget( endiannessLabel );
endiannessLayout->addItem( new QSpacerItem( 20, 10, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
endiannessLayout->addWidget( endiannessComboBox );
m_widgetEndianness = new QWidget();
m_widgetEndianness->setLayout( endiannessLayout );
m_widgetEndianness->setVisible( true );
/*
* Frame rate format
*/
@@ -212,13 +233,11 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) :
dialogButtonOkCancel->setCenterButtons( false );
MainLayout->addItem( new QSpacerItem( 10, 5, QSizePolicy::Minimum ) );
// MainLayout->addLayout( standardResolutionLayout );
// MainLayout->addItem( new QSpacerItem( 10, 10, QSizePolicy::Minimum ) );
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->addWidget( m_widgetEndianness );
MainLayout->addLayout( framerateFormatLayout );
MainLayout->addItem( new QSpacerItem( 10, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
MainLayout->addWidget( dialogButtonOkCancel );
@@ -226,8 +245,9 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) :
connect( m_comboBoxStandardResolution, SIGNAL( currentIndexChanged(int) ), this, SLOT( slotStandardResolutionSelected(int) ) );
connect( m_spinBoxWidth, SIGNAL( valueChanged(int) ), this, SLOT( slotResolutionChange() ) );
connect( m_spinBoxheight, SIGNAL( valueChanged(int) ), this, SLOT( slotResolutionChange() ) );
connect( m_comboBoxColorSpace, SIGNAL( currentIndexChanged(int) ), this, SLOT( slotColorSpaceChange(int) ) );
connect( m_spinBoxBits, SIGNAL( valueChanged(int) ), this, SLOT( slotBitsChange(int) ) );
connect( dialogButtonOkCancel, SIGNAL( accepted() ), this, SLOT( accept() ) );
connect( dialogButtonOkCancel, SIGNAL( rejected() ), this, SLOT( reject() ) );
@@ -237,7 +257,7 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) :
}
Int ConfigureFormatDialog::runConfigureFormatDialog( QString Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBits, UInt& rFrameRate )
Int ConfigureFormatDialog::runConfigureFormatDialog( QString Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBits, UInt& rEndianess, UInt& rFrameRate )
{
// Set default values
//setWindowTitle( "Configure resolution for " + Filename );
@@ -340,4 +360,16 @@ Void ConfigureFormatDialog::slotColorSpaceChange( Int idx )
m_comboBoxPixelFormat->setCurrentIndex( 0 );
}
Void ConfigureFormatDialog::slotBitsChange( Int idx )
{
if( idx > 8 )
{
m_widgetEndianness->setVisible( true );
}
else
{
m_widgetEndianness->setVisible( false );
}
}
} // NAMESPACE
+4 -1
View File
@@ -50,12 +50,13 @@ Q_OBJECT
public:
ConfigureFormatDialog( QWidget *parent = 0 );
Int runConfigureFormatDialog( QString Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBits, UInt& rFrameRate );
Int runConfigureFormatDialog( QString Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBits, UInt& rEndianess, UInt& rFrameRate );
private Q_SLOTS:
void slotStandardResolutionSelected( int );
void slotResolutionChange();
void slotColorSpaceChange( int );
void slotBitsChange( int );
private:
QStringList standardResolutionNames;
@@ -68,6 +69,8 @@ private:
QComboBox *m_comboBoxColorSpace;
QComboBox *m_comboBoxPixelFormat;
QSpinBox *m_spinBoxBits;
QWidget* m_widgetEndianness;
QHBoxLayout* framerateFormatLayout;
QSpinBox *m_spinBoxFrameRate;
};
+8 -6
View File
@@ -51,6 +51,7 @@ QDataStream& operator<<( QDataStream& out, const PlaYUVerStreamInfoVector& array
<< d.m_uiHeight
<< d.m_iPelFormat
<< d.m_uiBitsPelPixel
<< d.m_uiEndianness
<< d.m_uiFrameRate
<< d.m_uiFileSize;
}
@@ -69,6 +70,7 @@ QDataStream& operator>>( QDataStream& in, PlaYUVerStreamInfoVector& array )
in >> d.m_uiHeight;
in >> d.m_iPelFormat;
in >> d.m_uiBitsPelPixel;
in >> d.m_uiEndianness;
in >> d.m_uiFrameRate;
in >> d.m_uiFileSize;
array.append( d );
@@ -306,7 +308,7 @@ Void VideoSubWindow::refreshSubWindow()
Bool VideoSubWindow::loadFile( QString cFilename, Bool bForceDialog )
{
ConfigureFormatDialog formatDialog( this );
UInt Width = 0, Height = 0, BitsPel = 8, FrameRate = 30;
UInt Width = 0, Height = 0, BitsPel = 8, Endianness = 0, FrameRate = 30;
Int InputFormat = PlaYUVerFrame::YUV420p;
if( m_pCurrStream )
@@ -319,7 +321,7 @@ Bool VideoSubWindow::loadFile( QString cFilename, Bool bForceDialog )
if( guessFormat( cFilename, Width, Height, InputFormat, FrameRate ) || bForceDialog )
{
if( formatDialog.runConfigureFormatDialog( QFileInfo( cFilename ).fileName(), Width, Height, InputFormat, BitsPel, FrameRate ) == QDialog::Rejected )
if( formatDialog.runConfigureFormatDialog( QFileInfo( cFilename ).fileName(), Width, Height, InputFormat, BitsPel, Endianness, FrameRate ) == QDialog::Rejected )
{
return false;
}
@@ -327,15 +329,15 @@ Bool VideoSubWindow::loadFile( QString cFilename, Bool bForceDialog )
try
{
m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, BitsPel, FrameRate );
m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, BitsPel, Endianness, FrameRate );
}
catch( const char *msg )
{
if( formatDialog.runConfigureFormatDialog( QFileInfo( cFilename ).fileName(), Width, Height, InputFormat, BitsPel, FrameRate ) == QDialog::Rejected )
if( formatDialog.runConfigureFormatDialog( QFileInfo( cFilename ).fileName(), Width, Height, InputFormat, BitsPel, Endianness, FrameRate ) == QDialog::Rejected )
{
return false;
}
m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, BitsPel, FrameRate );
m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, BitsPel, Endianness, FrameRate );
}
m_sStreamInfo.m_cFilename = cFilename;
@@ -365,7 +367,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_uiBitsPelPixel, streamInfo->m_uiFrameRate ) )
streamInfo->m_uiBitsPelPixel, streamInfo->m_uiEndianness, streamInfo->m_uiFrameRate ) )
{
return false;
}
+1
View File
@@ -52,6 +52,7 @@ typedef struct
UInt m_uiHeight;
Int m_iPelFormat;
UInt m_uiBitsPelPixel;
UInt m_uiEndianness;
UInt m_uiFrameRate;
UInt64 m_uiFileSize;
} PlaYUVerStreamInfo;
+3 -3
View File
@@ -112,7 +112,7 @@ Void LibAvContextHandle::closeAvFormat()
m_bHasStream = false;
}
Bool LibAvContextHandle::initAvFormat( const char* filename, UInt& width, UInt& height, Int& pixel_format, UInt& bits_pel, Double& frame_rate,
Bool LibAvContextHandle::initAvFormat( const char* filename, UInt& width, UInt& height, Int& pixel_format, UInt& endianness, UInt& bits_pel, Double& frame_rate,
UInt64& num_frames )
{
fmt_ctx = NULL;
@@ -177,9 +177,9 @@ Bool LibAvContextHandle::initAvFormat( const char* filename, UInt& width, UInt&
getMem1D( &m_pchFrameBuffer, m_uiFrameBufferSize );
}
const char *name = avcodec_get_name( video_dec_ctx->codec_id );
const char *name = avcodec_get_name( video_dec_ctx->codec_id );
sprintf( m_acCodecName, "%s", name );
Double fr = 30;
if( video_stream->avg_frame_rate.den && video_stream->avg_frame_rate.num )
fr = av_q2d( video_stream->avg_frame_rate );
+1 -1
View File
@@ -65,7 +65,7 @@ public:
m_bHasStream( false )
{
}
Bool initAvFormat( const char* filename, UInt& width, UInt& height, Int& pixel_format, UInt& bits_pel, Double& frame_rate, UInt64& num_frames );
Bool initAvFormat( const char* filename, UInt& width, UInt& height, Int& pixel_format, UInt& bits_pel, UInt& endianness, Double& frame_rate, UInt64& num_frames );
Void closeAvFormat();
Bool decodeAvFormat();
+1
View File
@@ -119,6 +119,7 @@ enum RGBcomponent
COLOR_A,
};
inline std::string lowercase( const std::string& in )
{
std::string out;
+20 -7
View File
@@ -174,7 +174,7 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel
m_iNumberChannels = 3;
m_uiBitsPel = bitsPixel > 8 ? bitsPixel : 8;
m_uiHalfPelValue = 1 << ( m_uiBitsPel - 1 );
if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > 16 )
{
throw "Cannot create a PlYUVerFrame of this type";
@@ -385,18 +385,30 @@ Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame, UInt xPos, UInt yPos )
m_bHasHistogram = false;
}
Void PlaYUVerFrame::frameFromBuffer( Byte *Buff, UInt64 uiBuffSize )
Void PlaYUVerFrame::frameFromBuffer( Byte *Buff, UInt64 uiBuffSize, Int endianess )
{
if( uiBuffSize != getBytesPerFrame() )
return;
Byte* ppBuff[MAX_NUMBER_PLANES];
Byte* pTmpBuff;
Pel* pTmpPel;
Pel* pPel;
UInt bytesPixel = ( m_uiBitsPel - 1 ) / 8 + 1;
UInt shiftInput, shiftOutput;
Int ratioH, ratioW, step;
UInt i, ch, b;
if( endianess == 1 )
{
shiftInput = 8;
shiftOutput = 0;
}
else
{
shiftInput = 0;
shiftOutput = 8;
}
ppBuff[0] = Buff;
for( i = 1; i < MAX_NUMBER_PLANES; i++ )
{
@@ -411,18 +423,18 @@ Void PlaYUVerFrame::frameFromBuffer( Byte *Buff, UInt64 uiBuffSize )
ratioH = ch > 0 ? m_pcPelFormat->log2ChromaHeight : 0;
step = m_pcPelFormat->comp[ch].step_minus1 + 1;
pTmpPel = m_pppcInputPel[ch][0];
pPel = 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 ); i++ )
{
*pTmpPel = *pTmpBuff;
*pPel = *pTmpBuff;
for( b = 1; b < bytesPixel; b++ )
{
pTmpBuff++;
*pTmpPel |= ( *pTmpBuff << ( 8 * b ) );
*pPel = ( *pPel << shiftOutput ) + ( *pTmpBuff << shiftInput );
}
pTmpPel++;
pPel++;
pTmpBuff += step;
}
}
@@ -1186,3 +1198,4 @@ Double PlaYUVerFrame::getSSIM( PlaYUVerFrame* Org, Int component )
}
} // NAMESPACE
+1 -1
View File
@@ -211,7 +211,7 @@ public:
Void copyFrom( PlaYUVerFrame* );
Void copyFrom( PlaYUVerFrame*, UInt, UInt );
Void frameFromBuffer( Byte*, UInt64 );
Void frameFromBuffer( Byte*, UInt64, Int );
Void frameToBuffer( Byte* );
Void fillRGBBuffer();
+8 -7
View File
@@ -190,7 +190,7 @@ Void PlaYUVerStream::findHandler()
}
}
Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::string input_format_name, UInt bitsPel, UInt frame_rate, Bool bInput )
Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::string input_format_name, UInt bitsPel, UInt endianness, UInt frame_rate, Bool bInput )
{
UInt width;
UInt height;
@@ -212,10 +212,10 @@ Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::st
break;
}
}
return open( filename, width, height, input_format, bitsPel, frame_rate, bInput );
return open( filename, width, height, input_format, bitsPel, endianness, frame_rate, bInput );
}
Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int input_format, UInt bitsPel, UInt frame_rate, Bool bInput )
Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int input_format, UInt bitsPel, UInt endianness, UInt frame_rate, Bool bInput )
{
if( m_bInit )
{
@@ -228,6 +228,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
m_uiHeight = height;
m_iPixelFormat = input_format;
m_uiBitsPerPixel = bitsPel;
m_uiEndianness = endianness;
m_dFrameRate = frame_rate;
m_pchFilename = new Char[m_cFilename.size() + 1];
@@ -247,7 +248,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in
#ifdef USE_FFMPEG
if( m_iStreamHandler == FFMPEG )
{
if( !m_cLibAvContext->initAvFormat( m_pchFilename, m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel, m_dFrameRate, m_uiTotalFrameNum ) )
if( !m_cLibAvContext->initAvFormat( m_pchFilename, m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel, m_uiEndianness, m_dFrameRate, m_uiTotalFrameNum ) )
{
throw "Cannot open file using FFmpeg libs";
}
@@ -370,7 +371,7 @@ Bool PlaYUVerStream::reload()
if( m_iStreamHandler == FFMPEG )
{
m_cLibAvContext->closeAvFormat();
if( !m_cLibAvContext->initAvFormat( m_pchFilename, m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel, m_dFrameRate, m_uiTotalFrameNum ) )
if( !m_cLibAvContext->initAvFormat( m_pchFilename, m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel, m_uiEndianness, m_dFrameRate, m_uiTotalFrameNum ) )
{
throw "Cannot open file using FFmpeg libs";
}
@@ -578,7 +579,7 @@ Void PlaYUVerStream::readFrame()
throw "[PlaYUVerStream] Error reading frame from libav";
return;
}
m_pcNextFrame->frameFromBuffer( m_cLibAvContext->m_pchFrameBuffer, m_cLibAvContext->m_uiFrameBufferSize );
m_pcNextFrame->frameFromBuffer( m_cLibAvContext->m_pchFrameBuffer, m_cLibAvContext->m_uiFrameBufferSize, m_uiEndianness );
}
#endif
if( m_iStreamHandler == YUV_IO )
@@ -590,7 +591,7 @@ Void PlaYUVerStream::readFrame()
throw "[PlaYUVerStream] Cannot read file";
return;
}
m_pcNextFrame->frameFromBuffer( m_pStreamBuffer, bytes_read );
m_pcNextFrame->frameFromBuffer( m_pStreamBuffer, bytes_read, m_uiEndianness );
}
m_uiCurrFrameFileIdx++;
return;
+3 -2
View File
@@ -95,8 +95,8 @@ public:
END_OF_SEQ,
};
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 );
Bool open( std::string filename, std::string resolution, std::string input_format, UInt bitsPel, UInt endianness, UInt frame_rate, Bool bInput = true );
Bool open( std::string filename, UInt width, UInt height, Int input_format, UInt bitsPel, UInt endianness, UInt frame_rate, Bool bInput = true );
Bool reload();
@@ -194,6 +194,7 @@ private:
UInt m_uiHeight;
Int m_iPixelFormat;
UInt m_uiBitsPerPixel;
UInt m_uiEndianness;
Double m_dFrameRate;
UInt64 m_uiTotalFrameNum;
Int64 m_iCurrFrameNum;
+13 -1
View File
@@ -76,6 +76,18 @@ Int PlaYUVerTools::openInputs()
{
uiBitPerPixel = m_cCmdLineHandler.m_uiBitsPerPixel;
}
UInt uiEndianness = 0;
if( m_cCmdLineHandler.Opts()["endianness"]->count() )
{
if( m_cCmdLineHandler.m_strEndianness == "big" )
{
uiEndianness = 0;
}
if( m_cCmdLineHandler.m_strEndianness == "little" )
{
uiEndianness = 1;
}
}
std::vector<std::string> inputFileNames = m_cCmdLineHandler.m_apcInputs;
@@ -85,7 +97,7 @@ Int PlaYUVerTools::openInputs()
pcStream = new PlaYUVerStream;
try
{
if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, uiBitPerPixel, 1 ) )
if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, uiBitPerPixel, uiEndianness, 1 ) )
{
m_cCmdLineHandler.log( LOG_ERROR, "Cannot open input stream %s! ", inputFileNames[i].c_str() );
return 2;
+1
View File
@@ -71,6 +71,7 @@ Int PlaYUVerToolsCmdParser::parseToolsArgs( Int argc, Char *argv[] )
( "size,s", m_strResolution, "size (WxH)" ) /**/
( "pel_fmt", m_strPelFmt, "pixel format" ) /**/
( "bits_pel", m_uiBitsPerPixel, "bits per pixel" ) /**/
( "endianness", m_strEndianness, "File endianness (big, little)" ) /**/
( "frames,f", m_iFrames, "number of frames to parse" );
Opts().addOptions()/**/
+2
View File
@@ -78,6 +78,8 @@ private:
std::string m_strResolution;
std::string m_strPelFmt;
UInt m_uiBitsPerPixel;
std::string m_strEndianness;
UInt m_uiEndianness;
Bool m_bListPelFmts;
Int64 m_iFrames;