Change the standard resolution definition and add code to guess the resolution from the filesize

This commit is contained in:
jfmcarreira committed 2014-07-06 21:46:36 +01:00
1 parent 54da444b4f
commit 8c2bb0fd03
4 files changed
+114 -46

No files matched your search

+6 -4
View File
@@ -43,7 +43,9 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) :
// Config dialog
setStandardResolutionSizes();
struct PlaYUVerStream::StandardResolution stdRes = PlaYUVerStream::standardResolutionSizes();
standardResolutionNames = stdRes.stringListFullName;
standardResolutionSizes = stdRes.sizeResolution;
setObjectName( QStringLiteral( "ConfigureFormat" ) );
resize( 392, 350 );
@@ -184,9 +186,9 @@ Int ConfigureFormatDialog::runConfigureFormatDialog( UInt& rWidth, UInt& rHeight
m_spinBoxheight->setValue( rHeight );
m_comboBoxPixelFormat->setCurrentIndex( rInputFormat >= 0 ? rInputFormat : 0 );
m_spinBoxFrameRate->setValue( rFrameRate );
for( Int i = 0; i < standardResolutionSizesList.size(); i++ )
for( Int i = 0; i < standardResolutionSizes.size(); i++ )
{
if( standardResolutionSizesList.at( i ) == QSize( rWidth, rHeight ) )
if( standardResolutionSizes.at( i ) == QSize( rWidth, rHeight ) )
{
m_comboBoxStandardResolution->setCurrentIndex( i );
}
@@ -208,7 +210,7 @@ void ConfigureFormatDialog::StandardResolutionSelection()
if( currIdx == -1 )
return;
QSize currSize = standardResolutionSizesList.at( currIdx );
QSize currSize = standardResolutionSizes.at( currIdx );
m_spinBoxWidth->setValue( currSize.width() );
m_spinBoxheight->setValue( currSize.height() );
}
+1 -17
View File
@@ -63,7 +63,7 @@ private Q_SLOTS:
private:
QStringList standardResolutionNames;
QList<QSize> standardResolutionSizesList;
QVector<QSize> standardResolutionSizes;
QComboBox *m_comboBoxStandardResolution;
QSpinBox *m_spinBoxWidth;
@@ -71,22 +71,6 @@ private:
QComboBox *m_comboBoxPixelFormat;
QSpinBox *m_spinBoxFrameRate;
Void setStandardResolutionSizes()
{
ADD_STANDARD_RESOLUTION( "CIF (352x288)", 352, 288 );
ADD_STANDARD_RESOLUTION( "VGA (640x480)", 640, 480 );
ADD_STANDARD_RESOLUTION( "WVGA (832x480)", 832, 480 );
ADD_STANDARD_RESOLUTION( "XVGA (1024x768)", 1024, 768 );
ADD_STANDARD_RESOLUTION( "HD (1280x720)", 1280, 720 );
ADD_STANDARD_RESOLUTION( "SXGA- (1280x900)", 1280, 900 );
ADD_STANDARD_RESOLUTION( "SXGA (1280x1024)", 1280, 1024 );
ADD_STANDARD_RESOLUTION( "WSXGA (1440x900)", 1440, 900 );
ADD_STANDARD_RESOLUTION( "Full HD (1920x1080)", 1920, 1080 );
ADD_STANDARD_RESOLUTION( "WQXGA (2560x1600)", 2560, 1600 );
ADD_STANDARD_RESOLUTION( "Ultra HD (3840x2160)", 3840, 2160 );
ADD_STANDARD_RESOLUTION( "8K", 8192, 4608 );
}
};
} // NAMESPACE
+75 -24
View File
@@ -115,7 +115,7 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_
{
switch( m_iFileFormat )
{
case PGMINPUT:
case PGMINPUT:
break;
}
@@ -252,7 +252,7 @@ Void PlaYUVerStream::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat,
{
rWidth = 0;
rHeight = 0;
rInputFormat = -1;
rInputFormat = PlaYUVerFrame::YUV420p;
rFrameRate = 30;
}
}
@@ -264,27 +264,7 @@ Bool PlaYUVerStream::guessFormat( QString filename, UInt& rWidth, UInt& rHeight,
if( !fileExtension.compare( "yuv" ) )
{
bRet = true;
// Guess resolution - match %dx%d
#if( QT_VERSION_PLAYUVER == 5 )
QRegularExpressionMatch resolutionMatch = QRegularExpression( "_\\d*x\\d*" ).match( filename );
if( resolutionMatch.hasMatch() )
{
QString resolutionString = resolutionMatch.captured( 0 );
if( resolutionString.startsWith( "_" ) || resolutionString.endsWith( "_" ) )
{
resolutionString.remove( "_" );
QStringList resolutionArgs = resolutionString.split( "x" );
qDebug( ) << "Found resolution = "
<< resolutionArgs;
if( resolutionArgs.size() == 2 )
{
rWidth = resolutionArgs.at( 0 ).toUInt();
rHeight = resolutionArgs.at( 1 ).toUInt();
}
}
}
#endif
// Guess pixel format
// Guess pixel format
QStringList formats_list = PlaYUVerFrame::supportedPixelFormatList();
for( Int i = 0; i < formats_list.size(); i++ )
{
@@ -294,6 +274,77 @@ Bool PlaYUVerStream::guessFormat( QString filename, UInt& rWidth, UInt& rHeight,
break;
}
}
if( rWidth == 0 || rHeight == 0 )
{
// Guess resolution - match resolution name
QStringList stdResName = standardResolutionSizes().stringListName;
for( Int i = 0; i < stdResName.size(); i++ )
{
if( filename.contains( stdResName.at( i ) ) )
{
rWidth = standardResolutionSizes().sizeResolution.at( i ).width();
rHeight = standardResolutionSizes().sizeResolution.at( i ).height();
break;
}
}
// Guess resolution - match %dx%d
#if( QT_VERSION_PLAYUVER == 5 )
QRegularExpressionMatch resolutionMatch = QRegularExpression( "_\\d*x\\d*" ).match( filename );
if( resolutionMatch.hasMatch() )
{
QString resolutionString = resolutionMatch.captured( 0 );
if( resolutionString.startsWith( "_" ) || resolutionString.endsWith( "_" ) )
{
resolutionString.remove( "_" );
QStringList resolutionArgs = resolutionString.split( "x" );
qDebug( ) << "Found resolution = "
<< resolutionArgs;
if( resolutionArgs.size() == 2 )
{
rWidth = resolutionArgs.at( 0 ).toUInt();
rHeight = resolutionArgs.at( 1 ).toUInt();
}
}
}
#endif
}
// Guess resolution by file size
if( rWidth == 0 && rHeight == 0 )
{
Char *filename_char = new char[filename.length() + 1];
memcpy( filename_char, filename.toUtf8().constData(), filename.length() + 1 * sizeof(char) );
FILE* pF = fopen( filename_char, "rb" );
fseek( pF, 0, SEEK_END );
UInt64 uiFileSize = ftell( pF );
fclose( pF );
delete[] filename_char;
if( pF != NULL )
{
Int count = 0, module, frame_bytes, match;
QVector<QSize> sizeResolution = standardResolutionSizes().sizeResolution;
for( Int i = 0; i < sizeResolution.size(); i++ )
{
frame_bytes = PlaYUVerFrame::getBytesPerFrame( sizeResolution.at( i ).width(), sizeResolution.at( i ).height(), rInputFormat );
module = uiFileSize % frame_bytes;
if( module == 0 )
{
match = i;
count++;
}
}
if( count == 1 )
{
rWidth = sizeResolution.at( match ).width();
rHeight = sizeResolution.at( match ).height();
}
}
}
if( rWidth > 0 && rHeight > 0 && rInputFormat >= 0 )
bRet = false;
}
@@ -331,7 +382,7 @@ Void PlaYUVerStream::loadAll()
m_iCurrFrameNum = -1;
seekInput( 0 );
setNextFrame();
for( UInt i = m_uiFrameBufferIndex; i < m_uiFrameBufferSize ; i++ )
for( UInt i = m_uiFrameBufferIndex; i < m_uiFrameBufferSize; i++ )
{
readFrame();
setNextFrame();
+32 -1
View File
@@ -172,6 +172,36 @@ public:
return formatsName;
}
#define REGIST_STANDARD_RESOLUTION( name, width, height) \
stdRes.stringListName.append( QString( name ) ); \
stdRes.stringListFullName.append( QString( "%1 (%2x%3)" ).arg( name ).arg( width ).arg( height ) ); \
stdRes.sizeResolution.append( QSize( width, height ) )
struct StandardResolution
{
QStringList stringListName;
QStringList stringListFullName;
QVector<QSize> sizeResolution;
};
static struct StandardResolution standardResolutionSizes()
{
struct StandardResolution stdRes;
REGIST_STANDARD_RESOLUTION( "CIF", 352, 288 );
REGIST_STANDARD_RESOLUTION( "VGA", 640, 480 );
REGIST_STANDARD_RESOLUTION( "WVGA", 832, 480 );
REGIST_STANDARD_RESOLUTION( "XVGA", 1024, 768 );
REGIST_STANDARD_RESOLUTION( "HD", 1280, 720 );
REGIST_STANDARD_RESOLUTION( "SXGA-", 1280, 900 );
REGIST_STANDARD_RESOLUTION( "SXGA", 1280, 1024 );
REGIST_STANDARD_RESOLUTION( "WSXGA", 1440, 900 );
REGIST_STANDARD_RESOLUTION( "FullHD", 1920, 1080 );
REGIST_STANDARD_RESOLUTION( "WQXGA", 2560, 1600 );
REGIST_STANDARD_RESOLUTION( "UltraHD", 3840, 2160 );
REGIST_STANDARD_RESOLUTION( "8K", 8192, 4608 );
return stdRes;
}
enum PlaYUVerStreamErrors
{
NO_STREAM_ERROR = 0,
@@ -184,7 +214,8 @@ public:
Bool open( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate, Bool bInput = true );
Void close();
Bool guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate );
static Bool guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate );
Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate );
Void loadAll();