From 3cf0d866ad1308ba3e0a0a09e0ef67516a290b46 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 8 Feb 2014 01:29:48 +0000 Subject: [PATCH] Fix last commit. Use just one QImage for every frame --- source/InputStream.cpp | 11 ++++---- source/InputStream.h | 2 +- source/SubWindowHandle.cpp | 56 ++++++++++++++++++++++---------------- source/SubWindowHandle.h | 7 +++-- source/plaYUVerApp.cpp | 13 ++++----- 5 files changed, 48 insertions(+), 41 deletions(-) diff --git a/source/InputStream.cpp b/source/InputStream.cpp index be2f955..1a0cef5 100755 --- a/source/InputStream.cpp +++ b/source/InputStream.cpp @@ -243,14 +243,14 @@ Void InputStream::readFrame() Bool InputStream::writeFrame( const QString& filename ) { - getFrameQImage().save( filename ); + QImage img( m_uiWidth, m_uiHeight, QImage::Format_RGB888 ); + getFrame( &img ); + img.save( filename ); return true; } -QImage InputStream::getFrameQImage() +Void InputStream::getFrame( QImage *qimage ) { - // Create QImage - QImage img( m_uiWidth, m_uiHeight, QImage::Format_RGB888 ); Pel*** bufferRGB = m_cCurrFrame->getPelBufferRGB(); if( sizeof(Pel) == sizeof(unsigned char) ) @@ -259,7 +259,7 @@ QImage InputStream::getFrameQImage() { for( Int x = 0; x < m_uiWidth; x++ ) { - img.setPixel( x, y, qRgb( bufferRGB[0][y][x], bufferRGB[1][y][x], bufferRGB[2][y][x] ) ); + qimage->setPixel( x, y, qRgb( bufferRGB[0][y][x], bufferRGB[1][y][x], bufferRGB[2][y][x] ) ); } } } @@ -267,7 +267,6 @@ QImage InputStream::getFrameQImage() { Q_ASSERT( 0 ); } - return img; } #ifdef USE_OPENCV diff --git a/source/InputStream.h b/source/InputStream.h index 544dc8d..7935d41 100755 --- a/source/InputStream.h +++ b/source/InputStream.h @@ -103,7 +103,7 @@ public: Bool writeFrame( const QString& filename ); - QImage getFrameQImage(); + Void getFrame( QImage *qimage ); #ifdef USE_OPENCV cv::Mat getFrameCvMat(); #endif diff --git a/source/SubWindowHandle.cpp b/source/SubWindowHandle.cpp index 7a1d06f..e997343 100644 --- a/source/SubWindowHandle.cpp +++ b/source/SubWindowHandle.cpp @@ -61,28 +61,32 @@ bool SubWindowHandle::loadFile( const QString &fileName ) { ConfigureFormatDialog formatDialog( this ); - if( m_currStream.needFormatDialog( fileName ) ) + m_pCurrStream = new InputStream; + + if( m_pCurrStream->needFormatDialog( fileName ) ) { if( formatDialog.exec() == QDialog::Rejected ) { return false; } - m_currStream.init( fileName, formatDialog.getResolution().width(), formatDialog.getResolution().height(), formatDialog.getPixelFormat(), + m_pCurrStream->init( fileName, formatDialog.getResolution().width(), formatDialog.getResolution().height(), formatDialog.getPixelFormat(), formatDialog.getFrameRate() ); } else { - m_currStream.init( fileName, 0, 0, 0, 0 ); + m_pCurrStream->init( fileName, 0, 0, 0, 0 ); } QApplication::setOverrideCursor( Qt::WaitCursor ); QApplication::restoreOverrideCursor(); - if( m_currStream.getStatus() == 0 ) + if( m_pCurrStream->getStatus() == 0 ) { return false; } - m_currStream.readFrame(); - if( m_currStream.checkErrors( READING ) ) + m_pCurrFrameQImage = new QImage( m_pCurrStream->getWidth(), m_pCurrStream->getHeight(), QImage::Format_RGB888 ); + + m_pCurrStream->readFrame(); + if( m_pCurrStream->checkErrors( READING ) ) { QMessageBox::warning( this, tr( "plaYUVer" ), tr( "Cannot read %1." ).arg( fileName ) ); return false; @@ -90,12 +94,13 @@ bool SubWindowHandle::loadFile( const QString &fileName ) QApplication::restoreOverrideCursor(); - m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); + m_pCurrStream->getFrame( m_pCurrFrameQImage ); + m_cViewArea->setImage( QPixmap::fromImage( *m_pCurrFrameQImage ) ); normalSize(); - m_cWindowName = QString( "ola" ); - m_cWindowName = m_currStream.getStreamInformationString(); + m_cWindowName = QString( " " ); + m_cWindowName = m_pCurrStream->getStreamInformationString(); m_cCurrFileName = fileName; @@ -122,7 +127,7 @@ bool SubWindowHandle::save() QApplication::setOverrideCursor( Qt::WaitCursor ); - if( !m_currStream.writeFrame( fileName ) ) + if( !m_pCurrStream->writeFrame( fileName ) ) { QApplication::restoreOverrideCursor(); QMessageBox::warning( this, tr( "SCode" ), tr( "Cannot save file %1" ).arg( fileName ) ); @@ -134,31 +139,34 @@ bool SubWindowHandle::save() return true; } -int SubWindowHandle::playEvent() +bool SubWindowHandle::playEvent() { + bool iRet = true; if( m_bIsPlaying ) { - m_currStream.readFrame(); - if( m_currStream.checkErrors( READING ) ) + m_pCurrStream->readFrame(); + if( m_pCurrStream->checkErrors( READING ) ) { QMessageBox::warning( this, tr( "plaYUVer" ), tr( "Cannot read %1." ).arg( m_cCurrFileName ) ); return false; } - else if( m_currStream.checkErrors( END_OF_SEQ ) ) + else if( m_pCurrStream->checkErrors( END_OF_SEQ ) ) { - m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); - return false; + iRet = false; } - m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); + m_pCurrStream->getFrame( m_pCurrFrameQImage ); + m_cViewArea->setImage( QPixmap::fromImage( *m_pCurrFrameQImage ) ); + return iRet; } - return true; + return false; } Void SubWindowHandle::stopEvent() { - m_currStream.seekInput( 0 ); - m_currStream.readFrame(); - m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); + m_pCurrStream->seekInput( 0 ); + m_pCurrStream->readFrame(); + m_pCurrStream->getFrame( m_pCurrFrameQImage ); + m_cViewArea->setImage( QPixmap::fromImage( *m_pCurrFrameQImage ) ); return; } @@ -173,7 +181,7 @@ Void SubWindowHandle::zoomToFit() { // Scale to a smaller size that the real to a nicer look QSize niceFit( m_cScrollArea->viewport()->size().width() - 10, m_cScrollArea->viewport()->size().height() - 10 ); - if( m_currStream.getWidth() <= niceFit.width() && m_currStream.getHeight() <= niceFit.height() ) + if( m_pCurrStream->getWidth() <= niceFit.width() && m_pCurrStream->getHeight() <= niceFit.height() ) { normalSize(); return; @@ -196,7 +204,7 @@ Void SubWindowHandle::scaleView( Int width, Int height ) Void SubWindowHandle::scaleView( const QSize & size ) { - QSize imgViewSize( m_currStream.getWidth(), m_currStream.getHeight() ); + QSize imgViewSize( m_pCurrStream->getWidth(), m_pCurrStream->getHeight() ); QSize newSize = imgViewSize; newSize.scale( size, Qt::KeepAspectRatio ); @@ -233,7 +241,7 @@ QSize SubWindowHandle::sizeHint() const maxSize = p->size(); } - QSize isize = QSize( m_currStream.getWidth() + 500, m_currStream.getHeight() + 500 ); + QSize isize = QSize( m_pCurrStream->getWidth() + 500, m_pCurrStream->getHeight() + 500 ); // If the SubWindowHandle needs more space that the avaiable, we'll give // to the subwindow a reasonable size preserving the image aspect ratio. diff --git a/source/SubWindowHandle.h b/source/SubWindowHandle.h index 174eac5..91745d1 100644 --- a/source/SubWindowHandle.h +++ b/source/SubWindowHandle.h @@ -50,7 +50,8 @@ private: QScrollArea* m_cScrollArea; ViewArea* m_cViewArea; - InputStream m_currStream; + InputStream* m_pCurrStream; + QImage* m_pCurrFrameQImage; QString m_cWindowName; QString m_cCurrFileName; @@ -70,7 +71,7 @@ public: InputStream* getInputStream() { - return &m_currStream; + return m_pCurrStream; } /** @@ -127,7 +128,7 @@ protected: Void closeEvent( QCloseEvent *event ); public Q_SLOTS: - int playEvent(); + bool playEvent(); }; } // NAMESPACE diff --git a/source/plaYUVerApp.cpp b/source/plaYUVerApp.cpp index 6f9f453..c0e44e0 100644 --- a/source/plaYUVerApp.cpp +++ b/source/plaYUVerApp.cpp @@ -139,24 +139,23 @@ void plaYUVerApp::play() UInt frameRate = activeSubWindow()->getInputStream()->getFrameRate(); UInt timeInterval = ( UInt )( 1000.0 / frameRate + 0.5 ); playingTimer->start( timeInterval ); - //connect( playingTimer, SIGNAL( timeout() ), activeSubWindow(), SLOT( playEvent() ) ); - connect( playingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) ); + connect( playingTimer, SIGNAL( timeout() ), activeSubWindow(), SLOT( playEvent() ) ); + //connect( playingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) ); } } void plaYUVerApp::pause() { playingTimer->stop(); + disconnect( activeSubWindow(), SLOT( playEvent() ) ); } void plaYUVerApp::stop() { - if( activeSubWindow() ) - { - activeSubWindow()->stopEvent(); - } + activeSubWindow()->stopEvent(); + disconnect( activeSubWindow(), SLOT( playEvent() ) ); playingTimer->stop(); - //disconnect( playingTimer, SIGNAL( timeout() ), 0, 0 ); + } void plaYUVerApp::playEvent()