Refactor pixel formats enum

This commit is contained in:
jfmcarreira committed 2021-10-27 23:07:46 +01:00
1 parent 90a5c32bb6
commit bb2a1ac228
35 files changed
+289 -277

No files matched your search

+9 -9
View File
@@ -166,7 +166,7 @@ bool VideoStreamSubWindow::loadFile( QString cFilename, bool bForceDialog )
ConfigureFormatDialog formatDialog( this );
unsigned int Width = 0, Height = 0, BitsPel = 8, FrameRate = 30;
int Endianness = CLP_LITTLE_ENDIAN;
int InputFormat = CLP_YUV420P;
auto InputFormat = ClpPixelFormats::CLP_YUV420P;
QSettings appSettings;
if( m_pCurrStream )
@@ -220,7 +220,7 @@ bool VideoStreamSubWindow::loadFile( QString cFilename, bool bForceDialog )
m_sStreamInfo.m_cFilename = cFilename;
m_sStreamInfo.m_uiWidth = Width;
m_sStreamInfo.m_uiHeight = Height;
m_sStreamInfo.m_iPelFormat = InputFormat;
m_sStreamInfo.m_iPelFormat = static_cast<std::int64_t>( InputFormat );
m_sStreamInfo.m_uiBitsPelPixel = BitsPel;
m_sStreamInfo.m_iEndianness = Endianness;
m_sStreamInfo.m_uiFrameRate = FrameRate;
@@ -259,7 +259,7 @@ bool VideoStreamSubWindow::loadFile( CalypFileInfo streamInfo )
m_pCurrStream = m_pcResourceManager->getResourceAsset( m_uiResourceId );
if( !m_pCurrStream->open( streamInfo.m_cFilename.toStdString(), streamInfo.m_uiWidth, streamInfo.m_uiHeight,
streamInfo.m_iPelFormat, streamInfo.m_uiBitsPelPixel, streamInfo.m_iEndianness,
static_cast<ClpPixelFormats>( streamInfo.m_iPelFormat ), streamInfo.m_uiBitsPelPixel, streamInfo.m_iEndianness,
streamInfo.m_uiFrameRate, streamInfo.m_bForceRaw, CalypStream::Type::Input ) )
{
return false;
@@ -281,7 +281,7 @@ bool VideoStreamSubWindow::loadFile( CalypFileInfo streamInfo )
return true;
}
bool VideoStreamSubWindow::guessFormat( const QString& filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel,
bool VideoStreamSubWindow::guessFormat( const QString& filename, unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& rInputFormat, unsigned int& rBitsPerPixel,
int& rEndianness, unsigned int& rFrameRate )
{
std::vector<CalypStandardResolution> stdResList = CalypStream::stdResolutionSizes();
@@ -299,12 +299,12 @@ bool VideoStreamSubWindow::guessFormat( const QString& filename, unsigned int& r
{
bGuessed = false;
// Guess pixel format
auto formats_list = CalypFrame::supportedPixelFormatListNames();
for( std::size_t i = 0; i < formats_list.size(); i++ )
const auto& formats_list = CalypFrame::supportedPixelFormatListNames();
for( const auto& [key, name] : formats_list )
{
if( FilenameShort.contains( formats_list[i].c_str(), Qt::CaseInsensitive ) )
if( FilenameShort.contains( QString::fromStdString( std::string( name ) ), Qt::CaseInsensitive ) )
{
rInputFormat = i;
rInputFormat = key;
break;
}
}
@@ -427,7 +427,7 @@ bool VideoStreamSubWindow::guessFormat( const QString& filename, unsigned int& r
rEndianness = CLP_LITTLE_ENDIAN;
}
if( rWidth > 0 && rHeight > 0 && rInputFormat >= 0 )
if( rWidth > 0 && rHeight > 0 && rInputFormat != ClpPixelFormats::CLP_INVALID_FMT )
bGuessed = true && !bGuessedByFilesize;
}
return !bGuessed;
+1 -1
View File
@@ -107,7 +107,7 @@ public:
private:
bool goToNextFrame( bool bThreaded );
static bool guessFormat( const QString& filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBitsPerPixel,
static bool guessFormat( const QString& filename, unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& rInputFormat, unsigned int& rBitsPerPixel,
int& rEndianness, unsigned int& rFrameRate );
private: // NO_LINT
+28 -31
View File
@@ -382,8 +382,28 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget* parent )
setFixedSize( MainLayout->sizeHint() );
}
auto findPelFormatColorSpace( ClpPixelFormats rInputFormat ) -> std::pair<int, std::int64_t>
{
if( rInputFormat != ClpPixelFormats::CLP_INVALID_FMT )
{
auto pelFmtName = CalypFrame::pixelFormatName( rInputFormat );
for( unsigned int j = 0; j < CalypFrame::supportedColorSpacesListNames().size(); j++ )
{
const auto& formats_list = CalypFrame::supportedPixelFormatListNames( j );
for( const auto& [key, name] : formats_list )
{
if( pelFmtName == name )
{
return std::make_pair( j, static_cast<int>( key ) );
}
}
}
}
return std::make_pair( 0, 0 );
}
int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, unsigned int& rWidth, unsigned int& rHeight,
int& rInputFormat, unsigned int& rBits, int& rEndianess, unsigned int& rFrameRate )
ClpPixelFormats& rInputFormat, unsigned int& rBits, int& rEndianess, unsigned int& rFrameRate )
{
// Set default values
// setWindowTitle( "Configure resolution for " + Filename );
@@ -391,24 +411,8 @@ int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, un
m_spinBoxWidth->setValue( rWidth );
m_spinBoxheight->setValue( rHeight );
int colorSpace = 0;
int sampling = 0;
if( rInputFormat >= 0 )
{
std::string pelFmtName = CalypFrame::supportedPixelFormatListNames()[rInputFormat];
for( unsigned int j = 0; j < CalypFrame::supportedColorSpacesListNames().size(); j++ )
{
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames( j ).size(); i++ )
{
if( pelFmtName == CalypFrame::supportedPixelFormatListNames( j )[i] )
{
colorSpace = j;
sampling = i;
break;
}
}
}
}
auto [colorSpace, sampling] = findPelFormatColorSpace( rInputFormat );
m_comboBoxColorSpace->setCurrentIndex( colorSpace );
m_comboBoxPixelFormat->setCurrentIndex( sampling );
m_spinBoxBits->setValue( rBits );
@@ -441,16 +445,8 @@ int ConfigureFormatDialog::runConfigureFormatDialog( const QString& Filename, un
rWidth = m_spinBoxWidth->value();
rHeight = m_spinBoxheight->value();
colorSpace = m_comboBoxColorSpace->currentIndex();
sampling = m_comboBoxPixelFormat->currentIndex();
std::string pelFmtName = CalypFrame::supportedPixelFormatListNames( colorSpace )[sampling];
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames().size(); i++ )
{
if( pelFmtName == CalypFrame::supportedPixelFormatListNames()[i] )
{
rInputFormat = i;
break;
}
}
sampling = m_comboBoxPixelFormat->currentData().toInt();
rInputFormat = static_cast<ClpPixelFormats>( sampling );
rBits = m_spinBoxBits->value();
rEndianess = m_comboBoxEndianness->currentIndex();
rFrameRate = m_spinBoxFrameRate->value();
@@ -512,9 +508,10 @@ void ConfigureFormatDialog::slotColorSpaceChange( int idx )
return;
m_comboBoxPixelFormat->clear();
for( unsigned int i = 0; i < CalypFrame::supportedPixelFormatListNames( idx ).size(); i++ )
const auto& formats_list = CalypFrame::supportedPixelFormatListNames( idx );
for( const auto& [key, name] : formats_list )
{
m_comboBoxPixelFormat->insertItem( i, CalypFrame::supportedPixelFormatListNames( idx )[i].c_str() );
m_comboBoxPixelFormat->addItem( QString::fromStdString( std::string( name ) ), static_cast<int>( key ) );
}
m_comboBoxPixelFormat->setCurrentIndex( 0 );
}
+1 -1
View File
@@ -51,7 +51,7 @@ class ConfigureFormatDialog : public QDialog
public:
ConfigureFormatDialog( QWidget* parent = 0 );
int runConfigureFormatDialog( const QString& Filename, unsigned int& rWidth, unsigned int& rHeight, int& rInputFormat, unsigned int& rBits,
int runConfigureFormatDialog( const QString& Filename, unsigned int& rWidth, unsigned int& rHeight, ClpPixelFormats& rInputFormat, unsigned int& rBits,
int& rEndianess, unsigned int& rFrameRate );
void readSettings();