diff --git a/app/SubWindowHandle.cpp b/app/SubWindowHandle.cpp index 4bb7f9e..50c8523 100644 --- a/app/SubWindowHandle.cpp +++ b/app/SubWindowHandle.cpp @@ -60,6 +60,8 @@ SubWindowHandle::SubWindowHandle( QWidget * parent, Bool isModule ) : m_cScrollArea->setWidget( m_cViewArea ); m_cScrollArea->setWidgetResizable( true ); + m_pCurrStream = new PlaYUVerStream; + m_cWindowName = QString( " " ); m_cLastScroll = QPoint(); } @@ -69,8 +71,7 @@ SubWindowHandle::~SubWindowHandle() disableModule(); delete m_cViewArea; delete m_cScrollArea; - if( m_pCurrStream ) - delete m_pCurrStream; + delete m_pCurrStream; } Void SubWindowHandle::reloadFile() @@ -85,11 +86,6 @@ Bool SubWindowHandle::loadFile( QString cFilename, Bool bForceDialog ) UInt Width = 0, Height = 0, FrameRate = 30; Int InputFormat = -1; - if( !m_pCurrStream ) - { - m_pCurrStream = new PlaYUVerStream; - } - m_pCurrStream->getFormat( Width, Height, InputFormat, FrameRate ); if( m_pCurrStream->guessFormat( cFilename, Width, Height, InputFormat, FrameRate ) || bForceDialog ) @@ -102,10 +98,8 @@ Bool SubWindowHandle::loadFile( QString cFilename, Bool bForceDialog ) } QApplication::setOverrideCursor( Qt::WaitCursor ); QApplication::restoreOverrideCursor(); - if( !m_pCurrStream->open( cFilename, Width, Height, InputFormat, FrameRate ) ) - { - return false; - } + + m_pCurrStream->open( cFilename, Width, Height, InputFormat, FrameRate ); m_cViewArea->setInputStream( m_pCurrStream ); @@ -117,16 +111,12 @@ Bool SubWindowHandle::loadFile( QString cFilename, Bool bForceDialog ) m_cWindowName = m_pCurrStream->getStreamInformationString(); m_cWindowShortName = QFileInfo( cFilename ).fileName(); setWindowTitle( m_cWindowName ); + qDebug() << "File " << m_cWindowName << "was successfully opened"; return true; } Bool SubWindowHandle::loadFile( PlaYUVerStreamInfo* streamInfo ) { - if( !m_pCurrStream ) - { - m_pCurrStream = new PlaYUVerStream; - } - if( !m_pCurrStream->open( streamInfo->m_cFilename, streamInfo->m_uiWidth, streamInfo->m_uiHeight, streamInfo->m_iPelFormat, streamInfo->m_uiFrameRate ) ) { diff --git a/app/plaYUVerApp.cpp b/app/plaYUVerApp.cpp index 2270ee4..9e8fb69 100644 --- a/app/plaYUVerApp.cpp +++ b/app/plaYUVerApp.cpp @@ -167,19 +167,19 @@ Void plaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* streamInfo ) return; } interfaceChild = new SubWindowHandle( this ); //createSubWindow(); - Bool retChild = false; if( !streamInfo ) { Int idx = findPlaYUVerStreamInfo( m_aRecentFileStreamInfo, fileName ); streamInfo = ( PlaYUVerStreamInfo* )( idx >= 0 ? &m_aRecentFileStreamInfo.at( idx ) : NULL ); } - if( !streamInfo ) - retChild = interfaceChild->loadFile( fileName ); - else - retChild = interfaceChild->loadFile( streamInfo ); - if( retChild ) + try { + if( !streamInfo ) + interfaceChild->loadFile( fileName ); + else + interfaceChild->loadFile( streamInfo ); + statusBar()->showMessage( tr( "Loading file..." ) ); mdiArea->addSubWindow( interfaceChild ); interfaceChild->show(); @@ -197,18 +197,18 @@ Void plaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* streamInfo ) m_aRecentFileStreamInfo.remove( idx ); m_aRecentFileStreamInfo.prepend( interfaceChild->getStreamInfo() ); while( m_aRecentFileStreamInfo.size() > MAX_RECENT_FILES ) -//#if( QT_VERSION_PLAYUVER == 5) -// m_aRecentFileStreamInfo.removeLast(); -//#else m_aRecentFileStreamInfo.remove( m_aRecentFileStreamInfo.size() - 1 ); -//#endif updateRecentFileActions(); statusBar()->showMessage( tr( "File loaded" ), 2000 ); } - else + catch( const char *msg ) { interfaceChild->close(); + QString warningMsg = "Cannot open file " + QFileInfo( fileName ).fileName() + " with the following error: \n" + msg; + QMessageBox::warning( this, QApplication::applicationName(), warningMsg ); + statusBar()->showMessage( warningMsg, 2000 ); + qDebug() << warningMsg; } } @@ -306,7 +306,18 @@ Void plaYUVerApp::format() { if( m_pcCurrentSubWindow ) { - m_pcCurrentSubWindow->loadFile( m_pcCurrentSubWindow->getCurrentFileName(), true ); + try + { + m_pcCurrentSubWindow->loadFile( m_pcCurrentSubWindow->getCurrentFileName(), true ); + } + catch( const char *msg ) + { + QString warningMsg = "Cannot change format of " + QFileInfo( m_pcCurrentSubWindow->getCurrentFileName() ).fileName() + " with the following error: \n" + msg; + QMessageBox::warning( this, QApplication::applicationName(), warningMsg ); + statusBar()->showMessage( warningMsg, 2000 ); + qDebug() << warningMsg; + m_pcCurrentSubWindow->close(); + } m_pcCurrentSubWindow = NULL; chageSubWindowSelection(); } diff --git a/lib/PlaYUVerDefs.h b/lib/PlaYUVerDefs.h index 96d64c7..c1b3020 100644 --- a/lib/PlaYUVerDefs.h +++ b/lib/PlaYUVerDefs.h @@ -126,26 +126,6 @@ enum RGBcomponent COLOR_B, }; -//typedef struct __pixel_definition -//{ -// Int color_space; -// union -// { -// Pel Luma; -// Pel ColorR; -// }; -// union -// { -// Pel ChromaU; -// Pel ColorG; -// }; -// union -// { -// Pel ChromaV; -// Pel ColorB; -// }; -//}Pixel; - } // NAMESPACE #endif // __TYPEDEF_H__ diff --git a/lib/PlaYUVerFramePixelFormats.cpp b/lib/PlaYUVerFramePixelFormats.cpp index 62149ba..7079789 100644 --- a/lib/PlaYUVerFramePixelFormats.cpp +++ b/lib/PlaYUVerFramePixelFormats.cpp @@ -340,7 +340,7 @@ PlaYUVerFramePelFormat g_PlaYUVerFramePelFormatsList[PLAYUVER_NUMBER_FORMATS] = yuv422p, yuyv422, gray, - rgb24, + /*rgb24,*/ BGR24, }; diff --git a/lib/PlaYUVerFramePixelFormats.h b/lib/PlaYUVerFramePixelFormats.h index 27951fa..5e8dfe0 100644 --- a/lib/PlaYUVerFramePixelFormats.h +++ b/lib/PlaYUVerFramePixelFormats.h @@ -102,7 +102,7 @@ struct structPlaYUVerFramePelFormat typedef struct structPlaYUVerFramePelFormat PlaYUVerFramePelFormat; -#define PLAYUVER_NUMBER_FORMATS 7 +#define PLAYUVER_NUMBER_FORMATS 6 extern PlaYUVerFramePelFormat g_PlaYUVerFramePelFormatsList[PLAYUVER_NUMBER_FORMATS]; } // NAMESPACE diff --git a/lib/PlaYUVerStream.cpp b/lib/PlaYUVerStream.cpp index bfae19a..d89f72d 100644 --- a/lib/PlaYUVerStream.cpp +++ b/lib/PlaYUVerStream.cpp @@ -139,6 +139,7 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ if( m_iFileFormat == INVALID_INPUT ) { close(); + throw "Invalid file format"; return m_bInit; } m_cFormatName = PlaYUVerStream::supportedReadFormatsExt().at( m_iFileFormat ).toUpper(); @@ -171,8 +172,8 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ if( m_uiWidth <= 0 || m_uiHeight <= 0 || m_iPixelFormat < 0 ) { - qDebug( ) << "Incorrect configuration"; close(); + throw "[PlaYUVerStream] Incorrect configuration"; return m_bInit; } @@ -182,8 +183,8 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat ); if( !m_ppcFrameBuffer[i] ) { - qDebug( ) << "Cannot allocated frame buffer"; close(); + throw "[PlaYUVerStream] Cannot allocated frame buffer"; return m_bInit; } } @@ -197,6 +198,7 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ if( !openFile() ) { close(); + throw "[PlaYUVerStream] Cannot open file"; return m_bInit; } m_cFormatName = QString::fromUtf8( "YUV" ); @@ -213,8 +215,8 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ if( fileSize % frame_bytes_input ) { Int remaining = fileSize % frame_bytes_input; - qDebug( ) << "Incorrect configuration: failed ( fileSize % frame_bytes_input = " << remaining << " )"; close(); + throw "[PlaYUVerStream] Incorrect configuration: failed ( fileSize % frame_bytes_input = " << remaining << " )"; return m_bInit; } #endif @@ -226,25 +228,20 @@ Bool PlaYUVerStream::open( QString filename, UInt width, UInt height, Int input_ if( m_bIsInput && m_uiTotalFrameNum <= 0 ) { - qDebug( ) << "Incorrect configuration: less than one frame"; close(); + throw "[PlaYUVerStream] Incorrect configuration: less than one frame"; return m_bInit; } if( !getMem1D( &m_pStreamBuffer, m_pcCurrFrame->getBytesPerFrame() ) ) { close(); + throw "[PlaYUVerStream] Cannot allocated memory"; return m_bInit; } - m_cStreamInformationString = QString( "[" ); - m_cStreamInformationString.append( m_cFormatName ); - m_cStreamInformationString.append( QString( " / " ) ); - m_cStreamInformationString.append( m_cCodedName ); - m_cStreamInformationString.append( QString( " / " ) ); - m_cStreamInformationString.append( PlaYUVerFrame::supportedPixelFormatListNames().at( m_iPixelFormat ) ); - m_cStreamInformationString.append( "] " ); - m_cStreamInformationString.append( QFileInfo( m_cFilename ).fileName() ); + m_cStreamInformationString = "[" + m_cFormatName + " / " + m_cCodedName + " / " + PlaYUVerFrame::supportedPixelFormatListNames().at( m_iPixelFormat ) + "] " + + QFileInfo( m_cFilename ).fileName(); m_sStreamInfo.m_cFilename = m_cFilename; m_sStreamInfo.m_uiWidth = m_uiWidth; @@ -387,7 +384,6 @@ Bool PlaYUVerStream::guessFormat( QString filename, UInt& rWidth, UInt& rHeight, { resolutionString.remove( "_" ); QStringList resolutionArgs = resolutionString.split( "x" ); - qDebug( ) << "Found resolution = " << resolutionArgs; if( resolutionArgs.size() == 2 ) { rWidth = resolutionArgs.at( 0 ).toUInt();