Change InputStream init function and clean code the SubWindowHandle
This commit is contained in:
1 parent
49b3ede802
commit
9e2b017a4b
3 files changed
+28
-47
No files matched your search
+17
-22
@@ -40,25 +40,20 @@ namespace plaYUVer
|
||||
|
||||
InputStream::InputStream()
|
||||
{
|
||||
m_iStatus = 0;
|
||||
m_bInit = false;
|
||||
m_iErrorStatus = 0;
|
||||
|
||||
m_pFile = NULL;
|
||||
m_uiWidth = 0;
|
||||
m_uiHeight = 0;
|
||||
m_uiTotalFrameNum = 0;
|
||||
m_iCurrFrameNum = -1;
|
||||
m_iErrorStatus = 0;
|
||||
m_iPixelFormat = -1;
|
||||
|
||||
m_uiFrameRate = 25;
|
||||
|
||||
m_uiFrameRate = 30;
|
||||
m_iFileFormat = INVALID;
|
||||
|
||||
m_pInputBuffer = NULL;
|
||||
|
||||
m_cFilename = QString( "" );
|
||||
m_cStreamInformationString = QString( "" );
|
||||
|
||||
m_pcCurrFrame = NULL;
|
||||
m_pcNextFrame = NULL;
|
||||
m_ppcFrameBuffer = NULL;
|
||||
@@ -152,15 +147,16 @@ Bool InputStream::guessFormat( QString filename, UInt& rWidth, UInt& rHeight, In
|
||||
return bRet;
|
||||
}
|
||||
|
||||
Void InputStream::init( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate )
|
||||
Bool InputStream::open( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate )
|
||||
{
|
||||
Bool avStatus = false;
|
||||
|
||||
if( m_iStatus == 1 )
|
||||
if( m_bInit )
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
m_bInit = false;
|
||||
m_cFilename = filename;
|
||||
m_uiWidth = width;
|
||||
m_uiHeight = height;
|
||||
@@ -181,8 +177,7 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for
|
||||
|
||||
if( m_uiWidth <= 0 || m_uiHeight <= 0 )
|
||||
{
|
||||
//Error
|
||||
return;
|
||||
return m_bInit;
|
||||
}
|
||||
|
||||
getMem1D<PlaYUVerFrame*>( &m_ppcFrameBuffer, m_uiFrameBufferSize );
|
||||
@@ -200,20 +195,18 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for
|
||||
m_pFile = fopen( m_cFilename.toLocal8Bit().data(), "rb" );
|
||||
if( m_pFile == NULL )
|
||||
{
|
||||
// Error
|
||||
return;
|
||||
close();
|
||||
return m_bInit;
|
||||
}
|
||||
fseek( m_pFile, 0, SEEK_END );
|
||||
m_uiTotalFrameNum = ftell( m_pFile ) / ( frame_bytes_input );
|
||||
fseek( m_pFile, 0, SEEK_SET );
|
||||
|
||||
m_cFormatName = QString::fromUtf8( "Raw Video" );
|
||||
|
||||
}
|
||||
if( !getMem1D<Pel>( &m_pInputBuffer, m_pcCurrFrame->getBytesPerFrame() ) )
|
||||
{
|
||||
//Error
|
||||
return;
|
||||
close();
|
||||
return m_bInit;
|
||||
}
|
||||
|
||||
m_cStreamInformationString = QString( "[" );
|
||||
@@ -224,12 +217,14 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for
|
||||
m_cStreamInformationString.append( QFileInfo( m_cFilename ).fileName() );
|
||||
|
||||
m_iCurrFrameNum = -1;
|
||||
m_iStatus = 1;
|
||||
|
||||
readNextFrame();
|
||||
setNextFrame();
|
||||
readNextFrame();
|
||||
return;
|
||||
if( m_uiTotalFrameNum > 1 )
|
||||
readNextFrame();
|
||||
|
||||
m_bInit = true;
|
||||
|
||||
return m_bInit;
|
||||
}
|
||||
|
||||
Void InputStream::close()
|
||||
|
||||
@@ -59,6 +59,7 @@ class InputStream
|
||||
{
|
||||
private:
|
||||
|
||||
Bool m_bInit;
|
||||
Int m_iStatus;
|
||||
Int m_iErrorStatus;
|
||||
|
||||
@@ -106,7 +107,7 @@ public:
|
||||
Bool needFormatDialog( QString filename );
|
||||
Bool guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate );
|
||||
|
||||
Void init( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate );
|
||||
Bool open( QString filename, UInt width, UInt height, Int input_format, UInt frame_rate );
|
||||
Void close();
|
||||
|
||||
Void readNextFrame();
|
||||
@@ -121,9 +122,9 @@ public:
|
||||
|
||||
Bool checkErrors( Int error_type );
|
||||
|
||||
Int getStatus()
|
||||
Bool isInit()
|
||||
{
|
||||
return m_iStatus;
|
||||
return m_bInit;
|
||||
}
|
||||
QString getFileName()
|
||||
{
|
||||
|
||||
@@ -85,15 +85,10 @@ Bool SubWindowHandle::loadFile( const QString &fileName )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_pCurrStream->init( fileName, Width, Height, InputFormat, FrameRate );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pCurrStream->init( fileName, 0, 0, 0, 0 );
|
||||
}
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
QApplication::restoreOverrideCursor();
|
||||
if( m_pCurrStream->getStatus() == 0 )
|
||||
if( !m_pCurrStream->open( fileName, Width, Height, InputFormat, FrameRate ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -108,13 +103,9 @@ Bool SubWindowHandle::loadFile( const QString &fileName )
|
||||
refreshFrame();
|
||||
//normalSize();
|
||||
|
||||
m_cWindowName = QString( " " );
|
||||
m_cWindowName = m_pCurrStream->getStreamInformationString();
|
||||
|
||||
m_cCurrFileName = fileName;
|
||||
|
||||
m_cWindowName = m_pCurrStream->getStreamInformationString();
|
||||
setWindowTitle( m_cWindowName );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -146,17 +137,17 @@ Void SubWindowHandle::disableModule()
|
||||
|
||||
Void SubWindowHandle::refreshFrame()
|
||||
{
|
||||
PlaYUVerFrame* CurrSubWindowFrame;
|
||||
PlaYUVerFrame* currFrame;
|
||||
if( m_pcCurrentModule )
|
||||
{
|
||||
CurrSubWindowFrame = m_pcCurrentModule->process( m_pCurrStream->getCurrFrame() );
|
||||
currFrame = m_pcCurrentModule->process( m_pCurrStream->getCurrFrame() );
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrSubWindowFrame = m_pCurrStream->getCurrFrame();
|
||||
currFrame = m_pCurrStream->getCurrFrame();
|
||||
}
|
||||
CurrSubWindowFrame->FrametoRGB8();
|
||||
QImage qimg = QImage( CurrSubWindowFrame->getQImageBuffer(), CurrSubWindowFrame->getWidth(), CurrSubWindowFrame->getHeight(), QImage::Format_RGB888 );
|
||||
currFrame->FrametoRGB8();
|
||||
QImage qimg = QImage( currFrame->getQImageBuffer(), currFrame->getWidth(), currFrame->getHeight(), QImage::Format_RGB888 );
|
||||
m_cViewArea->setImage( QPixmap::fromImage( qimg ) );
|
||||
}
|
||||
|
||||
@@ -167,28 +158,22 @@ Bool SubWindowHandle::save()
|
||||
formats.prepend( " (" );
|
||||
formats.append( ")" );
|
||||
supported.append( formats ); // supported=="Supported Files (*.pbm *.jpg...)"
|
||||
|
||||
QStringList filter;
|
||||
filter << supported
|
||||
<< InputStream::supportedWriteFormatsList()
|
||||
<< tr( "All Files (*)" );
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName( this, tr( "Save As" ), m_cCurrFileName, filter.join( ";;" ) );
|
||||
|
||||
if( fileName.isEmpty() )
|
||||
return false;
|
||||
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
|
||||
if( m_pCurrFrameQImage->save( fileName ) )
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
QMessageBox::warning( this, tr( "plaYUVer" ), tr( "Cannot save file %1" ).arg( fileName ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user