diff --git a/source/ImageInterface.cpp b/source/ImageInterface.cpp index 3427a4a..ce86ae4 100644 --- a/source/ImageInterface.cpp +++ b/source/ImageInterface.cpp @@ -96,22 +96,37 @@ bool ImageInterface::loadFile( const QString &fileName ) bool ImageInterface::save() { + QString supported = tr("Supported Files"); + QString formats = InputStream::supportedWriteFormats(); + formats.prepend(" ("); + formats.append(")"); + supported.append(formats); // supported=="Supported Files (*.pbm *.jpg...)" -} + QStringList filter; + filter << supported + << InputStream::supportedWriteFormatsList() + << tr( "All Files (*)" ); -bool ImageInterface::saveAs() -{ - QString fileName = QFileDialog::getSaveFileName( this, tr( "Save As" ), m_cCurrFileName ); - if( fileName.isEmpty() ) - return false; + QString fileName = QFileDialog::getSaveFileName( this, tr( "Save As" ), + m_cCurrFileName, filter.join(";;") ); - return saveFile( fileName ); -} + if ( fileName.isEmpty() ) + return false; -bool ImageInterface::saveFile( const QString &fileName ) -{ + QApplication::setOverrideCursor( Qt::WaitCursor ); - return true; + if ( !m_currStream.writeFrame( fileName ) ) + { + QApplication::restoreOverrideCursor(); + QMessageBox::warning( this, tr( "SCode" ), + tr( "Cannot save file %1" ) + .arg( fileName )); + return false; + } + + QApplication::restoreOverrideCursor(); + + return true; } bool ImageInterface::nextVideoFrame() diff --git a/source/ImageInterface.h b/source/ImageInterface.h index 8ab247f..6404d54 100644 --- a/source/ImageInterface.h +++ b/source/ImageInterface.h @@ -65,8 +65,6 @@ public: bool loadFile( const QString &fileName ); bool save(); - bool saveAs(); - bool saveFile( const QString &fileName ); bool nextVideoFrame(); diff --git a/source/InputStream.cpp b/source/InputStream.cpp index 42594c3..1f9492c 100755 --- a/source/InputStream.cpp +++ b/source/InputStream.cpp @@ -70,6 +70,18 @@ QString InputStream::supportedReadFormats() return formats; } +QString InputStream::supportedWriteFormats() +{ + QString formats; + formats = "*.bmp " // Windows Bitmap + "*.jpg " // Joint Photographic Experts Group + "*.jpeg " // Joint Photographic Experts Group + "*.png " // Portable Network Graphics + ; + + return formats; +} + QStringList InputStream::supportedReadFormatsList() { QStringList formats; @@ -78,6 +90,22 @@ QStringList InputStream::supportedReadFormatsList() return formats; } +QStringList InputStream::supportedWriteFormatsList() +{ + QStringList formats; + formats << "Windows Bitmap (*.bmp)" + << "Joint Photographic Experts Group (*.jpg *.jpeg)" + << "Portable Network Graphics (*.png)" + << "Portable Bitmap (*.pbm)" + << "Portable Graymap (*.pgm)" + << "Portable Pixmap (*.ppm)" + << "Tagged Image File Format (*.tiff)" + << "X11 Bitmap (*.xbm)" + << "X11 Pixmap (*.xpm)"; + + return formats; +} + QStringList InputStream::supportedPixelFormatList() { QStringList formats; @@ -288,6 +316,12 @@ Void InputStream::readFrame() return; } +Bool InputStream::writeFrame( const QString& filename ) +{ + getFrameQImage().save(filename); + return true; +} + QImage InputStream::getFrameQImage() { // Create QImage @@ -315,6 +349,15 @@ QImage InputStream::getFrameQImage() return img; } +#ifdef USE_OPENCV +cv::Mat InputStream::getFrameCvMat() +{ + cv::Mat cvMat( m_uiHeight, m_uiWidth, CV_8UC3 ); + + return cvMat; +} +#endif + Void InputStream::seekInput( Int new_frame_num ) { UInt64 frame_bytes_input = m_uiWidth * m_uiHeight * 1.5; diff --git a/source/InputStream.h b/source/InputStream.h index 8fe5e1f..984236e 100755 --- a/source/InputStream.h +++ b/source/InputStream.h @@ -32,6 +32,10 @@ #include #include +#ifdef USE_OPENCV +#include +#endif + #include "TypeDef.h" namespace plaYUVer @@ -67,9 +71,13 @@ public: ~InputStream(); static QString supportedReadFormats(); + static QString supportedWriteFormats(); static QStringList supportedReadFormatsList(); + static QStringList supportedWriteFormatsList(); + static QStringList supportedPixelFormatList(); + enum InputStreamColorSpace { YUV420, @@ -88,7 +96,12 @@ public: Void readFrame(); + Bool writeFrame( const QString& filename ); + QImage getFrameQImage(); +#ifdef USE_OPENCV + cv::Mat getFrameCvMat(); +#endif Void seekInput( Int new_frame_num ); diff --git a/source/plaYUVerApp.cpp b/source/plaYUVerApp.cpp index 3a8d35f..e0140a2 100644 --- a/source/plaYUVerApp.cpp +++ b/source/plaYUVerApp.cpp @@ -122,9 +122,10 @@ void plaYUVerApp::open() play(); } -void plaYUVerApp::saveAs() +void plaYUVerApp::save() { - + if( activeImageInterface() ) + activeImageInterface()->save(); } // ----------------------- Playing Functions -------------------- @@ -136,7 +137,6 @@ void plaYUVerApp::play() } - void plaYUVerApp::playEvent() { if( activeImageInterface() ) @@ -195,7 +195,7 @@ void plaYUVerApp::about() void plaYUVerApp::updateMenus() { Bool hasImageInterface = ( activeImageInterface() != 0 ); - saveAsAct->setEnabled( hasImageInterface ); + saveAct->setEnabled( hasImageInterface ); closeAct->setEnabled( hasImageInterface ); closeAllAct->setEnabled( hasImageInterface ); tileAct->setEnabled( hasImageInterface ); @@ -271,10 +271,10 @@ Void plaYUVerApp::createActions() openAct->setStatusTip( tr( "Open an existing file" ) ); connect( openAct, SIGNAL( triggered() ), this, SLOT( open() ) ); - saveAsAct = new QAction( QIcon( ":/images/saveas.png" ), tr( "Save &As..." ), this ); - saveAsAct->setShortcuts( QKeySequence::SaveAs ); - saveAsAct->setStatusTip( tr( "Save the document under a new name" ) ); - connect( saveAsAct, SIGNAL( triggered() ), this, SLOT( saveAs() ) ); + saveAct = new QAction( QIcon( ":/images/save.png" ), tr( "&Save..." ), this ); + saveAct->setShortcuts( QKeySequence::SaveAs ); + saveAct->setStatusTip( tr( "Save the document under a new name" ) ); + connect( saveAct, SIGNAL( triggered() ), this, SLOT( save() ) ); exitAct = new QAction( tr( "E&xit" ), this ); exitAct->setShortcuts( QKeySequence::Quit ); @@ -318,7 +318,6 @@ Void plaYUVerApp::createActions() // ------------ Playing ------------ - // ------------ Window ------------ tileAct = new QAction( tr( "&Tile" ), this ); @@ -359,7 +358,7 @@ Void plaYUVerApp::createMenus() fileMenu = menuBar()->addMenu( tr( "&File" ) ); fileMenu->addAction( openAct ); fileMenu->addSeparator(); - fileMenu->addAction( saveAsAct ); + fileMenu->addAction( saveAct ); fileMenu->addSeparator(); fileMenu->addAction( closeAct ); fileMenu->addAction( exitAct ); @@ -385,7 +384,7 @@ Void plaYUVerApp::createToolBars() { fileToolBar = addToolBar( tr( "File" ) ); fileToolBar->addAction( openAct ); - fileToolBar->addAction( saveAsAct ); + fileToolBar->addAction( saveAct ); fileToolBar->addAction( closeAct ); viewToolBar = addToolBar( tr( "Zoom" ) ); diff --git a/source/plaYUVerApp.h b/source/plaYUVerApp.h index 944ef16..2d9d0b2 100644 --- a/source/plaYUVerApp.h +++ b/source/plaYUVerApp.h @@ -54,7 +54,7 @@ private slots: //! File functions void open(); - void saveAs(); + void save(); //! Playing functions void play(); @@ -108,7 +108,6 @@ private: QAction *openAct; QAction *saveAct; - QAction *saveAsAct; QAction *exitAct; QAction *closeAct; QAction *closeAllAct;