diff --git a/CMakeLists.txt b/CMakeLists.txt index 535f465..d82dffc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ SET( PROJECT_NAME "playuver" ) PROJECT( ${PROJECT_NAME} ) SET( PLAYUVER_VERSION_MAJOR "0" ) SET( PLAYUVER_VERSION_MINOR "6" ) -SET( PLAYUVER_VERSION_PATCH "0" ) +SET( PLAYUVER_VERSION_PATCH "3" ) SET( PLAYUVER_VERSION "${PLAYUVER_VERSION_MAJOR}.${PLAYUVER_VERSION_MINOR}.${PLAYUVER_VERSION_PATCH}") diff --git a/README.md b/README.md index 0de8b61..b6a1604 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,33 @@ plaYUVer is an open-source video player with the following features: - Support for wide range of raw video formats; - Support for OpenCV imag/video processing library - Advanced frame zoom with easy to use pan function +- Synchronized zoom across several videos (perfect for comparison operations) - Usefull information in status bar, *e.g.*, pixel information -- Usefull sidebars with stream and frame information, *e.g.*, frame histogram + Usefull sidebars with frame information, *e.g.*, frame histogram - Constant growing libs for stream and frame processing (PlaYUVerStream PlaYUVerFrame) - Advanced API for frame/video processing algorithms - Frame level quality measurement API based on the PlaYUVerFrame class +- Command-line tool for quality and frame processing algorithms (uses the referred APIs) +Supported Quality Metrics +---------------------------------------------------------------- +- PSNR +- SSIM +- MSE + +Frame Processing Modules +---------------------------------------------------------------- +- FilterComponentLuma +- FilterComponentChromaU +- FilterComponentChromaV +- FrameDifference +- AbsoluteFrameDifference +- FrameCrop +- FrameBinarization +- EightBitsSampling +- LumaAverage +- DisparityStereoVar +- DisparityStereoBM Developers ---------------------------------------------------------------- @@ -21,25 +42,20 @@ Developers - LuiĀ­s Lucas (luisfrlucas@gmail.com) -Builds +Build ---------------------------------------------------------------- Download update build for windows and linux from our SourceForge project page +Building yourself -Build/Install using cmake ----------------------------------------------------------------- - -1. The following are required for compilation: +1. Dependencies - an ordinary C++ development environment (g++, make, C++ libraries and headers, ...) - cmake - a Qt development environment (libraries, headers, qmake, ...): only QtCore, QtGui and QtWidgets are required, at least in version 4 - -2. Optional Dependencies: - - QtDBus - - OpenCv - - FFmpeg - -3. Run the following commands: (this will create an executable named playuver) + - QtDBus (optional) + - OpenCv (optional) + - FFmpeg (optional) +2. Example configuration command ``` mkdir build cd build diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 53c9f25..7eccdda 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -45,16 +45,16 @@ ENDIF() set(plaYUVer_App_SRCS # Main main.cpp - plaYUVerApp.cpp + PlaYUVerApp.cpp PlaYUVerSubWindowHandle.cpp PlaYUVerMdiSubWindow.cpp - SubWindowHandle.cpp + SubWindowAbstract.cpp Settings.cpp # Module Video VideoSubWindow.cpp ViewArea.cpp VideoHandle.cpp - FramePropertiesSidebar.cpp + FramePropertiesDock.cpp # Module Quality QualityHandle.cpp QualityMeasurementSidebar.cpp @@ -62,6 +62,7 @@ set(plaYUVer_App_SRCS external/qcustomplot.cpp # Module Plugins ModulesHandle.cpp + ModulesHandleOptDialog.cpp ModuleHandleDock.cpp PlaYUVerAppModuleIf.cpp GridManager.cpp @@ -69,6 +70,7 @@ set(plaYUVer_App_SRCS AboutDialog.cpp ConfigureFormatDialog.cpp DialogSubWindowSelector.cpp + ProgressBar.cpp # Widgets HistogramWidget.cpp WidgetFrameNumber.cpp diff --git a/app/ConfigureFormatDialog.cpp b/app/ConfigureFormatDialog.cpp index e5dc4fa..ab3caf4 100644 --- a/app/ConfigureFormatDialog.cpp +++ b/app/ConfigureFormatDialog.cpp @@ -32,16 +32,6 @@ namespace plaYUVer ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) : QDialog( parent ) { - QFont titleFont, menusFont; - - titleFont.setPointSize( 14 ); - titleFont.setBold( true ); - titleFont.setWeight( 75 ); - - menusFont.setBold( true ); - menusFont.setWeight( 75 ); - - QString Name; UInt uiWidth, uiHeight; std::vector listPlaYUVerStdResolution = PlaYUVerStream::stdResolutionSizes(); @@ -51,174 +41,238 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget *parent ) : uiWidth = listPlaYUVerStdResolution[i].uiWidth; uiHeight = listPlaYUVerStdResolution[i].uiHeight; standardResolutionNames.append( QString( "%1 (%2x%3)" ).arg( Name ).arg( uiWidth ).arg( uiHeight ) ); - standardResolutionSizes.append( QSize( uiWidth, uiHeight) ); + standardResolutionSizes.append( QSize( uiWidth, uiHeight ) ); } setObjectName( "ConfigureFormat" ); - resize( 400, 370 ); setWindowTitle( "Configure Resolution" ); setWindowIcon( QIcon( ":/images/configureformat.png" ) ); QVBoxLayout* MainLayout = new QVBoxLayout( this ); - MainLayout->setObjectName( QStringLiteral( "MainLayout" ) ); - // headLayout - QHBoxLayout* headLayout = new QHBoxLayout(); - QLabel* dialogTitleLabel = new QLabel(); - dialogTitleLabel->setFont( titleFont ); - dialogTitleLabel->setText( "Configure Resolution" ); - QLabel* dialogIconLabel = new QLabel(); - dialogIconLabel->setObjectName( QStringLiteral( "dialogIconLabel" ) ); - dialogIconLabel->setPixmap( QPixmap( ":/images/dialogheader-grid.png" ) ); - headLayout->addWidget( dialogTitleLabel ); - headLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); - headLayout->addWidget( dialogIconLabel ); + QFont titleFont, menusFont, normalFont; - MainLayout->addLayout( headLayout ); + titleFont.setPointSize( 12 ); + titleFont.setBold( true ); + titleFont.setWeight( 75 ); - MainLayout->addItem( new QSpacerItem( 10, 20, QSizePolicy::Minimum ) ); + menusFont.setBold( true ); + titleFont.setWeight( 75 ); - // Filename layout -// QHBoxLayout* filenameLayout = new QHBoxLayout(); -// QLabel* filenameLabel = new QLabel(); -// filenameLabel->setText( "Name" ); -// filenameLabel->setFont( menusFont ); -// m_labelFilename = new QLabel(); -// m_labelFilename->setText( "Test" ); -// filenameLayout->addWidget( filenameLabel ); -// filenameLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); -// filenameLayout->addWidget( m_labelFilename ); - //MainLayout->addLayout( filenameLayout ); + normalFont.setBold( false ); + // menusFont.setPointSize( 12 ); + +// // headLayout +// QHBoxLayout* headLayout = new QHBoxLayout(); +// QLabel* dialogTitleLabel = new QLabel(); +// dialogTitleLabel->setFont( titleFont ); +// dialogTitleLabel->setText( "Configure Resolution" ); +// headLayout->addWidget( dialogTitleLabel ); +// headLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); +// +// MainLayout->addLayout( headLayout ); +// MainLayout->addItem( new QSpacerItem( 10, 20, QSizePolicy::Minimum ) ); + + /* + * Filename layout + */ + QHBoxLayout* filenameLayout = new QHBoxLayout(); + QLabel* filenameLabel = new QLabel(); + filenameLabel->setText( "Name" ); + filenameLabel->setFont( menusFont ); + m_labelFilename = new QLabel(); + m_labelFilename->setFont( titleFont ); + filenameLayout->addWidget( filenameLabel ); + filenameLayout->addItem( new QSpacerItem( 20, 10, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); + filenameLayout->addWidget( m_labelFilename ); + MainLayout->addLayout( filenameLayout ); - // standardResolutionLayout - MainLayout->addItem( new QSpacerItem( 10, 20, QSizePolicy::Minimum ) ); - QHBoxLayout* standardResolutionLayout = new QHBoxLayout(); - QLabel* standardResolutionLabel = new QLabel(); - standardResolutionLabel->setText( "Standard Resolution" ); - standardResolutionLabel->setFont( menusFont ); - m_comboBoxStandardResolution = new QComboBox(); QSizePolicy sizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ); sizePolicy.setHorizontalStretch( 0 ); sizePolicy.setVerticalStretch( 0 ); - sizePolicy.setHeightForWidth( m_comboBoxStandardResolution->sizePolicy().hasHeightForWidth() ); + + /* + * Resolution + */ + QGroupBox* resolutionGroup = new QGroupBox(); + resolutionGroup->setTitle( QStringLiteral( "Resolution" ) ); + resolutionGroup->setFont( menusFont ); + + QGridLayout* resolutionGrid = new QGridLayout(); + resolutionGroup->setLayout( resolutionGrid ); + + m_comboBoxStandardResolution = new QComboBox(); + + m_comboBoxStandardResolution->setFont( normalFont ); m_comboBoxStandardResolution->setSizePolicy( sizePolicy ); m_comboBoxStandardResolution->setAcceptDrops( true ); m_comboBoxStandardResolution->clear(); m_comboBoxStandardResolution->insertItems( 0, standardResolutionNames ); m_comboBoxStandardResolution->setCurrentIndex( -1 ); - standardResolutionLayout->addWidget( standardResolutionLabel ); - standardResolutionLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); - standardResolutionLayout->addWidget( m_comboBoxStandardResolution ); - MainLayout->addLayout( standardResolutionLayout ); - - // Resolution Grid - //resolutionGridVerticalSpacer = new QSpacerItem( 10, 20, QSizePolicy::Minimum ); - MainLayout->addItem( new QSpacerItem( 10, 20, QSizePolicy::Minimum ) ); - - QGridLayout* resolutionGrid = new QGridLayout(); - - QLabel* resolutionLabel = new QLabel(); - resolutionLabel->setFont( menusFont ); - resolutionLabel->setText( "Resolution chosen" ); - resolutionLabel->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ) ); QLabel* widthLabel = new QLabel( "Width" ); + widthLabel->setFont( normalFont ); m_spinBoxWidth = new QSpinBox(); - m_spinBoxWidth->setRange( 0, 9999 ); + m_spinBoxWidth->setRange( 0, 99999 ); m_spinBoxWidth->setValue( 0 ); + m_spinBoxWidth->setFont( normalFont ); QLabel* heightLabel = new QLabel( "Height" ); + heightLabel->setFont( normalFont ); m_spinBoxheight = new QSpinBox(); - m_spinBoxheight->setRange( 0, 9999 ); + m_spinBoxheight->setRange( 0, 99999 ); m_spinBoxheight->setValue( 0 ); + m_spinBoxheight->setFont( normalFont ); QLabel* pixelsLabel = new QLabel(); pixelsLabel->setText( "Pixels" ); + pixelsLabel->setFont( normalFont ); + resolutionGrid->addWidget( m_comboBoxStandardResolution, 1, 0, Qt::AlignCenter ); + resolutionGrid->addWidget( widthLabel, 0, 1, Qt::AlignCenter ); + resolutionGrid->addWidget( m_spinBoxWidth, 1, 1, Qt::AlignCenter ); + resolutionGrid->addWidget( heightLabel, 0, 2, Qt::AlignCenter ); + resolutionGrid->addWidget( m_spinBoxheight, 1, 2, Qt::AlignCenter ); + resolutionGrid->addWidget( pixelsLabel, 1, 3, Qt::AlignCenter ); - resolutionGrid->addWidget( resolutionLabel, 1, 0, 1, 1 ); - resolutionGrid->addWidget( widthLabel, 0, 1, 1, 1 ); - resolutionGrid->addWidget( m_spinBoxWidth, 1, 1, 1, 1 ); - resolutionGrid->addWidget( heightLabel, 0, 2, 1, 1 ); - resolutionGrid->addWidget( m_spinBoxheight, 1, 2, 1, 1 ); - resolutionGrid->addWidget( pixelsLabel, 1, 3, 1, 1 ); - MainLayout->addLayout( resolutionGrid ); + /* + * Pixel format + */ + QGroupBox* pixelGroup = new QGroupBox(); + pixelGroup->setTitle( QStringLiteral( "Pixel Format" ) ); + pixelGroup->setFont( menusFont ); + QGridLayout* pixelGridLayout = new QGridLayout(); + pixelGroup->setLayout( pixelGridLayout ); + + QLabel* colorSpaceLabel = new QLabel(); + colorSpaceLabel->setText( "Color Space" ); + colorSpaceLabel->setFont( normalFont ); + m_comboBoxColorSpace = new QComboBox(); + m_comboBoxColorSpace->setSizePolicy( sizePolicy ); + m_comboBoxColorSpace->setFont( normalFont ); + m_comboBoxColorSpace->clear(); - // Pixel format - QHBoxLayout* pixelFormatLayout = new QHBoxLayout(); QLabel* pixelFormatLabel = new QLabel(); - pixelFormatLabel->setText( "Pixel Format" ); - pixelFormatLabel->setFont( menusFont ); + pixelFormatLabel->setText( "Sampling" ); + pixelFormatLabel->setFont( normalFont ); m_comboBoxPixelFormat = new QComboBox(); - QSizePolicy sizePolicyPixelFormat( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ); - sizePolicyPixelFormat.setHorizontalStretch( 0 ); - sizePolicyPixelFormat.setVerticalStretch( 0 ); - sizePolicyPixelFormat.setHeightForWidth( m_comboBoxPixelFormat->sizePolicy().hasHeightForWidth() ); - m_comboBoxPixelFormat->setSizePolicy( sizePolicyPixelFormat ); - m_comboBoxPixelFormat->setAcceptDrops( true ); + m_comboBoxPixelFormat->setSizePolicy( sizePolicy ); + m_comboBoxPixelFormat->setFont( normalFont ); m_comboBoxPixelFormat->clear(); - for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames().size(); i++ ) + + for( UInt i = 0; i < PlaYUVerFrame::supportedColorSpacesListNames().size(); i++ ) { - m_comboBoxPixelFormat->insertItem( i, PlaYUVerFrame::supportedPixelFormatListNames()[i].c_str() ); + m_comboBoxColorSpace->insertItem( i, PlaYUVerFrame::supportedColorSpacesListNames()[i].c_str() ); } - m_comboBoxPixelFormat->setCurrentIndex( 1 ); + m_comboBoxColorSpace->setCurrentIndex( 1 ); - MainLayout->addItem( new QSpacerItem( 10, 20, QSizePolicy::Minimum ) ); - pixelFormatLayout->addWidget( pixelFormatLabel ); - pixelFormatLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); - pixelFormatLayout->addWidget( m_comboBoxPixelFormat ); - MainLayout->addLayout( pixelFormatLayout ); + pixelGridLayout->addWidget( colorSpaceLabel, 0, 0 ); + pixelGridLayout->addItem( new QSpacerItem( 10, 10, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 ); + pixelGridLayout->addWidget( m_comboBoxColorSpace, 0, 2 ); - // Frame rate format + pixelGridLayout->addWidget( pixelFormatLabel, 1, 0 ); + pixelGridLayout->addItem( new QSpacerItem( 10, 10, QSizePolicy::Expanding, QSizePolicy::Minimum ), 1, 1 ); + pixelGridLayout->addWidget( m_comboBoxPixelFormat, 1, 2 ); + + QHBoxLayout* bitsPerPelLayout = new QHBoxLayout(); + QLabel* bitsPerPelLabel = new QLabel(); + bitsPerPelLabel->setFont( normalFont ); + bitsPerPelLabel->setText( "Pixel bit depth" ); + m_spinBoxBits = new QSpinBox(); + m_spinBoxBits->setFont( normalFont ); + m_spinBoxBits->setMinimumWidth( 30 ); + m_spinBoxBits->setRange( 0, 16 ); + m_spinBoxBits->setValue( 8 ); + pixelGridLayout->addWidget( bitsPerPelLabel, 2, 0 ); + pixelGridLayout->addItem( new QSpacerItem( 20, 10, QSizePolicy::Expanding, QSizePolicy::Minimum ), 2, 1 ); + pixelGridLayout->addWidget( m_spinBoxBits, 2, 2 ); + + /* + * Frame rate format + */ QHBoxLayout* framerateFormatLayout = new QHBoxLayout(); QLabel* framerateFormatLabel = new QLabel(); framerateFormatLabel->setFont( menusFont ); framerateFormatLabel->setText( "Frame Rate" ); m_spinBoxFrameRate = new QSpinBox(); + m_spinBoxFrameRate->setSuffix( QStringLiteral( " Hz" ) ); + m_spinBoxFrameRate->setMinimumWidth( 30 ); m_spinBoxFrameRate->setRange( 0, 200 ); m_spinBoxFrameRate->setValue( 30 ); - - MainLayout->addItem( new QSpacerItem( 10, 20, QSizePolicy::Minimum ) ); framerateFormatLayout->addWidget( framerateFormatLabel ); - framerateFormatLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); + framerateFormatLayout->addItem( new QSpacerItem( 20, 10, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); framerateFormatLayout->addWidget( m_spinBoxFrameRate ); - MainLayout->addLayout( framerateFormatLayout ); - - // Confirmation buttons - - MainLayout->addItem( new QSpacerItem( 20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); - + /* + * Confirmation buttons + */ QDialogButtonBox* dialogButtonOkCancel = new QDialogButtonBox(); dialogButtonOkCancel->setObjectName( QString::fromUtf8( "dialogButtonBox" ) ); dialogButtonOkCancel->setStandardButtons( QDialogButtonBox::Cancel | QDialogButtonBox::Ok ); dialogButtonOkCancel->setCenterButtons( false ); + MainLayout->addItem( new QSpacerItem( 10, 5, QSizePolicy::Minimum ) ); + // MainLayout->addLayout( standardResolutionLayout ); + // MainLayout->addItem( new QSpacerItem( 10, 10, QSizePolicy::Minimum ) ); + MainLayout->addWidget( resolutionGroup ); + MainLayout->addItem( new QSpacerItem( 10, 5, QSizePolicy::Minimum ) ); + MainLayout->addWidget( pixelGroup ); + MainLayout->addLayout( bitsPerPelLayout ); + MainLayout->addItem( new QSpacerItem( 10, 5, QSizePolicy::Minimum ) ); + MainLayout->addLayout( framerateFormatLayout ); + MainLayout->addItem( new QSpacerItem( 10, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); MainLayout->addWidget( dialogButtonOkCancel ); - connect( m_comboBoxStandardResolution, SIGNAL( currentIndexChanged(int) ), this, SLOT( StandardResolutionSelection() ) ); + connect( m_comboBoxStandardResolution, SIGNAL( currentIndexChanged(int) ), this, SLOT( slotStandardResolutionSelected(int) ) ); + connect( m_spinBoxWidth, SIGNAL( valueChanged(int) ), this, SLOT( slotResolutionChange() ) ); + connect( m_spinBoxheight, SIGNAL( valueChanged(int) ), this, SLOT( slotResolutionChange() ) ); + + connect( m_comboBoxColorSpace, SIGNAL( currentIndexChanged(int) ), this, SLOT( slotColorSpaceChange(int) ) ); connect( dialogButtonOkCancel, SIGNAL( accepted() ), this, SLOT( accept() ) ); connect( dialogButtonOkCancel, SIGNAL( rejected() ), this, SLOT( reject() ) ); - QMetaObject::connectSlotsByName( this ); + m_comboBoxColorSpace->setCurrentIndex( 0 ); + + setFixedSize( MainLayout->sizeHint() ); } -Int ConfigureFormatDialog::runConfigureFormatDialog( QString Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ) +Int ConfigureFormatDialog::runConfigureFormatDialog( QString Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBits, UInt& rFrameRate ) { // Set default values - //m_labelFilename->setText( Filename ); - setWindowTitle( "Configure resolution for " + Filename ); - //m_labelFilename->setText( QFileInfo( Filename ).fileName() ); + //setWindowTitle( "Configure resolution for " + Filename ); + m_labelFilename->setText( QFileInfo( Filename ).fileName() ); m_spinBoxWidth->setValue( rWidth ); m_spinBoxheight->setValue( rHeight ); - m_comboBoxPixelFormat->setCurrentIndex( rInputFormat >= 0 ? rInputFormat : 0 ); + + Int colorSpace = 0; + Int sampling = 0; + if( rInputFormat >= 0 ) + { + std::string pelFmtName = PlaYUVerFrame::supportedPixelFormatListNames()[rInputFormat]; + for( UInt j = 0; j < PlaYUVerFrame::supportedColorSpacesListNames().size(); j++ ) + { + for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames( j ).size(); i++ ) + { + if( pelFmtName == PlaYUVerFrame::supportedPixelFormatListNames( j )[i] ) + { + colorSpace = j; + sampling = i; + break; + } + } + } + } + m_comboBoxColorSpace->setCurrentIndex( colorSpace ); + m_comboBoxPixelFormat->setCurrentIndex( sampling ); + m_spinBoxBits->setValue( rBits ); m_spinBoxFrameRate->setValue( rFrameRate ); for( Int i = 0; i < standardResolutionSizes.size(); i++ ) { if( standardResolutionSizes.at( i ) == QSize( rWidth, rHeight ) ) { m_comboBoxStandardResolution->setCurrentIndex( i ); + break; } } if( exec() == QDialog::Rejected ) @@ -227,20 +281,63 @@ Int ConfigureFormatDialog::runConfigureFormatDialog( QString Filename, UInt& rWi } rWidth = m_spinBoxWidth->value(); rHeight = m_spinBoxheight->value(); - rInputFormat = m_comboBoxPixelFormat->currentIndex(); + colorSpace = m_comboBoxColorSpace->currentIndex(); + sampling = m_comboBoxPixelFormat->currentIndex(); + std::string pelFmtName = PlaYUVerFrame::supportedPixelFormatListNames( colorSpace )[sampling]; + for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames().size(); i++ ) + { + if( pelFmtName == PlaYUVerFrame::supportedPixelFormatListNames()[i] ) + { + rInputFormat = i; + break; + } + } + rBits = m_spinBoxBits->value(); rFrameRate = m_spinBoxFrameRate->value(); return QDialog::Accepted; } -void ConfigureFormatDialog::StandardResolutionSelection() +void ConfigureFormatDialog::slotStandardResolutionSelected( Int idx ) { - Int currIdx = m_comboBoxStandardResolution->currentIndex(); - if( currIdx == -1 ) - return; - - QSize currSize = standardResolutionSizes.at( currIdx ); - m_spinBoxWidth->setValue( currSize.width() ); - m_spinBoxheight->setValue( currSize.height() ); + if( idx >= 0 ) + { + QSize currSize = standardResolutionSizes.at( idx ); + m_spinBoxWidth->blockSignals( true ); + m_spinBoxWidth->setValue( currSize.width() ); + m_spinBoxWidth->blockSignals( false ); + m_spinBoxheight->blockSignals( true ); + m_spinBoxheight->setValue( currSize.height() ); + m_spinBoxheight->blockSignals( false ); + } } -} // Namespace SCode +void ConfigureFormatDialog::slotResolutionChange() +{ + m_comboBoxStandardResolution->blockSignals( true ); + Int newIdx = -1; + for( Int i = 0; i < standardResolutionSizes.size(); i++ ) + { + if( standardResolutionSizes.at( i ) == QSize( m_spinBoxWidth->value(), m_spinBoxheight->value() ) ) + { + newIdx = i; + break; + } + } + m_comboBoxStandardResolution->setCurrentIndex( newIdx ); + m_comboBoxStandardResolution->blockSignals( false ); +} + +Void ConfigureFormatDialog::slotColorSpaceChange( Int idx ) +{ + if( idx == -1 ) + return; + + m_comboBoxPixelFormat->clear(); + for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames( idx ).size(); i++ ) + { + m_comboBoxPixelFormat->insertItem( i, PlaYUVerFrame::supportedPixelFormatListNames( idx )[i].c_str() ); + } + m_comboBoxPixelFormat->setCurrentIndex( 0 ); +} + +} // NAMESPACE diff --git a/app/ConfigureFormatDialog.h b/app/ConfigureFormatDialog.h index cb10ab4..fe74524 100644 --- a/app/ConfigureFormatDialog.h +++ b/app/ConfigureFormatDialog.h @@ -34,18 +34,12 @@ #endif #include - - class QPixmap; class QColor; namespace plaYUVer { -#define ADD_STANDARD_RESOLUTION( name, width, height) \ - standardResolutionNames.push_back( QString( name ) ); \ - standardResolutionSizesList.push_back( QSize( width, height ) ) - /** * */ @@ -56,10 +50,12 @@ Q_OBJECT public: ConfigureFormatDialog( QWidget *parent = 0 ); - Int runConfigureFormatDialog ( QString Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ); + Int runConfigureFormatDialog( QString Filename, UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBits, UInt& rFrameRate ); private Q_SLOTS: - void StandardResolutionSelection(); + void slotStandardResolutionSelected( int ); + void slotResolutionChange(); + void slotColorSpaceChange( int ); private: QStringList standardResolutionNames; @@ -69,7 +65,9 @@ private: QComboBox *m_comboBoxStandardResolution; QSpinBox *m_spinBoxWidth; QSpinBox *m_spinBoxheight; + QComboBox *m_comboBoxColorSpace; QComboBox *m_comboBoxPixelFormat; + QSpinBox *m_spinBoxBits; QSpinBox *m_spinBoxFrameRate; }; diff --git a/app/DialogSubWindowSelector.cpp b/app/DialogSubWindowSelector.cpp index 0b7d191..fd9a644 100644 --- a/app/DialogSubWindowSelector.cpp +++ b/app/DialogSubWindowSelector.cpp @@ -22,6 +22,8 @@ * \brief Dialog box to select sub windows */ +#include +#include #include "PlaYUVerSubWindowHandle.h" #include "DialogSubWindowSelector.h" #include "VideoSubWindow.h" @@ -29,135 +31,140 @@ namespace plaYUVer { -DialogSubWindowSelector::DialogSubWindowSelector( QWidget *parent, PlaYUVerSubWindowHandle *windowManager, UInt uiCategory, Int minWindowsSelected, Int maxWindowsSelected ) : +DialogSubWindowSelector::DialogSubWindowSelector( QWidget *parent, PlaYUVerSubWindowHandle *windowManager, UInt uiCategory, Int minWindowsSelected, + Int maxWindowsSelected ) : QDialog( parent ), m_uiCategory( uiCategory ), m_iMinSelectedWindows( minWindowsSelected ), m_iMaxSlectedWindows( maxWindowsSelected ), m_pcMainWindowManager( windowManager ) { - QFont titleFont, menusFont; - - titleFont.setPointSize( 14 ); - titleFont.setBold( true ); - titleFont.setWeight( 75 ); - - menusFont.setBold( true ); - menusFont.setWeight( 75 ); QSize windowSize( 350, 80 ); resize( windowSize ); - setWindowTitle( "Sub Windows Selection" ); + setWindowTitle( "Select desired Sub-Windows" ); - QHBoxLayout* MainLayout = new QHBoxLayout( this ); + QVBoxLayout* mainLayout = new QVBoxLayout( this ); - // Window list and add button - m_comboBoxWindowList = new QComboBox(); - QSizePolicy sizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ); - sizePolicy.setHorizontalStretch( 0 ); - sizePolicy.setVerticalStretch( 0 ); - sizePolicy.setHeightForWidth( m_comboBoxWindowList->sizePolicy().hasHeightForWidth() ); - m_comboBoxWindowList->setSizePolicy( sizePolicy ); - m_comboBoxWindowList->setAcceptDrops( true ); + minWindowsSelected = minWindowsSelected == 0 ? 1 : minWindowsSelected; + + m_pcGroupCheckBox = new QGroupBox(); + m_pcGroupCheckBox->setLayout( new QVBoxLayout() ); + + mainLayout->addWidget( m_pcGroupCheckBox ); - m_pushButtonAdd = new QPushButton( "Add", this ); m_pushButtonAddAll = new QPushButton( "Add all", this ); - m_pushButtonRemove = new QPushButton( "Remove", this ); m_pushButtonRemoveAll = new QPushButton( "Remove All", this ); - m_pushButtonRemove->setEnabled( false ); m_pushButtonRemoveAll->setEnabled( false ); - // Selected Sub Window List - m_listSelectedWindows = new QListWidget( this ); - // Confirmation buttons m_pushButtonOkCancel = new QDialogButtonBox(); m_pushButtonOkCancel->setStandardButtons( QDialogButtonBox::Cancel | QDialogButtonBox::Ok ); - m_pushButtonOkCancel->setOrientation( Qt::Vertical ); + m_pushButtonOkCancel->setOrientation( Qt::Horizontal ); m_pushButtonOkCancel->setCenterButtons( false ); m_pushButtonOkCancel->buttons().at( 0 )->setEnabled( false ); - // Create Layouts - QVBoxLayout* LeftVLayout = new QVBoxLayout(); - LeftVLayout->addWidget( m_comboBoxWindowList ); - //LeftVLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) ); - LeftVLayout->addWidget( m_listSelectedWindows ); - - QVBoxLayout* RightVLayout = new QVBoxLayout(); - RightVLayout->addWidget( m_pushButtonAdd ); - RightVLayout->addWidget( m_pushButtonAddAll ); - RightVLayout->addWidget( m_pushButtonRemove ); - RightVLayout->addWidget( m_pushButtonRemoveAll ); - RightVLayout->addItem( new QSpacerItem( 40, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ) ); - RightVLayout->addWidget( m_pushButtonOkCancel ); + QHBoxLayout* BottomHLayout = new QHBoxLayout(); + BottomHLayout->addWidget( m_pushButtonAddAll ); + BottomHLayout->addWidget( m_pushButtonRemoveAll ); + BottomHLayout->addWidget( m_pushButtonOkCancel ); // Add components - //MainLayout->addItem( new QSpacerItem( 10, 5, QSizePolicy::Expanding, QSizePolicy::Fixed ) ); - MainLayout->addLayout( LeftVLayout ); - MainLayout->addLayout( RightVLayout ); + mainLayout->addLayout( BottomHLayout ); - setLayout( MainLayout ); + setLayout( mainLayout ); // Create actions connect( m_pushButtonOkCancel, SIGNAL( accepted() ), this, SLOT( accept() ) ); connect( m_pushButtonOkCancel, SIGNAL( rejected() ), this, SLOT( reject() ) ); - connect( m_pushButtonAdd, SIGNAL( clicked() ), this, SLOT( addSubWindow() ) ); - connect( m_pushButtonAddAll, SIGNAL( clicked() ), this, SLOT( addAllSubWindow() ) ); - connect( m_pushButtonRemove, SIGNAL( clicked() ), this, SLOT( removeSubWindow() ) ); - connect( m_pushButtonRemoveAll, SIGNAL( clicked() ), this, SLOT( removeAllSubWindow() ) ); - QMetaObject::connectSlotsByName( this ); - updateSubWindowList(); + connect( m_pushButtonAddAll, SIGNAL( clicked() ), this, SLOT( addAllSubWindow() ) ); + connect( m_pushButtonRemoveAll, SIGNAL( clicked() ), this, SLOT( removeAllSubWindow() ) ); + + m_mapperWindowsList = new QSignalMapper( this ); + connect( m_mapperWindowsList, SIGNAL( mapped(int) ), this, SLOT( toggleSubWindow(int) ) ); + + SubWindowAbstract *subWindow; + QString currSubWindowName; + QCheckBox* windowCheckBox; + m_apcSubWindowList = m_pcMainWindowManager->findSubWindow( m_uiCategory ); + for( Int i = 0; i < m_apcSubWindowList.size(); i++ ) + { + subWindow = m_apcSubWindowList.at( i ); + currSubWindowName = subWindow->getWindowName(); + windowCheckBox = new QCheckBox( currSubWindowName, this ); + connect( windowCheckBox, SIGNAL( stateChanged(int) ), m_mapperWindowsList, SLOT( map() ) ); + m_mapperWindowsList->setMapping( windowCheckBox, i ); + m_apcWindowsListCheckBox.append( windowCheckBox ); + } + + update(); + + setFixedSize( mainLayout->sizeHint() ); + } Void DialogSubWindowSelector::updateSubWindowList() { - SubWindowHandle *subWindow; - QString currSubWindowName; - m_pcWindowListNames.clear(); - QList subWindowList = m_pcMainWindowManager->findSubWindow( m_uiCategory ); - for( Int i = 0; i < subWindowList.size(); i++ ) - { - subWindow = subWindowList.at( i ); - currSubWindowName = subWindow->getWindowName(); - if( !m_pcSelectedWindowListNames.contains( currSubWindowName ) ) - m_pcWindowListNames.append( currSubWindowName ); - } - m_comboBoxWindowList->clear(); - m_comboBoxWindowList->insertItems( 0, m_pcWindowListNames ); - m_comboBoxWindowList->setCurrentIndex( -1 ); + QLayout* pcLayout = m_pcGroupCheckBox->layout(); + QLayoutItem* pcLayoutItem; + QCheckBox* windowCheckBox; + Int iIdx; - Bool enableAddAll = true; - - if( m_iMaxSlectedWindows >= 0 ) + /** + * Remove all check boxes + */ + for( Int i = 0; i < pcLayout->count(); i++ ) { - if( m_pcSelectedWindowListNames.size() >= m_iMaxSlectedWindows ) + pcLayoutItem = pcLayout->itemAt( i ); + if( pcLayoutItem ) { - m_pushButtonAdd->setEnabled( false ); - } - else - { - m_pushButtonAdd->setEnabled( true ); - } - if( m_pcWindowListNames.size() > m_iMaxSlectedWindows ) - { - enableAddAll = false; + pcLayout->removeWidget( pcLayoutItem->widget() ); + pcLayout->removeItem( pcLayoutItem ); } } - m_pushButtonAddAll->setEnabled( enableAddAll ); - if( m_pcSelectedWindowListNames.size() > 0 ) + for( Int i = 0; i < m_apcSelectedSubWindowList.size(); i++ ) + { + iIdx = m_apcSubWindowList.indexOf( m_apcSelectedSubWindowList.at( i ) ); + if( iIdx >= 0 ) + { + windowCheckBox = m_apcWindowsListCheckBox.at( iIdx ); + m_pcGroupCheckBox->layout()->addWidget( windowCheckBox ); + } + } + for( Int i = 0; i < m_apcWindowsListCheckBox.size(); i++ ) + { + if( !m_apcSelectedSubWindowList.contains( m_apcSubWindowList.at( i ) ) ) + m_pcGroupCheckBox->layout()->addWidget( m_apcWindowsListCheckBox.at( i ) ); + } + +// qDebug( ) << "Selected windows: " +// << m_apcSelectedSubWindowList.size(); +} + +Void DialogSubWindowSelector::selectSubWindow( SubWindowAbstract * subWindow ) +{ + Int iIdx = m_apcSubWindowList.indexOf( subWindow ); + if( iIdx >= 0 ) + { + m_apcWindowsListCheckBox.at( iIdx )->setChecked( true ); + //m_apcSelectedSubWindowList.append( m_apcSubWindowList.at( iIdx ) ); + } +} + +Void DialogSubWindowSelector::update() +{ + if( m_apcSelectedSubWindowList.size() > 0 ) { - m_pushButtonRemove->setEnabled( true ); m_pushButtonRemoveAll->setEnabled( true ); } else { - m_pushButtonRemove->setEnabled( false ); m_pushButtonRemoveAll->setEnabled( false ); } - if( m_pcSelectedWindowListNames.size() >= m_iMinSelectedWindows ) + if( m_apcSelectedSubWindowList.size() >= m_iMinSelectedWindows ) { m_pushButtonOkCancel->buttons().at( 0 )->setEnabled( true ); } @@ -166,68 +173,76 @@ Void DialogSubWindowSelector::updateSubWindowList() m_pushButtonOkCancel->buttons().at( 0 )->setEnabled( false ); } -} - -Void DialogSubWindowSelector::setSubWindowList( QStringList cWindowListNames ) -{ - m_pcSelectedWindowListNames = cWindowListNames; - m_listSelectedWindows->clear(); - m_listSelectedWindows->insertItems( 0, cWindowListNames ); + if( m_iMaxSlectedWindows > 0 ) + { + if( m_apcWindowsListCheckBox.size() > m_iMaxSlectedWindows ) + { + m_pushButtonAddAll->setEnabled( false ); + } + else + { + m_pushButtonAddAll->setEnabled( true ); + } + if( m_apcSelectedSubWindowList.size() >= m_iMaxSlectedWindows ) + { + for( Int i = 0; i < m_apcWindowsListCheckBox.size(); i++ ) + { + if( m_apcSelectedSubWindowList.contains( m_apcSubWindowList.at( i ) ) ) + { + m_apcWindowsListCheckBox.at( i )->setEnabled( true ); + } + else + { + m_apcWindowsListCheckBox.at( i )->setEnabled( false ); + } + } + } + else + { + for( Int i = 0; i < m_apcWindowsListCheckBox.size(); i++ ) + { + m_apcWindowsListCheckBox.at( i )->setEnabled( true ); + } + } + } updateSubWindowList(); } // ----------------------- Slot Functions ----------------------- -Void DialogSubWindowSelector::addSubWindow() +Void DialogSubWindowSelector::toggleSubWindow( Int idx ) { - Int iSelectedIdx = m_comboBoxWindowList->currentIndex(); - if( iSelectedIdx >= 0 ) + Bool isChecked = m_apcWindowsListCheckBox.at( idx )->isChecked(); + + if( isChecked ) { - m_pcSelectedWindowListNames.append( m_pcWindowListNames.at( iSelectedIdx ) ); - m_listSelectedWindows->clear(); - m_listSelectedWindows->insertItems( 0, m_pcSelectedWindowListNames ); - updateSubWindowList(); + m_apcSelectedSubWindowList.append( m_apcSubWindowList.at( idx ) ); } + else + { + m_apcSelectedSubWindowList.removeOne( m_apcSubWindowList.at( idx ) ); + } + update(); } Void DialogSubWindowSelector::addAllSubWindow() { - if( m_iMaxSlectedWindows <= 0 || m_pcWindowListNames.size() <= m_iMaxSlectedWindows ) + m_apcSelectedSubWindowList.clear(); + for( Int i = 0; i < m_apcWindowsListCheckBox.size(); i++ ) { - for( Int i = 0; i < m_pcWindowListNames.size(); i++ ) - { - m_pcSelectedWindowListNames.append( m_pcWindowListNames.at( i ) ); - } - m_listSelectedWindows->clear(); - m_listSelectedWindows->insertItems( 0, m_pcSelectedWindowListNames ); - updateSubWindowList(); - } -} - -Void DialogSubWindowSelector::removeSubWindow() -{ - QList selectedWindows = m_listSelectedWindows->selectedItems(); - if( selectedWindows.size() ) - { - for( Int i = 0; i < selectedWindows.size(); i++ ) - { - QString currName = selectedWindows.at( i )->text(); - Int indexCurrName = m_pcSelectedWindowListNames.indexOf( currName ); - m_pcSelectedWindowListNames.removeAt( indexCurrName ); - m_listSelectedWindows->removeItemWidget( selectedWindows[i] ); - } - m_listSelectedWindows->clear(); - m_listSelectedWindows->insertItems( 0, m_pcSelectedWindowListNames ); - updateSubWindowList(); + m_apcWindowsListCheckBox.at( i )->setChecked( true ); } + update(); } Void DialogSubWindowSelector::removeAllSubWindow() { - QList selectedWindows = m_listSelectedWindows->selectedItems(); - m_listSelectedWindows->clear(); - m_pcSelectedWindowListNames.clear(); - updateSubWindowList(); + for( Int i = 0; i < m_apcWindowsListCheckBox.size(); i++ ) + { + m_apcWindowsListCheckBox.at( i )->setChecked( false ); + } + m_apcSelectedSubWindowList.clear(); + update(); } } // Namespace SCode diff --git a/app/DialogSubWindowSelector.h b/app/DialogSubWindowSelector.h index 3779826..619b508 100644 --- a/app/DialogSubWindowSelector.h +++ b/app/DialogSubWindowSelector.h @@ -34,13 +34,19 @@ #endif #include +#include + class QPixmap; class QColor; +class QCheckBox; +class QGroupBox; namespace plaYUVer { class PlaYUVerSubWindowHandle; +class SubWindowAbstract; + /** * Class to define the dialog box to select sub windows * This class enable the selection of several group of windows @@ -50,35 +56,37 @@ class DialogSubWindowSelector: public QDialog Q_OBJECT public: - DialogSubWindowSelector( QWidget *parent, PlaYUVerSubWindowHandle *windowManager, UInt uiCategory, Int minWindowsSelected = 0, Int maxWindowsSelected = -1 ); + DialogSubWindowSelector( QWidget *parent, PlaYUVerSubWindowHandle *windowManager, UInt uiCategory, Int minWindowsSelected = 1, Int maxWindowsSelected = -1 ); - Void setSubWindowList( QStringList cWindowListNames ); - QStringList getSelectedWindows() + Void selectSubWindow( SubWindowAbstract* subWindow ); + QList getSelectedWindows() { - return m_pcSelectedWindowListNames; + return m_apcSelectedSubWindowList; } private: UInt m_uiCategory; Int m_iMinSelectedWindows; Int m_iMaxSlectedWindows; PlaYUVerSubWindowHandle* m_pcMainWindowManager; - QStringList m_pcWindowListNames; - QStringList m_pcSelectedWindowListNames; + + QList m_apcSubWindowList; + QList m_apcSelectedSubWindowList; + + QSignalMapper* m_mapperWindowsList; + QGroupBox* m_pcGroupCheckBox; + QVector m_apcWindowsListCheckBox; QComboBox* m_comboBoxWindowList; QDialogButtonBox* m_pushButtonOkCancel; - QPushButton* m_pushButtonAdd; QPushButton* m_pushButtonAddAll; - QPushButton* m_pushButtonRemove; QPushButton* m_pushButtonRemoveAll; - QListWidget* m_listSelectedWindows; Void updateSubWindowList(); + Void update(); private Q_SLOTS: - void addSubWindow(); + void toggleSubWindow( int ); void addAllSubWindow(); - void removeSubWindow(); void removeAllSubWindow(); }; diff --git a/app/FramePropertiesSidebar.cpp b/app/FramePropertiesDock.cpp similarity index 92% rename from app/FramePropertiesSidebar.cpp rename to app/FramePropertiesDock.cpp index 205ed42..dfa2c33 100644 --- a/app/FramePropertiesSidebar.cpp +++ b/app/FramePropertiesDock.cpp @@ -18,19 +18,19 @@ */ /** - * \file FramePropertiesSideBar.cpp + * \file FramePropertiesDock.cpp * \brief Main side bar definition */ #include #include #include -#include "FramePropertiesSidebar.h" +#include "FramePropertiesDock.h" namespace plaYUVer { -FramePropertiesSideBar::FramePropertiesSideBar( QWidget* parent, Bool* pbMainPlaySwitch ) : +FramePropertiesDock::FramePropertiesDock( QWidget* parent, Bool* pbMainPlaySwitch ) : QWidget( parent ), pbMainPlaySwitch( pbMainPlaySwitch ) { @@ -235,14 +235,14 @@ FramePropertiesSideBar::FramePropertiesSideBar( QWidget* parent, Bool* pbMainPla connect( renderingButtonGroup, SIGNAL( buttonClicked(int) ), this, SLOT( slotRenderingChanged(int) ) ); connect( histogramWidget, SIGNAL( signalIntervalChanged( int, int ) ), this, SLOT( slotUpdateInterval(int, int) ) ); connect( histogramWidget, SIGNAL( signalMaximumValueChanged(int) ), this, SLOT( slotUpdateIntervRange(int) ) ); - connect( histogramWidget, SIGNAL( signalHistogramComputationDone(bool) ), this, SLOT( slotRefreshOptions(bool) ) ); + connect( histogramWidget, SIGNAL( signalHistogramComputationDone(int) ), this, SLOT( slotRefreshOptions(int) ) ); connect( histogramWidget, SIGNAL( signalHistogramComputationFailed(void) ), this, SLOT( slotHistogramComputationFailed(void) ) ); connect( minInterv, SIGNAL( valueChanged (int) ), this, SLOT( slotMinValueChanged(int) ) ); connect( maxInterv, SIGNAL( valueChanged (int) ), this, SLOT( slotMaxValueChanged(int) ) ); } -FramePropertiesSideBar::~FramePropertiesSideBar() +FramePropertiesDock::~FramePropertiesDock() { // If there is a currently histogram computation when dialog is closed, // stop it before the image data are deleted automatically! @@ -251,7 +251,7 @@ FramePropertiesSideBar::~FramePropertiesSideBar() delete histogramWidget; } -QSize FramePropertiesSideBar::sizeHint() const +QSize FramePropertiesDock::sizeHint() const { QSize currSize = size(); QSize bestSize( 180, currSize.height() ); @@ -260,7 +260,7 @@ QSize FramePropertiesSideBar::sizeHint() const return currSize; } -Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame, Bool isPlaying ) +Void FramePropertiesDock::setData( PlaYUVerFrame* pcFrame, Bool isPlaying ) { m_pbIsPlaying = isPlaying; if( !pcFrame ) @@ -284,7 +284,7 @@ Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame, Bool isPlaying ) if( m_iLastFrameType != colorSpace ) { m_iLastFrameType = colorSpace; - if ( colorSpace == PlaYUVerFrame::COLOR_RGB || colorSpace == PlaYUVerFrame::COLOR_ARGB ) + if( colorSpace == PlaYUVerFrame::COLOR_RGB || colorSpace == PlaYUVerFrame::COLOR_ARGB ) { channelCB->clear(); channelCB->clear(); @@ -340,7 +340,7 @@ Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame, Bool isPlaying ) } } setEnabled( true ); - if( m_pcFrame || !(*pbMainPlaySwitch) ) + if( m_pcFrame || !( *pbMainPlaySwitch ) ) { m_pcFrame = pcFrame; updateDataHistogram(); @@ -348,7 +348,7 @@ Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame, Bool isPlaying ) } } -Void FramePropertiesSideBar::setSelection( const QRect &selectionArea ) +Void FramePropertiesDock::setSelection( const QRect &selectionArea ) { // This is necessary to stop computation because image.bits() is // currently used by threaded histogram algorithm. @@ -360,9 +360,8 @@ Void FramePropertiesSideBar::setSelection( const QRect &selectionArea ) if( selectionArea.isValid() ) { histogramWidget->stopHistogramComputation(); - histogramWidget->updateSelectionData( new PlaYUVerFrame(m_pcFrame, - selectionArea.x(), selectionArea.y(), - selectionArea.width(), selectionArea.height() ) ); + histogramWidget->updateSelectionData( + new PlaYUVerFrame( m_pcFrame, selectionArea.x(), selectionArea.y(), selectionArea.width(), selectionArea.height() ) ); fullImageButton->show(); selectionImageButton->show(); selectionImageButton->click(); @@ -377,7 +376,7 @@ Void FramePropertiesSideBar::setSelection( const QRect &selectionArea ) } } -Void FramePropertiesSideBar::updateDataHistogram() +Void FramePropertiesDock::updateDataHistogram() { if( m_pcFrame->isValid() && isVisible() ) { @@ -404,7 +403,7 @@ Void FramePropertiesSideBar::updateDataHistogram() } } -Void FramePropertiesSideBar::updateStatistiques() +Void FramePropertiesDock::updateStatistiques() { QString value; @@ -445,7 +444,7 @@ Void FramePropertiesSideBar::updateStatistiques() } } -Void FramePropertiesSideBar::stopHistogram() +Void FramePropertiesDock::stopHistogram() { histogramWidget->stopHistogramComputation(); } @@ -454,7 +453,7 @@ Void FramePropertiesSideBar::stopHistogram() // SLOTS //////////////////////////////////////////////////////////////////////////////// -Void FramePropertiesSideBar::slotRefreshOptions( bool /*depth*/) +Void FramePropertiesDock::slotRefreshOptions( int range ) { if( !isVisible() ) return; @@ -477,12 +476,12 @@ Void FramePropertiesSideBar::slotRefreshOptions( bool /*depth*/) } } -Void FramePropertiesSideBar::slotHistogramComputationFailed() +Void FramePropertiesDock::slotHistogramComputationFailed() { m_pcFrame = NULL; } -Void FramePropertiesSideBar::slotChannelChanged( Int channel ) +Void FramePropertiesDock::slotChannelChanged( Int channel ) { if( m_pcFrame->getColorSpace() == PlaYUVerFrame::COLOR_YUV ) channel += 1; @@ -520,13 +519,13 @@ Void FramePropertiesSideBar::slotChannelChanged( Int channel ) updateStatistiques(); } -Void FramePropertiesSideBar::slotScaleChanged( Int scale ) +Void FramePropertiesDock::slotScaleChanged( Int scale ) { histogramWidget->m_scaleType = scale; histogramWidget->update(); } -Void FramePropertiesSideBar::slotColorsChanged( Int color ) +Void FramePropertiesDock::slotColorsChanged( Int color ) { switch( color ) { @@ -545,14 +544,14 @@ Void FramePropertiesSideBar::slotColorsChanged( Int color ) updateStatistiques(); } -Void FramePropertiesSideBar::slotRenderingChanged( Int rendering ) +Void FramePropertiesDock::slotRenderingChanged( Int rendering ) { histogramWidget->m_renderingType = rendering; histogramWidget->update(); updateStatistiques(); } -Void FramePropertiesSideBar::slotMinValueChanged( Int min ) +Void FramePropertiesDock::slotMinValueChanged( Int min ) { // Called when user changes values of spin box. // Communicate the change to histogram widget. @@ -566,7 +565,7 @@ Void FramePropertiesSideBar::slotMinValueChanged( Int min ) updateStatistiques(); } -Void FramePropertiesSideBar::slotMaxValueChanged( Int max ) +Void FramePropertiesDock::slotMaxValueChanged( Int max ) { if( max == minInterv->value() - 1 ) minInterv->setValue( max ); @@ -576,7 +575,7 @@ Void FramePropertiesSideBar::slotMaxValueChanged( Int max ) updateStatistiques(); } -Void FramePropertiesSideBar::slotUpdateInterval( Int min, Int max ) +Void FramePropertiesDock::slotUpdateInterval( Int min, Int max ) { // Called when value is set from within histogram widget. // Block signals to prevent slotMinValueChanged and @@ -594,7 +593,7 @@ Void FramePropertiesSideBar::slotUpdateInterval( Int min, Int max ) updateStatistiques(); } -Void FramePropertiesSideBar::slotUpdateIntervRange( Int range ) +Void FramePropertiesDock::slotUpdateIntervRange( Int range ) { maxInterv->blockSignals( true ); maxInterv->setMaximum( range ); diff --git a/app/FramePropertiesSidebar.h b/app/FramePropertiesDock.h similarity index 90% rename from app/FramePropertiesSidebar.h rename to app/FramePropertiesDock.h index 71a9b0f..dbb34ad 100644 --- a/app/FramePropertiesSidebar.h +++ b/app/FramePropertiesDock.h @@ -18,12 +18,12 @@ */ /** - * \file FramePropertiesSidebar.h + * \file FramePropertiesDock.h * \brief Main side bar definition */ -#ifndef __FRAMEPROPERTIESSIDEBAR_H__ -#define __FRAMEPROPERTIESSIDEBAR_H__ +#ifndef __FRAMEPROPERTIESDOCK_H__ +#define __FRAMEPROPERTIESDOCK_H__ #include "config.h" #include "PlaYUVerAppDefs.h" @@ -40,12 +40,12 @@ namespace plaYUVer { -class FramePropertiesSideBar: public QWidget +class FramePropertiesDock: public QWidget { Q_OBJECT public: - FramePropertiesSideBar( QWidget* parent, Bool* pbMainPlaySwitch ); - ~FramePropertiesSideBar(); + FramePropertiesDock( QWidget* parent, Bool* pbMainPlaySwitch ); + ~FramePropertiesDock(); QSize sizeHint() const; @@ -116,7 +116,7 @@ private: Void updateDataHistogram(); private Q_SLOTS: - void slotRefreshOptions( bool sixteenBit ); + void slotRefreshOptions( int range ); void slotHistogramComputationFailed( void ); void slotChannelChanged( int channel ); void slotScaleChanged( int scale ); @@ -132,4 +132,4 @@ private Q_SLOTS: } // NAMESPACE -#endif // __FRAMEPROPERTIESSIDEBAR_H__ +#endif // __FRAMEPROPERTIESDOCK_H__ diff --git a/app/HistogramWidget.cpp b/app/HistogramWidget.cpp index d1502bf..3c8e40c 100644 --- a/app/HistogramWidget.cpp +++ b/app/HistogramWidget.cpp @@ -58,7 +58,7 @@ public: if( m_histogram && m_parent ) { EventData *eventData = new EventData(); -// eventData->starting = true; +// eventDm_imageHistogramata->starting = true; // eventData->success = false; // eventData->histogram = m_histogram; // QCoreApplication::postEvent( m_parent, eventData ); @@ -125,7 +125,7 @@ public: HistogramWidgetPrivate() { blinkTimer = 0; - sixteenBits = false; + imageBits = 8; inSelected = false; blinkFlag = false; clearFlag = HistogramNone; @@ -146,7 +146,7 @@ public: // Image informations Int imageChannels; Int imageColorSpace; - bool sixteenBits; + Int imageBits; bool guideVisible; // Display color guide. bool statisticsVisible; // Display tooltip histogram statistics. @@ -313,7 +313,7 @@ Void HistogramWidget::customEvent( QEvent *event ) setUpdatesEnabled( false ); notifyValuesChanged(); - emit signalHistogramComputationDone( d->sixteenBits ); + emit signalHistogramComputationDone( d->range ); setUpdatesEnabled( true ); update(); @@ -397,7 +397,7 @@ Void HistogramWidget::stopHistogramComputation() Void HistogramWidget::updateData( const PlaYUVerFrame *pcFrame, const PlaYUVerFrame *pcFrameSelection ) { - d->sixteenBits = false; + d->imageBits = pcFrame->getBitsPel(); //d->imageColorSpace = image.getPelFormat(); d->imageColorSpace = pcFrame->getColorSpace(); d->imageChannels = pcFrame->getNumberChannels(); @@ -409,7 +409,7 @@ Void HistogramWidget::updateData( const PlaYUVerFrame *pcFrame, const PlaYUVerFr // Do not using PlaYUVerFrameStatistics::getHistogramSegment() // method here because histogram hasn't yet been computed. - d->range = d->sixteenBits ? 65535 : 255; + d->range = ( 1 << d->imageBits ) - 1; emit signalMaximumValueChanged( d->range ); m_imageHistogram = ( PlaYUVerFrameStats* )pcFrame; diff --git a/app/HistogramWidget.h b/app/HistogramWidget.h index 393f63f..a5242ec 100644 --- a/app/HistogramWidget.h +++ b/app/HistogramWidget.h @@ -152,7 +152,7 @@ public: Q_SIGNALS: void signalIntervalChanged( int min, int max ); void signalMaximumValueChanged( int ); - void signalHistogramComputationDone( bool ); + void signalHistogramComputationDone( int ); void signalHistogramComputationFailed( void ); public Q_SLOTS: diff --git a/app/ModulesHandle.cpp b/app/ModulesHandle.cpp index 4e19ce7..6470667 100644 --- a/app/ModulesHandle.cpp +++ b/app/ModulesHandle.cpp @@ -23,11 +23,14 @@ */ #include +#include "PlaYUVerApp.h" #include "ModulesHandle.h" #include "PlaYUVerSubWindowHandle.h" +#include "VideoSubWindow.h" #include "VideoHandle.h" #include "PlaYUVerModuleFactory.h" #include "DialogSubWindowSelector.h" +#include "ModulesHandleOptDialog.h" namespace plaYUVer { @@ -163,24 +166,23 @@ Void ModulesHandle::updateMenus() { m_arrayActions.at( i )->setEnabled( false ); } - m_arrayActions[DISABLE_ACT]->setEnabled( hasSubWindow ); - m_arrayActions[DISABLE_ALL_ACT]->setEnabled( hasSubWindow ); m_arrayActions[FORCE_NEW_WINDOW_ACT]->setEnabled( hasSubWindow ); + m_arrayActions[DISABLE_ALL_ACT]->setEnabled( m_pcPlaYUVerAppModuleIfList.size() > 0 ); + if( pcSubWindow ) { QList apcCurrentModule = pcSubWindow->getModuleArray(); + m_arrayActions[DISABLE_ACT]->setEnabled( apcCurrentModule.size() > 0 ); if( pcSubWindow->getDisplayModule() ) { m_arrayActions[APPLY_ALL_ACT]->setEnabled( true ); m_arrayActions[SWAP_FRAMES_ACT]->setEnabled( true ); - apcCurrentModule.append( pcSubWindow->getDisplayModule() ); } for( Int i = 0; i < apcCurrentModule.size(); i++ ) { currModuleAction = apcCurrentModule.at( i )->m_pcModuleAction; currModuleAction->setChecked( true ); } - } } @@ -248,27 +250,34 @@ Void ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf ) QString windowName; QList videoSubWindowList; - UInt numberOfFrames = pcCurrModuleIf->m_pcModule->m_uiNumberOfFrames; + Int numberOfFrames = pcCurrModuleIf->m_pcModule->m_uiNumberOfFrames; if( numberOfFrames > MODULE_REQUIRES_ONE_FRAME ) // Show dialog to select sub windows { - DialogSubWindowSelector dialogWindowsSelection( m_pcParent, m_pcMainWindowManager, SubWindowHandle::VIDEO_SUBWINDOW, numberOfFrames, numberOfFrames ); + DialogSubWindowSelector dialogWindowsSelection( m_pcParent, m_pcMainWindowManager, SubWindowAbstract::VIDEO_SUBWINDOW, numberOfFrames, numberOfFrames ); + QList windowsList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW ); + + if( windowsList.size() <= numberOfFrames ) + { + for( Int i = 0; i < windowsList.size(); i++ ) + { + dialogWindowsSelection.selectSubWindow( windowsList.at( i ) ); + } + } + else + { + dialogWindowsSelection.selectSubWindow( pcVideoSubWindow ); + } + if( dialogWindowsSelection.exec() == QDialog::Accepted ) { - QStringList selectedWindows = dialogWindowsSelection.getSelectedWindows(); VideoSubWindow *videoSubWindow; - QList subWindowList = m_pcMainWindowManager->findSubWindow(); - for( Int j = 0; j < selectedWindows.size(); j++ ) + QList subWindowList = dialogWindowsSelection.getSelectedWindows(); + for( Int i = 0; i < subWindowList.size(); i++ ) { - for( Int i = 0; i < subWindowList.size(); i++ ) - { - videoSubWindow = qobject_cast( subWindowList.at( i ) ); - if( videoSubWindow->getWindowName() == selectedWindows.at( j ) ) - { - videoSubWindowList.append( videoSubWindow ); - pcCurrModuleIf->m_pcSubWindow[j] = videoSubWindow; - } - } + videoSubWindow = qobject_cast( subWindowList.at( i ) ); + videoSubWindowList.append( videoSubWindow ); } + } // Check for same fmt in more than one frame modules for( Int i = 1; i < videoSubWindowList.size(); i++ ) @@ -288,7 +297,7 @@ Void ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf ) if( videoSubWindowList.size() == 0 ) { - qobject_cast( m_pcParent )->statusBar()->showMessage( "Error! Module cannot be applied", 2000 ); + qobject_cast( m_pcParent )->printMessage( "Error! Module cannot be applied", LOG_ERROR ); destroyModuleIf( pcCurrModuleIf ); return; } @@ -302,11 +311,41 @@ Void ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf ) pcCurrModuleIf->m_pcSubWindow[i] = videoSubWindowList.at( i ); } + if( pcCurrModuleIf->m_pcModule->m_uiModuleRequirements & MODULE_REQUIRES_OPTIONS ) + { + ModulesHandleOptDialog moduleOptDialog( m_pcParent, pcCurrModuleIf ); + moduleOptDialog.runConfiguration(); + } + + // Create Module + Bool moduleCreated = false; + if( pcCurrModuleIf->m_pcModule->m_iModuleAPI == MODULE_API_2 ) + { + std::vector apcFrameList; + for( UInt i = 0; i < pcCurrModuleIf->m_pcModule->m_uiNumberOfFrames; i++ ) + { + apcFrameList.push_back( pcCurrModuleIf->m_pcSubWindow[i]->getCurrFrame() ); + } + moduleCreated = pcCurrModuleIf->m_pcModule->create( apcFrameList ); + } + else if( pcCurrModuleIf->m_pcModule->m_iModuleAPI == MODULE_API_1 ) + { + pcCurrModuleIf->m_pcModule->create( pcCurrModuleIf->m_pcSubWindow[0]->getCurrFrame() ); + moduleCreated = true; + } + + if( !moduleCreated ) + { + qobject_cast( m_pcParent )->printMessage( "Error! Module cannot be applied", LOG_ERROR ); + destroyModuleIf( pcCurrModuleIf ); + return; + } + if( pcCurrModuleIf->m_pcModule->m_iModuleType == FRAME_PROCESSING_MODULE ) { if( ( pcCurrModuleIf->m_pcModule->m_uiModuleRequirements & MODULE_REQUIRES_NEW_WINDOW ) || bShowModulesNewWindow ) { - pcModuleSubWindow = new VideoSubWindow( VideoSubWindow::MODULE_SUBWINDOW, this ); + pcModuleSubWindow = new VideoSubWindow( VideoSubWindow::MODULE_SUBWINDOW ); pcModuleSubWindow->setWindowShortName( windowName ); pcModuleSubWindow->setWindowName( windowName ); @@ -322,23 +361,17 @@ Void ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf ) else if( pcCurrModuleIf->m_pcModule->m_iModuleType == FRAME_MEASUREMENT_MODULE ) { pcCurrModuleIf->m_pcDisplaySubWindow = NULL; - if( pcCurrModuleIf->m_pcModule->m_uiModuleRequirements & MODULE_REQUIRES_SIDEBAR ) - { - pcCurrModuleIf->m_pcModuleDock = new ModuleHandleDock( m_pcParent, pcCurrModuleIf ); - QString titleDockWidget; - titleDockWidget.append( pcCurrModuleIf->m_pcModule->m_pchModuleName ); - titleDockWidget.append( " Information" ); - pcCurrModuleIf->m_pcDockWidget = new QDockWidget( titleDockWidget, m_pcParent ); - pcCurrModuleIf->m_pcDockWidget->setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable ); - pcCurrModuleIf->m_pcDockWidget->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); - pcCurrModuleIf->m_pcDockWidget->setWidget( pcCurrModuleIf->m_pcModuleDock ); - qobject_cast( m_pcParent )->addDockWidget( Qt::RightDockWidgetArea, pcCurrModuleIf->m_pcDockWidget ); - } + pcCurrModuleIf->m_pcModuleDock = new ModuleHandleDock( m_pcParent, pcCurrModuleIf ); + QString titleDockWidget; + titleDockWidget.append( pcCurrModuleIf->m_pcModule->m_pchModuleName ); + titleDockWidget.append( " Information" ); + pcCurrModuleIf->m_pcDockWidget = new QDockWidget( titleDockWidget, m_pcParent ); + pcCurrModuleIf->m_pcDockWidget->setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable ); + pcCurrModuleIf->m_pcDockWidget->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); + pcCurrModuleIf->m_pcDockWidget->setWidget( pcCurrModuleIf->m_pcModuleDock ); + qobject_cast( m_pcParent )->addDockWidget( Qt::RightDockWidgetArea, pcCurrModuleIf->m_pcDockWidget ); } - // Create Module - pcCurrModuleIf->m_pcModule->create( pcCurrModuleIf->m_pcSubWindow[0]->getCurrFrame() ); - // Associate module with subwindows if( !pcCurrModuleIf->m_pcDisplaySubWindow && !pcCurrModuleIf->m_pcModuleDock ) { @@ -348,7 +381,7 @@ Void ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf ) { if( pcCurrModuleIf->m_pcDisplaySubWindow ) pcCurrModuleIf->m_pcDisplaySubWindow->enableModule( pcCurrModuleIf ); - for( UInt i = 0; i < numberOfFrames; i++ ) + for( Int i = 0; i < numberOfFrames; i++ ) { pcCurrModuleIf->m_pcSubWindow[i]->associateModule( pcCurrModuleIf ); } @@ -426,7 +459,8 @@ Void ModulesHandle::destroyAllModulesIf() Bool ModulesHandle::applyModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf, Bool isPlaying, Bool disableThreads ) { Bool bRet = false; - if( !isPlaying || ( isPlaying && pcCurrModuleIf->m_pcModule->m_bApplyWhilePlaying ) ) + QApplication::setOverrideCursor( Qt::WaitCursor ); + if( !( isPlaying && ( pcCurrModuleIf->m_pcModule->m_uiModuleRequirements & MODULE_REQUIRES_SKIP_WHILE_PLAY ) ) ) { #ifdef PLAYUVER_THREADED_MODULES if( !disableThreads ) @@ -444,6 +478,7 @@ Bool ModulesHandle::applyModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf, Bool isP { bRet = true; } + QApplication::restoreOverrideCursor(); return bRet; } diff --git a/app/ModulesHandle.h b/app/ModulesHandle.h index 4329111..498a281 100644 --- a/app/ModulesHandle.h +++ b/app/ModulesHandle.h @@ -82,7 +82,6 @@ private: QMenu* m_pcModulesMenu; QList m_pcModulesSubMenuList; - QList m_pcPlaYUVerModulesIfList; QList m_pcPlaYUVerAppModuleIfList; QVector m_arrayModulesActions; diff --git a/app/ModulesHandleOptDialog.cpp b/app/ModulesHandleOptDialog.cpp new file mode 100644 index 0000000..17e3ad3 --- /dev/null +++ b/app/ModulesHandleOptDialog.cpp @@ -0,0 +1,133 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file ModulesHandleOptDialog.cpp + * \brief Dialog box to config modules opts + */ + +#include "ModulesHandleOptDialog.h" +#include "lib/ProgramOptions.h" +#include +#include +#include +#include +#include + +namespace plaYUVer +{ + +class OpionConfiguration: public QWidget +{ +public: + OpionConfiguration( OptionBase* option ) + { + m_cName = option->opt_string; + m_pcDescription = new QLabel; + m_pcDescription->setText( QString::fromStdString( option->opt_desc ) ); + m_pcValue = new QLineEdit; + m_pcValue->setMinimumWidth( 40 ); + m_pcValue->setMaximumWidth( 65 ); + QHBoxLayout* layout = new QHBoxLayout; + layout->addWidget( m_pcDescription, Qt::AlignLeft ); + layout->addWidget( m_pcValue, Qt::AlignRight ); + layout->setContentsMargins( 1, 1, 1, 1 ); + setLayout( layout ); + } + const QString getValue() const + { + return m_pcValue->text(); + } + const std::string& getName() + { + return m_cName; + } +private: + QLineEdit* m_pcValue; + QLabel* m_pcDescription; + std::string m_cName; +}; + +ModulesHandleOptDialog::ModulesHandleOptDialog( QWidget *parent, PlaYUVerAppModuleIf *pcCurrModuleIf ) : + QDialog( parent ), + m_pcCurrModuleIf( pcCurrModuleIf ) +{ + resize( 400, 10 ); + setWindowTitle( "Select module parameters" ); + setWindowIcon( QIcon( ":/images/configureformat.png" ) ); + + const Options::OptionsList& moduleOptions = m_pcCurrModuleIf->m_pcModule->m_cModuleOptions.getOptionList(); + + QVBoxLayout* optionsLayout = new QVBoxLayout; + OpionConfiguration* pcOption; + for( Options::OptionsList::const_iterator it = moduleOptions.begin(); it != moduleOptions.end(); ++it ) + { + pcOption = new OpionConfiguration( ( *it )->opt ); + m_apcOptionList.append( pcOption ); + optionsLayout->addWidget( pcOption ); + } + + QDialogButtonBox* dialogButtonOkCancel = new QDialogButtonBox(); + dialogButtonOkCancel->setObjectName( QString::fromUtf8( "dialogButtonBox" ) ); + dialogButtonOkCancel->setStandardButtons( QDialogButtonBox::Cancel | QDialogButtonBox::Ok ); + dialogButtonOkCancel->setCenterButtons( false ); + + QVBoxLayout* mainLayout = new QVBoxLayout; + mainLayout->addItem( optionsLayout ); + mainLayout->addWidget( dialogButtonOkCancel ); + setLayout( mainLayout ); + + setFixedSize( mainLayout->sizeHint() ); + + connect( dialogButtonOkCancel, SIGNAL( accepted() ), this, SLOT( accept() ) ); + connect( dialogButtonOkCancel, SIGNAL( rejected() ), this, SLOT( reject() ) ); +} + +Int ModulesHandleOptDialog::runConfiguration() +{ + if( exec() == QDialog::Rejected ) + { + return QDialog::Rejected; + } + + std::vector argsArray; + std::string optionString; + QString valueString( "" ); + + for( Int i = 0; i < m_apcOptionList.size(); i++ ) + { + valueString = m_apcOptionList.at( i )->getValue(); + if( !valueString.isEmpty() ) + { + optionString.append( "--" ); + optionString.append( m_apcOptionList.at( i )->getName() ); + optionString.append( "=" ); + optionString.append( valueString.toStdString() ); + argsArray.push_back( optionString ); + } + optionString.clear(); + } + if( argsArray.size() > 0 ) + { + m_pcCurrModuleIf->m_pcModule->m_cModuleOptions.scanArgs( argsArray ); + } + return QDialog::Accepted; +} + +} // NAMESPACE diff --git a/app/ModulesHandleOptDialog.h b/app/ModulesHandleOptDialog.h new file mode 100644 index 0000000..bb7eac2 --- /dev/null +++ b/app/ModulesHandleOptDialog.h @@ -0,0 +1,56 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file ModulesHandleOptDialog.h + * \brief Dialog box to config modules opts + */ + +#ifndef __MODULEHANDLEOPTDIALOG_H__ +#define __MODULEHANDLEOPTDIALOG_H__ + +#include "config.h" +#include "PlaYUVerAppDefs.h" +#include "PlaYUVerAppModuleIf.h" +#include +#include + +namespace plaYUVer +{ + +class OpionConfiguration; + +/** + * + */ +class ModulesHandleOptDialog: public QDialog +{ +Q_OBJECT + +public: + ModulesHandleOptDialog( QWidget *parent, PlaYUVerAppModuleIf *pcCurrModuleIf ); + Int runConfiguration(); +private: + PlaYUVerAppModuleIf *m_pcCurrModuleIf; + QVector m_apcOptionList; +}; + +} // NAMESPACE + +#endif // __MODULEHANDLEOPTDIALOG_H__ diff --git a/app/plaYUVerApp.cpp b/app/PlaYUVerApp.cpp similarity index 84% rename from app/plaYUVerApp.cpp rename to app/PlaYUVerApp.cpp index 4119ced..de6f705 100644 --- a/app/plaYUVerApp.cpp +++ b/app/PlaYUVerApp.cpp @@ -18,20 +18,30 @@ */ /** - * \file plaYUVerApp.cpp - * \brief Main definition of the plaYUVerApp app + * \file PlaYUVerApp.cpp + * \brief Main definition of the PlaYUVerApp app */ #include -#include "plaYUVerApp.h" +#include +#include +#include +#include +#include +#include +#include +#include "PlaYUVerApp.h" #ifdef USE_FERVOR #include "fvupdater.h" #endif +#include "lib/PlaYUVerCmdParser.h" #include "PlaYUVerSubWindowHandle.h" +#include "AboutDialog.h" +#include "SubWindowAbstract.h" +#include "VideoSubWindow.h" #include "VideoHandle.h" #include "QualityHandle.h" #include "ModulesHandle.h" - #include "DialogSubWindowSelector.h" #define SYNCHRONISED_ZOON 1 @@ -39,7 +49,10 @@ namespace plaYUVer { -plaYUVerApp::plaYUVerApp() +PlaYUVerApp::PlaYUVerApp() : + m_pcCurrentSubWindow( NULL ), + m_pcCurrentVideoSubWindow( NULL ), + m_pcAboutDialog( NULL ) { setWindowModality( Qt::ApplicationModal ); @@ -78,37 +91,64 @@ plaYUVerApp::plaYUVerApp() connect( m_appModuleQuality, SIGNAL( changed() ), this, SLOT( update() ) ); connect( m_appModuleExtensions, SIGNAL( changed() ), this, SLOT( update() ) ); - m_pcAboutDialog = NULL; - m_pcCurrentSubWindow = NULL; - m_pcCurrentVideoSubWindow = NULL; } -Void plaYUVerApp::parseArgs( Int argc, Char *argv[] ) +Bool PlaYUVerApp::parseArgs( Int argc, Char *argv[] ) { - if( argc >= 2 ) + Bool bRet = false; + m_pcCmdParser = new PlaYUVerCmdParser(); + m_pcCmdParser->config( argc, argv ); + + std::vector m_apcInputs; + std::string strResolution( "" ); + std::string strPelFmt( "" ); + + m_pcCmdParser->Opts().addOptions()/**/ + ( "input,i", m_apcInputs, "input file" ) /**/ + ( "size,s", strResolution, "size (WxH)" ) /**/ + ( "pel_fmt", strPelFmt, "pixel format" ); + + if( !m_pcCmdParser->parse() ) { - for( Int i = 1; i < argc; i++ ) - { - loadFile( argv[i] ); - } - m_pcWindowHandle->tileSubWindows(); - zoomToFitAll(); + bRet |= true; } + + if( m_pcCmdParser->Opts()["help"]->count() ) + { + printf( "Usage: %s [options] input_file[s]\n", argv[0] ); + m_pcCmdParser->Opts().doHelp( std::cout ); + bRet |= true; + } + if( m_pcCmdParser->Opts()["input"]->count() ) + { + for( UInt i = 1; i < m_apcInputs.size(); i++ ) + { + loadFile( QString::fromStdString( m_apcInputs[i] ) ); + } + } + std::list& argv_unhandled = m_pcCmdParser->getNoArgs(); + for( std::list::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++ ) + { + loadFile( QString::fromStdString( *it ) ); + } + m_pcWindowHandle->tileSubWindows(); + zoomToFitAll(); + return bRet; } -Void plaYUVerApp::about() +Void PlaYUVerApp::about() { if( !m_pcAboutDialog ) m_pcAboutDialog = new AboutDialog( this ); m_pcAboutDialog->exec(); } -Void plaYUVerApp::closeEvent( QCloseEvent *event ) +Void PlaYUVerApp::closeEvent( QCloseEvent *event ) { Int mayCloseAll = true; Int msgBoxCloseRet = QMessageBox::Yes; - QList subWindowList = m_pcWindowHandle->findSubWindow(); + QList subWindowList = m_pcWindowHandle->findSubWindow(); if( subWindowList.size() >= 1 ) { QMessageBox msgBoxClose( QMessageBox::Question, "PlaYUVer", "There are open files!", QMessageBox::Yes | QMessageBox::No, this ); @@ -143,26 +183,26 @@ Void plaYUVerApp::closeEvent( QCloseEvent *event ) } } -Void plaYUVerApp::closeAll() +Void PlaYUVerApp::closeAll() { m_pcWindowHandle->removeAllSubWindow(); } -Void plaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo ) +Void PlaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo ) { if( !QFileInfo( fileName ).exists() ) { - statusBar()->showMessage( "File " + fileName + " do not exist!", 2000 ); + printMessage( "File " + fileName + " do not exist!", LOG_ERROR ); return; } - VideoSubWindow *videoSubWindow = plaYUVerApp::findVideoStreamSubWindow( m_pcWindowHandle, fileName ); + VideoSubWindow *videoSubWindow = PlaYUVerApp::findVideoStreamSubWindow( m_pcWindowHandle, fileName ); if( videoSubWindow ) { m_pcWindowHandle->setActiveSubWindow( videoSubWindow ); return; } videoSubWindow = new VideoSubWindow( VideoSubWindow::VIDEO_STREAM_SUBWINDOW ); //createSubWindow(); - SubWindowHandle *subWindow = videoSubWindow; + SubWindowAbstract *subWindow = videoSubWindow; if( !pStreamInfo ) { Int idx = findPlaYUVerStreamInfo( m_aRecentFileStreamInfo, fileName ); @@ -180,11 +220,13 @@ Void plaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo ) if( opened ) { - statusBar()->showMessage( tr( "Loading file..." ) ); + printMessage( "Loading file...", LOG_INFO ); m_pcWindowHandle->addSubWindow( videoSubWindow ); videoSubWindow->show(); connect( videoSubWindow->getViewArea(), SIGNAL( selectionChanged( QRect ) ), m_appModuleVideo, SLOT( updateSelectionArea( QRect ) ) ); + + connect( subWindow, SIGNAL( aboutToClose( SubWindowAbstract* ) ), m_appModuleVideo, SLOT( closeSubWindow( SubWindowAbstract* ) ) ); connect( subWindow, SIGNAL( zoomFactorChanged_SWindow( const double, const QPoint ) ), m_appModuleVideo, SLOT( zoomToFactorAll( double, QPoint ) ) ); connect( subWindow, SIGNAL( scrollBarMoved_SWindow( const QPoint ) ), m_appModuleVideo, SLOT( moveAllScrollBars( const QPoint ) ) ); @@ -194,7 +236,7 @@ Void plaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo ) addStreamInfoToRecentList( videoSubWindow->getStreamInfo() ); - statusBar()->showMessage( tr( "File loaded" ), 2000 ); + printMessage( "File loaded", LOG_INFO ); m_cLastOpenPath = QFileInfo( fileName ).path(); } else @@ -207,14 +249,13 @@ Void plaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo ) videoSubWindow->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; + printMessage( warningMsg, LOG_ERROR ); } } // ----------------------- File Functions ----------------------- -Void plaYUVerApp::open() +Void PlaYUVerApp::open() { QString supported = tr( "Supported Files (" ); QStringList formatsList; @@ -250,7 +291,7 @@ Void plaYUVerApp::open() } } -Void plaYUVerApp::openRecent() +Void PlaYUVerApp::openRecent() { QAction *action = qobject_cast( sender() ); PlaYUVerStreamInfo recentFile = action->data().value(); @@ -258,7 +299,7 @@ Void plaYUVerApp::openRecent() loadFile( recentFile.m_cFilename, &recentFile ); } -Void plaYUVerApp::save() +Void PlaYUVerApp::save() { if( m_pcCurrentVideoSubWindow ) { @@ -301,7 +342,7 @@ Void plaYUVerApp::save() } } -Void plaYUVerApp::format() +Void PlaYUVerApp::format() { if( m_pcCurrentVideoSubWindow ) { @@ -317,7 +358,7 @@ Void plaYUVerApp::format() { QString warningMsg = "Cannot change format of " + QFileInfo( pcVideoSubWindow->getCurrentFileName() ).fileName() + " with the following error: \n" + msg; QMessageBox::warning( this, QApplication::applicationName(), warningMsg ); - statusBar()->showMessage( warningMsg, 2000 ); + printMessage( warningMsg, LOG_ERROR ); qDebug( ) << warningMsg; m_pcCurrentSubWindow->close(); } @@ -326,47 +367,51 @@ Void plaYUVerApp::format() } } -Void plaYUVerApp::reload() +Void PlaYUVerApp::reload() { - if( m_pcCurrentVideoSubWindow ) + if( m_pcCurrentSubWindow ) { - m_pcCurrentVideoSubWindow->reloadFile(); + m_pcCurrentSubWindow->refreshSubWindow(); m_pcCurrentSubWindow = NULL; update(); } } -Void plaYUVerApp::reloadAll() +Void PlaYUVerApp::reloadAll() { - VideoSubWindow *videoSubWindow; - QList subWindowList = m_pcWindowHandle->findSubWindow( SubWindowHandle::VIDEO_SUBWINDOW ); - for( Int i = 0; i < subWindowList.size(); i++ ) + UInt windowCategoryOrder[] = { - videoSubWindow = qobject_cast( subWindowList.at( i ) ); - if( !videoSubWindow->getIsModule() ) + SubWindowAbstract::VIDEO_STREAM_SUBWINDOW, + SubWindowAbstract::MODULE_SUBWINDOW, + SubWindowAbstract::MODULE_SUBWINDOW }; + + for( UInt c = 0; c < 3; c++ ) + { + QList subWindowList = m_pcWindowHandle->findSubWindow( windowCategoryOrder[c] ); + for( Int i = 0; i < subWindowList.size(); i++ ) { - videoSubWindow->reloadFile(); + subWindowList.at( i )->refreshSubWindow(); } } m_pcCurrentSubWindow = NULL; update(); } -Void plaYUVerApp::loadAll() +Void PlaYUVerApp::loadAll() { if( m_pcCurrentVideoSubWindow ) { - statusBar()->showMessage( tr( "Loading file into memory ..." ) ); + printMessage( "Loading file into memory...", LOG_INFO ); m_pcCurrentVideoSubWindow->loadAll(); - statusBar()->showMessage( tr( "File loaded" ), 2000 ); + printMessage( "File loaded", LOG_INFO ); } } -Void plaYUVerApp::setTool( Int idxTool ) +Void PlaYUVerApp::setTool( Int idxTool ) { m_uiViewTool = idxTool; actionGroupTools->actions().at( m_uiViewTool )->setChecked( true ); - QList subWindowList = m_pcWindowHandle->findSubWindow(); + QList subWindowList = m_pcWindowHandle->findSubWindow(); for( Int i = 0; i < subWindowList.size(); i++ ) { subWindowList.at( i )->setTool( m_uiViewTool ); @@ -375,7 +420,7 @@ Void plaYUVerApp::setTool( Int idxTool ) // ----------------------- Zoom Functions ----------------------- -Void plaYUVerApp::normalSize() +Void PlaYUVerApp::normalSize() { if( m_pcCurrentSubWindow ) { @@ -384,7 +429,7 @@ Void plaYUVerApp::normalSize() } } -Void plaYUVerApp::zoomToFit() +Void PlaYUVerApp::zoomToFit() { if( m_pcCurrentSubWindow ) { @@ -393,10 +438,10 @@ Void plaYUVerApp::zoomToFit() } } -Void plaYUVerApp::zoomToFitAll() +Void PlaYUVerApp::zoomToFitAll() { VideoSubWindow *videoSubWindow; - QList subWindowList = m_pcWindowHandle->findSubWindow( SubWindowHandle::VIDEO_SUBWINDOW ); + QList subWindowList = m_pcWindowHandle->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW ); for( Int i = 0; i < subWindowList.size(); i++ ) { videoSubWindow = qobject_cast( subWindowList.at( i ) ); @@ -407,7 +452,7 @@ Void plaYUVerApp::zoomToFitAll() updateZoomFactorSBox(); } -Void plaYUVerApp::scaleFrame( int ratio ) +Void PlaYUVerApp::scaleFrame( int ratio ) { if( m_pcCurrentSubWindow ) { @@ -416,9 +461,9 @@ Void plaYUVerApp::scaleFrame( int ratio ) } } -Void plaYUVerApp::zoomFromSBox( double zoom ) +Void PlaYUVerApp::zoomFromSBox( double zoom ) { - SubWindowHandle *activeSubWindow = m_pcWindowHandle->activeSubWindow(); + SubWindowAbstract *activeSubWindow = m_pcWindowHandle->activeSubWindow(); Double factor = zoom / 100; if( activeSubWindow ) { @@ -426,7 +471,7 @@ Void plaYUVerApp::zoomFromSBox( double zoom ) } } -Void plaYUVerApp::updateZoomFactorSBox() +Void PlaYUVerApp::updateZoomFactorSBox() { Double factor; if( m_pcCurrentSubWindow ) @@ -438,14 +483,14 @@ Void plaYUVerApp::updateZoomFactorSBox() // ----------------------- Drag and drop functions ---------------------- -Void plaYUVerApp::dragEnterEvent( QDragEnterEvent *event ) +Void PlaYUVerApp::dragEnterEvent( QDragEnterEvent *event ) { //setText(tr("")); //mdiArea->setBackgroundRole( QPalette::Highlight ); event->acceptProposedAction(); } -Void plaYUVerApp::dropEvent( QDropEvent *event ) +Void PlaYUVerApp::dropEvent( QDropEvent *event ) { const QMimeData *mimeData = event->mimeData(); QList urlList = mimeData->urls(); @@ -459,11 +504,11 @@ Void plaYUVerApp::dropEvent( QDropEvent *event ) // ----------------------- Sub Window Functions ----------------------- -VideoSubWindow* plaYUVerApp::findVideoStreamSubWindow( const PlaYUVerSubWindowHandle* windowManager, const QString& fileName ) +VideoSubWindow* PlaYUVerApp::findVideoStreamSubWindow( const PlaYUVerSubWindowHandle* windowManager, const QString& fileName ) { QString canonicalFilePath = QFileInfo( fileName ).canonicalFilePath(); VideoSubWindow* pcSubWindow; - QList subWindowList = windowManager->findSubWindow( SubWindowHandle::VIDEO_STREAM_SUBWINDOW ); + QList subWindowList = windowManager->findSubWindow( SubWindowAbstract::VIDEO_STREAM_SUBWINDOW ); for( Int i = 0; i < subWindowList.size(); i++ ) { pcSubWindow = qobject_cast( subWindowList.at( i ) ); @@ -475,9 +520,9 @@ VideoSubWindow* plaYUVerApp::findVideoStreamSubWindow( const PlaYUVerSubWindowHa // ----------------------- Update Functions ----------------------- -Void plaYUVerApp::update() +Void PlaYUVerApp::update() { - SubWindowHandle *activeSubWindow = m_pcWindowHandle->activeSubWindow(); + SubWindowAbstract *activeSubWindow = m_pcWindowHandle->activeSubWindow(); QCoreApplication::processEvents(); //if( activeSubWindow() != m_pcCurrentSubWindow ) { @@ -487,7 +532,7 @@ Void plaYUVerApp::update() { m_pcCurrentSubWindow = activeSubWindow; - if( m_pcCurrentSubWindow->getCategory() & SubWindowHandle::VIDEO_SUBWINDOW ) + if( m_pcCurrentSubWindow->getCategory() & SubWindowAbstract::VIDEO_SUBWINDOW ) { m_pcCurrentVideoSubWindow = qobject_cast( m_pcCurrentSubWindow ); } @@ -507,25 +552,30 @@ Void plaYUVerApp::update() updateMenus(); } -Void plaYUVerApp::updateStatusBar( const QString& statusBarString ) +Void PlaYUVerApp::printMessage( const QString& msg ) { - if( !statusBarString.isEmpty() ) + printMessage( msg, 0 ); +} + +Void PlaYUVerApp::printMessage( const QString& msg, UInt logLevel ) +{ + if( !msg.isEmpty() ) { - statusBar()->showMessage( statusBarString, 5000 ); - } - else - { - statusBar()->showMessage( " " ); + statusBar()->showMessage( msg, 5000 ); + if( logLevel >= LOG_INFO ) + { + m_pcWindowHandle->processLogMsg( msg ); + } } } -Void plaYUVerApp::updateMenus() +Void PlaYUVerApp::updateMenus() { Bool hasSubWindow = ( m_pcWindowHandle->activeSubWindow() != 0 ); Bool hasVideoStreamSubWindow = false; if( m_pcCurrentSubWindow ) - if( m_pcCurrentSubWindow->getCategory() & SubWindowHandle::VIDEO_STREAM_SUBWINDOW ) + if( m_pcCurrentSubWindow->getCategory() & SubWindowAbstract::VIDEO_STREAM_SUBWINDOW ) hasVideoStreamSubWindow = true; m_arrayMenu[RECENT_MENU]->setEnabled( m_aRecentFileStreamInfo.size() > 0 ? true : false ); @@ -533,10 +583,10 @@ Void plaYUVerApp::updateMenus() m_arrayActions[SAVE_ACT]->setEnabled( hasSubWindow ); m_arrayActions[CLOSE_ACT]->setEnabled( hasSubWindow ); m_arrayActions[CLOSEALL_ACT]->setEnabled( hasSubWindow ); + m_arrayActions[RELOAD_ACT]->setEnabled( hasSubWindow ); + m_arrayActions[RELOAD_ALL_ACT]->setEnabled( hasSubWindow ); m_arrayActions[FORMAT_ACT]->setEnabled( hasVideoStreamSubWindow ); - m_arrayActions[RELOAD_ACT]->setEnabled( hasVideoStreamSubWindow ); - m_arrayActions[RELOAD_ALL_ACT]->setEnabled( hasVideoStreamSubWindow ); m_arrayActions[LOAD_ALL_ACT]->setEnabled( hasVideoStreamSubWindow ); m_arrayActions[ZOOM_IN_ACT]->setEnabled( hasSubWindow ); @@ -556,7 +606,7 @@ Void plaYUVerApp::updateMenus() // ----------------------- Create Functions ----------------------- -Void plaYUVerApp::createActions() +Void PlaYUVerApp::createActions() { m_arrayActions.resize( TOTAL_ACT ); @@ -609,7 +659,7 @@ Void plaYUVerApp::createActions() m_arrayActions[CLOSEALL_ACT] = new QAction( tr( "Close &All" ), this ); m_arrayActions[CLOSEALL_ACT]->setStatusTip( tr( "Close all the windows" ) ); - connect( m_arrayActions[CLOSEALL_ACT], SIGNAL( triggered() ), this, SLOT( closeAll() ) ); + connect( m_arrayActions[CLOSEALL_ACT], SIGNAL( triggered() ), m_pcWindowHandle, SLOT( removeAllSubWindow() ) ); m_arrayActions[EXIT_ACT] = new QAction( tr( "E&xit" ), this ); m_arrayActions[EXIT_ACT]->setShortcuts( QKeySequence::Quit ); @@ -696,7 +746,7 @@ Void plaYUVerApp::createActions() connect( m_arrayActions[ABOUTQT_ACT], SIGNAL( triggered() ), qApp, SLOT( aboutQt() ) ); } -Void plaYUVerApp::createMenus() +Void PlaYUVerApp::createMenus() { m_arrayMenu.resize( TOTAL_MENUS ); @@ -764,7 +814,7 @@ Void plaYUVerApp::createMenus() } -Void plaYUVerApp::createToolBars() +Void PlaYUVerApp::createToolBars() { m_arrayToolBars.resize( TOTAL_TOOLBAR ); @@ -799,7 +849,7 @@ Void plaYUVerApp::createToolBars() } -Void plaYUVerApp::createDockWidgets() +Void PlaYUVerApp::createDockWidgets() { // Properties Dock Window m_arraySideBars.resize( TOTAL_DOCK ); @@ -807,14 +857,14 @@ Void plaYUVerApp::createDockWidgets() addDockWidget( Qt::RightDockWidgetArea, m_appModuleQuality->createDock() ); } -Void plaYUVerApp::createStatusBar() +Void PlaYUVerApp::createStatusBar() { -//! Warning: the following widget cannot change size too much + //! Warning: the following widget cannot change size too much statusBar()->addPermanentWidget( m_appModuleVideo->createStatusBarMessage() ); - statusBar()->showMessage( tr( "Ready" ) ); + printMessage( "Ready!", LOG_INFO ); } -Void plaYUVerApp::addStreamInfoToRecentList( PlaYUVerStreamInfo streamInfo ) +Void PlaYUVerApp::addStreamInfoToRecentList( PlaYUVerStreamInfo streamInfo ) { Int idx = findPlaYUVerStreamInfo( m_aRecentFileStreamInfo, streamInfo.m_cFilename ); if( idx >= 0 ) @@ -825,7 +875,7 @@ Void plaYUVerApp::addStreamInfoToRecentList( PlaYUVerStreamInfo streamInfo ) updateRecentFileActions(); } -Void plaYUVerApp::updateRecentFileActions() +Void PlaYUVerApp::updateRecentFileActions() { Int numRecentFiles = m_aRecentFileStreamInfo.size(); numRecentFiles = qMin( numRecentFiles, MAX_RECENT_FILES ); @@ -848,7 +898,7 @@ Void plaYUVerApp::updateRecentFileActions() m_arrayMenu[RECENT_MENU]->setEnabled( m_aRecentFileStreamInfo.size() > 0 ? true : false ); } -Void plaYUVerApp::checkRecentFileActions() +Void PlaYUVerApp::checkRecentFileActions() { Int i = 0; while( i < m_aRecentFileStreamInfo.size() ) @@ -871,7 +921,7 @@ Void plaYUVerApp::checkRecentFileActions() } } -Void plaYUVerApp::readSettings() +Void PlaYUVerApp::readSettings() { QSettings appSettings; @@ -893,9 +943,10 @@ Void plaYUVerApp::readSettings() m_appModuleVideo->readSettings(); m_appModuleQuality->readSettings(); m_appModuleExtensions->readSettings(); + m_pcWindowHandle->readSettings(); } -Void plaYUVerApp::writeSettings() +Void PlaYUVerApp::writeSettings() { QSettings appSettings; @@ -911,6 +962,7 @@ Void plaYUVerApp::writeSettings() m_appModuleVideo->writeSettings(); m_appModuleQuality->writeSettings(); m_appModuleExtensions->writeSettings(); + m_pcWindowHandle->writeSettings(); } } // NAMESPACE diff --git a/app/plaYUVerApp.h b/app/PlaYUVerApp.h similarity index 88% rename from app/plaYUVerApp.h rename to app/PlaYUVerApp.h index 13fb5e2..be14e14 100644 --- a/app/plaYUVerApp.h +++ b/app/PlaYUVerApp.h @@ -18,9 +18,9 @@ */ /** - * \file plaYUVerApp.h + * \file PlaYUVerApp.h * \ingroup PlaYUVerApp - * \brief Main definition of the plaYUVerApp app + * \brief Main definition of the PlaYUVerApp app * * @defgroup PlaYUVerApp PlaYUVer App (GUI) * @{ @@ -37,40 +37,50 @@ #define __PLAYUVERAPP_H__ #include "config.h" +#include +#include +#include #include "PlaYUVerAppDefs.h" -#if( QT_VERSION_PLAYUVER == 5 ) -#include -#elif( QT_VERSION_PLAYUVER == 4 ) -#include -#endif #ifdef USE_QTDBUS #include "PlaYUVerAppAdaptor.h" #endif -#include - -#include "SubWindowHandle.h" -#include "AboutDialog.h" #include "VideoSubWindow.h" +class QCloseEvent; +class QDragEnterEvent; +class QDropEvent; +class QDoubleSpinBox; +class QActionGroup; +class QAction; +class QSignalMapper; + namespace plaYUVer { +class PlaYUVerCmdParser; class PlaYUVerStream; class PlaYUVerSubWindowHandle; class VideoHandle; class QualityHandle; class ModulesHandle; class PlaYUVerAppAdaptor; +class VideoSubWindow; +class SubWindowAbstract; +class AboutDialog; -class plaYUVerApp: public QMainWindow +class PlaYUVerApp: public QMainWindow { Q_OBJECT public: - plaYUVerApp(); - Void parseArgs( Int argc, Char *argv[] ); + PlaYUVerApp(); + Bool parseArgs( Int argc, Char *argv[] ); Void loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo = NULL ); +public Q_SLOTS: + void printMessage( const QString& msg ); + void printMessage( const QString& msg, UInt logLevel ); + protected: Void closeEvent( QCloseEvent *event ); @@ -108,16 +118,15 @@ private Q_SLOTS: void update(); void updateZoomFactorSBox(); - void updateStatusBar( const QString& ); private: PlaYUVerAppAdaptor* m_pDBusAdaptor; - + PlaYUVerCmdParser* m_pcCmdParser; /** * Save the current subwindow for every category */ - SubWindowHandle* m_pcCurrentSubWindow; //!< General always set + SubWindowAbstract* m_pcCurrentSubWindow; //!< General always set VideoSubWindow* m_pcCurrentVideoSubWindow; QString m_cLastOpenPath; @@ -246,3 +255,4 @@ private: } // NAMESPACE #endif // __PLAYUVERAPP_H__ + diff --git a/app/PlaYUVerAppAdaptor.cpp b/app/PlaYUVerAppAdaptor.cpp index 9314035..ff1d86d 100644 --- a/app/PlaYUVerAppAdaptor.cpp +++ b/app/PlaYUVerAppAdaptor.cpp @@ -24,12 +24,12 @@ #include #include "PlaYUVerAppAdaptor.h" -#include "plaYUVerApp.h" +#include "PlaYUVerApp.h" namespace plaYUVer { -PlaYUVerAppAdaptor::PlaYUVerAppAdaptor( plaYUVerApp *app ) : +PlaYUVerAppAdaptor::PlaYUVerAppAdaptor( PlaYUVerApp *app ) : QDBusAbstractAdaptor( app ), m_app( app ) { diff --git a/app/PlaYUVerAppAdaptor.h b/app/PlaYUVerAppAdaptor.h index 4210724..ae64e69 100644 --- a/app/PlaYUVerAppAdaptor.h +++ b/app/PlaYUVerAppAdaptor.h @@ -38,7 +38,7 @@ namespace plaYUVer #define PLAYUVER_DBUS_SESSION_NAME "org.pixlra.PlaYUVer.application" #define PLAYUVER_DBUS_PATH "/MainApplication" -class plaYUVerApp; +class PlaYUVerApp; class PlaYUVerAppAdaptor: public QDBusAbstractAdaptor { @@ -46,7 +46,7 @@ Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.pixlra.PlaYUVer.application") Q_PROPERTY(QString activeSession READ activeSession) public: - PlaYUVerAppAdaptor( plaYUVerApp *app ); + PlaYUVerAppAdaptor( PlaYUVerApp *app ); ~PlaYUVerAppAdaptor(); /** * emit the exiting signal @@ -78,7 +78,7 @@ Q_SIGNALS: public: QString activeSession(); private: - plaYUVerApp *m_app; + PlaYUVerApp *m_app; }; } // NAMESPACE diff --git a/app/PlaYUVerAppModuleIf.cpp b/app/PlaYUVerAppModuleIf.cpp index 5145312..1732cf9 100644 --- a/app/PlaYUVerAppModuleIf.cpp +++ b/app/PlaYUVerAppModuleIf.cpp @@ -24,6 +24,7 @@ #include "PlaYUVerAppModuleIf.h" #include "VideoSubWindow.h" +#include "VideoSubWindow.h" namespace plaYUVer { @@ -47,37 +48,36 @@ PlaYUVerAppModuleIf::PlaYUVerAppModuleIf( QObject* parent, QAction* action, PlaY void PlaYUVerAppModuleIf::run() { + m_pcProcessedFrame = NULL; m_dMeasurementResult = 0; + std::vector apcFrameList; + for( UInt i = 0; i < m_pcModule->m_uiNumberOfFrames; i++ ) + { + apcFrameList.push_back( m_pcSubWindow[i]->getCurrFrame() ); + } + if( m_pcModule->m_iModuleType == FRAME_PROCESSING_MODULE ) { - switch( m_pcModule->m_uiNumberOfFrames ) + if( m_pcModule->m_iModuleAPI == MODULE_API_2 ) + { + m_pcProcessedFrame = m_pcModule->process( apcFrameList ); + } + else { - case MODULE_REQUIRES_ONE_FRAME: m_pcProcessedFrame = m_pcModule->process( m_pcSubWindow[0]->getCurrFrame() ); - break; - case MODULE_REQUIRES_TWO_FRAMES: - m_pcProcessedFrame = m_pcModule->process( m_pcSubWindow[0]->getCurrFrame(), m_pcSubWindow[1]->getCurrFrame() ); - break; - case MODULE_REQUIRES_THREE_FRAMES: - m_pcProcessedFrame = m_pcModule->process( m_pcSubWindow[0]->getCurrFrame(), m_pcSubWindow[1]->getCurrFrame(), m_pcSubWindow[2]->getCurrFrame() ); - break; } } else if( m_pcModule->m_iModuleType == FRAME_MEASUREMENT_MODULE ) { - switch( m_pcModule->m_uiNumberOfFrames ) + if( m_pcModule->m_iModuleAPI == MODULE_API_2 ) + { + m_dMeasurementResult = m_pcModule->measure( apcFrameList ); + } + else { - case MODULE_REQUIRES_ONE_FRAME: m_dMeasurementResult = m_pcModule->measure( m_pcSubWindow[0]->getCurrFrame() ); - break; - case MODULE_REQUIRES_TWO_FRAMES: - m_dMeasurementResult = m_pcModule->measure( m_pcSubWindow[0]->getCurrFrame(), m_pcSubWindow[1]->getCurrFrame() ); - break; - case MODULE_REQUIRES_THREE_FRAMES: - m_dMeasurementResult = m_pcModule->measure( m_pcSubWindow[0]->getCurrFrame(), m_pcSubWindow[1]->getCurrFrame(), m_pcSubWindow[2]->getCurrFrame() ); - break; } } else diff --git a/app/PlaYUVerAppModuleIf.h b/app/PlaYUVerAppModuleIf.h index 5dda03d..69524b3 100644 --- a/app/PlaYUVerAppModuleIf.h +++ b/app/PlaYUVerAppModuleIf.h @@ -43,20 +43,20 @@ class VideoSubWindow; class PlaYUVerAppModuleIf #ifdef PLAYUVER_THREADED_MODULES - : public QThread + : public QThread #else - : public QObject + : public QObject #endif { friend class ModulesHandle; friend class ModuleHandleDock; + friend class ModulesHandleOptDialog; private: QAction* m_pcModuleAction; PlaYUVerModuleIf* m_pcModule; - VideoSubWindow* m_pcSubWindow[MAX_NUMBER_FRAMES]; VideoSubWindow* m_pcDisplaySubWindow; @@ -83,8 +83,10 @@ public: PlaYUVerAppModuleIf* m_pcModule; }; - PlaYUVerAppModuleIf( QObject* parent, QAction* action, PlaYUVerModuleIf* module ); - virtual ~PlaYUVerAppModuleIf() {} + PlaYUVerAppModuleIf( QObject* parent, QAction* action, PlaYUVerModuleIf* module ); + virtual ~PlaYUVerAppModuleIf() + { + } protected: virtual void run(); diff --git a/app/PlaYUVerMdiSubWindow.cpp b/app/PlaYUVerMdiSubWindow.cpp index e29348f..7f407d6 100644 --- a/app/PlaYUVerMdiSubWindow.cpp +++ b/app/PlaYUVerMdiSubWindow.cpp @@ -22,8 +22,9 @@ * \brief Re-implementation QMdiSubWindow */ +#include #include "PlaYUVerMdiSubWindow.h" -#include "SubWindowHandle.h" +#include "SubWindowAbstract.h" namespace plaYUVer { @@ -31,6 +32,8 @@ namespace plaYUVer PlaYUVerMdiSubWindow::PlaYUVerMdiSubWindow( QWidget *parent ) : QMdiSubWindow( parent ) { + setAttribute( Qt::WA_DeleteOnClose ); + setBackgroundRole( QPalette::Background ); } QSize PlaYUVerMdiSubWindow::sizeHint() const @@ -38,7 +41,7 @@ QSize PlaYUVerMdiSubWindow::sizeHint() const QSize maxSize; if( parent() ) maxSize = parentWidget()->size(); - QSize sizeHint = qobject_cast( widget() )->sizeHint( maxSize ); + QSize sizeHint = qobject_cast( widget() )->sizeHint( maxSize ); return sizeHint; } diff --git a/app/PlaYUVerMdiSubWindow.h b/app/PlaYUVerMdiSubWindow.h index 5b78920..6982339 100644 --- a/app/PlaYUVerMdiSubWindow.h +++ b/app/PlaYUVerMdiSubWindow.h @@ -27,11 +27,8 @@ #include "config.h" #include "PlaYUVerAppDefs.h" -#if( QT_VERSION_PLAYUVER == 5 ) -#include -#elif( QT_VERSION_PLAYUVER == 4 ) -#include -#endif +#include + namespace plaYUVer { diff --git a/app/PlaYUVerSubWindowHandle.cpp b/app/PlaYUVerSubWindowHandle.cpp index 1958d3d..f377814 100644 --- a/app/PlaYUVerSubWindowHandle.cpp +++ b/app/PlaYUVerSubWindowHandle.cpp @@ -22,10 +22,10 @@ * \brief Handle multiple sub-windows */ -#include "plaYUVerApp.h" #include "PlaYUVerSubWindowHandle.h" +#include "PlaYUVerApp.h" #include "PlaYUVerMdiSubWindow.h" -#include "SubWindowHandle.h" +#include "SubWindowAbstract.h" namespace plaYUVer { @@ -33,130 +33,203 @@ namespace plaYUVer class PlaYUVerMdiArea: public QMdiArea { public: - PlaYUVerMdiArea( QWidget *parent ) : + PlaYUVerMdiArea( QWidget *parent = 0 ) : QMdiArea( parent ), m_pixmapLogo( ":/images/playuver-backgroud-logo.png" ) { setBackgroundRole( QPalette::Background ); } + + Void appendLogMessage( const QString& msg ) + { + m_acLogMessages.push_front( msg ); + if( m_acLogMessages.size() > 5 ) + m_acLogMessages.removeLast(); + update(); + } protected: void paintEvent( QPaintEvent *event ) { QMdiArea::paintEvent( event ); QPainter painter( viewport() ); - QPixmap pixFinalLogo = m_pixmapLogo.scaled( 2 * size() / 3, Qt::KeepAspectRatio ); - // Calculate the logo position - the bottom right corner of the mdi area. int x = width() / 2 - pixFinalLogo.width() / 2; int y = height() / 2 - pixFinalLogo.height() / 2; painter.drawPixmap( x, y, pixFinalLogo ); + +// for( Int i = 0; i < m_acLogMessages.size(); i++ ) +// { +// painter.drawText( 5, height() - 5 - i * 15, m_acLogMessages.at( i ) ); +// } +// QPoint bottomLeftCorner( 0, viewport()->height() ); } private: + QVector m_acLogMessages; QPixmap m_pixmapLogo; }; PlaYUVerSubWindowHandle::PlaYUVerSubWindowHandle( QWidget *parent ) : QWidget( parent ) { - m_uiWindowMode = 0; - - setWindowMode( MdiWSubWindows ); - + m_iWindowMode = -1; + m_pcWindowManagerLayout = NULL; + m_pcMdiArea = NULL; m_pcActiveWindow = NULL; m_apcSubWindowList.clear(); m_apcMdiSubWindowList.clear(); + + m_pcApp = qobject_cast( parentWidget() ); + //setWindowMode( DETACHEDSUBWINDOWMODE ); + setWindowMode( MDISUBWINDOWMODE ); +} + +Void PlaYUVerSubWindowHandle::processLogMsg( const QString& msg ) +{ + if( m_pcMdiArea ) + { + m_pcMdiArea->appendLogMessage( msg ); + } } Void PlaYUVerSubWindowHandle::resetWindowMode() { - if( m_uiWindowMode == MdiWSubWindows ) + QList apcSubWindowList = m_apcSubWindowList; + + if( m_iWindowMode == DETACHEDSUBWINDOWMODE ) { - removeAllSubWindow(); + + } + if( m_iWindowMode == MDISUBWINDOWMODE ) + { + m_cMdiModeWindowPosition = m_pcApp->pos(); + m_cMdiModeWindowSize = m_pcApp->size(); + for( Int i = 0; i < m_apcSubWindowList.size(); i++ ) + { + m_apcSubWindowList.at( i )->setParent( NULL ); + } + for( Int i = 0; i < m_apcMdiSubWindowList.size(); i++ ) + { + disconnect( m_apcMdiSubWindowList.at( i ), SIGNAL( aboutToClose( PlaYUVerMdiSubWindow* ) ), this, SLOT( removeMdiSubWindow( PlaYUVerMdiSubWindow* ) ) ); + m_apcMdiSubWindowList.at( i )->close(); + } m_apcMdiSubWindowList.clear(); if( m_pcMdiArea ) delete m_pcMdiArea; if( m_pcWindowManagerLayout ) delete m_pcWindowManagerLayout; + } } -Void PlaYUVerSubWindowHandle::setWindowMode( UInt uiWindowMode ) +Void PlaYUVerSubWindowHandle::setWindowMode( Int iWindowMode ) { - if( m_uiWindowMode == uiWindowMode ) + if( m_iWindowMode == iWindowMode ) return; resetWindowMode(); - if( uiWindowMode == NormalSubWindows ) + if( iWindowMode == DETACHEDSUBWINDOWMODE ) { - + for( Int i = 0; i < m_apcSubWindowList.size(); i++ ) + { + m_apcSubWindowList.at( i )->setParent( NULL ); + m_apcSubWindowList.at( i )->resize( m_apcSubWindowList.at( i )->sizeHint() ); + m_apcSubWindowList.at( i )->show(); + } + setVisible( false ); + parentWidget()->update(); + m_pcApp->showNormal(); + qApp->processEvents(); + QSize screenSize = QApplication::desktop()->availableGeometry().size(); + m_pcApp->move( 0, 0 ); + m_pcApp->resize( screenSize.width(), 5 ); + m_pcApp->setWindowTitle( QApplication::applicationName() ); } - if( uiWindowMode == MdiWSubWindows ) + if( iWindowMode == MDISUBWINDOWMODE ) { - m_pcMdiArea = new PlaYUVerMdiArea( this ); + setVisible( true ); + m_pcMdiArea = new PlaYUVerMdiArea; m_pcMdiArea->setActivationOrder( QMdiArea::ActivationHistoryOrder ); connect( m_pcMdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( updateActiveSubWindow() ) ); m_pcWindowManagerLayout = new QHBoxLayout( this ); m_pcWindowManagerLayout->addWidget( m_pcMdiArea ); setLayout( m_pcWindowManagerLayout ); + for( Int i = 0; i < m_apcSubWindowList.size(); i++ ) + { + addMdiSubWindow( m_apcSubWindowList.at( i ) ); + m_apcSubWindowList.at( i )->resize( m_apcSubWindowList.at( i )->sizeHint() ); + } + m_pcApp->move( m_cMdiModeWindowPosition ); + m_pcApp->resize( m_cMdiModeWindowSize ); + if( m_pcActiveWindow ) + { + m_pcApp->setWindowTitle( QApplication::applicationName() + " :: " + m_pcActiveWindow->getWindowName() ); + } } - - m_uiWindowMode = uiWindowMode; + m_iWindowMode = iWindowMode; + //tileSubWindows(); + parentWidget()->update(); + qApp->processEvents(); } -Void PlaYUVerSubWindowHandle::updateActiveSubWindow( SubWindowHandle *window ) +Void PlaYUVerSubWindowHandle::updateActiveSubWindow( SubWindowAbstract *window ) { - if( m_uiWindowMode == NormalSubWindows ) + if( m_iWindowMode == DETACHEDSUBWINDOWMODE ) { if( window ) + { m_pcActiveWindow = window; + emit changed(); + } } - if( m_uiWindowMode == MdiWSubWindows ) + if( m_iWindowMode == MDISUBWINDOWMODE ) { m_pcActiveWindow = NULL; QMdiSubWindow* mdiSubWindow = m_pcMdiArea->activeSubWindow(); if( mdiSubWindow ) { QWidget* activeWidget = m_pcMdiArea->activeSubWindow()->widget(); - Int windowIdx = m_apcSubWindowList.indexOf( qobject_cast( activeWidget ) ); + Int windowIdx = m_apcSubWindowList.indexOf( qobject_cast( activeWidget ) ); if( windowIdx >= 0 ) { m_pcActiveWindow = m_apcSubWindowList.at( windowIdx ); emit changed(); } } + if( m_pcActiveWindow ) + { + m_pcApp->setWindowTitle( QApplication::applicationName() + " :: " + m_pcActiveWindow->getWindowName() ); + } } - - if( m_pcActiveWindow ) - { - parentWidget()->setWindowTitle( QApplication::applicationName() + " :: " + m_pcActiveWindow->getWindowName() ); - } - } -Void PlaYUVerSubWindowHandle::addSubWindow( SubWindowHandle *window, Qt::WindowFlags flags ) +Void PlaYUVerSubWindowHandle::addMdiSubWindow( SubWindowAbstract *window ) +{ + PlaYUVerMdiSubWindow* mdiSubWindow = new PlaYUVerMdiSubWindow; + mdiSubWindow->setWidget( window ); + m_pcMdiArea->addSubWindow( mdiSubWindow ); + m_apcMdiSubWindowList.append( mdiSubWindow ); + window->setSubWindow( mdiSubWindow ); + connect( mdiSubWindow, SIGNAL( aboutToClose( PlaYUVerMdiSubWindow* ) ), this, SLOT( removeMdiSubWindow( PlaYUVerMdiSubWindow* ) ) ); +} + +Void PlaYUVerSubWindowHandle::addSubWindow( SubWindowAbstract *window, Qt::WindowFlags flags ) { if( window ) { - connect( window, SIGNAL( updateStatusBar( const QString& ) ), qobject_cast( parent() ), SLOT( updateStatusBar( const QString& ) ) ); - connect( window, SIGNAL( zoomFactorChanged_SWindow( const double, const QPoint ) ), qobject_cast( parent() ), - SLOT( updateZoomFactorSBox() ) ); - if( m_uiWindowMode == NormalSubWindows ) + connect( window, SIGNAL( updateStatusBar( const QString& ) ), m_pcApp, SLOT( printMessage( const QString& ) ) ); + connect( window, SIGNAL( zoomFactorChanged_SWindow( const double, const QPoint ) ), m_pcApp, SLOT( updateZoomFactorSBox() ) ); + if( m_iWindowMode == DETACHEDSUBWINDOWMODE ) { - connect( window, SIGNAL( aboutToActivate( SubWindowHandle* ) ), this, SLOT( updateActiveSubWindow( SubWindowHandle* ) ) ); - connect( window, SIGNAL( aboutToClose( SubWindowHandle* ) ), this, SLOT( removeSubWindow( SubWindowHandle* ) ) ); + connect( window, SIGNAL( aboutToActivate( SubWindowAbstract* ) ), this, SLOT( updateActiveSubWindow( SubWindowAbstract* ) ) ); + connect( window, SIGNAL( aboutToClose( SubWindowAbstract* ) ), this, SLOT( removeSubWindow( SubWindowAbstract* ) ) ); } - if( m_uiWindowMode == MdiWSubWindows ) + if( m_iWindowMode == MDISUBWINDOWMODE ) { - PlaYUVerMdiSubWindow* mdiSubWindow = new PlaYUVerMdiSubWindow; - mdiSubWindow->setWidget( window ); - m_pcMdiArea->addSubWindow( mdiSubWindow ); - m_apcMdiSubWindowList.append( mdiSubWindow ); - window->setSubWindow( mdiSubWindow ); - connect( mdiSubWindow, SIGNAL( aboutToClose( PlaYUVerMdiSubWindow* ) ), this, SLOT( removeMdiSubWindow( PlaYUVerMdiSubWindow* ) ) ); + addMdiSubWindow( window ); } m_apcSubWindowList.append( window ); } @@ -166,13 +239,13 @@ Void PlaYUVerSubWindowHandle::removeSubWindow( Int windowIdx ) { if( windowIdx >= 0 ) { - if( m_uiWindowMode == NormalSubWindows ) + if( m_iWindowMode == DETACHEDSUBWINDOWMODE ) { - SubWindowHandle* subWindow = m_apcSubWindowList.at( windowIdx ); + SubWindowAbstract* subWindow = m_apcSubWindowList.at( windowIdx ); m_apcSubWindowList.removeAt( windowIdx ); subWindow->close(); } - if( m_uiWindowMode == MdiWSubWindows ) + if( m_iWindowMode == MDISUBWINDOWMODE ) { PlaYUVerMdiSubWindow* mdiSubWindow = m_apcMdiSubWindowList.at( windowIdx ); m_apcMdiSubWindowList.removeAt( windowIdx ); @@ -190,7 +263,7 @@ Void PlaYUVerSubWindowHandle::removeSubWindow( Int windowIdx ) } } -Void PlaYUVerSubWindowHandle::removeSubWindow( SubWindowHandle* window ) +Void PlaYUVerSubWindowHandle::removeSubWindow( SubWindowAbstract* window ) { removeSubWindow( m_apcSubWindowList.indexOf( window ) ); } @@ -213,14 +286,14 @@ Void PlaYUVerSubWindowHandle::removeActiveSubWindow() removeSubWindow( m_pcActiveWindow ); } -SubWindowHandle* PlaYUVerSubWindowHandle::activeSubWindow() const +SubWindowAbstract* PlaYUVerSubWindowHandle::activeSubWindow() const { return m_pcActiveWindow; } -QList PlaYUVerSubWindowHandle::findSubWindow( const UInt uiCategory ) const +QList PlaYUVerSubWindowHandle::findSubWindow( const UInt uiCategory ) const { - QList apcSubWindowList; + QList apcSubWindowList; if( uiCategory == 0 ) { apcSubWindowList = m_apcSubWindowList; @@ -236,10 +309,10 @@ QList PlaYUVerSubWindowHandle::findSubWindow( const UInt uiCat return apcSubWindowList; } -QList PlaYUVerSubWindowHandle::findSubWindow( const QString &windowName, const UInt uiCategory ) const +QList PlaYUVerSubWindowHandle::findSubWindow( const QString &windowName, const UInt uiCategory ) const { - QList subWindowList = findSubWindow( uiCategory ); - QList apcSubWindowList; + QList subWindowList = findSubWindow( uiCategory ); + QList apcSubWindowList; if( !windowName.isEmpty() ) { for( Int i = 0; i < subWindowList.size(); i++ ) @@ -251,9 +324,9 @@ QList PlaYUVerSubWindowHandle::findSubWindow( const QString &w return apcSubWindowList; } -SubWindowHandle* PlaYUVerSubWindowHandle::findSubWindow( const SubWindowHandle* subWindow ) const +SubWindowAbstract* PlaYUVerSubWindowHandle::findSubWindow( const SubWindowAbstract* subWindow ) const { - QList subWindowList = findSubWindow(); + QList subWindowList = findSubWindow(); for( Int i = 0; i < subWindowList.size(); i++ ) { if( subWindow == subWindowList.at( i ) ) @@ -267,21 +340,89 @@ Void PlaYUVerSubWindowHandle::setActiveSubWindow( QWidget *window ) if( !window ) return; - m_pcActiveWindow = qobject_cast( window ); - m_pcActiveWindow->window()->activateWindow(); + m_pcActiveWindow = qobject_cast( window ); + + if( m_iWindowMode == DETACHEDSUBWINDOWMODE ) + { + m_pcActiveWindow->window()->activateWindow(); + } + if( m_iWindowMode == MDISUBWINDOWMODE ) + { + m_pcActiveWindow->setFocus(); + } } Void PlaYUVerSubWindowHandle::tileSubWindows() { - if( m_uiWindowMode == MdiWSubWindows ) + UInt numberOfWindows = m_apcSubWindowList.size(); + if( numberOfWindows == 0 ) + return; + + if( m_iWindowMode == DETACHEDSUBWINDOWMODE ) + { + QSize screenSize = QApplication::desktop()->availableGeometry().size(); + UInt minWindowsInRow = 1; + while( ( screenSize.width() / minWindowsInRow ) > 500 ) + { + minWindowsInRow++; + } + m_pcApp->showNormal(); + qApp->processEvents(); + m_pcApp->move( 0, 0 ); + m_pcApp->resize( screenSize.width(), 5 ); + QSize appSize = m_pcApp->size(); + QPoint topLeftCornerWindow( 0, appSize.height() ); + //Select the arrangement based on the number of windows + + if( numberOfWindows % 2 != 0 && numberOfWindows > minWindowsInRow ) + { + numberOfWindows++; + } + UInt numberTillingRows = 1; + UInt numberTillingColumns; + if( numberOfWindows > minWindowsInRow ) + { + numberTillingColumns = minWindowsInRow; + for( Int i = numberOfWindows; i > 0; ) + { + numberTillingRows = ( numberOfWindows + numberTillingColumns - 1 ) / numberTillingColumns; + if( numberTillingColumns > numberTillingRows ) + { + break; + } + numberTillingColumns++; + } + } + else + { + numberTillingColumns = numberOfWindows; + } + if( numberOfWindows / numberTillingRows == 1 ) + { + numberTillingColumns = numberTillingRows; + } + + QSize totalWindowsSize( screenSize.width(), screenSize.height() - topLeftCornerWindow.y() ); + QSize windowsSize( totalWindowsSize.width() / numberTillingColumns, totalWindowsSize.height() / numberTillingRows ); + QPoint windowRelativePos; + for( Int i = 0; i < m_apcSubWindowList.size(); i++ ) + { + windowRelativePos.setY( ( i / numberTillingColumns ) * windowsSize.height() ); + windowRelativePos.setX( ( i % numberTillingColumns ) * windowsSize.width() ); + m_apcSubWindowList.at( i )->resize( windowsSize ); + m_apcSubWindowList.at( i )->move( topLeftCornerWindow + windowRelativePos ); + } + } + if( m_iWindowMode == MDISUBWINDOWMODE ) { m_pcMdiArea->tileSubWindows(); } + } Void PlaYUVerSubWindowHandle::cascadeSubWindows() { - if( m_uiWindowMode == MdiWSubWindows ) + if( m_iWindowMode == MDISUBWINDOWMODE ) { m_pcMdiArea->cascadeSubWindows(); } @@ -294,6 +435,32 @@ Void PlaYUVerSubWindowHandle::createActions() m_arrayActions.resize( TOTAL_ACT ); + // ------------ Tools ------------ + m_actionGroupWindowMode = new QActionGroup( this ); + m_actionGroupWindowMode->setExclusive( true ); + + m_mapperWindowMode = new QSignalMapper( this ); + connect( m_mapperWindowMode, SIGNAL( mapped(int) ), this, SLOT( setWindowMode(int) ) ); + + m_arrayActions[NORMAL_SUBWINDOW_MODE_ACT] = new QAction( tr( "&Detached SubWindows" ), this ); + m_arrayActions[NORMAL_SUBWINDOW_MODE_ACT]->setCheckable( true ); + m_actionGroupWindowMode->addAction( m_arrayActions[NORMAL_SUBWINDOW_MODE_ACT] ); + connect( m_arrayActions[NORMAL_SUBWINDOW_MODE_ACT], SIGNAL( triggered() ), m_mapperWindowMode, SLOT( map() ) ); + m_mapperWindowMode->setMapping( m_arrayActions[NORMAL_SUBWINDOW_MODE_ACT], DETACHEDSUBWINDOWMODE ); + + m_arrayActions[MDI_SUBWINDOW_MODE_ACT] = new QAction( "&MDI SubWindows", this ); + m_arrayActions[MDI_SUBWINDOW_MODE_ACT]->setCheckable( true ); + m_actionGroupWindowMode->addAction( m_arrayActions[MDI_SUBWINDOW_MODE_ACT] ); + connect( m_arrayActions[MDI_SUBWINDOW_MODE_ACT], SIGNAL( triggered() ), m_mapperWindowMode, SLOT( map() ) ); + m_mapperWindowMode->setMapping( m_arrayActions[MDI_SUBWINDOW_MODE_ACT], MDISUBWINDOWMODE ); + + m_actionGroupWindowMode->actions().at( m_iWindowMode )->setChecked( true ); + + m_arrayActions[CLOSE_ACT] = new QAction( tr( "&Close" ), this ); + m_arrayActions[CLOSE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogCloseButton ) ); + m_arrayActions[CLOSE_ACT]->setStatusTip( tr( "Close the active window" ) ); + connect( m_arrayActions[CLOSE_ACT], SIGNAL( triggered() ), this, SLOT( removeActiveSubWindow() ) ); + m_arrayActions[CLOSE_ACT] = new QAction( tr( "&Close" ), this ); m_arrayActions[CLOSE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogCloseButton ) ); m_arrayActions[CLOSE_ACT]->setStatusTip( tr( "Close the active window" ) ); @@ -306,7 +473,7 @@ Void PlaYUVerSubWindowHandle::createActions() m_arrayActions[TILE_WINDOWS_ACT] = new QAction( tr( "Tile" ), this ); m_arrayActions[TILE_WINDOWS_ACT]->setIcon( QIcon( ":images/windowstile.png" ) ); m_arrayActions[TILE_WINDOWS_ACT]->setStatusTip( tr( "Tile the windows" ) ); - //connect( m_arrayActions[TILE_WINDOWS_ACT], SIGNAL( triggered() ), mdiArea, SLOT( tileSubWindows() ) ); +//connect( m_arrayActions[TILE_WINDOWS_ACT], SIGNAL( triggered() ), mdiArea, SLOT( tileSubWindows() ) ); connect( m_arrayActions[TILE_WINDOWS_ACT], SIGNAL( triggered() ), this, SLOT( tileSubWindows() ) ); m_arrayActions[CASCADE_WINDOWS_ACT] = new QAction( tr( "Cascade" ), this ); @@ -318,13 +485,13 @@ Void PlaYUVerSubWindowHandle::createActions() m_arrayActions[NEXT_WINDOWS_ACT]->setShortcuts( QKeySequence::NextChild ); m_arrayActions[NEXT_WINDOWS_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_ArrowRight ) ) ); m_arrayActions[NEXT_WINDOWS_ACT]->setStatusTip( tr( "Move the focus to the next window" ) ); - // connect( m_arrayActions[NEXT_WINDOWS_ACT], SIGNAL( triggered() ), this, SLOT( activateNextSubWindow() ) ); +// connect( m_arrayActions[NEXT_WINDOWS_ACT], SIGNAL( triggered() ), this, SLOT( activateNextSubWindow() ) ); m_arrayActions[PREVIOUS_WINDOWS_ACT] = new QAction( tr( "Pre&vious" ), this ); m_arrayActions[PREVIOUS_WINDOWS_ACT]->setShortcuts( QKeySequence::PreviousChild ); m_arrayActions[PREVIOUS_WINDOWS_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_ArrowLeft ) ) ); m_arrayActions[PREVIOUS_WINDOWS_ACT]->setStatusTip( tr( "Move the focus to the previous window" ) ); - // connect( m_arrayActions[PREVIOUS_WINDOWS_ACT], SIGNAL( triggered() ), this, SLOT( activatePreviousSubWindow() ) ); +// connect( m_arrayActions[PREVIOUS_WINDOWS_ACT], SIGNAL( triggered() ), this, SLOT( activatePreviousSubWindow() ) ); m_arrayActions[SEPARATOR_ACT] = new QAction( this ); m_arrayActions[SEPARATOR_ACT]->setSeparator( true ); @@ -342,15 +509,18 @@ QMenu* PlaYUVerSubWindowHandle::createMenu() Void PlaYUVerSubWindowHandle::updateMenu() { m_pcMenuWindow->clear(); + m_pcMenuWindow->addAction( m_arrayActions[NORMAL_SUBWINDOW_MODE_ACT] ); + m_pcMenuWindow->addAction( m_arrayActions[MDI_SUBWINDOW_MODE_ACT] ); + m_pcMenuWindow->addSeparator(); m_pcMenuWindow->addAction( m_arrayActions[CLOSE_ACT] ); m_pcMenuWindow->addAction( m_arrayActions[CLOSE_ALL_ACT] ); m_pcMenuWindow->addSeparator(); m_pcMenuWindow->addAction( m_arrayActions[TILE_WINDOWS_ACT] ); m_pcMenuWindow->addAction( m_arrayActions[CASCADE_WINDOWS_ACT] ); m_pcMenuWindow->addSeparator(); - m_pcMenuWindow->addAction( m_arrayActions[NEXT_WINDOWS_ACT] ); - m_pcMenuWindow->addAction( m_arrayActions[PREVIOUS_WINDOWS_ACT] ); - m_pcMenuWindow->addSeparator(); +// m_pcMenuWindow->addAction( m_arrayActions[NEXT_WINDOWS_ACT] ); +// m_pcMenuWindow->addAction( m_arrayActions[PREVIOUS_WINDOWS_ACT] ); +// m_pcMenuWindow->addSeparator(); Int number_windows = m_apcSubWindowList.size(); if( number_windows > 1 ) @@ -368,7 +538,7 @@ Void PlaYUVerSubWindowHandle::updateMenu() for( Int i = 0; i < number_windows; ++i ) { - SubWindowHandle *subWindow = m_apcSubWindowList.at( i ); + SubWindowAbstract *subWindow = m_apcSubWindowList.at( i ); QString text; if( i < 9 ) @@ -389,12 +559,20 @@ Void PlaYUVerSubWindowHandle::updateMenu() Void PlaYUVerSubWindowHandle::readSettings() { - + QSettings appSettings; + m_cMdiModeWindowPosition = appSettings.value( "SubWindowManager/LastMdiPosition", QPoint( 200, 200 ) ).toPoint(); + m_cMdiModeWindowSize = appSettings.value( "SubWindowManager/LastMdiSize", QSize( 500, 400 ) ).toSize(); + Int iWindowMode = appSettings.value( "SubWindowManager/SubWindowMode", MDISUBWINDOWMODE ).toInt(); + setWindowMode( iWindowMode ); + m_actionGroupWindowMode->actions().at( iWindowMode )->setChecked( true ); } Void PlaYUVerSubWindowHandle::writeSettings() { - + QSettings appSettings; + appSettings.setValue( "SubWindowManager/LastMdiPosition", m_cMdiModeWindowPosition ); + appSettings.setValue( "SubWindowManager/LastMdiSize", m_cMdiModeWindowSize ); + appSettings.setValue( "SubWindowManager/SubWindowMode", m_iWindowMode ); } } // NAMESPACE diff --git a/app/PlaYUVerSubWindowHandle.h b/app/PlaYUVerSubWindowHandle.h index b7c682c..ad7412f 100644 --- a/app/PlaYUVerSubWindowHandle.h +++ b/app/PlaYUVerSubWindowHandle.h @@ -36,7 +36,8 @@ namespace plaYUVer { -class SubWindowHandle; +class PlaYUVerApp; +class SubWindowAbstract; class PlaYUVerMdiArea; class PlaYUVerMdiSubWindow; @@ -47,13 +48,15 @@ Q_OBJECT public: PlaYUVerSubWindowHandle( QWidget *parent ); - Void addSubWindow( SubWindowHandle *widget, Qt::WindowFlags flags = 0 ); + Void processLogMsg( const QString& msg ); - SubWindowHandle *activeSubWindow() const; + Void addSubWindow( SubWindowAbstract *widget, Qt::WindowFlags flags = 0 ); - QList findSubWindow( const UInt uiCategory = 0 ) const; - QList findSubWindow( const QString &aName, const UInt uiCategory = 0 ) const; - SubWindowHandle* findSubWindow( const SubWindowHandle* subWindow ) const; + SubWindowAbstract *activeSubWindow() const; + + QList findSubWindow( const UInt uiCategory = 0 ) const; + QList findSubWindow( const QString &aName, const UInt uiCategory = 0 ) const; + SubWindowAbstract* findSubWindow( const SubWindowAbstract* subWindow ) const; Void createActions(); QMenu* createMenu(); @@ -63,22 +66,28 @@ public: enum WindowMode { - NormalSubWindows = 0, - MdiWSubWindows = 1, + DETACHEDSUBWINDOWMODE = 0, + MDISUBWINDOWMODE = 1, }; private: - UInt m_uiWindowMode; - QList m_apcSubWindowList; + PlaYUVerApp* m_pcApp; + Int m_iWindowMode; + QList m_apcSubWindowList; QHBoxLayout* m_pcWindowManagerLayout; PlaYUVerMdiArea* m_pcMdiArea; QList m_apcMdiSubWindowList; - SubWindowHandle* m_pcActiveWindow; + SubWindowAbstract* m_pcActiveWindow; + + QPoint m_cMdiModeWindowPosition; + QSize m_cMdiModeWindowSize; enum { + NORMAL_SUBWINDOW_MODE_ACT, + MDI_SUBWINDOW_MODE_ACT, CLOSE_ACT, CLOSE_ALL_ACT, TILE_WINDOWS_ACT, @@ -89,20 +98,23 @@ private: TOTAL_ACT, }; QVector m_arrayActions; + QSignalMapper* m_mapperWindowMode; + QActionGroup* m_actionGroupWindowMode; QSignalMapper* m_mapperWindow; QMenu* m_pcMenuWindow; /** * Internal functions */ + Void addMdiSubWindow( SubWindowAbstract *window ); Void resetWindowMode(); - Void setWindowMode( UInt uiWindowMode ); Void removeSubWindow( Int windowIdx ); public Q_SLOTS: - void updateActiveSubWindow( SubWindowHandle *window = 0 ); + void setWindowMode( int iWindowMode ); + void updateActiveSubWindow( SubWindowAbstract *window = 0 ); void setActiveSubWindow( QWidget *window ); - void removeSubWindow( SubWindowHandle *window ); + void removeSubWindow( SubWindowAbstract *window ); void removeMdiSubWindow( PlaYUVerMdiSubWindow* window ); void removeActiveSubWindow(); void removeAllSubWindow(); diff --git a/app/PlotSubWindow.cpp b/app/PlotSubWindow.cpp index 35b019b..9916e03 100644 --- a/app/PlotSubWindow.cpp +++ b/app/PlotSubWindow.cpp @@ -23,44 +23,75 @@ */ #include "PlotSubWindow.h" +#include "qcustomplot.h" namespace plaYUVer { -PlotSubWindow::PlotSubWindow( QWidget * parent ) : - SubWindowHandle( parent, SubWindowHandle::PLOT_SUBWINDOW ) +Void PlotSubWindow::definePlotColors() { - setParent( parent ); - - setAttribute( Qt::WA_DeleteOnClose ); - setBackgroundRole( QPalette::Light ); - setVisible( false ); - - m_cPlotArea = new QCustomPlot( this ); - setWidget( m_cPlotArea ); - - Example(); - + m_arrayColorList.append( Qt::blue ); + m_arrayColorList.append( Qt::red ); + m_arrayColorList.append( Qt::green ); + m_arrayColorList.append( Qt::black ); + m_arrayColorList.append( Qt::cyan ); + m_arrayColorList.append( Qt::magenta ); + m_arrayColorList.append( Qt::yellow ); + m_arrayColorList.append( Qt::gray ); + m_arrayColorList.append( Qt::darkRed ); + m_arrayColorList.append( Qt::darkGreen ); + m_arrayColorList.append( Qt::darkRed ); + m_arrayColorList.append( Qt::darkBlue ); + m_arrayColorList.append( Qt::darkMagenta ); + m_arrayColorList.append( Qt::darkCyan ); + m_arrayColorList.append( Qt::darkYellow ); } -Void PlotSubWindow::Example() +PlotSubWindow::PlotSubWindow( const QString& windowTitle, QWidget * parent ) : + SubWindowAbstract( parent, SubWindowAbstract::PLOT_SUBWINDOW ) { - // add two new graphs and set their look: - m_cPlotArea->addGraph(); - m_cPlotArea->graph( 0 )->setPen( QPen( Qt::blue ) ); // line color blue for first graph - m_cPlotArea->graph( 0 )->setBrush( QBrush( QColor( 0, 0, 255, 20 ) ) ); // first graph will be filled with translucent blue - m_cPlotArea->addGraph(); - m_cPlotArea->graph( 1 )->setPen( QPen( Qt::red ) ); // line color red for second graph - // generate some points of data (y0 for first, y1 for second graph): - QVector x( 250 ), y0( 250 ), y1( 250 ); - for( int i = 0; i < 250; ++i ) - { - x[i] = i; - y0[i] = exp( -i / 150.0 ) * cos( i / 10.0 ); // exponentially decaying cosine - y1[i] = exp( -i / 150.0 ); // exponential envelope - } + + definePlotColors(); + m_iNumberPlots = 0; + m_dScaleFactor = 1; + + setWindowName( windowTitle ); + + m_cPlotArea = new QCustomPlot( this ); + + QSizePolicy sizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding ); + sizePolicy.setHorizontalStretch( 0 ); + sizePolicy.setVerticalStretch( 0 ); + sizePolicy.setHeightForWidth( m_cPlotArea->sizePolicy().hasHeightForWidth() ); + m_cPlotArea->setSizePolicy( sizePolicy ); + + m_cPlotArea->setBackgroundRole( backgroundRole() ); + + QBrush backgroundBrush = palette().brush( backgroundRole() ); + QBrush foregroundBrush = palette().brush( foregroundRole() ); + + m_cPlotArea->setBackground( backgroundBrush ); + + m_cPlotArea->xAxis->setLabelColor( palette().text().color() ); + m_cPlotArea->yAxis->setLabelColor( palette().text().color() ); + m_cPlotArea->xAxis->setTickLabelColor( palette().text().color() ); + m_cPlotArea->yAxis->setTickLabelColor( palette().text().color() ); + m_cPlotArea->xAxis->setBasePen( QPen( foregroundBrush, 1 ) ); + m_cPlotArea->yAxis->setBasePen( QPen( foregroundBrush, 1 ) ); + m_cPlotArea->xAxis->setTickPen( QPen( foregroundBrush, 1 ) ); + m_cPlotArea->yAxis->setTickPen( QPen( foregroundBrush, 1 ) ); + m_cPlotArea->xAxis->setSubTickPen( QPen( foregroundBrush, 1 ) ); + m_cPlotArea->yAxis->setSubTickPen( QPen( foregroundBrush, 1 ) ); + m_cPlotArea->xAxis2->setSubTickPen( QPen( foregroundBrush, 1 ) ); + m_cPlotArea->yAxis2->setSubTickPen( QPen( foregroundBrush, 1 ) ); + m_cPlotArea->xAxis2->setBasePen( QPen( foregroundBrush, 1 ) ); + m_cPlotArea->yAxis2->setBasePen( QPen( foregroundBrush, 1 ) ); + m_cPlotArea->xAxis2->setTickPen( QPen( foregroundBrush, 1 ) ); + m_cPlotArea->yAxis2->setTickPen( QPen( foregroundBrush, 1 ) ); + // configure right and top axis to show ticks but no labels: // (see QCPAxisRect::setupFullAxesBox for a quicker method to do this) + m_cPlotArea->axisRect( 0 )->setupFullAxesBox( true ); m_cPlotArea->xAxis2->setVisible( true ); m_cPlotArea->xAxis2->setTickLabels( false ); m_cPlotArea->yAxis2->setVisible( true ); @@ -68,17 +99,22 @@ Void PlotSubWindow::Example() // make left and bottom axes always transfer their ranges to right and top axes: connect( m_cPlotArea->xAxis, SIGNAL( rangeChanged(QCPRange) ), m_cPlotArea->xAxis2, SLOT( setRange(QCPRange) ) ); connect( m_cPlotArea->yAxis, SIGNAL( rangeChanged(QCPRange) ), m_cPlotArea->yAxis2, SLOT( setRange(QCPRange) ) ); - // pass data points to graphs: - m_cPlotArea->graph( 0 )->setData( x, y0 ); - m_cPlotArea->graph( 1 )->setData( x, y1 ); - // let the ranges scale themselves so graph 0 fits perfectly in the visible area: - m_cPlotArea->graph( 0 )->rescaleAxes(); - // same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0): - m_cPlotArea->graph( 1 )->rescaleAxes( true ); - // Note: we could have also just called m_cPlotArea->rescaleAxes(); instead - // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking: - m_cPlotArea->setInteractions( QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables ); + QFont legendFont = font(); // start out with MainWindow's font.. + legendFont.setPointSize( 9 ); // and make a bit smaller for legend + m_cPlotArea->legend->setFont( legendFont ); + m_cPlotArea->legend->setBrush( backgroundBrush ); + m_cPlotArea->legend->setTextColor( palette().text().color() ); + m_cPlotArea->legend->setBorderPen( QPen( palette().brush( QPalette::Active, QPalette::Shadow ), 1 ) ); + m_cPlotArea->legend->setVisible( false ); + + m_cPlotArea->setInteractions( QCP::iRangeZoom | QCP::iRangeDrag ); //QCP::iSelectPlottables + + m_cPlotPen.setStyle( Qt::SolidLine ); + m_cPlotPen.setColor( Qt::black ); + m_cPlotPen.setWidthF( 2 ); + + setWidget( m_cPlotArea ); } PlotSubWindow::~PlotSubWindow() @@ -88,12 +124,15 @@ PlotSubWindow::~PlotSubWindow() Void PlotSubWindow::normalSize() { - + m_cPlotArea->xAxis->setRange( m_aAxisRange[HORIZONTAL][0], m_aAxisRange[HORIZONTAL][1] ); + m_cPlotArea->yAxis->setRange( m_aAxisRange[VERTICAL][0], m_aAxisRange[VERTICAL][1] ); + m_cPlotArea->replot(); + m_dScaleFactor = 1; } Void PlotSubWindow::zoomToFit() { - + normalSize(); } Void PlotSubWindow::zoomToFactor( Double factor, QPoint center ) @@ -103,18 +142,103 @@ Void PlotSubWindow::zoomToFactor( Double factor, QPoint center ) Void PlotSubWindow::scaleView( Double scale, QPoint center ) { + scale -= 1; + scale /= 10; + scale += 1; + m_dScaleFactor *= scale; +// +// UInt aNewAxisRange[2][2]; +// for( UInt axis = 0; axis < 2; axis++ ) +// for( UInt dim = 0; dim < 2; dim++ ) +// aNewAxisRange[axis][dim] = m_aAxisRange[axis][dim] / m_dScaleFactor; +// +// m_cPlotArea->xAxis->setRange( aNewAxisRange[HORIZONTAL][0], aNewAxisRange[HORIZONTAL][1] ); +// m_cPlotArea->yAxis->setRange( aNewAxisRange[VERTICAL][0], aNewAxisRange[VERTICAL][1] ); + + m_cPlotArea->xAxis->scaleRange( scale, 0 ); + m_cPlotArea->yAxis->scaleRange( scale, 0 ); + m_cPlotArea->replot(); } -//QSize PlotSubWindow::sizeHint() const -//{ -// -//} -// -// -//QSize PlotSubWindow::sizeHint( const QSize & maxSize ) const -//{ -// -//} +QSize PlotSubWindow::sizeHint() const +{ + QSize maxSize; + QWidget *p = parentWidget(); + if( p ) + { + maxSize = p->size(); + } + else + { + maxSize = QApplication::desktop()->availableGeometry().size(); + } + return sizeHint( maxSize ); +} + +QSize PlotSubWindow::sizeHint( const QSize & maxSize ) const +{ + return maxSize * 2 / 3; +} + +Void PlotSubWindow::setAxisName( const QString& nameAxisX, const QString& nameAxisY ) +{ + m_cPlotArea->xAxis->setLabel( nameAxisX ); + m_cPlotArea->yAxis->setLabel( nameAxisY ); +} + +Void PlotSubWindow::setAxisRange( const QLine& axisLimits ) +{ + setAxisRange( HORIZONTAL, axisLimits.x1(), axisLimits.x2() ); + setAxisRange( VERTICAL, axisLimits.y1(), axisLimits.y2() ); +} + +Void PlotSubWindow::setAxisRange( PlotSubWindow::Axis eAxis, const Int& axisStart, const Int& axisEnd ) +{ + if( eAxis == HORIZONTAL ) + { + m_cPlotArea->xAxis->setRange( axisStart, axisEnd ); + //horizontalScrollBar()->setRange( axisStart * 100, axisEnd * 100 ); + m_aAxisRange[HORIZONTAL][0] = axisStart; + m_aAxisRange[HORIZONTAL][1] = axisEnd; + } + if( eAxis == VERTICAL ) + { + m_cPlotArea->yAxis->setRange( axisStart, axisEnd ); + //verticalScrollBar()->setRange( axisStart * 100, axisEnd * 100 ); + m_aAxisRange[VERTICAL][0] = axisStart; + m_aAxisRange[VERTICAL][1] = axisEnd; + } + m_cPlotArea->replot(); +} + +Void PlotSubWindow::addPlot( const QVector &arrayX, const QVector &arrayY, const QString& key ) +{ + QCPGraph *newPlot = m_cPlotArea->addGraph(); + QColor plotColor = m_arrayColorList.at( 0 ); + if( m_iNumberPlots < m_arrayColorList.size() ) + { + plotColor = m_arrayColorList.at( m_iNumberPlots ); + } + m_cPlotPen.setColor( plotColor ); + newPlot->setPen( m_cPlotPen ); // line style + // pass data points to graphs: + newPlot->setData( arrayX, arrayY ); + // let the ranges scale themselves so graph 0 fits perfectly in the visible area: + newPlot->rescaleAxes( m_iNumberPlots > 1 ? true : false ); + + if( !key.isEmpty() ) + { + m_cPlotArea->legend->setVisible( true ); + newPlot->setName( key ); + } + + m_aAxisRange[HORIZONTAL][0] = m_cPlotArea->xAxis->range().lower; + m_aAxisRange[HORIZONTAL][1] = m_cPlotArea->xAxis->range().upper; + m_aAxisRange[VERTICAL][0] = m_cPlotArea->yAxis->range().lower; + m_aAxisRange[VERTICAL][1] = m_cPlotArea->yAxis->range().upper; + + m_iNumberPlots++; +} } // NAMESPACE diff --git a/app/PlotSubWindow.h b/app/PlotSubWindow.h index 9dfb063..81538a6 100644 --- a/app/PlotSubWindow.h +++ b/app/PlotSubWindow.h @@ -32,31 +32,50 @@ #elif( QT_VERSION_PLAYUVER == 4 ) #include #endif -#include "SubWindowHandle.h" -#include "qcustomplot.h" +#include "SubWindowAbstract.h" + +class QCustomPlot; namespace plaYUVer { -class PlotSubWindow: public SubWindowHandle +class PlotSubWindow: public SubWindowAbstract { Q_OBJECT private: QCustomPlot* m_cPlotArea; - Void Example(); + QVector m_arrayColorList; + QPen m_cPlotPen; + + enum Axis + { + HORIZONTAL, + VERTICAL, + }; + Double m_aAxisRange[2][2]; + Double m_dScaleFactor; + Int m_iNumberPlots; public: - PlotSubWindow( QWidget * parent = 0 ); + + PlotSubWindow( const QString& windowTitle, QWidget * parent = NULL ); ~PlotSubWindow(); + Void definePlotColors(); + + Void refreshSubWindow() + { + + } + Void setTool( UInt uiTool ) { } /** - * Virtual functions from SubWindowHandle + * Virtual functions from SubWindowAbstract */ Void normalSize(); Void zoomToFit(); @@ -65,14 +84,24 @@ public: Double getScaleFactor() { - return 0; + return m_dScaleFactor; } /** * Size related functions */ -// QSize sizeHint() const; -// QSize sizeHint( const QSize & ) const; + QSize sizeHint() const; + QSize sizeHint( const QSize & ) const; + + Void setAxisName( const QString& nameAxisX, const QString& nameAxisY ); + + Void setAxisRange( const QLine& axisLimits ); + Void setAxisRange( PlotSubWindow::Axis eAxis, const Int& axisStart, const Int& axisEnd ); + + Void setKey( const QString& key ); + + Void addPlot( const QVector &arrayX, const QVector &arrayY, const QString& key = QString() ); + }; } // NAMESPACE diff --git a/app/ProgressBar.cpp b/app/ProgressBar.cpp new file mode 100644 index 0000000..6f0104f --- /dev/null +++ b/app/ProgressBar.cpp @@ -0,0 +1,64 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file ProgressBar.cpp + * \brief Progress bar code + */ + +#include "ProgressBar.h" +#include +#include +#include +#include +#include + +namespace plaYUVer +{ + +ProgressBar::ProgressBar( QWidget *parent, UInt maxValue ) : + QWidget( parent ), + m_uiTotalProgress( maxValue ), + m_uiProgress( 0 ) +{ + QVBoxLayout* mainLayout = new QVBoxLayout( this ); + m_pcProgressBar = new QProgressBar; + m_pcProgressBar->setMaximum( m_uiTotalProgress ); + m_pcProgressBar->setAlignment( Qt::AlignCenter ); + mainLayout->addWidget( m_pcProgressBar ); + setLayout( mainLayout ); + setWindowTitle( QStringLiteral( "Progress" ) ); + +// QSize appSize = QApplication::desktop()->availableGeometry().size(); +// QPoint appCenter = QApplication::desktop()->availableGeometry().center(); + QSize appSize = parent->size(); + QPoint appPos = parent->pos(); + QPoint appCenter = QPoint( appPos.x() + appSize.width() / 2, appPos.y() + appSize.height() / 2 ); + resize( appSize.width() / 4, appSize.height() / 10 ); + move( appCenter.x() - appSize.width() / 8, appCenter.y() - appSize.height() / 20 ); + show(); +} + +Void ProgressBar::incrementProgress( UInt increment ) +{ + m_uiProgress += increment; + m_pcProgressBar->setValue( m_uiProgress ); + update(); +} +} // NAMESPACE diff --git a/app/ProgressBar.h b/app/ProgressBar.h new file mode 100644 index 0000000..8cba896 --- /dev/null +++ b/app/ProgressBar.h @@ -0,0 +1,54 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file ProgressBar.h + * \brief Progress bar code + */ + +#ifndef __PROGRESSBAR_H__ +#define __PROGRESSBAR_H__ + +#include "PlaYUVerAppDefs.h" +#include +#include + +class QProgressBar; + +namespace plaYUVer +{ + +class ProgressBar: public QWidget +{ +Q_OBJECT + +public: + ProgressBar( QWidget *parent, UInt maxValue ); + + Void incrementProgress( UInt ); + +private: + UInt m_uiTotalProgress; + UInt m_uiProgress; + QProgressBar* m_pcProgressBar; +}; + +} // NAMESPACE + +#endif // __PROGRESSBAR_H__ diff --git a/app/QualityHandle.cpp b/app/QualityHandle.cpp index 0230970..ab20471 100644 --- a/app/QualityHandle.cpp +++ b/app/QualityHandle.cpp @@ -23,11 +23,16 @@ */ #include +#include "lib/LibMemory.h" #include "PlaYUVerSubWindowHandle.h" #include "QualityHandle.h" #include "VideoSubWindow.h" #include "PlotSubWindow.h" #include "DialogSubWindowSelector.h" +#include "ProgressBar.h" +#if( QT_VERSION_PLAYUVER == 5 ) +#include "QtConcurrent/qtconcurrentrun.h" +#endif namespace plaYUVer { @@ -62,10 +67,14 @@ Void QualityHandle::createActions() } m_arrayActions.resize( TOTAL_ACT ); - m_arrayActions[SELECT_REF_ACT] = new QAction( "Select Reference", this ); - connect( m_arrayActions[SELECT_REF_ACT], SIGNAL( triggered() ), this, SLOT( slotSelectReference() ) ); - m_arrayActions[PLOT_QUALITY] = new QAction( "CREATE_PLOT", this ); - connect( m_arrayActions[PLOT_QUALITY], SIGNAL( triggered() ), this, SLOT( slotCreatePlot() ) ); + + m_arrayActions[SELECT_CURR_REF_ACT] = new QAction( "Mark as Reference", this ); + connect( m_arrayActions[SELECT_CURR_REF_ACT], SIGNAL( triggered() ), this, SLOT( slotSelectCurrentAsReference() ) ); + + m_arrayActions[PLOT_QUALITY] = new QAction( "Plot Window's Quality", this ); + connect( m_arrayActions[PLOT_QUALITY], SIGNAL( triggered() ), this, SLOT( slotPlotQualitySingle() ) ); + m_arrayActions[PLOT_SEVERAL_QUALITY] = new QAction( "Plot Several Quality", this ); + connect( m_arrayActions[PLOT_SEVERAL_QUALITY], SIGNAL( triggered() ), this, SLOT( slotPlotQualitySeveral() ) ); } QMenu* QualityHandle::createMenu() @@ -73,9 +82,10 @@ QMenu* QualityHandle::createMenu() m_pcMenuQuality = new QMenu( "Quality", this ); m_pcSubMenuQualityMetrics = m_pcMenuQuality->addMenu( "Quality Metrics" ); m_pcSubMenuQualityMetrics->addActions( m_actionGroupQualityMetric->actions() ); - m_pcMenuQuality->addAction( m_arrayActions[SELECT_REF_ACT] ); + m_pcMenuQuality->addAction( m_arrayActions[SELECT_CURR_REF_ACT] ); m_pcMenuQuality->addSeparator(); - //m_pcMenuQuality->addAction( m_arrayActions[PLOT_QUALITY] ); + m_pcMenuQuality->addAction( m_arrayActions[PLOT_QUALITY] ); + m_pcMenuQuality->addAction( m_arrayActions[PLOT_SEVERAL_QUALITY] ); return m_pcMenuQuality; } @@ -96,12 +106,35 @@ QDockWidget* QualityHandle::createDock() Void QualityHandle::updateMenus() { - VideoSubWindow* pcSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); - Bool hasSubWindow = pcSubWindow ? true : false; + VideoSubWindow* pcCurrentVideoSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + Bool hasSubWindow = pcCurrentVideoSubWindow ? true : false; + Bool hasReference = false; + Bool isReference = false; + + if( hasSubWindow ) + { + hasReference = pcCurrentVideoSubWindow->getRefSubWindow() != NULL ? true : false; + if( hasSubWindow && !hasReference ) + { + VideoSubWindow* pcVideoSubWindow; + QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_STREAM_SUBWINDOW ); + for( Int i = 0; i < subWindowList.size(); i++ ) + { + pcVideoSubWindow = qobject_cast( subWindowList.at( i ) ); + if( pcVideoSubWindow->getRefSubWindow() == pcCurrentVideoSubWindow ) + { + isReference = true; + break; + } + } + } + } m_pcSubMenuQualityMetrics->setEnabled( hasSubWindow ); - m_arrayActions[SELECT_REF_ACT]->setEnabled( hasSubWindow ); - m_arrayActions[PLOT_QUALITY]->setEnabled( hasSubWindow ); + m_arrayActions[SELECT_CURR_REF_ACT]->setEnabled( hasSubWindow ); + + m_arrayActions[PLOT_QUALITY]->setEnabled( hasReference ); + m_arrayActions[PLOT_SEVERAL_QUALITY]->setEnabled( hasReference | isReference ); m_pcQualityHandleSideBar->updateSideBar( hasSubWindow ); } @@ -127,6 +160,87 @@ Void QualityHandle::update( VideoSubWindow* currSubWindow ) m_pcQualityHandleSideBar->updateCurrentWindow( currSubWindow ); } +Void QualityHandle::measureQuality( QVector apcWindowList ) +{ + QVector* padQualityValues; + UInt numberOfWindows = apcWindowList.size(); + UInt64 currFrames = 0; + UInt64 numberOfFrames = INT_MAX; + + //! Check reference window + for( UInt i = 0; i < numberOfWindows; i++ ) + { + if( !apcWindowList.at( i )->getRefSubWindow() ) + { + return; + } + } + VideoSubWindow* pcReferenceWindow = apcWindowList.at( 0 )->getRefSubWindow(); + + numberOfFrames = pcReferenceWindow->getInputStream()->getFrameNum(); + for( UInt i = 0; i < numberOfWindows; i++ ) + { + currFrames = apcWindowList.at( i )->getInputStream()->getFrameNum(); + if( currFrames < numberOfFrames ) + numberOfFrames = currFrames; + apcWindowList.at( i )->stop(); + } + pcReferenceWindow->stop(); + + ProgressBar* pcProgressBar = new ProgressBar( m_pcParet, numberOfFrames ); + + padQualityValues = new QVector [numberOfWindows + 1]; + + PlaYUVerFrame* pcReferenceFrame; + PlaYUVerFrame* pcCurrFrame; + for( UInt f = 0; f < numberOfFrames; f++ ) + { + padQualityValues[0].append( f ); + pcReferenceFrame = pcReferenceWindow->getCurrFrame(); + for( UInt i = 0; i < numberOfWindows; i++ ) + { + pcCurrFrame = apcWindowList.at( i )->getCurrFrame(); + padQualityValues[i + 1].append( pcCurrFrame->getQuality( m_iQualityMetricIdx, pcReferenceFrame, LUMA ) ); + apcWindowList.at( i )->seekRelativeEvent( true ); + } + pcReferenceWindow->seekRelativeEvent( true ); + pcProgressBar->incrementProgress( 1 ); + } + for( UInt i = 0; i < numberOfWindows; i++ ) + { + apcWindowList.at( i )->stop(); + } + pcReferenceWindow->stop(); + + QString plotWindowTitle( QStringLiteral( "Quality" ) ); + if( apcWindowList.size() == 1 ) + { + plotWindowTitle += " - " + apcWindowList.at( 0 )->getWindowName(); + } + PlotSubWindow* pcPlotWindow = new PlotSubWindow( plotWindowTitle ); + pcPlotWindow->setAxisName( "Frame Number", QString::fromStdString( PlaYUVerFrame::supportedQualityMetricsList()[m_iQualityMetricIdx] ) ); + + if( apcWindowList.size() > 1 ) + { + QString key; + for( UInt i = 0; i < numberOfWindows; i++ ) + { + key = apcWindowList.at( i )->getWindowName(); + pcPlotWindow->addPlot( padQualityValues[0], padQualityValues[i + 1], key ); + } + } + else + { + pcPlotWindow->addPlot( padQualityValues[0], padQualityValues[1] ); + } + + m_pcMainWindowManager->addSubWindow( pcPlotWindow ); + pcPlotWindow->show(); + + pcProgressBar->close(); + +} + Void QualityHandle::slotQualityMetricChanged( Int idx ) { m_actionGroupQualityMetric->actions().at( idx )->setChecked( true ); @@ -135,40 +249,85 @@ Void QualityHandle::slotQualityMetricChanged( Int idx ) m_iQualityMetricIdx = idx; } -Void QualityHandle::slotSelectReference() +Void QualityHandle::slotSelectCurrentAsReference() { - DialogSubWindowSelector dialogWindowSelection( this, m_pcMainWindowManager, SubWindowHandle::VIDEO_SUBWINDOW, 1, 1 ); - if( dialogWindowSelection.exec() == QDialog::Accepted ) + VideoSubWindow* pcRefSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + if( pcRefSubWindow ) { VideoSubWindow* pcVideoSubWindow; - VideoSubWindow* pcRefSubWindow = NULL; - QStringList selectedWindows = dialogWindowSelection.getSelectedWindows(); - QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowHandle::VIDEO_SUBWINDOW ); + QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW ); for( Int i = 0; i < subWindowList.size(); i++ ) { pcVideoSubWindow = qobject_cast( subWindowList.at( i ) ); - if( pcVideoSubWindow->getWindowName() == selectedWindows.at( 0 ) ) - { - pcRefSubWindow = pcVideoSubWindow; - break; - } - } - for( Int i = 0; i < subWindowList.size(); i++ ) - { - pcVideoSubWindow = qobject_cast( subWindowList.at( i ) ); - pcVideoSubWindow->setRefSubWindow( pcRefSubWindow ); + if( pcVideoSubWindow != pcRefSubWindow ) + pcVideoSubWindow->setRefSubWindow( pcRefSubWindow ); } m_pcQualityHandleSideBar->updateSidebarData(); m_pcQualityHandleDock->show(); + emit changed(); } } -Void QualityHandle::slotCreatePlot() +Void QualityHandle::slotPlotQualitySingle() { - PlotSubWindow* pcPlotWindow = new PlotSubWindow( m_pcParet ); - m_pcMainWindowManager->addSubWindow( pcPlotWindow ); - pcPlotWindow->show(); + VideoSubWindow* pcSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + if( pcSubWindow ) + { + if( pcSubWindow->getRefSubWindow() ) + { + QVector apcWindowList; + apcWindowList.append( pcSubWindow ); +//#ifndef QT_NO_CONCURRENT +// m_cMeasurementResult.waitForFinished(); +// m_cMeasurementResult = QtConcurrent::run( this, &QualityHandle::measureQuality, apcWindowList ); +//#else + QApplication::setOverrideCursor( Qt::WaitCursor ); + measureQuality( apcWindowList ); + QApplication::restoreOverrideCursor(); +//#endif + emit changed(); + } + } +} + +Void QualityHandle::slotPlotQualitySeveral() +{ + VideoSubWindow* pcSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + if( pcSubWindow ) + { + QVector apcWindowList; + + VideoSubWindow* pcRefSubWindow = pcSubWindow->getRefSubWindow(); + if( !pcRefSubWindow ) + { + pcRefSubWindow = pcSubWindow; + } + + VideoSubWindow* pcVideoSubWindow; + QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_STREAM_SUBWINDOW ); + for( Int i = 0; i < subWindowList.size(); i++ ) + { + pcVideoSubWindow = qobject_cast( subWindowList.at( i ) ); + if( pcVideoSubWindow->getRefSubWindow() == pcRefSubWindow ) + { + apcWindowList.append( pcVideoSubWindow ); + } + } + + if( apcWindowList.size() > 0 ) + { +//#ifndef QT_NO_CONCURRENT +// m_cMeasurementResult.waitForFinished(); +// m_cMeasurementResult = QtConcurrent::run( this, &QualityHandle::measureQuality, apcWindowList ); +//#else + QApplication::setOverrideCursor( Qt::WaitCursor ); + measureQuality( apcWindowList ); + QApplication::restoreOverrideCursor(); +//#endif + emit changed(); + } + } } } // NAMESPACE diff --git a/app/QualityHandle.h b/app/QualityHandle.h index faa42d5..e1bc0b4 100644 --- a/app/QualityHandle.h +++ b/app/QualityHandle.h @@ -33,6 +33,7 @@ #elif( QT_VERSION_PLAYUVER == 4 ) #include #endif +#include "QFuture" #include "QualityMeasurementSidebar.h" namespace plaYUVer @@ -61,10 +62,12 @@ public: private: QWidget* m_pcParet; PlaYUVerSubWindowHandle* m_pcMainWindowManager; + enum { - SELECT_REF_ACT, + SELECT_CURR_REF_ACT, PLOT_QUALITY, + PLOT_SEVERAL_QUALITY, TOTAL_ACT, }; QVector m_arrayActions; @@ -78,13 +81,17 @@ private: QDockWidget* m_pcQualityHandleDock; QualityMeasurementSidebar* m_pcQualityHandleSideBar; + QFuture m_cMeasurementResult; + Void measureQuality( QVector apcWindowList ); + Q_SIGNALS: void changed(); private Q_SLOTS: void slotQualityMetricChanged( int ); - void slotSelectReference(); - void slotCreatePlot(); + void slotSelectCurrentAsReference(); + void slotPlotQualitySingle(); + void slotPlotQualitySeveral(); }; } // NAMESPACE diff --git a/app/QualityMeasurementSidebar.cpp b/app/QualityMeasurementSidebar.cpp index e140dd4..b8772bc 100644 --- a/app/QualityMeasurementSidebar.cpp +++ b/app/QualityMeasurementSidebar.cpp @@ -56,15 +56,17 @@ QualityMeasurementSidebar::QualityMeasurementSidebar( QWidget* parent, PlaYUVerS m_comboBoxMetric->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); m_comboBoxRef = new QComboBox; - m_comboBoxRef->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLength ); + QSpacerItem* spaceQuality = new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed ); + //m_comboBoxRef->setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLength ); m_comboBoxRef->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); updateSubWindowList(); QGridLayout *mainLayout = new QGridLayout; mainLayout->addWidget( MetricLabel, 0, 0, Qt::AlignLeft ); mainLayout->addWidget( m_comboBoxMetric, 0, 1, Qt::AlignLeft ); + mainLayout->addItem( spaceQuality, 0, 2, Qt::AlignRight ); mainLayout->addWidget( RefLabel, 1, 0, Qt::AlignLeft ); - mainLayout->addWidget( m_comboBoxRef, 1, 1, Qt::AlignLeft ); + mainLayout->addWidget( m_comboBoxRef, 1, 1, 1, 2, Qt::AlignLeft ); m_ppcLabelQualityLabel[LUMA] = new QLabel( "PSNR Y:" ); m_ppcLabelQualityLabel[LUMA]->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); @@ -134,7 +136,7 @@ Void QualityMeasurementSidebar::updateSubWindowList() m_pcVideoWindowList.clear(); VideoSubWindow* pcVideoSubWindow; - QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowHandle::VIDEO_SUBWINDOW ); + QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW ); for( Int i = 0; i < subWindowList.size(); i++ ) { pcVideoSubWindow = qobject_cast( subWindowList.at( i ) ); @@ -185,7 +187,7 @@ Void QualityMeasurementSidebar::updateCurrentWindow( VideoSubWindow *subWindow ) Void QualityMeasurementSidebar::updateSidebarData() { - QString value( "0.0000" ); + QString zeroValue( "0.0000" ); if( m_pcCurrentVideoSubWindow ) { VideoSubWindow* refSubWindow = m_pcCurrentVideoSubWindow->getRefSubWindow(); @@ -194,12 +196,18 @@ Void QualityMeasurementSidebar::updateSidebarData() PlaYUVerFrame* currFrame = m_pcCurrentVideoSubWindow->getCurrFrame(); PlaYUVerFrame* refFrame = refSubWindow->getCurrFrame(); Double quality; - - for( Int component = 0; component < 3; component++ ) + QString value; + UInt component = 0; + for( ; component < currFrame->getNumberChannels(); component++ ) { quality = currFrame->getQuality( m_comboBoxMetric->currentIndex(), refFrame, component ); m_ppcLabelQualityValue[component]->setText( value.setNum( quality, 'f', 4 ) ); } + for( ; component < 3; component++ ) + { + quality = currFrame->getQuality( m_comboBoxMetric->currentIndex(), refFrame, component ); + m_ppcLabelQualityValue[component]->setText( zeroValue ); + } return; } else @@ -209,7 +217,7 @@ Void QualityMeasurementSidebar::updateSidebarData() } for( Int component = 0; component < 3; component++ ) { - m_ppcLabelQualityValue[component]->setText( value ); + m_ppcLabelQualityValue[component]->setText( zeroValue ); } } diff --git a/app/SubWindowAbstract.cpp b/app/SubWindowAbstract.cpp new file mode 100644 index 0000000..ab88e7a --- /dev/null +++ b/app/SubWindowAbstract.cpp @@ -0,0 +1,117 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file SubWindowAbstract.cpp + * \brief Abstract class to handle subwindows + */ + +#include +#include +#include +#include +#include +#include "SubWindowAbstract.h" +#include "PlaYUVerMdiSubWindow.h" + +namespace plaYUVer +{ + +SubWindowAbstract::SubWindowAbstract( QWidget * parent, UInt category ) : + QWidget( parent ), + m_cSubWindow( NULL ) +{ + setParent( parent ); + setVisible( false ); + setFocusPolicy( Qt::WheelFocus ); + setAttribute( Qt::WA_DeleteOnClose ); + setBackgroundRole( QPalette::Background ); + + setWindowIcon( QIcon( ":/images/playuver.png" ) ); + + //setWidgetResizable( true ); + m_pcLayout = NULL; + m_uiCategory = category; + m_cWindowName = QString( " " ); + + connect( this, SIGNAL( destroyed() ), this, SLOT( onDestroyed() ) ); +} + +SubWindowAbstract::~SubWindowAbstract() +{ + return; +} + +Void SubWindowAbstract::setWidget( QWidget* widget ) +{ + QGridLayout *layout = new QGridLayout( this ); + layout->setContentsMargins( 0, 0, 0, 0 ); + layout->addWidget( widget, 0, 0 ); +} + +void SubWindowAbstract::onDestroyed() +{ + return; +} + +Void SubWindowAbstract::setWindowName( QString name ) +{ + m_cWindowName = name; + setWindowTitle( m_cWindowName ); +} + +QString SubWindowAbstract::getWindowName() +{ + return m_cWindowName; +} + +Bool SubWindowAbstract::mayClose() +{ + return true; +} + +QSize SubWindowAbstract::sizeHint() const +{ + return QSize(); +} + +QSize SubWindowAbstract::sizeHint( const QSize & ) const +{ + return QSize(); +} + +Void SubWindowAbstract::focusInEvent( QFocusEvent * event ) +{ + emit aboutToActivate( this ); +} + +Void SubWindowAbstract::closeEvent( QCloseEvent *event ) +{ + emit aboutToClose( this ); + event->accept(); +} + +Void SubWindowAbstract::closeSubWindow() +{ + close(); + if( m_cSubWindow ) + m_cSubWindow->close(); +} + +} // NAMESPACE diff --git a/app/SubWindowHandle.h b/app/SubWindowAbstract.h similarity index 71% rename from app/SubWindowHandle.h rename to app/SubWindowAbstract.h index 8b77dc1..cd89aff 100644 --- a/app/SubWindowHandle.h +++ b/app/SubWindowAbstract.h @@ -18,9 +18,9 @@ */ /** - * \file SubWindowHandle.h + * \file SubWindowAbstract.h * \ingroup PlaYUVerApp PlaYUVerApp_Subwindow - * \brief Sub windows handling + * \brief Abstract class to handle subwindows * * @defgroup PlaYUVerApp_Subwindow SubWindow definition * @{ @@ -34,30 +34,31 @@ * @} */ -#ifndef __SUBWINDOWHANDLE_H__ -#define __SUBWINDOWHANDLE_H__ +#ifndef __SUBWINDOWABSTRACT_H__ +#define __SUBWINDOWABSTRACT_H__ #include "config.h" #include "PlaYUVerAppDefs.h" -#if( QT_VERSION_PLAYUVER == 5 ) -#include -#elif( QT_VERSION_PLAYUVER == 4 ) -#include -#endif +#include +#include +#include +#include + +class QHBoxLayout; +class QFocusEvent; +class QCloseEvent; namespace plaYUVer { class PlaYUVerMdiSubWindow; -class SubWindowHandle: public QScrollArea +class SubWindowAbstract: public QWidget { Q_OBJECT private: - QPoint m_cLastScroll; - QPoint m_cCurrScroll; - + QHBoxLayout* m_pcLayout; UInt m_uiCategory; QString m_cWindowName; @@ -73,8 +74,13 @@ public: PLOT_SUBWINDOW = 8, }; - SubWindowHandle( QWidget *, UInt ); - ~SubWindowHandle(); + SubWindowAbstract( QWidget *, UInt ); + ~SubWindowAbstract(); + + /** + * Show the image at its original size + */ + virtual Void refreshSubWindow() = 0; /** * Show the image at its original size @@ -105,7 +111,7 @@ public: /** * Size related functions */ - //virtual QSize sizeHint() const; + virtual QSize sizeHint() const; virtual QSize sizeHint( const QSize & ) const; /** @@ -117,11 +123,28 @@ public: virtual Bool mayClose(); + /** + * Get category of the SubWindow + * @return category value based on enum SubWindowCategories + * @note This function should be used with enum SubWindowCategories + * with an & operation and it may belong to several categories + */ UInt getCategory() { return m_uiCategory; } + /** + * Check category of the SubWindow + * @param checkCateory SubWindow category to check against; + * it should be enum SubWindowCategories type + * @return true when SubWindow belong to checkCateory + */ + Bool checkCategory( UInt checkCateory ) + { + return m_uiCategory & checkCateory; + } + Void setSubWindow( PlaYUVerMdiSubWindow* subWindow ) { m_cSubWindow = subWindow; @@ -130,9 +153,10 @@ public: Void closeSubWindow(); protected: - void focusInEvent( QFocusEvent * event ); - void closeEvent( QCloseEvent *event ); - QSize getScrollSize(); + void focusInEvent( QFocusEvent* event ); + void closeEvent( QCloseEvent* event ); + + Void setWidget( QWidget* widget ); Q_SIGNALS: /** @@ -148,19 +172,15 @@ Q_SIGNALS: */ void updateStatusBar( const QString& ); - void aboutToActivate( SubWindowHandle* ); - void aboutToClose( SubWindowHandle* ); + void aboutToActivate( SubWindowAbstract* ); + void aboutToClose( SubWindowAbstract* ); public Q_SLOTS: void onDestroyed(); - void adjustScrollBarByScale( double scale, QPoint center ); - void adjustScrollBarByOffset( QPoint Offset ); - void updateCurScrollValues(); - void setCurScrollValues(); }; } // NAMESPACE -#endif // __SUBWINDOWHANDLE_H__ +#endif // __SUBWINDOWABSTRACT_H__ diff --git a/app/SubWindowHandle.cpp b/app/SubWindowHandle.cpp deleted file mode 100644 index 7830ba9..0000000 --- a/app/SubWindowHandle.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* This file is a part of plaYUVer project - * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** - * \file SubWindowHandle.cpp - * \brief Sub windows handling - */ - -#include "SubWindowHandle.h" -#include "PlaYUVerMdiSubWindow.h" -namespace plaYUVer -{ - -SubWindowHandle::SubWindowHandle( QWidget * parent, UInt category ) : - QScrollArea( parent ), - m_cSubWindow( NULL ) -{ - setParent( parent ); - setFocusPolicy( Qt::WheelFocus ); - setAttribute( Qt::WA_DeleteOnClose ); - setBackgroundRole( QPalette::Background ); - - setWindowIcon( QIcon( ":/images/playuver.png" ) ); - - // Create a new scroll area inside the sub-window - connect( horizontalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateCurScrollValues() ) ); - connect( verticalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateCurScrollValues() ) ); - - setWidgetResizable( true ); - - m_uiCategory = category; - m_cLastScroll = QPoint(); - m_cWindowName = QString( " " ); - - connect(this, SIGNAL(destroyed()), this, SLOT(onDestroyed())); -} - -void SubWindowHandle::onDestroyed() -{ - return; -} - -SubWindowHandle::~SubWindowHandle() -{ - return; -} - -QSize SubWindowHandle::getScrollSize() -{ - return QSize( viewport()->size().width() - 5, viewport()->size().height() - 5 ); -} - -Void SubWindowHandle::adjustScrollBarByOffset( QPoint Offset ) -{ - QPoint cLastScroll = m_cCurrScroll; - QScrollBar *scrollBarH, *scrollBarV; - Int valueX, valueY; - - valueX = int( cLastScroll.x() + Offset.x() ); - valueY = int( cLastScroll.y() + Offset.y() ); - - scrollBarH = horizontalScrollBar(); - if( valueX > scrollBarH->maximum() ) - valueX = scrollBarH->maximum(); - if( valueX < scrollBarH->minimum() ) - valueX = scrollBarH->minimum(); - m_cCurrScroll.setX(valueX); - - scrollBarV = verticalScrollBar(); - if( valueY > scrollBarV->maximum() ) - valueY = scrollBarV->maximum(); - if( valueY < scrollBarV->minimum() ) - valueY = scrollBarV->minimum(); - m_cCurrScroll.setY( valueY ); - - // Update window scroll - scrollBarH->setValue( m_cCurrScroll.x() ); - scrollBarV->setValue( m_cCurrScroll.y() ); -} - -// This function was developed with help of the schematics presented in -// http://stackoverflow.com/questions/13155382/jscrollpane-zoom-relative-to-mouse-position -Void SubWindowHandle::adjustScrollBarByScale( Double scale, QPoint center ) -{ - QPoint cLastScroll = m_cCurrScroll; - QScrollBar *scrollBarH, *scrollBarV; - - scrollBarH = horizontalScrollBar(); - if( center.isNull() ) - { - m_cCurrScroll.setX(int( scale * cLastScroll.x() + ( ( scale - 1 ) * scrollBarH->pageStep() / 2 ) )); - } - else - { - Int x = center.x() - cLastScroll.x(); - Int value = int( scale * cLastScroll.x() + ( ( scale - 1 ) * x ) ); - if( value > scrollBarH->maximum() ) - value = scrollBarH->maximum(); - if( value < scrollBarH->minimum() ) - value = scrollBarH->minimum(); - m_cCurrScroll.setX(value); - } - - scrollBarV = verticalScrollBar(); - if( center.isNull() ) - { - m_cCurrScroll.setY(int( scale * cLastScroll.y() + ( ( scale - 1 ) * scrollBarV->pageStep() / 2 ) )); - } - else - { - Int y = center.y() - cLastScroll.y(); - Int value = int( scale * cLastScroll.y() + ( ( scale - 1 ) * y ) ); - if( value > scrollBarV->maximum() ) - value = scrollBarV->maximum(); - if( value < scrollBarV->minimum() ) - value = scrollBarV->minimum(); - m_cCurrScroll.setY(value); - } - - // Update window scroll - scrollBarH->setValue( m_cCurrScroll.x() ); - scrollBarV->setValue( m_cCurrScroll.y() ); - -} - -Void SubWindowHandle::updateCurScrollValues() -{ - QScrollBar *scrollBar = horizontalScrollBar(); - m_cCurrScroll.setX( scrollBar->value() ); - scrollBar = verticalScrollBar(); - m_cCurrScroll.setY( scrollBar->value() ); -} - -Void SubWindowHandle::setCurScrollValues() -{ - QScrollBar *scrollBar = horizontalScrollBar(); - scrollBar->setValue(m_cCurrScroll.x() ); - scrollBar = verticalScrollBar(); - scrollBar->setValue(m_cCurrScroll.y() ); -} - -Void SubWindowHandle::setWindowName( QString name ) -{ - m_cWindowName = name; - setWindowTitle( m_cWindowName ); -} - -QString SubWindowHandle::getWindowName() -{ - return m_cWindowName; -} - -Bool SubWindowHandle::mayClose() -{ - return true; -} - -QSize SubWindowHandle::sizeHint( const QSize & ) const -{ - return QSize(); -} - -Void SubWindowHandle::focusInEvent( QFocusEvent * event ) -{ - emit aboutToActivate( this ); -} - -Void SubWindowHandle::closeEvent( QCloseEvent *event ) -{ - emit aboutToClose( this ); - event->accept(); -} - -Void SubWindowHandle::closeSubWindow() -{ - close(); - if( m_cSubWindow ) - m_cSubWindow->close(); -} - -} // NAMESPACE diff --git a/app/VideoHandle.cpp b/app/VideoHandle.cpp index 759dafb..7d53411 100644 --- a/app/VideoHandle.cpp +++ b/app/VideoHandle.cpp @@ -22,10 +22,20 @@ * \brief Class to handle video playback */ -#include -#include "PlaYUVerSubWindowHandle.h" +#include "PlaYUVerApp.h" #include "VideoHandle.h" +#include "VideoSubWindow.h" +#include "PlaYUVerSubWindowHandle.h" #include "DialogSubWindowSelector.h" +#include "FramePropertiesDock.h" +#include "WidgetFrameNumber.h" +#include +#include +#include +#include +#include +#include +#include #if( _CONTROL_PLAYING_TIME_ == 1 ) #include #endif @@ -121,6 +131,7 @@ QToolBar* VideoHandle::createToolBar() m_toolbarVideo->addAction( m_arrayActions[STOP_ACT] ); QLabel* pcLockLabel = new QLabel( "PlayingLock", this ); + pcLockLabel->setAlignment( Qt::AlignCenter ); m_arrayActions[VIDEO_LOCK_ACT] = m_toolbarVideo->addWidget( pcLockLabel ); m_arrayActions[VIDEO_LOCK_ACT]->setVisible( false ); @@ -136,7 +147,7 @@ QToolBar* VideoHandle::createToolBar() QDockWidget* VideoHandle::createDock() { - m_pcFramePropertiesSideBar = new FramePropertiesSideBar( this, &m_bIsPlaying ); + m_pcFramePropertiesSideBar = new FramePropertiesDock( this, &m_bIsPlaying ); m_pcFramePropertiesDock = new QDockWidget( tr( "Frame Information" ), this ); m_pcFramePropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); m_pcFramePropertiesDock->setWidget( m_pcFramePropertiesSideBar ); @@ -232,19 +243,20 @@ Void VideoHandle::update() total_frame_num = getMaxFrameNumber(); resolution.append( QString( "@%1" ).arg( pcStream->getFrameRate() ) ); } - else - { - m_pcFrameNumInfo->setCurrFrameNum( 0 ); - } if( pcFrame ) + { + resolution.append( QString( " %1 bpp" ).arg( pcFrame->getBitsPel() ) ); m_pcResolutionLabel->setText( resolution ); + } m_pcFramePropertiesSideBar->setData( pcFrame, m_pcCurrentVideoSubWindow->isPlaying() ); - m_pcFrameSlider->setValue( frame_num ); - m_pcFrameSlider->setMaximum( total_frame_num - 1 ); m_pcFrameNumInfo->setTotalFrameNum( total_frame_num ); + m_pcFrameSlider->setMaximum( total_frame_num - 1 ); + + m_pcFrameNumInfo->setCurrFrameNum( frame_num ); + m_pcFrameSlider->setValue( frame_num ); if( m_pcCurrentVideoSubWindow->isPlaying() ) m_arrayActions[PLAY_ACT]->setIcon( style()->standardIcon( QStyle::SP_MediaPause ) ); @@ -276,11 +288,13 @@ Void VideoHandle::updateSelectionArea( QRect area ) } } -Void VideoHandle::closeSubWindow( VideoSubWindow* currSubWindow ) +Void VideoHandle::closeSubWindow( SubWindowAbstract* subWindow ) { - if( m_acPlayingSubWindows.contains( currSubWindow ) ) + VideoSubWindow* videoSubWindow = qobject_cast( subWindow ); + + if( m_acPlayingSubWindows.contains( videoSubWindow ) ) { - Int pos = m_acPlayingSubWindows.indexOf( currSubWindow ); + Int pos = m_acPlayingSubWindows.indexOf( videoSubWindow ); m_acPlayingSubWindows.at( pos )->stop(); m_acPlayingSubWindows.remove( pos ); if( m_acPlayingSubWindows.size() < 2 ) @@ -299,8 +313,8 @@ Void VideoHandle::zoomToFactorAll( const Double scale, const QPoint center ) factor = m_pcCurrentVideoSubWindow->getScaleFactor(); - SubWindowHandle *subWindow; - QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowHandle::VIDEO_SUBWINDOW ); + SubWindowAbstract *subWindow; + QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW ); for( Int i = 0; i < subWindowList.size(); i++ ) { subWindow = subWindowList.at( i ); @@ -319,11 +333,11 @@ Void VideoHandle::moveAllScrollBars( const QPoint offset ) QPoint newOffset = offset; if( m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->isChecked() ) { - SubWindowHandle *subWindow; - QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowHandle::VIDEO_SUBWINDOW ); + VideoSubWindow *videoSubWindow; + QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW ); QScrollBar *scrollBar; - scrollBar = m_pcCurrentVideoSubWindow->horizontalScrollBar(); + scrollBar = m_pcCurrentVideoSubWindow->getScroll()->horizontalScrollBar(); // Do not move other images, if current image reached maximum or minimum scroll position if( scrollBar->value() == scrollBar->maximum() && offset.x() > 0 ) @@ -331,7 +345,7 @@ Void VideoHandle::moveAllScrollBars( const QPoint offset ) if( scrollBar->value() == scrollBar->minimum() && offset.x() < 0 ) newOffset.setX( 0 ); - scrollBar = m_pcCurrentVideoSubWindow->verticalScrollBar(); + scrollBar = m_pcCurrentVideoSubWindow->getScroll()->verticalScrollBar(); if( scrollBar->value() == scrollBar->maximum() && offset.y() > 0 ) newOffset.setY( 0 ); if( scrollBar->value() == scrollBar->minimum() && offset.y() < 0 ) @@ -339,12 +353,12 @@ Void VideoHandle::moveAllScrollBars( const QPoint offset ) for( Int i = 0; i < subWindowList.size(); i++ ) { - subWindow = subWindowList.at( i ); - if( m_pcCurrentVideoSubWindow == subWindow ) + videoSubWindow = qobject_cast( subWindowList.at( i ) ); + if( m_pcCurrentVideoSubWindow == videoSubWindow ) continue; else { - subWindow->adjustScrollBarByOffset( newOffset ); + videoSubWindow->adjustScrollBarByOffset( newOffset ); } } } @@ -401,12 +415,12 @@ Void VideoHandle::setTimerStatus() else { #if( _CONTROL_PLAYING_TIME_ == 1 ) - if( m_pcPlayControlTimer ) + if( m_pcPlayControlTimer && m_pcPlayingTimer->interval() > 0 ) { qDebug( ) << "Desired Fps: " - << 1000 / m_pcPlayingTimer->interval() - << "Real Fps: " - << 1000 / m_dAverageFps; + << 1000 / m_pcPlayingTimer->interval() + << "Real Fps: " + << 1000 / m_dAverageFps; delete m_pcPlayControlTimer; m_pcPlayControlTimer = NULL; @@ -570,29 +584,21 @@ Void VideoHandle::seekSliderEvent( Int new_frame_num ) Void VideoHandle::videoSelectionButtonEvent() { - DialogSubWindowSelector dialogWindowsSelection( this, m_pcMainWindowManager, SubWindowHandle::VIDEO_STREAM_SUBWINDOW ); + DialogSubWindowSelector dialogWindowsSelection( this, m_pcMainWindowManager, SubWindowAbstract::VIDEO_STREAM_SUBWINDOW ); QStringList cWindowListNames; for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) { - cWindowListNames.append( m_acPlayingSubWindows.at( i )->getWindowName() ); - dialogWindowsSelection.setSubWindowList( cWindowListNames ); + dialogWindowsSelection.selectSubWindow( m_acPlayingSubWindows.at( i ) ); } if( dialogWindowsSelection.exec() == QDialog::Accepted ) { - QStringList selectedWindows = dialogWindowsSelection.getSelectedWindows(); m_acPlayingSubWindows.clear(); VideoSubWindow *videoSubWindow; - QString windowName; - QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowHandle::VIDEO_STREAM_SUBWINDOW ); - for( Int i = 0; i < subWindowList.size(); i++ ) + QList selectedSubWindowList = dialogWindowsSelection.getSelectedWindows(); + for( Int i = 0; i < selectedSubWindowList.size(); i++ ) { - videoSubWindow = qobject_cast( subWindowList.at( i ) ); - windowName = videoSubWindow->getWindowName(); - if( selectedWindows.contains( windowName ) ) - { - m_acPlayingSubWindows.append( videoSubWindow ); - videoSubWindow->seekAbsoluteEvent( m_acPlayingSubWindows.at( 0 )->getInputStream()->getCurrFrameNum() ); - } + videoSubWindow = qobject_cast( selectedSubWindowList.at( i ) ); + m_acPlayingSubWindows.append( videoSubWindow ); } if( m_acPlayingSubWindows.size() > 0 ) { diff --git a/app/VideoHandle.h b/app/VideoHandle.h index 1dc13e0..60d6c90 100644 --- a/app/VideoHandle.h +++ b/app/VideoHandle.h @@ -27,25 +27,29 @@ #include "config.h" #include "PlaYUVerAppDefs.h" -#include -#if( QT_VERSION_PLAYUVER == 5 ) -#include -#elif( QT_VERSION_PLAYUVER == 4 ) -#include -#endif -#include "VideoSubWindow.h" -#include "WidgetFrameNumber.h" -#include "FramePropertiesSidebar.h" -#define _CONTROL_PLAYING_TIME_ 1 +#include +#include +#include +#include +#define _CONTROL_PLAYING_TIME_ 0 + +class QToolBar; +class QDockWidget; +class QSignalMapper; +class QLabel; +class QSlider; class QElapsedTimer; namespace plaYUVer { class PlaYUVerSubWindowHandle; +class SubWindowAbstract; class VideoSubWindow; +class FramePropertiesDock; +class WidgetFrameNumber; class VideoHandle: public QWidget { @@ -66,8 +70,6 @@ public: Void update( VideoSubWindow* currSubWindow ); - Void closeSubWindow( VideoSubWindow* currSubWindow ); - private: QWidget* m_pcParet; PlaYUVerSubWindowHandle* m_pcMainWindowManager; @@ -93,7 +95,7 @@ private: QToolBar* m_toolbarVideo; QDockWidget* m_pcFramePropertiesDock; - FramePropertiesSideBar* m_pcFramePropertiesSideBar; + FramePropertiesDock* m_pcFramePropertiesSideBar; QLabel* m_pcVideoFormatLabel; QLabel* m_pcResolutionLabel; @@ -119,6 +121,7 @@ Q_SIGNALS: private Q_SLOTS: void update(); void updateSelectionArea( QRect area ); + void closeSubWindow( SubWindowAbstract* subWindow ); void zoomToFactorAll( const double factor, const QPoint center = QPoint() ); void moveAllScrollBars( const QPoint offset ); void play(); diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index f3c049b..479590d 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -24,8 +24,9 @@ #include "VideoSubWindow.h" #include "ModulesHandle.h" -#include "SubWindowHandle.h" #include "ConfigureFormatDialog.h" +#include "SubWindowAbstract.h" +#include #if( QT_VERSION_PLAYUVER == 5 ) #include "QtConcurrent/qtconcurrentrun.h" #endif @@ -43,6 +44,7 @@ QDataStream& operator<<( QDataStream& out, const PlaYUVerStreamInfoVector& array out << d.m_cFilename << d.m_uiWidth << d.m_uiHeight << d.m_iPelFormat + << d.m_uiBitsPelPixel << d.m_uiFrameRate << d.m_uiFileSize; } @@ -60,6 +62,7 @@ QDataStream& operator>>( QDataStream& in, PlaYUVerStreamInfoVector& array ) in >> d.m_uiWidth; in >> d.m_uiHeight; in >> d.m_iPelFormat; + in >> d.m_uiBitsPelPixel; in >> d.m_uiFrameRate; in >> d.m_uiFileSize; array.append( d ); @@ -76,7 +79,7 @@ Int findPlaYUVerStreamInfo( PlaYUVerStreamInfoVector array, QString filename ) } VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget * parent ) : - SubWindowHandle( parent, SubWindowHandle::VIDEO_SUBWINDOW | category ), + SubWindowAbstract( parent, SubWindowAbstract::VIDEO_SUBWINDOW | category ), m_pCurrStream( NULL ), m_pcCurrFrame( NULL ), m_pcCurrentDisplayModule( NULL ), @@ -84,10 +87,14 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget m_bIsPlaying( false ), m_bIsModule( category == MODULE_SUBWINDOW ) { - setVisible( false ); + + // Create a new scroll area inside the sub-window + m_pcScrollArea = new QScrollArea; + connect( m_pcScrollArea->horizontalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateCurScrollValues() ) ); + connect( m_pcScrollArea->verticalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateCurScrollValues() ) ); // Create a new interface to show images - m_cViewArea = new ViewArea( this ); + m_cViewArea = new ViewArea; connect( m_cViewArea, SIGNAL( zoomFactorChanged_byWheel( double , QPoint) ), this, SLOT( adjustScrollBarByScale( double, QPoint ) ) ); connect( m_cViewArea, SIGNAL( zoomFactorChanged_byWheel( double , QPoint) ), this, SIGNAL( zoomFactorChanged_SWindow( double, QPoint ) ) ); @@ -97,12 +104,18 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget connect( m_cViewArea, SIGNAL( selectionChanged( QRect ) ), this, SLOT( updateSelectedArea( QRect ) ) ); connect( m_cViewArea, SIGNAL( positionChanged( const QPoint & ) ), this, SLOT( updatePixelValueStatusBar( const QPoint & ) ) ); - setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); - setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + m_pcScrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + m_pcScrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); // Define the cViewArea as the widget inside the scroll area - m_cViewArea->setMinimumSize( size() ); - setWidget( m_cViewArea ); + // m_cViewArea->setMinimumSize( size() ); + + m_pcScrollArea->setWidget( m_cViewArea ); + m_pcScrollArea->setWidgetResizable( true ); + + setWidget( m_pcScrollArea ); + + m_cLastScroll = QPoint(); m_apcCurrentModule.clear(); @@ -110,6 +123,7 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget VideoSubWindow::~VideoSubWindow() { + m_pcCurrFrame = NULL; disableModule(); delete m_cViewArea; if( m_pCurrStream ) @@ -118,35 +132,46 @@ VideoSubWindow::~VideoSubWindow() Void VideoSubWindow::loadAll() { + QApplication::setOverrideCursor( Qt::WaitCursor ); m_pCurrStream->loadAll(); refreshFrame(); + QApplication::restoreOverrideCursor(); } -Void VideoSubWindow::reloadFile() +Void VideoSubWindow::refreshSubWindow() { - Int currFrameNum = m_pCurrStream->getCurrFrameNum(); - loadFile( m_cFilename, false ); - seekAbsoluteEvent( currFrameNum ); + if( getCategory() & SubWindowAbstract::VIDEO_STREAM_SUBWINDOW ) + { + Int currFrameNum = m_pCurrStream->getCurrFrameNum(); + if( !loadFile( m_cFilename, false ) ) + { + close(); + return; + } + seekAbsoluteEvent( currFrameNum ); + } + else + { + refreshFrame(); + } } Bool VideoSubWindow::loadFile( QString cFilename, Bool bForceDialog ) { - UInt Width = 0, Height = 0, FrameRate = 30; + UInt Width = 0, Height = 0, BitsPel = 8, FrameRate = 30; Int InputFormat = PlaYUVerFrame::YUV420p; if( m_pCurrStream ) - m_pCurrStream->getFormat( Width, Height, InputFormat, FrameRate ); + m_pCurrStream->getFormat( Width, Height, InputFormat, BitsPel, FrameRate ); if( guessFormat( cFilename, Width, Height, InputFormat, FrameRate ) || bForceDialog ) { ConfigureFormatDialog formatDialog( this ); - if( formatDialog.runConfigureFormatDialog( QFileInfo( cFilename ).fileName(), Width, Height, InputFormat, FrameRate ) == QDialog::Rejected ) + if( formatDialog.runConfigureFormatDialog( QFileInfo( cFilename ).fileName(), Width, Height, InputFormat, BitsPel, FrameRate ) == QDialog::Rejected ) { return false; } } - QApplication::setOverrideCursor( Qt::WaitCursor ); - QApplication::restoreOverrideCursor(); if( !m_pCurrStream ) { @@ -158,12 +183,13 @@ Bool VideoSubWindow::loadFile( QString cFilename, Bool bForceDialog ) m_pCurrStream = new PlaYUVerStream; } - m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, FrameRate ); + m_pCurrStream->open( cFilename.toStdString(), Width, Height, InputFormat, BitsPel, FrameRate ); m_sStreamInfo.m_cFilename = cFilename; m_sStreamInfo.m_uiWidth = Width; m_sStreamInfo.m_uiHeight = Height; m_sStreamInfo.m_iPelFormat = InputFormat; + m_sStreamInfo.m_uiBitsPelPixel = BitsPel; m_sStreamInfo.m_uiFrameRate = FrameRate; m_sStreamInfo.m_uiFileSize = QFileInfo( cFilename ).size(); @@ -190,7 +216,7 @@ Bool VideoSubWindow::loadFile( PlaYUVerStreamInfo* streamInfo ) } if( !m_pCurrStream->open( streamInfo->m_cFilename.toStdString(), streamInfo->m_uiWidth, streamInfo->m_uiHeight, streamInfo->m_iPelFormat, - streamInfo->m_uiFrameRate ) ) + streamInfo->m_uiBitsPelPixel, streamInfo->m_uiFrameRate ) ) { return false; } @@ -214,23 +240,23 @@ Bool VideoSubWindow::loadFile( PlaYUVerStreamInfo* streamInfo ) Void VideoSubWindow::updateVideoWindowInfo() { - if( m_pCurrStream ) + m_cStreamInformation = ""; + if( m_pcCurrentDisplayModule ) + { + m_cStreamInformation = "Module"; + } + else if( m_pCurrStream ) { QString m_cFormatName = QString::fromStdString( m_pCurrStream->getFormatName() ); QString m_cCodedName = QString::fromStdString( m_pCurrStream->getCodecName() ); - QString m_cPelFmtName = QString::fromStdString( m_pCurrStream->getPelFmtName() ); - m_cStreamInformation = m_cFormatName + " | " + m_cCodedName + " | " + m_cPelFmtName; + m_cStreamInformation = m_cFormatName + " | " + m_cCodedName; } - else if( m_pcCurrFrame ) + if( m_pcCurrFrame ) { - if( m_bIsModule || m_pcCurrentDisplayModule ) - { - m_cStreamInformation = "Module | "; - } - QString m_cPelFmtName = QString::fromStdString( PlaYUVerFrame::supportedPixelFormatListNames()[m_pcCurrFrame->getPelFormat()].c_str() ); - m_cStreamInformation += m_cPelFmtName; + QString m_cPelFmtName = QString::fromStdString( m_pcCurrFrame->getPelFmtName() ); + m_cStreamInformation += " | " + m_cPelFmtName; } - else + if( m_cStreamInformation.isEmpty() ) { m_cStreamInformation = " "; } @@ -309,7 +335,7 @@ Bool VideoSubWindow::guessFormat( QString filename, UInt& rWidth, UInt& rHeight, Int count = 0, module, frame_bytes, match; for( UInt i = 0; i < stdResList.size(); i++ ) { - frame_bytes = PlaYUVerFrame::getBytesPerFrame( stdResList[i].uiWidth, stdResList[i].uiHeight, rInputFormat ); + frame_bytes = PlaYUVerFrame::getBytesPerFrame( stdResList[i].uiWidth, stdResList[i].uiHeight, rInputFormat, 8 ); module = uiFileSize % frame_bytes; if( module == 0 ) { @@ -391,8 +417,8 @@ Void VideoSubWindow::disableModule( PlaYUVerAppModuleIf* pcModule ) } if( bRefresh ) { - updateVideoWindowInfo(); refreshFrame(); + updateVideoWindowInfo(); } } @@ -403,8 +429,12 @@ Void VideoSubWindow::associateModule( PlaYUVerAppModuleIf* pcModule ) Void VideoSubWindow::setCurrFrame( PlaYUVerFrame* pcCurrFrame ) { - m_pcCurrFrame = pcCurrFrame; - m_cViewArea->setImage( m_pcCurrFrame ); + // if( m_pcCurrFrame ) + { + m_pcCurrFrame = pcCurrFrame; + m_cViewArea->setImage( m_pcCurrFrame ); + updateVideoWindowInfo(); + } } Void VideoSubWindow::refreshFrameOperation() @@ -535,6 +565,100 @@ Void VideoSubWindow::stop() return; } +QSize VideoSubWindow::getScrollSize() +{ + return QSize( m_pcScrollArea->viewport()->size().width() - 5, m_pcScrollArea->viewport()->size().height() - 5 ); +} + +Void VideoSubWindow::adjustScrollBarByOffset( QPoint Offset ) +{ + QPoint cLastScroll = m_cCurrScroll; + QScrollBar *scrollBarH, *scrollBarV; + Int valueX, valueY; + + valueX = int( cLastScroll.x() + Offset.x() ); + valueY = int( cLastScroll.y() + Offset.y() ); + + scrollBarH = m_pcScrollArea->horizontalScrollBar(); + if( valueX > scrollBarH->maximum() ) + valueX = scrollBarH->maximum(); + if( valueX < scrollBarH->minimum() ) + valueX = scrollBarH->minimum(); + m_cCurrScroll.setX( valueX ); + + scrollBarV = m_pcScrollArea->verticalScrollBar(); + if( valueY > scrollBarV->maximum() ) + valueY = scrollBarV->maximum(); + if( valueY < scrollBarV->minimum() ) + valueY = scrollBarV->minimum(); + m_cCurrScroll.setY( valueY ); + + // Update window scroll + scrollBarH->setValue( m_cCurrScroll.x() ); + scrollBarV->setValue( m_cCurrScroll.y() ); +} + +// This function was developed with help of the schematics presented in +// http://stackoverflow.com/questions/13155382/jscrollpane-zoom-relative-to-mouse-position +Void VideoSubWindow::adjustScrollBarByScale( Double scale, QPoint center ) +{ + QPoint cLastScroll = m_cCurrScroll; + QScrollBar *scrollBarH, *scrollBarV; + + scrollBarH = m_pcScrollArea->horizontalScrollBar(); + if( center.isNull() ) + { + m_cCurrScroll.setX( int( scale * cLastScroll.x() + ( ( scale - 1 ) * scrollBarH->pageStep() / 2 ) ) ); + } + else + { + Int x = center.x() - cLastScroll.x(); + Int value = int( scale * cLastScroll.x() + ( ( scale - 1 ) * x ) ); + if( value > scrollBarH->maximum() ) + value = scrollBarH->maximum(); + if( value < scrollBarH->minimum() ) + value = scrollBarH->minimum(); + m_cCurrScroll.setX( value ); + } + + scrollBarV = m_pcScrollArea->verticalScrollBar(); + if( center.isNull() ) + { + m_cCurrScroll.setY( int( scale * cLastScroll.y() + ( ( scale - 1 ) * scrollBarV->pageStep() / 2 ) ) ); + } + else + { + Int y = center.y() - cLastScroll.y(); + Int value = int( scale * cLastScroll.y() + ( ( scale - 1 ) * y ) ); + if( value > scrollBarV->maximum() ) + value = scrollBarV->maximum(); + if( value < scrollBarV->minimum() ) + value = scrollBarV->minimum(); + m_cCurrScroll.setY( value ); + } + + // Update window scroll + scrollBarH->setValue( m_cCurrScroll.x() ); + scrollBarV->setValue( m_cCurrScroll.y() ); + +} + +Void VideoSubWindow::updateCurScrollValues() +{ + QScrollBar *scrollBar = m_pcScrollArea->horizontalScrollBar(); + m_cCurrScroll.setX( scrollBar->value() ); + scrollBar = m_pcScrollArea->verticalScrollBar(); + m_cCurrScroll.setY( scrollBar->value() ); +} + +Void VideoSubWindow::setCurScrollValues() +{ + QScrollBar *scrollBar = m_pcScrollArea->horizontalScrollBar(); + scrollBar->setValue( m_cCurrScroll.x() ); + scrollBar = m_pcScrollArea->verticalScrollBar(); + scrollBar->setValue( m_cCurrScroll.y() ); +} + Void VideoSubWindow::normalSize() { Double factor = 1.0; @@ -680,17 +804,17 @@ QSize VideoSubWindow::sizeHint( const QSize & maxSize ) const return isize; } -Void VideoSubWindow::closeEvent( QCloseEvent *event ) -{ - Bool bAccept = m_bIsPlaying ? false : true; - if( bAccept ) - { - event->accept(); - } - else - { - event->ignore(); - } -} +//Void VideoSubWindow::closeEvent( QCloseEvent *event ) +//{ +// Bool bAccept = m_bIsPlaying ? false : true; +// if( bAccept ) +// { +// event->accept(); +// } +// else +// { +// event->ignore(); +// } +//} -} // NAMESPACE +}// NAMESPACE diff --git a/app/VideoSubWindow.h b/app/VideoSubWindow.h index 2208f15..8654e00 100644 --- a/app/VideoSubWindow.h +++ b/app/VideoSubWindow.h @@ -26,17 +26,18 @@ #define __VIDEOSUBWINDOW_H__ #include "config.h" +#include +#include +#include +#include +#include #include "PlaYUVerAppDefs.h" -#if( QT_VERSION_PLAYUVER == 5 ) -#include -#elif( QT_VERSION_PLAYUVER == 4 ) -#include -#endif -#include "QFuture" #include "lib/PlaYUVerStream.h" -#include "SubWindowHandle.h" +#include "SubWindowAbstract.h" #include "ViewArea.h" +class QScrollArea; + namespace plaYUVer { @@ -49,6 +50,7 @@ typedef struct UInt m_uiWidth; UInt m_uiHeight; Int m_iPelFormat; + UInt m_uiBitsPelPixel; UInt m_uiFrameRate; UInt64 m_uiFileSize; } PlaYUVerStreamInfo; @@ -58,12 +60,16 @@ QDataStream& operator<<( QDataStream& out, const PlaYUVerStreamInfoVector& d ); QDataStream& operator>>( QDataStream& in, PlaYUVerStreamInfoVector& d ); Int findPlaYUVerStreamInfo( PlaYUVerStreamInfoVector array, QString filename ); -class VideoSubWindow: public SubWindowHandle +class VideoSubWindow: public SubWindowAbstract { Q_OBJECT private: + QScrollArea* m_pcScrollArea; + QPoint m_cLastScroll; + QPoint m_cCurrScroll; + ViewArea* m_cViewArea; QString m_cFilename; @@ -102,9 +108,10 @@ private: * zoom to fit */ Void scaleView( const QSize & size, QPoint center = QPoint() ); - Void updateVideoWindowInfo(); + QSize getScrollSize(); + public: enum VideoSubWindowCategories { @@ -117,9 +124,10 @@ public: Bool loadFile( QString cFilename, Bool bForceDialog = false ); Bool loadFile( PlaYUVerStreamInfo* streamInfo ); Void loadAll(); - Void reloadFile(); Bool save( QString filename ); + Void refreshSubWindow(); + Bool play(); Void pause(); Bool playEvent(); @@ -135,6 +143,10 @@ public: Void setCurrFrame( PlaYUVerFrame* pcCurrFrame ); + QScrollArea* getScroll() + { + return m_pcScrollArea; + } PlaYUVerStreamInfo getStreamInfo() { return m_sStreamInfo; @@ -187,7 +199,11 @@ public: QList getModuleArray() { - return m_apcCurrentModule; + QList apcModulesArray; + if( m_pcCurrentDisplayModule ) + apcModulesArray.append( m_pcCurrentDisplayModule ); + apcModulesArray.append( m_apcCurrentModule ); + return apcModulesArray; } Void setTool( UInt uiTool ) @@ -196,7 +212,7 @@ public: } /** - * Virtual functions from SubWindowHandle + * Virtual functions from SubWindowAbstract */ Void normalSize(); Void zoomToFit(); @@ -232,10 +248,14 @@ public: return m_bIsModule; } -protected: - void closeEvent( QCloseEvent *event ); +//protected: + //void closeEvent( QCloseEvent *event ); public Q_SLOTS: + void adjustScrollBarByScale( double scale, QPoint center ); + void adjustScrollBarByOffset( QPoint Offset ); + void updateCurScrollValues(); + void setCurScrollValues(); void updateSelectedArea( QRect area ); void updatePixelValueStatusBar( const QPoint& pos ); }; diff --git a/app/ViewArea.cpp b/app/ViewArea.cpp index 0d44545..6ebb6c7 100644 --- a/app/ViewArea.cpp +++ b/app/ViewArea.cpp @@ -71,6 +71,7 @@ ViewArea::ViewArea( QWidget *parent ) : void ViewArea::setImage( PlaYUVerFrame* pcFrame ) { m_pcCurrFrame = pcFrame; + m_uiPixelHalfScale = 1 << ( m_pcCurrFrame->getBitsPel() - 1 ); m_pcCurrFrame->fillRGBBuffer(); QImage qimg = QImage( m_pcCurrFrame->getRGBBuffer(), m_pcCurrFrame->getWidth(), m_pcCurrFrame->getHeight(), QImage::Format_RGB32 ); setImage( QPixmap::fromImage( qimg ) ); @@ -122,29 +123,28 @@ Double ViewArea::scaleZoomFactor( Double scale, QPoint center, QSize minimumSize return new_scale; Double zoomFactor = m_zoomFactor * scale * 100.0; - zoomFactor=round(zoomFactor); - zoomFactor=zoomFactor/100.0; - scale = zoomFactor/m_zoomFactor; + zoomFactor = round( zoomFactor ); + zoomFactor = zoomFactor / 100.0; + scale = zoomFactor / m_zoomFactor; - - if(!minimumSize.isNull()) + if( !minimumSize.isNull() ) { - Double cw = m_pixmap.width()*m_zoomFactor; - Double ch = m_pixmap.height()*m_zoomFactor; - Double fw = m_pixmap.width()*zoomFactor; - Double fh = m_pixmap.height()*zoomFactor; + Double cw = m_pixmap.width() * m_zoomFactor; + Double ch = m_pixmap.height() * m_zoomFactor; + Double fw = m_pixmap.width() * zoomFactor; + Double fh = m_pixmap.height() * zoomFactor; Double mw = minimumSize.width(); Double mh = minimumSize.height(); - if( (cw < mw) && (ch < mh) && (scale < 1) ) + if( ( cw < mw ) && ( ch < mh ) && ( scale < 1 ) ) { return new_scale; } - if( (fw < mw) && (fh < mh) && (scale < 1) ) + if( ( fw < mw ) && ( fh < mh ) && ( scale < 1 ) ) { - Double wfactor = mw/fw; - Double hfactor = mh/fh; + Double wfactor = mw / fw; + Double hfactor = mh / fh; if( wfactor < hfactor ) scale = wfactor; @@ -152,9 +152,9 @@ Double ViewArea::scaleZoomFactor( Double scale, QPoint center, QSize minimumSize scale = hfactor; zoomFactor = zoomFactor * scale * 100.0; - zoomFactor=round(zoomFactor); - zoomFactor=zoomFactor/100.0; - scale = zoomFactor/m_zoomFactor; + zoomFactor = round( zoomFactor ); + zoomFactor = zoomFactor / 100.0; + scale = zoomFactor / m_zoomFactor; } } @@ -163,14 +163,14 @@ Double ViewArea::scaleZoomFactor( Double scale, QPoint center, QSize minimumSize if( zoomFactor < minZoom ) { zoomFactor = minZoom; - new_scale = zoomFactor/m_zoomFactor; + new_scale = zoomFactor / m_zoomFactor; } else { if( zoomFactor > maxZoom ) { zoomFactor = maxZoom; - new_scale = zoomFactor/m_zoomFactor; + new_scale = zoomFactor / m_zoomFactor; } } @@ -335,7 +335,7 @@ void ViewArea::paintEvent( QPaintEvent *event ) { QRect winRect = event->rect(); - if(visibleRegion().isEmpty()) + if( visibleRegion().isEmpty() ) return; if( size().isEmpty() || m_pixmap.isNull() ) @@ -384,13 +384,12 @@ void ViewArea::paintEvent( QPaintEvent *event ) painter.restore(); - // Draw a border around the image. -/* if( m_xOffset || m_yOffset ) - { - painter.setPen( Qt::black ); - painter.drawRect( m_xOffset - 1, m_yOffset - 1, m_pixmap.width() * m_zoomFactor + 1, m_pixmap.height() * m_zoomFactor + 1 ); - }*/ + /* if( m_xOffset || m_yOffset ) + { + painter.setPen( Qt::black ); + painter.drawRect( m_xOffset - 1, m_yOffset - 1, m_pixmap.width() * m_zoomFactor + 1, m_pixmap.height() * m_zoomFactor + 1 ); + }*/ // Draw pixel values in grid if( m_zoomFactor >= 50.0 ) @@ -420,7 +419,7 @@ void ViewArea::paintEvent( QPaintEvent *event ) { sPixelValue = m_pcCurrFrame->getPixelValue( pixelTopLeft.x(), pixelTopLeft.y() ); - if( sPixelValue.Y() < 128 ) + if( sPixelValue.Y() < m_uiPixelHalfScale ) painter.setPen( QColor( Qt::white ) ); else painter.setPen( QColor( Qt::black ) ); @@ -433,7 +432,7 @@ void ViewArea::paintEvent( QPaintEvent *event ) { sPixelValue = m_pcCurrFrame->getPixelValue( pixelTopLeft.x(), pixelTopLeft.y() ); - if( sPixelValue.Y() < 128 ) + if( sPixelValue.Y() < m_uiPixelHalfScale ) painter.setPen( QColor( Qt::white ) ); else painter.setPen( QColor( Qt::black ) ); @@ -445,7 +444,7 @@ void ViewArea::paintEvent( QPaintEvent *event ) { sPixelValue = m_pcCurrFrame->getPixelValue( pixelTopLeft.x(), pixelTopLeft.y() ); - if( ( sPixelValue.R() + sPixelValue.G() + sPixelValue.B() ) < 128 * 3 ) + if( ( sPixelValue.R() + sPixelValue.G() + sPixelValue.B() ) < ( m_uiPixelHalfScale * 3 ) ) painter.setPen( QColor( Qt::white ) ); else painter.setPen( QColor( Qt::black ) ); @@ -457,7 +456,6 @@ void ViewArea::paintEvent( QPaintEvent *event ) } } - QColor color( Qt::white ); QPen mainPen = QPen( color, 1, Qt::SolidLine ); painter.setPen( mainPen ); @@ -540,7 +538,7 @@ void ViewArea::paintEvent( QPaintEvent *event ) QRect imgr = viewToWindow( QRect( 0, 0, m_pixmap.width(), m_pixmap.height() ) ); myPath.addRect( imgr ); - myPath.addRect( sr); //m_selectedArea + myPath.addRect( sr ); //m_selectedArea painter.drawPath( myPath ); // 2) Draw the selection rectangle @@ -627,14 +625,14 @@ void ViewArea::wheelEvent( QWheelEvent *event ) if( event->modifiers() & Qt::ControlModifier ) { scale = 0.001 * event->delta(); - if(scale>0) - scale=1.25; + if( scale > 0 ) + scale = 1.25; else - scale=0.8; + scale = 0.8; QWidget *p = parentWidget(); QSize minimumSize = QSize( p->size().width() - 5, p->size().height() - 5 ); - usedScale = scaleZoomFactor( scale , event->pos(), minimumSize ); + usedScale = scaleZoomFactor( scale, event->pos(), minimumSize ); if( usedScale != 1.0 ) { emit zoomFactorChanged_byWheel( usedScale, event->pos() ); @@ -763,7 +761,7 @@ void ViewArea::mouseMoveEvent( QMouseEvent *event ) // From left to right if( m_lastPos.x() < actualPos.x() ) { - QPoint bottomR = actualPos;// - QPoint( 1, 1 ); + QPoint bottomR = actualPos; // - QPoint( 1, 1 ); m_selectedArea = QRect( m_lastPos, bottomR ); } // From right to left @@ -788,7 +786,7 @@ void ViewArea::mouseMoveEvent( QMouseEvent *event ) // From right to left else { - QPoint bottomR = m_lastPos;// - QPoint( 1, 1 ); + QPoint bottomR = m_lastPos; // - QPoint( 1, 1 ); m_selectedArea = QRect( actualPos, bottomR ); } } @@ -895,57 +893,56 @@ void ViewArea::mouseReleaseEvent( QMouseEvent *event ) } } - //////////////////////////////////////////////////////////////////////////////// bool ViewArea::isPosValid( const QPoint &pos ) const { -if( pos.x() < 0 || pos.y() < 0 || pos.x() >= m_pixmap.width() || pos.y() >= m_pixmap.height() ) - return false; -else - return true; + if( pos.x() < 0 || pos.y() < 0 || pos.x() >= m_pixmap.width() || pos.y() >= m_pixmap.height() ) + return false; + else + return true; } //////////////////////////////////////////////////////////////////////////////// QPoint ViewArea::windowToView( const QPoint& pt ) const { -QPoint p; -p.setX( static_cast( ( pt.x() - m_xOffset ) / m_zoomFactor ) ); -p.setY( static_cast( ( pt.y() - m_yOffset ) / m_zoomFactor ) ); + QPoint p; + p.setX( static_cast( ( pt.x() - m_xOffset ) / m_zoomFactor ) ); + p.setY( static_cast( ( pt.y() - m_yOffset ) / m_zoomFactor ) ); -return p; + return p; } QRect ViewArea::windowToView( const QRect& rc ) const { -QRect r; + QRect r; -r.setTopLeft( windowToView( rc.topLeft() ) ); + r.setTopLeft( windowToView( rc.topLeft() ) ); // r.setRight ( (int)( ceil(( rc.right() - m_xOffset)/m_zoomFactor ))); // r.setBottom( (int)( ceil(( rc.bottom()- m_yOffset)/m_zoomFactor ))); // r.setRight ( static_cast(( rc.right() - m_xOffset ) / m_zoomFactor +1)); // r.setBottom( static_cast(( rc.bottom() - m_xOffset ) / m_zoomFactor+1)); -r.setBottomRight( windowToView( rc.bottomRight() ) ); -return r; + r.setBottomRight( windowToView( rc.bottomRight() ) ); + return r; } QPoint ViewArea::viewToWindow( const QPoint& pt ) const { -QPoint p; + QPoint p; -p.setX( static_cast( pt.x() * m_zoomFactor + m_xOffset ) ); -p.setY( static_cast( pt.y() * m_zoomFactor + m_yOffset ) ); + p.setX( static_cast( pt.x() * m_zoomFactor + m_xOffset ) ); + p.setY( static_cast( pt.y() * m_zoomFactor + m_yOffset ) ); -return p; + return p; } QRect ViewArea::viewToWindow( const QRect& rc ) const { -QRect r; + QRect r; -r.setTopLeft( viewToWindow( rc.topLeft() ) ); + r.setTopLeft( viewToWindow( rc.topLeft() ) ); // r.setRight ( (int)( ceil(( rc.right() +1+m_xOffset )*m_zoomFactor ) - 1 )); // r.setBottom( (int)( ceil(( rc.bottom()+1+m_yOffset )*m_zoomFactor ) - 1 )); // r.setRight ( (int)( ceil(( rc.right()+0.5)*m_zoomFactor )+ m_xOffset )-1); @@ -953,9 +950,9 @@ r.setTopLeft( viewToWindow( rc.topLeft() ) ); // qDebug()<<"Right = "<< r.right(); // r.setRight ( static_cast(( rc.right()+1) * m_zoomFactor + m_xOffset -1) ); // r.setBottom( static_cast(( rc.bottom()+1) * m_zoomFactor + m_yOffset -1)); -r.setBottomRight( viewToWindow( rc.bottomRight() ) ); + r.setBottomRight( viewToWindow( rc.bottomRight() ) ); -return r; + return r; } //////////////////////////////////////////////////////////////////////////////// @@ -963,41 +960,41 @@ return r; //////////////////////////////////////////////////////////////////////////////// void ViewArea::updateMask( const QRect &rect ) { -switch( tool() ) -{ -case MaskTool: -{ - // Add rect to the mask - QPainter painter( &m_mask ); - painter.setBrush( Qt::color1 ); - painter.setPen( Qt::NoPen ); - painter.drawRect( rect ); - painter.end(); - break; -} -case EraserTool: -{ - // Clears rect area in the mask - QPainter painter( &m_mask ); - painter.setBrush( Qt::color0 ); - painter.setPen( Qt::NoPen ); - painter.drawRect( rect ); - painter.end(); - break; -} -default: /* Do Nothing */ - ; -} + switch( tool() ) + { + case MaskTool: + { + // Add rect to the mask + QPainter painter( &m_mask ); + painter.setBrush( Qt::color1 ); + painter.setPen( Qt::NoPen ); + painter.drawRect( rect ); + painter.end(); + break; + } + case EraserTool: + { + // Clears rect area in the mask + QPainter painter( &m_mask ); + painter.setBrush( Qt::color0 ); + painter.setPen( Qt::NoPen ); + painter.drawRect( rect ); + painter.end(); + break; + } + default: /* Do Nothing */ + ; + } } void ViewArea::setInputStream( PlaYUVerStream *stream ) { -m_pStream = stream; + m_pStream = stream; } PlaYUVerStream* ViewArea::getInputStream() { -return m_pStream; + return m_pStream; } } // NameSpace plaYUVer diff --git a/app/ViewArea.h b/app/ViewArea.h index 4a1d4bd..dafec9f 100644 --- a/app/ViewArea.h +++ b/app/ViewArea.h @@ -51,7 +51,8 @@ public: enum ViewMode { - NormalMode, MaskMode, + NormalMode, + MaskMode, }; typedef enum { @@ -60,7 +61,7 @@ public: BlockSelectionTool, MaskTool, EraserTool - }eTool; + } eTool; ViewArea( QWidget *parent = 0 ); @@ -116,7 +117,7 @@ public: PlaYUVerStream* getInputStream(); // Scale function. Return used scale value (it may change when it touches the min or max zoom value) - Double scaleZoomFactor(Double scale, QPoint center, QSize minimumSize); + Double scaleZoomFactor( Double scale, QPoint center, QSize minimumSize ); void setTool( eTool tool ); @@ -126,7 +127,7 @@ Q_SIGNALS: void selectionChanged( const QRect &rect ); void positionChanged( const QPoint &pos ); void scrollBarMoved( QPoint offset ); - void zoomFactorChanged_byWheel( const double factor , const QPoint center); + void zoomFactorChanged_byWheel( const double factor, const QPoint center ); public Q_SLOTS: void setNormalMode(); @@ -163,6 +164,7 @@ private: QRect viewToWindow( const QRect& rc ) const; PlaYUVerFrame *m_pcCurrFrame; + Pel m_uiPixelHalfScale; QPixmap m_pixmap; QBitmap m_mask; QRect m_selectedArea; @@ -185,6 +187,6 @@ private: }; -} // NameSpace plaYUVer +} // NameSpace plaYUVer #endif // __VIEWAREA_H__ diff --git a/app/main.cpp b/app/main.cpp index 3e04ea1..4c86951 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -23,10 +23,10 @@ */ #include "config.h" -#include "PlaYUVerAppDefs.h" #include -#include "plaYUVerApp.h" -#include "SubWindowHandle.h" +#include "PlaYUVerAppDefs.h" +#include "PlaYUVerApp.h" +#include "VideoSubWindow.h" #ifdef USE_QTDBUS #include "PlaYUVerAppAdaptor.h" #endif @@ -48,8 +48,7 @@ int main( int argc, char *argv[] ) QApplication application( argc, argv ); QApplication::setApplicationName( "PlaYUVer" ); QApplication::setApplicationVersion( PLAYUVER_VERSION_STRING ); - QApplication::setOrganizationName( "pixlra" ); - QApplication::setOrganizationDomain( "playuver.pixlra" ); + QApplication::setOrganizationName( "PixLRA" ); #ifdef USE_QTDBUS /** @@ -93,33 +92,32 @@ int main( int argc, char *argv[] ) QStringList tokens; // open given files... - foreach(const QString & file, filenameList) + foreach(const QString & file, filenameList){ + QDBusMessage m = QDBusMessage::createMethodCall(PLAYUVER_DBUS_SESSION_NAME, + QStringLiteral(PLAYUVER_DBUS_PATH), QStringLiteral(PLAYUVER_DBUS_SESSION_NAME), QStringLiteral("loadFile")); + + QList dbusargs; + dbusargs.append( file ); + m.setArguments(dbusargs); + + QDBusMessage res = QDBusConnection::sessionBus().call(m); + if (res.type() == QDBusMessage::ReplyMessage) { - QDBusMessage m = QDBusMessage::createMethodCall(PLAYUVER_DBUS_SESSION_NAME, - QStringLiteral(PLAYUVER_DBUS_PATH), QStringLiteral(PLAYUVER_DBUS_SESSION_NAME), QStringLiteral("loadFile")); - - QList dbusargs; - dbusargs.append( file ); - m.setArguments(dbusargs); - - QDBusMessage res = QDBusConnection::sessionBus().call(m); - if (res.type() == QDBusMessage::ReplyMessage) + if (res.arguments().count() == 1) { - if (res.arguments().count() == 1) + QVariant v = res.arguments()[0]; + if (v.isValid()) { - QVariant v = res.arguments()[0]; - if (v.isValid()) + QString s = v.toString(); + if ((!s.isEmpty()) && (s != QStringLiteral("ERROR"))) { - QString s = v.toString(); - if ((!s.isEmpty()) && (s != QStringLiteral("ERROR"))) - { - tokens << s; - } + tokens << s; } } } } - // this will wait until exiting is emitted by the used instance, if wanted... + } + // this will wait until exiting is emitted by the used instance, if wanted... return needToBlock ? application.exec() : 0; } } @@ -129,13 +127,16 @@ int main( int argc, char *argv[] ) */ QDBusConnection::sessionBus().registerService( PLAYUVER_DBUS_SESSION_NAME ); #endif - plaYUVerApp mainwindow; + PlaYUVerApp mainwindow; mainwindow.show(); - mainwindow.parseArgs( argc, argv ); + if( mainwindow.parseArgs( argc, argv ) ) + { + return 0; + } #ifdef USE_FERVOR - FvUpdater::sharedUpdater()->SetFeedURL("http://192.168.96.201/share/PlaYUVerProject/PlaYUVerUpdate-" UPDATE_CHANNEL ".xml"); - FvUpdater::sharedUpdater()->SetDependencies("ALL"); + FvUpdater::sharedUpdater()->SetFeedURL( "http://192.168.96.201/share/PlaYUVerProject/PlaYUVerUpdate-" UPDATE_CHANNEL ".xml" ); + FvUpdater::sharedUpdater()->SetDependencies( "ALL" ); #endif return application.exec(); diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 758c9ae..89182f9 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -46,7 +46,7 @@ CONFIGURE_FILE( PlaYUVerConfig.cmake.in ${CMAKE_BINARY_DIR}/PlaYUVerConfig.cmake ADD_LIBRARY( PlaYUVerLib STATIC ${plaYUver_Lib_SRCS} ) INCLUDE_DIRECTORIES( ${FFMPEG_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} ) -TARGET_LINK_LIBRARIES( PlaYUVerLib ${FFMPEG_LIBRARIES} ${OpenCV_LIBRARIES} ${Boost_LIBRARIES} ) +TARGET_LINK_LIBRARIES( PlaYUVerLib ${FFMPEG_LIBRARIES} ${OpenCV_LIBRARIES} ) INSTALL(FILES ${plaYUver_Lib_HEADERS} DESTINATION include ) # INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libPlaYUVerLib${CMAKE_STATIC_LIBRARY_SUFFIX} DESTINATION lib ) diff --git a/lib/LibAvContextHandle.cpp b/lib/LibAvContextHandle.cpp index f9c5055..4c0c3aa 100644 --- a/lib/LibAvContextHandle.cpp +++ b/lib/LibAvContextHandle.cpp @@ -216,10 +216,10 @@ Bool LibAvContextHandle::initAvFormat( const char* filename, UInt& width, UInt& frame_rate = fr; /*if( video_stream->nb_frames ) - { - num_frames = video_stream->nb_frames; - } - else*/ if( fmt_ctx->duration != AV_NOPTS_VALUE ) + { + num_frames = video_stream->nb_frames; + } + else*/if( fmt_ctx->duration != AV_NOPTS_VALUE ) { Int64 duration = fmt_ctx->duration + 5000; m_uiSecs = duration / AV_TIME_BASE; @@ -316,8 +316,7 @@ Bool LibAvContextHandle::decodeVideoPkt() { pkt.size = 0; } - Bool bRet = got_frame > 0 ? true : false; - return bRet; + return got_frame > 0 ? true : false; } Bool LibAvContextHandle::decodeAvFormat() @@ -356,7 +355,8 @@ Bool LibAvContextHandle::decodeAvFormat() av_image_copy_to_buffer( m_pchFrameBuffer, m_uiFrameBufferSize, frame->data, frame->linesize, video_dec_ctx->pix_fmt, video_dec_ctx->width, video_dec_ctx->height, 1 ); - av_free_packet( &orig_pkt ); + if( orig_pkt.size ) + av_free_packet( &orig_pkt ); return true; } diff --git a/lib/LibOpenCVHandler.cpp b/lib/LibOpenCVHandler.cpp index ea191b8..a28516b 100644 --- a/lib/LibOpenCVHandler.cpp +++ b/lib/LibOpenCVHandler.cpp @@ -66,95 +66,23 @@ std::vector LibOpenCVHandler::supportedWriteFormatsName() std::vector LibOpenCVHandler::supportedSaveFormatsExt() { - std::vector formatsExt; - formatsExt.push_back( "bmp" ); - formatsExt.push_back( "bmp" ); - formatsExt.push_back( "jpg" ); - formatsExt.push_back( "png" ); - return formatsExt; + return supportedReadFormatsExt(); } std::vector LibOpenCVHandler::supportedSaveFormatsName() { - std::vector formatsName; - formatsName.push_back( "Windows Bitmap" ); - formatsName.push_back( "Windows Bitmap" ); - formatsName.push_back( "Joint Photographic Experts Group" ); - formatsName.push_back( "Portable Network Graphics" ); - return formatsName; + return supportedReadFormatsName(); } PlaYUVerFrame* LibOpenCVHandler::loadFrame( std::string filename ) { - cv::Mat pcCvFrame = cv::imread( filename ); - Int cvChannels = pcCvFrame.channels(); - std::string pelFormatName; - Int iPelFormat = -1; - switch( cvChannels ) - { - case 1: - pelFormatName = "GRAY"; - break; - case 3: - pelFormatName = "BRG24"; - break; - default: - return NULL; - } - - for( UInt i = 0; i < PlaYUVerFrame::supportedPixelFormatListNames().size(); i++ ) - { - if( PlaYUVerFrame::supportedPixelFormatListNames()[i] == pelFormatName ) - { - iPelFormat = i; - break; - } - } - - if( iPelFormat >= 0 ) - { - PlaYUVerFrame* pcFrame = new PlaYUVerFrame( pcCvFrame.cols, pcCvFrame.rows, iPelFormat ); - pcFrame->frameFromBuffer( pcCvFrame.ptr(), pcFrame->getBytesPerFrame() ); - return pcFrame; - } return NULL; } Bool LibOpenCVHandler::saveFrame( PlaYUVerFrame* pcFrame, std::string filename ) { - Int cvType = CV_8UC3; - switch( pcFrame->getNumberChannels() ) - { - case 3: - cvType = CV_8UC3; - break; - case 1: - cvType = CV_8UC1; - break; - default: - return false; - break; - } - - cv::Mat pcCvFrame( pcFrame->getHeight(), pcFrame->getWidth(), cvType ); - - if( pcFrame->getColorSpace() != PlaYUVerFrame::COLOR_GRAY ) - { - UChar* pCvPel = pcCvFrame.data; - UChar* pARGB = pcFrame->getRGBBuffer(); - for( UInt i = 0; i < pcFrame->getHeight() * pcFrame->getWidth(); i++ ) - { - *pCvPel++ = *pARGB++; - *pCvPel++ = *pARGB++; - *pCvPel++ = *pARGB++; - pARGB++; - } - } - else - { - memcpy( pcCvFrame.data, pcFrame->getPelBufferYUV()[LUMA][0], pcFrame->getHeight() * pcFrame->getWidth() * sizeof(Pel) ); - } - return cv::imwrite( filename, pcCvFrame ); + cv::Mat* pcCvFrame = pcFrame->getCvMat(); + return cv::imwrite( filename, *pcCvFrame ); } } // NAMESPACE diff --git a/lib/LibOpenCVHandler.h b/lib/LibOpenCVHandler.h index c310068..257ba5e 100644 --- a/lib/LibOpenCVHandler.h +++ b/lib/LibOpenCVHandler.h @@ -55,8 +55,6 @@ public: static PlaYUVerFrame* loadFrame( std::string filename ); static Bool saveFrame( PlaYUVerFrame* pcFrame, std::string filename ); -private: - std::string m_cFilename; }; } // NAMESPACE diff --git a/lib/PlaYUVerCmdParser.cpp b/lib/PlaYUVerCmdParser.cpp index 65bda94..bee40bc 100644 --- a/lib/PlaYUVerCmdParser.cpp +++ b/lib/PlaYUVerCmdParser.cpp @@ -55,17 +55,22 @@ Options& PlaYUVerCmdParser::Opts() return m_cParserOptions; } -Bool PlaYUVerCmdParser::parse( Int argc, Char *argv[] ) +std::list& PlaYUVerCmdParser::getNoArgs() +{ + return m_aUnhandledArgs; +} + +Bool PlaYUVerCmdParser::parse() { try { // m_cParserOptions.setDefaults(); - const std::list& argv_unhandled = scanArgv( m_cParserOptions, argc, ( const Char** )argv ); + m_aUnhandledArgs = m_cParserOptions.scanArgv( m_iArgc, ( const Char** )m_ppArgv ); - for( std::list::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++ ) - { - fprintf( stderr, "Unhandled argument ignored: `%s'\n", *it ); - } + // for( std::list::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++ ) + // { + // fprintf( stderr, "Unhandled argument ignored: `%s'\n", *it ); + // } if( checkListingOpts() ) { @@ -86,16 +91,32 @@ Bool PlaYUVerCmdParser::parse( Int argc, Char *argv[] ) return true; } +Bool PlaYUVerCmdParser::parse( Options& opts, Int argc, Char *argv[] ) +{ + try + { + // m_cParserOptions.setDefaults(); + m_aUnhandledArgs = opts.scanArgv( argc, ( const Char** )argv ); + + } + catch( std::exception& e ) + { + std::cerr << "error: " + << e.what() + << "\n"; + return false; + } + catch( ... ) + { + std::cerr << "Exception of unknown type!\n"; + } + return true; +} + Bool PlaYUVerCmdParser::checkListingOpts() { Bool bRet = false; - if( m_cParserOptions["help"]->count() ) - { - doHelp( std::cout, m_cParserOptions ); - bRet |= true; - } - if( m_cParserOptions["version"]->count() ) { std::cout << "PlaYUVer version " @@ -112,6 +133,15 @@ Bool PlaYUVerCmdParser::checkListingOpts() } bRet |= true; } + if( Opts()["quality_metrics"]->count() ) + { + printf( "PlaYUVer supported quality metrics: \n" ); + for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ ) + { + printf( " %s\n", PlaYUVerFrame::supportedQualityMetricsList()[i].c_str() ); + } + bRet |= true; + } return bRet; } diff --git a/lib/PlaYUVerCmdParser.h b/lib/PlaYUVerCmdParser.h index e602b6e..75ea8c7 100644 --- a/lib/PlaYUVerCmdParser.h +++ b/lib/PlaYUVerCmdParser.h @@ -25,7 +25,6 @@ #include "PlaYUVerDefs.h" #include "ProgramOptions.h" - namespace plaYUVer { @@ -35,12 +34,23 @@ public: PlaYUVerCmdParser(); ~PlaYUVerCmdParser(); - Bool parse( Int argc, Char *argv[] ); + Void config( Int argc, Char *argv[] ) + { + m_iArgc = argc; + m_ppArgv = argv; + } + Bool parse(); + Bool parse( Options& opts, Int argc, Char *argv[] ); + std::list& getNoArgs(); Options& Opts(); private: + Int m_iArgc; + Char** m_ppArgv; Options m_cParserOptions; + std::list m_aUnhandledArgs; Bool checkListingOpts(); + Void listModules(); }; } // NAMESPACE diff --git a/lib/PlaYUVerDefs.h b/lib/PlaYUVerDefs.h index fa07c3e..00c2985 100644 --- a/lib/PlaYUVerDefs.h +++ b/lib/PlaYUVerDefs.h @@ -18,13 +18,13 @@ */ /** - * \file TypeDef.h + * \file PlaYUVerDefs.h * \ingroup PlaYUVerLib * \brief Define basic types, new types and enumerations */ -#ifndef __TYPEDEF_H__ -#define __TYPEDEF_H__ +#ifndef __PLAYUVERDEFS_H__ +#define __PLAYUVERDEFS_H__ #include #include @@ -75,8 +75,8 @@ typedef unsigned long long UInt64; // Type definition // ==================================================================================================================== -typedef UChar Pel; ///< 8-bit pixel type -//typedef Short Pel; ///< 16-bit pixel type +typedef UShort Pel; ///< 16-bit pixel type +typedef UChar Byte; // ==================================================================================================================== // Limits definition @@ -106,6 +106,14 @@ typedef UChar Pel; ///< 8-bit pixel type // PlaYUVer definitions // ==================================================================================================================== +enum LOG_LEVEL +{ + LOG_INFO = 1, + LOG_WARNINGS = 2, + LOG_RESULT = 3, + LOG_ERROR = 4, +}; + enum YUVcomponent { LUMA = 0, @@ -130,4 +138,4 @@ inline std::string lowercase( const std::string& in ) } // NAMESPACE -#endif // __TYPEDEF_H__ +#endif // __PLAYUVERDEFS_H__ diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index 386875e..ef90a67 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -42,6 +42,15 @@ namespace plaYUVer { +std::vector PlaYUVerFrame::supportedColorSpacesListNames() +{ + std::vector colorSpaceList; + colorSpaceList.push_back( "YUV" ); + colorSpaceList.push_back( "RGB" ); + colorSpaceList.push_back( "GRAY" ); + return colorSpaceList; +} + std::vector PlaYUVerFrame::supportedPixelFormatListNames() { std::vector formatsList; @@ -53,6 +62,18 @@ std::vector PlaYUVerFrame::supportedPixelFormatListNames() return formatsList; } +std::vector PlaYUVerFrame::supportedPixelFormatListNames( Int colorSpace ) +{ + std::vector formatsList; + Int numberFormats = PLAYUVER_NUMBER_FORMATS; + for( Int i = 0; i < numberFormats; i++ ) + { + if( g_PlaYUVerPixFmtDescriptorsList[i].colorSpace == colorSpace ) + formatsList.push_back( g_PlaYUVerPixFmtDescriptorsList[i].name ); + } + return formatsList; +} + PlaYUVerFrame::Pixel PlaYUVerFrame::ConvertPixel( Pixel inputPixel, ColorSpace eOutputSpace ) { Int outA, outB, outC; @@ -78,20 +99,19 @@ PlaYUVerFrame::Pixel PlaYUVerFrame::ConvertPixel( Pixel inputPixel, ColorSpace e return outPixel; } -PlaYUVerFrame::PlaYUVerFrame( UInt width, UInt height, Int pel_format ) +PlaYUVerFrame::PlaYUVerFrame( UInt width, UInt height, Int pelFormat, Int bitsPixel ) { - init( width, height, pel_format ); + init( width, height, pelFormat, bitsPixel ); } PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other ) { - init( other->getWidth(), other->getHeight(), other->getPelFormat() ); + init( other->getWidth(), other->getHeight(), other->getPelFormat(), other->getBitsPel() ); copyFrom( other ); } PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other, UInt posX, UInt posY, UInt areaWidth, UInt areaHeight ) { - PlaYUVerPixFmtDescriptor* pcPelFormat = &( g_PlaYUVerPixFmtDescriptorsList[other->getPelFormat()] ); if( pcPelFormat->log2ChromaWidth ) { @@ -110,7 +130,7 @@ PlaYUVerFrame::PlaYUVerFrame( PlaYUVerFrame *other, UInt posX, UInt posY, UInt a areaHeight++; } - init( areaWidth, areaHeight, other->getPelFormat() ); + init( areaWidth, areaHeight, other->getPelFormat(), other->getBitsPel() ); copyFrom( other, posX, posY ); } @@ -159,7 +179,7 @@ static Int getMem3ImageComponents( Pel**** array3D, Int dim1, Int dim2, Int log2 return total_mem_size; } -Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format ) +Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format, Int bitsPixel ) { m_pppcInputPel = NULL; m_pcARGB32 = NULL; @@ -167,13 +187,11 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format ) m_uiHeight = height; m_iPixelFormat = pel_format; m_iNumberChannels = 3; - m_iBitsChannels = 8; + m_iBitsPel = bitsPixel > 8 ? bitsPixel : 8; - Int max_bits_per_pel = sizeof(Pel) * 8; - - if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || m_iBitsChannels > max_bits_per_pel ) + if( m_uiWidth == 0 || m_uiHeight == 0 || m_iPixelFormat == -1 || bitsPixel > 16 ) { - return; + throw "Cannot create a PlYUVerFrame of this type"; } m_pcPelFormat = &( g_PlaYUVerPixFmtDescriptorsList[pel_format] ); @@ -190,7 +208,7 @@ Void PlaYUVerFrame::init( UInt width, UInt height, Int pel_format ) getMem1D( &m_pcARGB32, m_uiHeight * m_uiWidth * 4 ); xSetupStatistics( this ); - openPixfc(); + m_cPelFmtName = PlaYUVerFrame::supportedPixelFormatListNames()[m_iPixelFormat].c_str(); } Int PlaYUVerFrame::getColorSpace() const @@ -205,28 +223,33 @@ UInt PlaYUVerFrame::getNumberChannels() const UInt64 PlaYUVerFrame::getBytesPerFrame() { - return getBytesPerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat ); + return getBytesPerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat, m_iBitsPel ); } -UInt64 PlaYUVerFrame::getBytesPerFrame( UInt uiWidth, UInt uiHeight, Int iPixelFormat ) +UInt64 PlaYUVerFrame::getBytesPerFrame( UInt uiWidth, UInt uiHeight, Int iPixelFormat, Int bitsPixel ) { PlaYUVerPixFmtDescriptor* pcPelFormat = &( g_PlaYUVerPixFmtDescriptorsList[iPixelFormat] ); + UInt bytesPerPixel = ( bitsPixel - 1 ) / 8 + 1; UInt64 numberBytes = uiWidth * uiHeight; if( pcPelFormat->numberChannels > 1 ) { UInt64 numberBytesChroma = CHROMASHIFT( uiWidth, pcPelFormat->log2ChromaWidth ) * CHROMASHIFT( uiHeight, pcPelFormat->log2ChromaHeight ); numberBytes += ( pcPelFormat->numberChannels - 1 ) * numberBytesChroma; } - return numberBytes; + return numberBytes * bytesPerPixel; } UInt PlaYUVerFrame::getChromaWidth() const { + if( m_pcPelFormat->colorSpace == GRAY ) + return 0; return CHROMASHIFT( m_uiWidth, m_pcPelFormat->log2ChromaWidth ); } UInt PlaYUVerFrame::getChromaHeight() const { + if( m_pcPelFormat->colorSpace == GRAY ) + return 0; return CHROMASHIFT( m_uiHeight, m_pcPelFormat->log2ChromaHeight ); } @@ -235,22 +258,24 @@ UInt PlaYUVerFrame::getChromaLength() const return getChromaWidth() * getChromaHeight(); } -Void PlaYUVerFrame::frameFromBuffer( Pel *Buff, UInt64 uiBuffSize ) +Void PlaYUVerFrame::frameFromBuffer( Byte *Buff, UInt64 uiBuffSize ) { if( uiBuffSize != getBytesPerFrame() ) return; - Pel* ppBuff[MAX_NUMBER_PLANES]; - Pel* pTmpPel, *pTmpBuff; + Byte* ppBuff[MAX_NUMBER_PLANES]; + Byte* pTmpBuff; + Pel* pTmpPel; + UInt bytesPixel = ( m_iBitsPel - 1 ) / 8 + 1; Int ratioH, ratioW, step; - UInt i, ch; + UInt i, ch, b; ppBuff[0] = Buff; - for( Int i = 1; i < MAX_NUMBER_PLANES; i++ ) + for( i = 1; i < MAX_NUMBER_PLANES; i++ ) { ratioW = i > 1 ? m_pcPelFormat->log2ChromaWidth : 0; ratioH = i > 1 ? m_pcPelFormat->log2ChromaHeight : 0; - ppBuff[i] = ppBuff[i - 1] + CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ); + ppBuff[i] = ppBuff[i - 1] + CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ) * bytesPixel; } for( ch = 0; ch < m_pcPelFormat->numberChannels; ch++ ) @@ -264,28 +289,35 @@ Void PlaYUVerFrame::frameFromBuffer( Pel *Buff, UInt64 uiBuffSize ) for( i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ); i++ ) { - *pTmpPel++ = *pTmpBuff; + *pTmpPel = *pTmpBuff; + for( b = 1; b < bytesPixel; b++ ) + { + pTmpBuff++; + *pTmpPel |= ( *pTmpBuff << ( 8 * b ) ); + } + pTmpPel++; pTmpBuff += step; } } - m_bHasRGBPel = false; m_bHasHistogram = false; } -Void PlaYUVerFrame::frameToBuffer( Pel *output_buffer ) +Void PlaYUVerFrame::frameToBuffer( Byte *output_buffer ) { - Pel* ppBuff[MAX_NUMBER_PLANES]; - Pel* pTmpPel, *pTmpBuff; + UInt bytesPixel = ( m_iBitsPel - 1 ) / 8 + 1; + Byte* ppBuff[MAX_NUMBER_PLANES]; + Byte* pTmpBuff; + Pel* pTmpPel; Int ratioH, ratioW, step; - UInt i, ch; + UInt i, ch, b; ppBuff[0] = output_buffer; for( Int i = 1; i < MAX_NUMBER_PLANES; i++ ) { ratioW = i > 1 ? m_pcPelFormat->log2ChromaWidth : 0; ratioH = i > 1 ? m_pcPelFormat->log2ChromaHeight : 0; - ppBuff[i] = ppBuff[i - 1] + CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ); + ppBuff[i] = ppBuff[i - 1] + CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ) * bytesPixel; } for( ch = 0; ch < m_pcPelFormat->numberChannels; ch++ ) @@ -299,7 +331,13 @@ Void PlaYUVerFrame::frameToBuffer( Pel *output_buffer ) for( i = 0; i < CHROMASHIFT( m_uiHeight, ratioH ) * CHROMASHIFT( m_uiWidth, ratioW ); i++ ) { - *pTmpBuff = *pTmpPel++; + *pTmpBuff = ( *pTmpPel & 0x00FF ); + for( b = 1; b < bytesPixel; b++ ) + { + pTmpBuff++; + *pTmpBuff = ( *pTmpPel >> ( 8 * b ) ) & 0x00FF; + } + pTmpPel++; pTmpBuff += step; } } @@ -310,24 +348,80 @@ Void PlaYUVerFrame::fillRGBBuffer() { if( m_bHasRGBPel ) return; - if( m_pcPelFormat->colorSpace == COLOR_RGB ) + Int iR, iG, iB; + Int shiftBits = m_iBitsPel - 8; + UInt* pARGB = ( UInt* )m_pcARGB32; + if( m_pcPelFormat->colorSpace == COLOR_GRAY ) + { + Pel* pY = m_pppcInputPel[LUMA][0]; + Int iY; + for( UInt i = 0; i < m_uiHeight * m_uiWidth; i++ ) + { + iY = *pY++; + iY >>= shiftBits; + iR = iY; + iG = iY; + iB = iY; + *pARGB++ = PEL_RGB( iR, iG, iB ); + } + } + else if( m_pcPelFormat->colorSpace == COLOR_RGB ) { Pel* pR = m_pppcInputPel[COLOR_R][0]; Pel* pG = m_pppcInputPel[COLOR_G][0]; Pel* pB = m_pppcInputPel[COLOR_B][0]; - Int iR, iG, iB; - UInt* pARGB = ( UInt* )m_pcARGB32; + for( UInt i = 0; i < m_uiHeight * m_uiWidth; i++ ) { iR = *pR++; iG = *pG++; iB = *pB++; - *pARGB++ = PEL_RGB( iR, iG, iB ); + *pARGB++ = PEL_RGB( ( iR >> shiftBits ), ( iG >> shiftBits ), ( iB >> shiftBits ) ); } } - else + else if( m_pcPelFormat->colorSpace == COLOR_YUV ) { - m_pcPelFormat->fillARGB32buffer( m_pppcInputPel, m_pcARGB32, m_uiWidth, m_uiHeight ); + Pel* pLineY = m_pppcInputPel[LUMA][0]; + Pel* pLineU = m_pppcInputPel[CHROMA_U][0]; + Pel* pLineV = m_pppcInputPel[CHROMA_V][0]; + UInt uiChromaStride = CHROMASHIFT( m_uiWidth, m_pcPelFormat->log2ChromaWidth ); + Pel* pY; + Pel* pU; + Pel* pV; + Int iY, iU, iV, iR, iG, iB; + UInt* pARGBLine = pARGB; + UInt* pARGB; + + UInt y, x; + Int i, j; + for( y = 0; y < m_uiHeight >> m_pcPelFormat->log2ChromaHeight; y++ ) + { + for( i = 0; i < 1 << m_pcPelFormat->log2ChromaHeight; i++ ) + { + pY = pLineY; + pU = pLineU; + pV = pLineV; + pARGB = pARGBLine; + for( x = 0; x < m_uiWidth >> m_pcPelFormat->log2ChromaWidth; x++ ) + { + iU = *pU++; + iU >>= shiftBits; + iV = *pV++; + iV >>= shiftBits; + for( j = 0; j < ( 1 << m_pcPelFormat->log2ChromaWidth ); j++ ) + { + iY = *pY++; + iY >>= shiftBits; + YUV2RGB( iY, iU, iV, iR, iG, iB ); + *pARGB++ = PEL_RGB( iR, iG, iB ); + } + } + pLineY += m_uiWidth; + pARGBLine += m_uiWidth; + } + pLineU += uiChromaStride; + pLineV += uiChromaStride; + } } m_bHasRGBPel = true; } @@ -431,47 +525,59 @@ Void PlaYUVerFrame::FrametoRGB8Pixfc() #endif } -Void PlaYUVerFrame::getCvMat( Void** ppCvFrame ) +cv::Mat* PlaYUVerFrame::getCvMat( Bool convertToGray ) { #ifdef USE_OPENCV - Int cvType = CV_8UC3; - switch( m_pcPelFormat->numberChannels ) + if( convertToGray && !( m_pcPelFormat->colorSpace == PlaYUVerFrame::COLOR_YUV || m_pcPelFormat->colorSpace == PlaYUVerFrame::COLOR_GRAY ) ) { - case 3: - cvType = CV_8UC4; - break; - case 1: - cvType = CV_8UC1; - break; - default: - break; + return NULL; } + Int cvType = CV_MAKETYPE( CV_8U, convertToGray ? 1 : m_pcPelFormat->numberChannels ); cv::Mat *pcCvFrame = new cv::Mat( m_uiHeight, m_uiWidth, cvType ); - if( m_pcPelFormat->colorSpace != PlaYUVerFrame::COLOR_GRAY ) + UChar* pCvPel = pcCvFrame->data; + if( !convertToGray && ( m_pcPelFormat->colorSpace == PlaYUVerFrame::COLOR_YUV || m_pcPelFormat->colorSpace == PlaYUVerFrame::COLOR_RGB ) ) { fillRGBBuffer(); - memcpy( pcCvFrame->data, m_pcARGB32, m_uiWidth * m_uiHeight * 4 * sizeof(UChar) ); + UChar* pARGB = m_pcARGB32; + for( UInt i = 0; i < m_uiWidth * m_uiHeight; i++ ) + { + *pCvPel++ = *pARGB++; + *pCvPel++ = *pARGB++; + *pCvPel++ = *pARGB++; + pARGB++; + } + } + else if( convertToGray || m_pcPelFormat->colorSpace == PlaYUVerFrame::COLOR_GRAY ) + { + Pel* pPel = m_pppcInputPel[LUMA][0]; + for( UInt i = 0; i < m_uiWidth * m_uiHeight; i++ ) + { + *pCvPel++ = *pPel++; + } } else { - memcpy( pcCvFrame->data, &( m_pppcInputPel[LUMA][0][0] ), m_uiWidth * m_uiHeight * sizeof(Pel) ); + if( pcCvFrame ) + delete pcCvFrame; + pcCvFrame = NULL; } - *ppCvFrame = pcCvFrame; + return pcCvFrame; +#else + return NULL; #endif } -Void PlaYUVerFrame::fromCvMat( Void* voidFrame ) +Void PlaYUVerFrame::fromCvMat( cv::Mat* pcCvFrame ) { #ifdef USE_OPENCV - cv::Mat* opencvFrame = ( cv::Mat* )voidFrame; if( m_iPixelFormat == NO_FMT ) { - switch( opencvFrame->channels() ) + switch( pcCvFrame->channels() ) { case 1: m_iPixelFormat = GRAY; break; - case 4: + case 3: m_iPixelFormat = RGB24; break; default: @@ -481,31 +587,32 @@ Void PlaYUVerFrame::fromCvMat( Void* voidFrame ) if( !isValid() ) { - init( opencvFrame->cols, opencvFrame->rows, m_iPixelFormat ); + init( pcCvFrame->cols, pcCvFrame->rows, m_iPixelFormat, 8 ); } m_bHasRGBPel = false; m_bHasHistogram = false; + UChar* pCvPel = pcCvFrame->data; if( m_iPixelFormat != GRAY ) { - Pel* pInputPelY = m_pppcInputPel[LUMA][0]; - Pel* pInputPelU = m_pppcInputPel[CHROMA_U][0]; - Pel* pInputPelV = m_pppcInputPel[CHROMA_V][0]; - Pel* pcRGBPelInterlaced = m_pcARGB32; - memcpy( pcRGBPelInterlaced, opencvFrame->data, m_uiWidth * m_uiHeight * 4 * sizeof(Pel) ); - UInt* buff = ( UInt* )pcRGBPelInterlaced; + Pel* pInputPelR = m_pppcInputPel[COLOR_R][0]; + Pel* pInputPelG = m_pppcInputPel[COLOR_G][0]; + Pel* pInputPelB = m_pppcInputPel[COLOR_B][0]; for( UInt i = 0; i < m_uiHeight * m_uiWidth; i++ ) { - *pInputPelY++ = pelRed( *buff ); - *pInputPelU++ = pelGreen( *buff ); - *pInputPelV++ = pelBlue( *buff++ ); + *pInputPelR++ = pelRed( *pCvPel++ ); + *pInputPelG++ = pelGreen( *pCvPel++ ); + *pInputPelB++ = pelBlue( *pCvPel++ ); } - m_bHasRGBPel = true; } else { - memcpy( m_pppcInputPel[LUMA][0], opencvFrame->data, m_uiWidth * m_uiHeight * sizeof(Pel) ); + Pel* pPel = m_pppcInputPel[LUMA][0]; + for( UInt i = 0; i < m_uiWidth * m_uiHeight; i++ ) + { + *pPel++ = *pCvPel++; + } } #endif } diff --git a/lib/PlaYUVerFrame.h b/lib/PlaYUVerFrame.h index 0625cd1..593d9ee 100644 --- a/lib/PlaYUVerFrame.h +++ b/lib/PlaYUVerFrame.h @@ -34,6 +34,10 @@ #include "PlaYUVerFrameStats.h" class PixFcSSE; +namespace cv +{ +class Mat; +} namespace plaYUVer { @@ -117,9 +121,9 @@ public: { COLOR_INVALID = -1, //!< Invalid COLOR_YUV = 0, //!< YUV - COLOR_RGB, //!< RGB - COLOR_ARGB, //!< RGB + Alpha - COLOR_GRAY, //!< Grayscale + COLOR_RGB = 1, //!< RGB + COLOR_ARGB = 3, //!< RGB + Alpha + COLOR_GRAY = 2, //!< Grayscale }; /** ColorSpace Enum @@ -138,19 +142,27 @@ public: NUMBER_FORMATS }; + /** + * Function that handles the supported color space + * of PlaYUVerFrame + * @return vector of strings with pixel formats names + */ + static std::vector supportedColorSpacesListNames(); + /** * Function that handles the supported pixel formats * of PlaYUVerFrame * @return vector of strings with pixel formats names */ static std::vector supportedPixelFormatListNames(); + static std::vector supportedPixelFormatListNames( Int colorSpace ); /** * Get number of bytes per frame of a specific * pixel format * @return number of bytes per frame */ - static UInt64 getBytesPerFrame( UInt, UInt, Int ); + static UInt64 getBytesPerFrame( UInt uiWidth, UInt uiHeight, Int iPixelFormat, Int bitsPixel ); /** * Convert a Pixel to a new color space @@ -169,7 +181,7 @@ public: * * @note this function might misbehave if the pixel format enum is not correct */ - PlaYUVerFrame( UInt width, UInt height, Int pel_format = 0 ); + PlaYUVerFrame( UInt width, UInt height, Int pelFormat = 0, Int bitsPixel = 8 ); /** * Creates and new frame with the configuration of an @@ -206,8 +218,8 @@ public: UInt getChromaHeight() const; UInt getChromaLength() const; - Void frameFromBuffer( Pel*, UInt64 ); - Void frameToBuffer( Pel* ); + Void frameFromBuffer( Byte*, UInt64 ); + Void frameToBuffer( Byte* ); Void fillRGBBuffer(); @@ -216,6 +228,10 @@ public: PlaYUVerFrame::Pixel getPixelValue( Int xPos, Int yPos, ColorSpace eColorSpace = COLOR_INVALID ); + std::string getPelFmtName() + { + return m_cPelFmtName; + } UInt getWidth() const { return m_uiWidth; @@ -228,9 +244,9 @@ public: { return m_iPixelFormat; } - Int getBitsChannel() const + Int getBitsPel() const { - return m_iBitsChannels; + return m_iBitsPel; } Bool isValid() const { @@ -278,8 +294,8 @@ public: /** * Interface with OpenCV lib */ - Void getCvMat( Void** ); - Void fromCvMat( Void* ); + cv::Mat* getCvMat( Bool convertToGray = false ); + Void fromCvMat( cv::Mat* ); /** * @defgroup PlaYUVerLib_QualityMetrics Quality Metrics Interface @@ -321,12 +337,13 @@ private: //! Strcut with the pixel format description. PlaYUVerPixFmtDescriptor* m_pcPelFormat; + std::string m_cPelFmtName; UInt m_uiWidth; //!< Width of the frame UInt m_uiHeight; //!< Height of the frame Int m_iPixelFormat; //!< Pixel format number (it follows the list of supported pixel formats) Int m_iNumberChannels; //!< Number of channels - Int m_iBitsChannels; //!< Bits per pixel/channel + Int m_iBitsPel; //!< Bits per pixel/channel Pel*** m_pppcInputPel; @@ -341,7 +358,7 @@ private: * @param pel_format pixel format index (always use PixelFormats enum) * */ - Void init( UInt width, UInt height, Int pel_format ); + Void init( UInt width, UInt height, Int pel_format, Int bitsPixel ); Void openPixfc(); Void closePixfc(); diff --git a/lib/PlaYUVerFramePixelFormats.cpp b/lib/PlaYUVerFramePixelFormats.cpp index 2ad9565..a916622 100644 --- a/lib/PlaYUVerFramePixelFormats.cpp +++ b/lib/PlaYUVerFramePixelFormats.cpp @@ -52,48 +52,8 @@ namespace plaYUVer #define ADD_FFMPEG_PEL_FMT( fmt ) 0 #endif - -Void fillARGB32bufferYUV( Pel*** in, UChar* out, UInt width, UInt height, UInt ratioChromaHor, UInt ratioChromaVer ) -{ - Pel* pLineY = in[LUMA][0]; - Pel* pLineU = in[CHROMA_U][0]; - Pel* pLineV = in[CHROMA_V][0]; - UInt uiChromaStride = CHROMASHIFT( width, ratioChromaHor ); - Pel* pY; - Pel* pU; - Pel* pV; - Int iY, iU, iV, iR, iG, iB; - UInt* pARGBLine = ( UInt* )out; - UInt* pARGB; - - for( UInt y = 0; y < height >> ratioChromaVer; y++ ) - { - for( Int i = 0; i < 1 << ratioChromaVer; i++ ) - { - pY = pLineY; - pU = pLineU; - pV = pLineV; - pARGB = pARGBLine; - for( UInt x = 0; x < width >> ratioChromaHor; x++ ) - { - iU = *pU++; - iV = *pV++; - for( Int j = 0; j < 1 << ratioChromaHor; j++ ) - { - iY = *pY++; - YUV2RGB( iY, iU, iV, iR, iG, iB ); - *pARGB++ = PEL_RGB( iR, iG, iB ); - } - } - pLineY += width; - pARGBLine += width; - } - pLineU += uiChromaStride; - pLineV += uiChromaStride; - } -} - -Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height ) +#if 0 +Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height, UInt depth ) { #ifdef USE_SSE if( ( width % 16 ) == 0 ) @@ -184,14 +144,14 @@ Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height ) b00 = _mm_srai_epi16( _mm_add_epi16( y00r0, bu00 ), 6 ); b01 = _mm_srai_epi16( _mm_add_epi16( y01r0, bu01 ), 6 ); - r00 = _mm_packus_epi16( r00, r01 ); // rrrr.. saturated - g00 = _mm_packus_epi16( g00, g01 ); // gggg.. saturated - b00 = _mm_packus_epi16( b00, b01 ); // bbbb.. saturated + r00 = _mm_packus_epi16( r00, r01 );// rrrr.. saturated + g00 = _mm_packus_epi16( g00, g01 );// gggg.. saturated + b00 = _mm_packus_epi16( b00, b01 );// bbbb.. saturated - r01 = _mm_unpacklo_epi8( r00, zero ); // 0r0r.. - gbgb = _mm_unpacklo_epi8( b00, g00 ); // gbgb.. - rgb0123 = _mm_unpacklo_epi16( gbgb, r01 ); // 0rgb0rgb.. - rgb4567 = _mm_unpackhi_epi16( gbgb, r01 ); // 0rgb0rgb.. + r01 = _mm_unpacklo_epi8( r00, zero );// 0r0r.. + gbgb = _mm_unpacklo_epi8( b00, g00 );// gbgb.. + rgb0123 = _mm_unpacklo_epi16( gbgb, r01 );// 0rgb0rgb.. + rgb4567 = _mm_unpackhi_epi16( gbgb, r01 );// 0rgb0rgb.. r01 = _mm_unpackhi_epi8( r00, zero ); gbgb = _mm_unpackhi_epi8( b00, g00 ); @@ -211,14 +171,14 @@ Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height ) b00 = _mm_srai_epi16( _mm_add_epi16( y00r1, bu00 ), 6 ); b01 = _mm_srai_epi16( _mm_add_epi16( y01r1, bu01 ), 6 ); - r00 = _mm_packus_epi16( r00, r01 ); // rrrr.. saturated - g00 = _mm_packus_epi16( g00, g01 ); // gggg.. saturated - b00 = _mm_packus_epi16( b00, b01 ); // bbbb.. saturated + r00 = _mm_packus_epi16( r00, r01 );// rrrr.. saturated + g00 = _mm_packus_epi16( g00, g01 );// gggg.. saturated + b00 = _mm_packus_epi16( b00, b01 );// bbbb.. saturated - r01 = _mm_unpacklo_epi8( r00, zero ); // 0r0r.. - gbgb = _mm_unpacklo_epi8( b00, g00 ); // gbgb.. - rgb0123 = _mm_unpacklo_epi16( gbgb, r01 ); // 0rgb0rgb.. - rgb4567 = _mm_unpackhi_epi16( gbgb, r01 ); // 0rgb0rgb.. + r01 = _mm_unpacklo_epi8( r00, zero );// 0r0r.. + gbgb = _mm_unpacklo_epi8( b00, g00 );// gbgb.. + rgb0123 = _mm_unpacklo_epi16( gbgb, r01 );// 0rgb0rgb.. + rgb4567 = _mm_unpackhi_epi16( gbgb, r01 );// 0rgb0rgb.. r01 = _mm_unpackhi_epi8( r00, zero ); gbgb = _mm_unpackhi_epi8( b00, g00 ); @@ -236,49 +196,10 @@ Void fillARGB32bufferYUV420p( Pel*** in, UChar* out, UInt width, UInt height ) else #endif { - fillARGB32bufferYUV( in, out, width, height, 1, 1 ); + fillARGB32bufferYUV( in, out, width, height, depth, 1, 1 ); } } - -Void fillARGB32bufferYUV444p( Pel*** in, UChar* out, UInt width, UInt height ) -{ - fillARGB32bufferYUV( in, out, width, height, 0, 0 ); -} - -Void fillARGB32bufferYUV422( Pel*** in, UChar* out, UInt width, UInt height ) -{ - fillARGB32bufferYUV( in, out, width, height, 1, 0 ); -} - -Void fillARGB32bufferGray( Pel*** in, UChar* out, UInt width, UInt height ) -{ - Pel *inPel = in[0][0]; - Pel iY; - UInt* buff = ( UInt* )out; - for( UInt i = 0; i < height * width; i++ ) - { - iY = *inPel; - *buff++ = PEL_RGB( iY, iY, iY ); - inPel++; - } -} - -Void fillARGB32bufferRGB( Pel*** in, UChar* out, UInt width, UInt height ) -{ - Pel* pR = in[COLOR_R][0]; - Pel* pG = in[COLOR_G][0]; - Pel* pB = in[COLOR_B][0]; - Int iR, iG, iB; - UInt* buff = ( UInt* )out; - for( UInt i = 0; i < height * width; i++ ) - { - iR = *pR++; - iG = *pG++; - iB = *pB++; - *buff++ = PEL_RGB( iR, iG, iB ); - } -} - +#endif PlaYUVerPixFmtDescriptor yuv420p = { @@ -294,7 +215,6 @@ PlaYUVerPixFmtDescriptor yuv420p = { 1, 0, 1, 0, 7 }, /* U */ { 2, 0, 1, 0, 7 }, /* V */ }, - fillARGB32bufferYUV420p, }; PlaYUVerPixFmtDescriptor yuv422p = @@ -311,7 +231,6 @@ PlaYUVerPixFmtDescriptor yuv422p = { 1, 0, 1, 0, 7 }, /* U */ { 2, 0, 1, 0, 7 }, /* V */ }, - fillARGB32bufferYUV422, }; PlaYUVerPixFmtDescriptor yuv444p = @@ -328,7 +247,6 @@ PlaYUVerPixFmtDescriptor yuv444p = { 1, 0, 1, 0, 7 }, /* U */ { 2, 0, 1, 0, 7 }, /* V */ }, - fillARGB32bufferYUV444p, }; PlaYUVerPixFmtDescriptor yuyv422 = @@ -345,7 +263,6 @@ PlaYUVerPixFmtDescriptor yuyv422 = { 0, 3, 2, 0, 7 }, /* U */ { 0, 3, 4, 0, 7 }, /* V */ }, - fillARGB32bufferYUV422, }; PlaYUVerPixFmtDescriptor gray = @@ -358,7 +275,6 @@ PlaYUVerPixFmtDescriptor gray = 0, ADD_FFMPEG_PEL_FMT( AV_PIX_FMT_GRAY8 ), { { 0, 0, 1, 0, 7 } }, /* Y */ - fillARGB32bufferGray, }; PlaYUVerPixFmtDescriptor RGB24 = @@ -375,7 +291,6 @@ PlaYUVerPixFmtDescriptor RGB24 = { 0, 2, 2, 0, 7 }, /* G */ { 0, 2, 3, 0, 7 }, /* B */ }, - fillARGB32bufferRGB, }; PlaYUVerPixFmtDescriptor BGR24 = @@ -392,7 +307,6 @@ PlaYUVerPixFmtDescriptor BGR24 = { 0, 2, 2, 0, 7 }, /* G */ { 0, 2, 1, 0, 7 }, /* B */ }, - fillARGB32bufferRGB, }; PlaYUVerPixFmtDescriptor g_PlaYUVerPixFmtDescriptorsList[PLAYUVER_NUMBER_FORMATS] = @@ -405,5 +319,4 @@ PlaYUVerPixFmtDescriptor g_PlaYUVerPixFmtDescriptorsList[PLAYUVER_NUMBER_FORMATS RGB24, BGR24, }; - } // NAMESPACE diff --git a/lib/PlaYUVerFramePixelFormats.h b/lib/PlaYUVerFramePixelFormats.h index 1052ade..deede8b 100644 --- a/lib/PlaYUVerFramePixelFormats.h +++ b/lib/PlaYUVerFramePixelFormats.h @@ -156,8 +156,6 @@ typedef struct PlaYUVerPixFmtDescriptor */ PlaYUVerComponentDescriptor comp[4]; - Void (*fillARGB32buffer)( Pel*** in, UChar* out, UInt width, UInt height ); - } PlaYUVerPixFmtDescriptor; #define MAX_NUMBER_PLANES 3 diff --git a/lib/PlaYUVerFrameStats.cpp b/lib/PlaYUVerFrameStats.cpp index 8337fe2..ab455ef 100644 --- a/lib/PlaYUVerFrameStats.cpp +++ b/lib/PlaYUVerFrameStats.cpp @@ -36,15 +36,15 @@ namespace plaYUVer { PlaYUVerFrameStats::PlaYUVerFrameStats() : - m_pdHistogram( NULL ), + m_puiHistogram( NULL ), m_bHasHistogram( false ) { } PlaYUVerFrameStats::~PlaYUVerFrameStats() { - if( m_pdHistogram ) - freeMem1D( m_pdHistogram ); + if( m_puiHistogram ) + freeMem1D( m_puiHistogram ); } @@ -56,7 +56,7 @@ Void PlaYUVerFrameStats::xSetupStatistics( const PlaYUVerFrame *pcFrame, UInt op m_uiImageHeight = pcFrame->getHeight(); m_uiChannels = pcFrame->getNumberChannels(); - m_uiHistoSegments = ( pcFrame->getBitsChannel() == 16 ) ? 65536 : 256; + m_uiHistoSegments = 1 << pcFrame->getBitsPel(); imageColorSpace = pcFrame->getColorSpace(); imageChromaSize = pcFrame->getChromaLength(); @@ -77,9 +77,9 @@ Void PlaYUVerFrameStats::calcHistogram() //m_bHasHistogram = false; if( m_bHasHistogram ) return; - getMem1D( &( m_pdHistogram ), m_uiHistoSegments * histoChannels ); + getMem1D( &( m_puiHistogram ), m_uiHistoSegments * histoChannels ); - if( !m_pdHistogram ) + if( !m_puiHistogram ) { // qWarning( ) << "PlaYUVerFrameStats::calcHistogramValuess: " // "Unable to allocate memory!" @@ -95,16 +95,16 @@ Void PlaYUVerFrameStats::calcHistogram() data[LUMA] = m_pppImageData[LUMA][0]; data[CHROMA_U] = m_pppImageData[CHROMA_U][0]; data[CHROMA_V] = m_pppImageData[CHROMA_V][0]; - for( i = 0; i < m_uiImageHeight * m_uiImageWidth; i++ ) + for( i = 0; i < m_uiImageHeight * m_uiImageWidth && m_bRunningFlag; i++ ) { - m_pdHistogram[*( data[LUMA] ) + LUMA * m_uiHistoSegments]++; + m_puiHistogram[*( data[LUMA] ) + LUMA * m_uiHistoSegments]++; data[LUMA] += 1; } for( i = 0; ( i < imageChromaSize ) && m_bRunningFlag; i++ ) { for( j = 1; j < m_uiChannels; j++ ) { - m_pdHistogram[*( data[j] ) + j * m_uiHistoSegments]++; + m_puiHistogram[*( data[j] ) + j * m_uiHistoSegments]++; } for( j = 1; j < m_uiChannels; j++ ) data[j] += 1; @@ -122,13 +122,13 @@ Void PlaYUVerFrameStats::calcHistogram() { for( j = 0; j < m_uiChannels; j++ ) { - m_pdHistogram[*( data[j] ) + j * m_uiHistoSegments]++; + m_puiHistogram[*( data[j] ) + j * m_uiHistoSegments]++; } if( calcLuma && ( imageColorSpace == PlaYUVerFrame::COLOR_RGB || imageColorSpace == PlaYUVerFrame::COLOR_ARGB ) ) { PlaYUVerFrame::Pixel currPixel( imageColorSpace, *( data[COLOR_R] ), *( data[COLOR_G] ), *( data[COLOR_B] ) ); luma = PlaYUVerFrame::ConvertPixel( currPixel, PlaYUVerFrame::COLOR_YUV ).Y(); - m_pdHistogram[luma + j * m_uiHistoSegments]++; + m_puiHistogram[luma + j * m_uiHistoSegments]++; } for( j = 0; j < m_uiChannels; j++ ) data[j] += 1; @@ -228,7 +228,7 @@ Double PlaYUVerFrameStats::getCount( Int channel, UInt start, UInt end ) Int indexStart; Double count = 0.0; - if( !m_pdHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end ) + if( !m_puiHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end ) { return 0.0; } @@ -244,14 +244,14 @@ Double PlaYUVerFrameStats::getCount( Int channel, UInt start, UInt end ) for( i = start; i <= end; i++ ) { - count += m_pdHistogram[indexStart + i]; + count += m_puiHistogram[indexStart + i]; } return count; } Double PlaYUVerFrameStats::getPixels() { - if( !m_pdHistogram ) + if( !m_puiHistogram ) { return 0.0; } @@ -266,7 +266,7 @@ Double PlaYUVerFrameStats::getMean( Int channel, UInt start, UInt end ) Double mean = 0.0; Double count; - if( !m_pdHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end ) + if( !m_puiHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end ) { return 0.0; } @@ -282,7 +282,7 @@ Double PlaYUVerFrameStats::getMean( Int channel, UInt start, UInt end ) for( UInt i = start; i <= end; i++ ) { - mean += i * m_pdHistogram[indexStart + i]; + mean += i * m_puiHistogram[indexStart + i]; } count = getCount( channel, start, end ); @@ -302,7 +302,7 @@ Int PlaYUVerFrameStats::getMedian( Int channel, UInt start, UInt end ) Double sum = 0.0; Double count; - if( !m_pdHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end ) + if( !m_puiHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end ) { return 0; } @@ -320,7 +320,7 @@ Int PlaYUVerFrameStats::getMedian( Int channel, UInt start, UInt end ) for( UInt i = start; i <= end; i++ ) { - sum += m_pdHistogram[indexStart + i]; + sum += m_puiHistogram[indexStart + i]; if( sum * 2 > count ) return i; } @@ -336,7 +336,7 @@ Double PlaYUVerFrameStats::getStdDev( Int channel, UInt start, UInt end ) Double count; Double mean; - if( !m_pdHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end ) + if( !m_puiHistogram || start < 0 || end > m_uiHistoSegments - 1 || start > end ) { return 0.0; } @@ -359,7 +359,7 @@ Double PlaYUVerFrameStats::getStdDev( Int channel, UInt start, UInt end ) for ( i = start ; i <= end ; i++ ) { - dev += ( i - mean ) * ( i - mean ) * m_pdHistogram[indexStart +i]; + dev += ( i - mean ) * ( i - mean ) * m_puiHistogram[indexStart +i]; } return sqrt( dev / count ); @@ -368,7 +368,7 @@ Double PlaYUVerFrameStats::getStdDev( Int channel, UInt start, UInt end ) for( UInt i = start; i <= end; i++ ) { - dev += ( i * i ) * m_pdHistogram[indexStart + i]; + dev += ( i * i ) * m_puiHistogram[indexStart + i]; } return sqrt( ( dev - count * mean * mean ) / ( count - 1 ) ); @@ -381,7 +381,7 @@ Double PlaYUVerFrameStats::getHistogramValue( Int channel, UInt bin ) Int histoChannel; Int indexStart; - if( !m_pdHistogram || bin < 0 || bin > m_uiHistoSegments - 1 ) + if( !m_puiHistogram || bin < 0 || bin > m_uiHistoSegments - 1 ) return 0.0; histoChannel = getRealHistoChannel( channel ); @@ -393,7 +393,7 @@ Double PlaYUVerFrameStats::getHistogramValue( Int channel, UInt bin ) indexStart = histoChannel * m_uiHistoSegments; - value = m_pdHistogram[indexStart + bin]; + value = m_puiHistogram[indexStart + bin]; return value; } @@ -405,7 +405,7 @@ Double PlaYUVerFrameStats::getMaximum( Int channel ) Int histoChannel; Int indexStart; - if( !m_pdHistogram ) + if( !m_puiHistogram ) return 0.0; histoChannel = getRealHistoChannel( channel ); @@ -419,9 +419,9 @@ Double PlaYUVerFrameStats::getMaximum( Int channel ) for( UInt x = 0; x < m_uiHistoSegments; x++ ) { - if( m_pdHistogram[indexStart + x] > max ) + if( m_puiHistogram[indexStart + x] > max ) { - max = m_pdHistogram[indexStart + x]; + max = m_puiHistogram[indexStart + x]; } } diff --git a/lib/PlaYUVerFrameStats.h b/lib/PlaYUVerFrameStats.h index d853a87..dce1c84 100644 --- a/lib/PlaYUVerFrameStats.h +++ b/lib/PlaYUVerFrameStats.h @@ -95,7 +95,7 @@ public: private: /** The histogram data.*/ - Double* m_pdHistogram; + UInt* m_puiHistogram; /** If true, calc the luminosity channel histogram when the image is RGB */ Bool calcLuma; diff --git a/lib/PlaYUVerStream.cpp b/lib/PlaYUVerStream.cpp index 901e598..5b09f1e 100644 --- a/lib/PlaYUVerStream.cpp +++ b/lib/PlaYUVerStream.cpp @@ -46,10 +46,10 @@ std::vector PlaYUVerStream::supportedReadFormatsExt() std::vector libAvFmt = LibAvContextHandle::supportedReadFormatsExt(); formatsExt.insert( formatsExt.end(), libAvFmt.begin(), libAvFmt.end() ); #endif -#ifdef USE_OPENCV - std::vector opencvFmt = LibOpenCVHandler::supportedReadFormatsExt(); - formatsExt.insert( formatsExt.end(), opencvFmt.begin(), opencvFmt.end() ); -#endif +//#ifdef USE_OPENCV +// std::vector opencvFmt = LibOpenCVHandler::supportedReadFormatsExt(); +// formatsExt.insert( formatsExt.end(), opencvFmt.begin(), opencvFmt.end() ); +//#endif return formatsExt; } @@ -61,10 +61,10 @@ std::vector PlaYUVerStream::supportedReadFormatsName() std::vector libAvFmt = LibAvContextHandle::supportedReadFormatsName(); formatsName.insert( formatsName.end(), libAvFmt.begin(), libAvFmt.end() ); #endif -#ifdef USE_OPENCV - std::vector opencvFmt = LibOpenCVHandler::supportedReadFormatsName(); - formatsName.insert( formatsName.end(), opencvFmt.begin(), opencvFmt.end() ); -#endif +//#ifdef USE_OPENCV +// std::vector opencvFmt = LibOpenCVHandler::supportedReadFormatsName(); +// formatsName.insert( formatsName.end(), opencvFmt.begin(), opencvFmt.end() ); +//#endif return formatsName; } @@ -84,28 +84,22 @@ std::vector PlaYUVerStream::supportedWriteFormatsName() std::vector PlaYUVerStream::supportedSaveFormatsExt() { - std::vector formatsExt; - std::vector writeExt = supportedWriteFormatsExt(); - formatsExt.insert( formatsExt.begin(), writeExt.begin(), writeExt.end() ); + std::vector formatsExt = supportedWriteFormatsExt(); #ifdef USE_OPENCV std::vector opencvFmt = LibOpenCVHandler::supportedSaveFormatsExt(); formatsExt.insert( formatsExt.end(), opencvFmt.begin(), opencvFmt.end() ); #endif - sort( formatsExt.begin(), formatsExt.end() ); formatsExt.erase( unique( formatsExt.begin(), formatsExt.end() ), formatsExt.end() ); return formatsExt; } std::vector PlaYUVerStream::supportedSaveFormatsName() { - std::vector formatsName; - std::vector writeName = supportedWriteFormatsName(); - formatsName.insert( formatsName.begin(), writeName.begin(), writeName.end() ); + std::vector formatsName = supportedWriteFormatsName(); #ifdef USE_OPENCV std::vector opencvFmt = LibOpenCVHandler::supportedSaveFormatsName(); formatsName.insert( formatsName.end(), opencvFmt.begin(), opencvFmt.end() ); #endif - sort( formatsName.begin(), formatsName.end() ); formatsName.erase( unique( formatsName.begin(), formatsName.end() ), formatsName.end() ); return formatsName; } @@ -141,7 +135,7 @@ PlaYUVerStream::PlaYUVerStream() m_bIsInput = true; m_bIsOpened = false; m_bLoadAll = false; - m_uiStreamHandler = 0; + m_iStreamHandler = INVALID_HANDLER; m_pFile = NULL; m_pchFilename = NULL; m_uiWidth = 0; @@ -149,8 +143,8 @@ PlaYUVerStream::PlaYUVerStream() m_uiTotalFrameNum = 0; m_iCurrFrameNum = -1; m_iPixelFormat = -1; + m_uiBitsPerPixel = 8; m_dFrameRate = 30; - m_iFileFormat = -1; m_pStreamBuffer = NULL; m_cFilename = ""; m_pcCurrFrame = NULL; @@ -169,7 +163,54 @@ PlaYUVerStream::~PlaYUVerStream() close(); } -Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::string input_format_name, UInt frame_rate, Bool bInput ) +Void PlaYUVerStream::findHandler() +{ + m_iStreamHandler = INVALID_HANDLER; + + if( m_uiBitsPerPixel != 8 ) + { + m_iStreamHandler = YUV_IO; + return; + } + + std::string currExt = m_cFilename.substr( m_cFilename.find_last_of( "." ) + 1 ); + if( m_bIsInput ) + { +#ifdef USE_FFMPEG + for( UInt i = 0; i < LibAvContextHandle::supportedReadFormatsExt().size(); i++ ) + { + if( LibAvContextHandle::supportedReadFormatsExt()[i] == currExt ) + { + m_cFormatName = LibAvContextHandle::supportedReadFormatsExt()[i]; + m_iStreamHandler = FFMPEG; + return; + } + } +#endif + if( m_iStreamHandler == INVALID_HANDLER ) + m_iStreamHandler = YUV_IO; + } + else + { +#ifdef USE_FFMPEG + for( UInt i = 0; i < LibAvContextHandle::supportedWriteFormatsExt().size(); i++ ) + { + if( LibAvContextHandle::supportedWriteFormatsExt()[i] == currExt ) + { + m_cFormatName = LibAvContextHandle::supportedWriteFormatsExt()[i]; + m_iStreamHandler = FFMPEG; + return; + } + } +#endif + if( currExt == "yuv" ) + { + m_iStreamHandler = YUV_IO; + } + } +} + +Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::string input_format_name, UInt bitsPel, UInt frame_rate, Bool bInput ) { UInt width; UInt height; @@ -191,10 +232,10 @@ Bool PlaYUVerStream::open( std::string filename, std::string resolution, std::st break; } } - return open( filename, width, height, input_format, frame_rate, bInput ); + return open( filename, width, height, input_format, bitsPel, frame_rate, bInput ); } -Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int input_format, UInt frame_rate, Bool bInput ) +Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int input_format, UInt bitsPel, UInt frame_rate, Bool bInput ) { if( m_bInit ) { @@ -206,71 +247,25 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in m_uiWidth = width; m_uiHeight = height; m_iPixelFormat = input_format; + m_uiBitsPerPixel = bitsPel; m_dFrameRate = frame_rate; m_pchFilename = new Char[m_cFilename.size() + 1]; std::copy( m_cFilename.begin(), m_cFilename.end(), m_pchFilename ); m_pchFilename[m_cFilename.size()] = '\0'; // don't forget the terminating 0 - if( m_bIsInput ) + findHandler(); + if( m_iStreamHandler == INVALID_HANDLER ) { - m_iFileFormat = INVALID_HANDLER; - - std::string currExt = filename.substr( filename.find_last_of( "." ) + 1 ); - for( UInt i = 0; i < PlaYUVerStream::supportedReadFormatsExt().size(); i++ ) - { - if( PlaYUVerStream::supportedReadFormatsExt()[i] == currExt ) - { - m_iFileFormat = i; - m_cFormatName = PlaYUVerStream::supportedReadFormatsExt()[i]; - break; - } - } - if( m_iFileFormat == INVALID_HANDLER ) - { - close(); - throw "Invalid file format"; - return m_bInit; - } - - if( m_cFormatName == "yuv" ) - { - m_uiStreamHandler = YUV_IO; - } -//#ifdef USE_OPENCV -// else if( m_cFormatName == "png" || m_cFormatName == "jpg" ) -// { -// m_uiStreamHandler = OPENCV_HANDLER; -// } -//#endif -#ifdef USE_FFMPEG - else - { - m_uiStreamHandler = FFMPEG; - } -#endif -#if 0 - if( !avStatus ) - { - switch( m_iFileFormat ) - { - case PGMINPUT: - - break; - } - } -#endif - m_uiFrameBufferSize = 2; - } - else - { - m_iFileFormat = 0; - m_uiStreamHandler = YUV_IO; - m_uiFrameBufferSize = 1; + close(); + throw "Invalid file format"; + return m_bInit; } + m_uiFrameBufferSize = m_bIsInput ? 2 : 1; + #ifdef USE_FFMPEG - if( m_uiStreamHandler == FFMPEG ) + if( m_iStreamHandler == FFMPEG ) { if( !m_cLibAvContext->initAvFormat( m_pchFilename, m_uiWidth, m_uiHeight, m_iPixelFormat, m_dFrameRate, m_uiTotalFrameNum ) ) { @@ -281,7 +276,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in #endif #ifdef USE_OPENCV - if( m_uiStreamHandler == OPENCV_HANDLER ) + if( m_iStreamHandler == OPENCV_HANDLER ) { m_pcCurrFrame = LibOpenCVHandler::loadFrame( m_cFilename ); if( m_pcCurrFrame ) @@ -300,9 +295,9 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in return m_bInit; } - if( m_uiStreamHandler != OPENCV_HANDLER ) + if( m_iStreamHandler != OPENCV_HANDLER ) { - if( m_uiStreamHandler == YUV_IO ) + if( m_iStreamHandler == YUV_IO ) { if( !openFile() ) { @@ -317,8 +312,11 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in getMem1D( &m_ppcFrameBuffer, m_uiFrameBufferSize ); for( UInt i = 0; i < m_uiFrameBufferSize; i++ ) { - m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat ); - if( !m_ppcFrameBuffer[i] ) + try + { + m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel ); + } + catch( const char *msg ) { close(); throw "[PlaYUVerStream] Cannot allocated frame buffer"; @@ -330,7 +328,7 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame(); - if( m_uiStreamHandler == YUV_IO && m_bIsInput ) + if( m_iStreamHandler == YUV_IO && m_bIsInput ) { fseek( m_pFile, 0, SEEK_END ); UInt64 fileSize = ftell( m_pFile ); @@ -362,17 +360,22 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in return m_bInit; } - if( !getMem1D( &m_pStreamBuffer, m_pcCurrFrame->getBytesPerFrame() ) ) + if( !getMem1D( &m_pStreamBuffer, m_pcCurrFrame->getBytesPerFrame() ) ) { close(); throw "[PlaYUVerStream] Cannot allocated memory"; return m_bInit; } - m_cPelFmtName = PlaYUVerFrame::supportedPixelFormatListNames()[m_iPixelFormat].c_str(); + if( m_pcCurrFrame ) + { + m_uiWidth = m_pcCurrFrame->getWidth(); + m_uiHeight = m_pcCurrFrame->getHeight(); + m_iPixelFormat = m_pcCurrFrame->getPelFormat(); + m_uiBitsPerPixel = m_pcCurrFrame->getBitsPel(); + } m_iCurrFrameNum = -1; - m_bInit = true; seekInput( 0 ); @@ -383,14 +386,14 @@ Bool PlaYUVerStream::open( std::string filename, UInt width, UInt height, Int in Bool PlaYUVerStream::openFile() { - //m_fsIOStream.open( m_cFilename, std::ios::in | std::ios::binary ) +//m_fsIOStream.open( m_cFilename, std::ios::in | std::ios::binary ) m_pFile = NULL; m_pFile = fopen( m_pchFilename, m_bIsInput ? "rb" : "wb" ); if( m_pFile == NULL ) { return false; } - if ( m_bIsInput ) + if( m_bIsInput ) { fseek( m_pFile, m_iCurrFrameNum >= 0 ? m_iCurrFrameNum : 0, SEEK_SET ); } @@ -408,11 +411,11 @@ Void PlaYUVerStream::close() if( !m_bInit ) return; - if( m_uiStreamHandler == YUV_IO ) + if( m_iStreamHandler == YUV_IO ) closeFile(); #ifdef USE_FFMPEG - if( m_uiStreamHandler == FFMPEG ) + if( m_iStreamHandler == FFMPEG ) m_cLibAvContext->closeAvFormat(); delete m_cLibAvContext; #endif @@ -430,7 +433,7 @@ Void PlaYUVerStream::close() } if( m_pStreamBuffer ) - freeMem1D( m_pStreamBuffer ); + freeMem1D( m_pStreamBuffer ); if( m_pchFilename ) delete[] m_pchFilename; @@ -439,13 +442,14 @@ Void PlaYUVerStream::close() m_bInit = false; } -Void PlaYUVerStream::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ) +Void PlaYUVerStream::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, UInt& rFrameRate ) { if( m_bInit ) { rWidth = m_uiWidth; rHeight = m_uiHeight; rInputFormat = m_iPixelFormat; + rBitsPerPel = m_uiBitsPerPixel; rFrameRate = m_dFrameRate; } else @@ -453,6 +457,7 @@ Void PlaYUVerStream::getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, rWidth = 0; rHeight = 0; rInputFormat = PlaYUVerFrame::YUV420p; + rBitsPerPel = 8; rFrameRate = 30; } } @@ -477,7 +482,7 @@ Void PlaYUVerStream::loadAll() getMem1D( &m_ppcFrameBuffer, m_uiFrameBufferSize ); for( UInt i = 0; i < m_uiFrameBufferSize; i++ ) { - m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat ); + m_ppcFrameBuffer[i] = new PlaYUVerFrame( m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiBitsPerPixel ); if( !m_ppcFrameBuffer[i] ) { close(); @@ -503,12 +508,14 @@ Void PlaYUVerStream::getDuration( Int* duration_array ) { Int hours, mins, secs; #ifdef USE_FFMPEG - if( m_cLibAvContext->getStatus() ) + if( m_iStreamHandler == FFMPEG ) { secs = m_cLibAvContext->getStreamDuration(); } else #endif + if( m_iStreamHandler == YUV_IO ) + { secs = m_uiTotalFrameNum / m_dFrameRate; } @@ -540,13 +547,13 @@ Void PlaYUVerStream::readFrame() return; } - if( m_uiStreamHandler == OPENCV_HANDLER ) + if( m_iStreamHandler == OPENCV_HANDLER ) { return; } #ifdef USE_FFMPEG - if( m_uiStreamHandler == FFMPEG ) + if( m_iStreamHandler == FFMPEG ) { if( !m_cLibAvContext->decodeAvFormat() ) { @@ -556,10 +563,10 @@ Void PlaYUVerStream::readFrame() m_pcNextFrame->frameFromBuffer( m_cLibAvContext->m_pchFrameBuffer, m_cLibAvContext->m_uiFrameBufferSize ); } #endif - if( m_uiStreamHandler == YUV_IO ) + if( m_iStreamHandler == YUV_IO ) { UInt64 frame_bytes_input = m_pcNextFrame->getBytesPerFrame(); - UInt64 bytes_read = fread( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile ); + UInt64 bytes_read = fread( m_pStreamBuffer, sizeof(Byte), frame_bytes_input, m_pFile ); if( bytes_read != frame_bytes_input ) { throw "[PlaYUVerStream] Cannot read file"; @@ -573,26 +580,16 @@ Void PlaYUVerStream::readFrame() Void PlaYUVerStream::writeFrame() { - if( m_uiStreamHandler == YUV_IO ) - { - UInt64 frame_bytes_input = m_pcCurrFrame->getBytesPerFrame(); - m_pcCurrFrame->frameToBuffer( m_pStreamBuffer ); - UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile ); - if( bytes_read != frame_bytes_input ) - { - throw "[PlaYUVerStream] Cannot write into the file"; - } - } - return; + writeFrame( m_pcCurrFrame ); } Void PlaYUVerStream::writeFrame( PlaYUVerFrame *pcFrame ) { - if( m_uiStreamHandler == YUV_IO ) + if( m_iStreamHandler == YUV_IO ) { UInt64 frame_bytes_input = pcFrame->getBytesPerFrame(); pcFrame->frameToBuffer( m_pStreamBuffer ); - UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Pel), frame_bytes_input, m_pFile ); + UInt64 bytes_read = fwrite( m_pStreamBuffer, sizeof(Byte), frame_bytes_input, m_pFile ); if( bytes_read != frame_bytes_input ) { throw "[PlaYUVerStream] Cannot write into the file"; @@ -611,7 +608,7 @@ Bool PlaYUVerStream::saveFrame( const std::string& filename, PlaYUVerFrame *save Int iFileFormat = INVALID_HANDLER; std::string fmtExt; - //std::string currExt = QFileInfo( qtString ).suffix().toStdString(); +//std::string currExt = QFileInfo( qtString ).suffix().toStdString(); std::string currExt = filename.substr( filename.find_last_of( "." ) + 1 ); for( UInt i = 0; i < PlaYUVerStream::supportedSaveFormatsExt().size(); i++ ) @@ -629,7 +626,7 @@ Bool PlaYUVerStream::saveFrame( const std::string& filename, PlaYUVerFrame *save if( fmtExt == "yuv" ) { PlaYUVerStream auxFrameStream; - if( !auxFrameStream.open( filename, saveFrame->getWidth(), saveFrame->getHeight(), saveFrame->getPelFormat(), 1, false ) ) + if( !auxFrameStream.open( filename, saveFrame->getWidth(), saveFrame->getHeight(), saveFrame->getPelFormat(), saveFrame->getBitsPel(), 1, false ) ) { return false; } @@ -662,12 +659,19 @@ Bool PlaYUVerStream::setNextFrame() { m_pcCurrFrame = m_pcNextFrame; m_iCurrFrameNum++; - m_uiFrameBufferIndex++; - if( m_uiFrameBufferIndex == m_uiFrameBufferSize ) + if( m_iCurrFrameNum + 1 < Int( m_uiTotalFrameNum ) ) { - m_uiFrameBufferIndex = 0; + m_uiFrameBufferIndex++; + if( m_uiFrameBufferIndex == m_uiFrameBufferSize ) + { + m_uiFrameBufferIndex = 0; + } + m_pcNextFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex]; + } + else + { + m_pcNextFrame = NULL; } - m_pcNextFrame = m_ppcFrameBuffer[m_uiFrameBufferIndex]; } else { @@ -728,17 +732,17 @@ Bool PlaYUVerStream::seekInput( UInt64 new_frame_num ) setNextFrame(); return true; } - if( m_uiStreamHandler == OPENCV_HANDLER ) + if( m_iStreamHandler == OPENCV_HANDLER ) { return true; } #ifdef USE_FFMPEG - if( m_uiStreamHandler == FFMPEG ) + if( m_iStreamHandler == FFMPEG ) { m_cLibAvContext->seekAvFormat( new_frame_num ); } #endif - if( m_uiStreamHandler == YUV_IO ) + if( m_iStreamHandler == YUV_IO ) { UInt64 frame_bytes_input = m_ppcFrameBuffer[0]->getBytesPerFrame(); UInt64 nbytes_seek = frame_bytes_input * new_frame_num; diff --git a/lib/PlaYUVerStream.h b/lib/PlaYUVerStream.h index a9429ab..c0b1b82 100644 --- a/lib/PlaYUVerStream.h +++ b/lib/PlaYUVerStream.h @@ -67,7 +67,7 @@ private: FFMPEG, TOTAL_HANDLERR }; - UInt m_uiStreamHandler; + Int m_iStreamHandler; LibAvContextHandle* m_cLibAvContext; std::string m_cFilename; @@ -75,15 +75,18 @@ private: std::string m_cFormatName; std::string m_cCodedName; - std::string m_cPelFmtName; + + UInt m_uiWidth; + UInt m_uiHeight; + Int m_iPixelFormat; + UInt m_uiBitsPerPixel; + Double m_dFrameRate; + UInt64 m_uiTotalFrameNum; + Int64 m_iCurrFrameNum; FILE* m_pFile; /**< The input file pointer >*/ std::fstream m_fsIOStream; /**< The input file pointer >*/ - - Int m_iFileFormat; - Int m_iPixelFormat; - - Pel* m_pStreamBuffer; + Byte* m_pStreamBuffer; UInt m_uiFrameBufferSize; PlaYUVerFrame **m_ppcFrameBuffer; @@ -92,11 +95,7 @@ private: UInt m_uiFrameBufferIndex; UInt64 m_uiCurrFrameFileIdx; - UInt m_uiWidth; - UInt m_uiHeight; - Double m_dFrameRate; - UInt64 m_uiTotalFrameNum; - Int64 m_iCurrFrameNum; + Void findHandler(); public: @@ -121,14 +120,14 @@ public: END_OF_SEQ, }; - Bool open( std::string filename, std::string resolution, std::string input_format, UInt frame_rate, Bool bInput = true ); - Bool open( std::string filename, UInt width, UInt height, Int input_format, UInt frame_rate, Bool bInput = true ); + Bool open( std::string filename, std::string resolution, std::string input_format, UInt bitsPel, UInt frame_rate, Bool bInput = true ); + Bool open( std::string filename, UInt width, UInt height, Int input_format, UInt bitsPel, UInt frame_rate, Bool bInput = true ); Void close(); Bool openFile(); Void closeFile(); - Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rFrameRate ); + Void getFormat( UInt& rWidth, UInt& rHeight, Int& rInputFormat, UInt& rBitsPerPel, UInt& rFrameRate ); Void loadAll(); @@ -165,10 +164,6 @@ public: { return m_cCodedName; } - std::string getPelFmtName() - { - return m_cPelFmtName; - } UInt getFrameNum() { diff --git a/lib/ProgramOptions.cpp b/lib/ProgramOptions.cpp index 5421e9a..a0432cb 100644 --- a/lib/ProgramOptions.cpp +++ b/lib/ProgramOptions.cpp @@ -51,9 +51,15 @@ using namespace std; namespace plaYUVer { +Options::Options( const std::string& name ) +{ + m_cOptionGroupName = name; + m_bAllowUnkonw = true; +} + Options::~Options() { - for( Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); it++ ) + for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ ) { delete *it; } @@ -66,12 +72,12 @@ OptionBase* Options::operator[]( const std::string& optName ) OptionBase* Options::getOption( const std::string& optName ) { - Options::NamesMap::iterator opt_it; + Options::OptionMap::iterator opt_it; opt_it = opt_short_map.find( optName ); if( opt_it != opt_short_map.end() ) { - NamesPtrList opt_list = ( *opt_it ).second; - for( Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) + OptionsList opt_list = ( *opt_it ).second; + for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) { return ( *it )->opt; } @@ -79,8 +85,8 @@ OptionBase* Options::getOption( const std::string& optName ) opt_it = opt_long_map.find( optName ); if( opt_it != opt_long_map.end() ) { - NamesPtrList opt_list = ( *opt_it ).second; - for( Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) + OptionsList opt_list = ( *opt_it ).second; + for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) { return ( *it )->opt; } @@ -90,7 +96,7 @@ OptionBase* Options::getOption( const std::string& optName ) void Options::addOption( OptionBase *opt ) { - Names* names = new Names(); + Option* names = new Option(); names->opt = opt; string& opt_string = opt->opt_string; @@ -130,29 +136,230 @@ OptionSpecific Options::addOptions() * default value */ Void Options::setDefaults() { -// for( Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); it++ ) +// for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ ) // { // ( *it )->opt->setDefault(); // } } -static void setOptions( Options::NamesPtrList& opt_list, const string& value ) +static void setOptions( Options::OptionsList& opt_list, const string& value ) { /* multiple options may be registered for the same name: * allow each to parse value */ - for( Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) + for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) { ( *it )->opt->parse( value ); } } +Bool Options::storePair( Bool allow_long, Bool allow_short, const string& name, const string& value ) +{ + bool found = false; + Options::OptionMap::iterator opt_it; + if( allow_long ) + { + opt_it = opt_long_map.find( name ); + if( opt_it != opt_long_map.end() ) + { + found = true; + } + } + + /* check for the short list */ + if( allow_short && !( found && allow_long ) ) + { + opt_it = opt_short_map.find( name ); + if( opt_it != opt_short_map.end() ) + { + found = true; + } + } + + if( !found ) + { + if( !m_bAllowUnkonw ) + { + /* not found */ + cerr << "Unknown option: `" + << name + << "' (value:`" + << value + << "')" + << endl; + } + return false; + } + + setOptions( ( *opt_it ).second, value ); + return true; +} + +Bool Options::storePair( const string& name, const string& value ) +{ + return storePair( true, true, name, value ); +} + +/** + * returns number of extra arguments consumed + */ +UInt Options::parseLONG( unsigned argc, const char* argv[] ) +{ + /* gnu style long options can take the forms: + * --option=arg + * --option arg + */ + string arg( argv[0] ); + size_t arg_opt_start = arg.find_first_not_of( '-' ); + size_t arg_opt_sep = arg.find_first_of( '=' ); + string option = arg.substr( arg_opt_start, arg_opt_sep - arg_opt_start ); + + unsigned extra_argc_consumed = 0; + if( arg_opt_sep == string::npos ) + { + /* no argument found => argument in argv[1] (maybe) */ + /* xxx, need to handle case where option isn't required */ +#if 0 + /* commented out, to return to true GNU style processing + * where longopts have to include an =, otherwise they are + * booleans */ + if (argc == 1) + return 0; /* run out of argv for argument */ + extra_argc_consumed = 1; +#endif + if( !storePair( true, false, option, "1" ) ) + { + return 0; + } + } + else + { + /* argument occurs after option_sep */ + string val = arg.substr( arg_opt_sep + 1 ); + storePair( true, false, option, val ); + } + return extra_argc_consumed; +} + +/** + * returns number of extra arguments consumed + */ +UInt Options::parseLONG( string arg ) +{ + /* gnu style long options can take the forms: + * --option=arg + * --option arg + */ + size_t arg_opt_start = arg.find_first_not_of( '-' ); + size_t arg_opt_sep = arg.find_first_of( '=' ); + string option = arg.substr( arg_opt_start, arg_opt_sep - arg_opt_start ); + + unsigned extra_argc_consumed = 0; + if( arg_opt_sep == string::npos ) + { + /* no argument found => argument in argv[1] (maybe) */ + /* xxx, need to handle case where option isn't required */ + if( !storePair( true, false, option, "1" ) ) + { + return 0; + } + } + else + { + /* argument occurs after option_sep */ + string val = arg.substr( arg_opt_sep + 1 ); + storePair( true, false, option, val ); + } + return extra_argc_consumed; +} + +unsigned Options::parseSHORT( unsigned argc, const char* argv[] ) +{ + /* short options can take the forms: + * --option arg + * -option arg + */ + string arg( argv[0] ); + size_t arg_opt_start = arg.find_first_not_of( '-' ); + string option = arg.substr( arg_opt_start ); + /* lookup option */ + + /* argument in argv[1] */ + /* xxx, need to handle case where option isn't required */ + if( argc == 1 ) + { + cerr << "Not processing option without argument `" + << option + << "'" + << endl; + return 0; /* run out of argv for argument */ + } + storePair( false, true, option, string( argv[1] ) ); + + return 1; +} + +list Options::scanArgv( unsigned argc, const char* argv[] ) +{ + /* a list for anything that didn't get handled as an option */ + list non_option_arguments; + + for( unsigned i = 1; i < argc; i++ ) + { + if( argv[i][0] != '-' ) + { + non_option_arguments.push_back( argv[i] ); + continue; + } + + if( argv[i][1] == 0 ) + { + /* a lone single dash is an argument (usually signifying stdin) */ + non_option_arguments.push_back( argv[i] ); + continue; + } + + if( argv[i][1] != '-' ) + { + /* handle short (single dash) options */ +#if 0 + i += parsePOSIX(opts, argc - i, &argv[i]); +#else + i += parseSHORT( argc - i, &argv[i] ); +#endif + continue; + } + + if( argv[i][2] == 0 ) + { + /* a lone double dash ends option processing */ + while( ++i < argc ) + non_option_arguments.push_back( argv[i] ); + break; + } + + /* handle long (double dash) options */ + i += parseLONG( argc - i, &argv[i] ); + } + + return non_option_arguments; +} + +Void Options::scanArgs( std::vector args_array) +{ + for( unsigned i = 0; i < args_array.size(); i++ ) + { + i += parseLONG( args_array[i] ); + } + return; +} + static const char spaces[41] = " "; /* format help text for a single option: * using the formatting: "-x, --long", * if a short/long option isn't specified, it is not printed */ -static void doHelpOpt( ostream& out, const Options::Names& entry, unsigned pad_short = 0 ) +static void doHelpOpt( ostream& out, const Options::Option& entry, unsigned pad_short = 0 ) { pad_short = min( pad_short, 8u ); @@ -181,12 +388,12 @@ static void doHelpOpt( ostream& out, const Options::Names& entry, unsigned pad_s } /* format the help text */ -void doHelp( ostream& out, Options& opts, unsigned columns ) +Void Options::doHelp( ostream& out, unsigned columns ) { const unsigned pad_short = 3; /* first pass: work out the longest option name */ unsigned max_width = 0; - for( Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++ ) + for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ ) { ostringstream line( ios_base::out ); doHelpOpt( line, **it, pad_short ); @@ -201,7 +408,7 @@ void doHelp( ostream& out, Options& opts, unsigned columns ) * - if the option text is longer than opt_width, place the help * text at opt_width on the next line. */ - for( Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++ ) + for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ ) { ostringstream line( ios_base::out ); line << " "; @@ -279,272 +486,5 @@ void doHelp( ostream& out, Options& opts, unsigned columns ) } } -bool storePair( Options& opts, bool allow_long, bool allow_short, const string& name, const string& value ) -{ - bool found = false; - Options::NamesMap::iterator opt_it; - if( allow_long ) - { - opt_it = opts.opt_long_map.find( name ); - if( opt_it != opts.opt_long_map.end() ) - { - found = true; - } - } - - /* check for the short list */ - if( allow_short && !( found && allow_long ) ) - { - opt_it = opts.opt_short_map.find( name ); - if( opt_it != opts.opt_short_map.end() ) - { - found = true; - } - } - - if( !found ) - { - /* not found */ - cerr << "Unknown option: `" - << name - << "' (value:`" - << value - << "')" - << endl; - return false; - } - - setOptions( ( *opt_it ).second, value ); - return true; -} - -bool storePair( Options& opts, const string& name, const string& value ) -{ - return storePair( opts, true, true, name, value ); -} - -/** - * returns number of extra arguments consumed - */ -unsigned parseGNU( Options& opts, unsigned argc, const char* argv[] ) -{ - /* gnu style long options can take the forms: - * --option=arg - * --option arg - */ - string arg( argv[0] ); - size_t arg_opt_start = arg.find_first_not_of( '-' ); - size_t arg_opt_sep = arg.find_first_of( '=' ); - string option = arg.substr( arg_opt_start, arg_opt_sep - arg_opt_start ); - - unsigned extra_argc_consumed = 0; - if( arg_opt_sep == string::npos ) - { - /* no argument found => argument in argv[1] (maybe) */ - /* xxx, need to handle case where option isn't required */ -#if 0 - /* commented out, to return to true GNU style processing - * where longopts have to include an =, otherwise they are - * booleans */ - if (argc == 1) - return 0; /* run out of argv for argument */ - extra_argc_consumed = 1; -#endif - if( !storePair( opts, true, false, option, "1" ) ) - { - return 0; - } - } - else - { - /* argument occurs after option_sep */ - string val = arg.substr( arg_opt_sep + 1 ); - storePair( opts, true, false, option, val ); - } - - return extra_argc_consumed; -} - -unsigned parseSHORT( Options& opts, unsigned argc, const char* argv[] ) -{ - /* short options can take the forms: - * --option arg - * -option arg - */ - string arg( argv[0] ); - size_t arg_opt_start = arg.find_first_not_of( '-' ); - string option = arg.substr( arg_opt_start ); - /* lookup option */ - - /* argument in argv[1] */ - /* xxx, need to handle case where option isn't required */ - if( argc == 1 ) - { - cerr << "Not processing option without argument `" - << option - << "'" - << endl; - return 0; /* run out of argv for argument */ - } - storePair( opts, false, true, option, string( argv[1] ) ); - - return 1; -} - -list scanArgv( Options& opts, unsigned argc, const char* argv[] ) -{ - /* a list for anything that didn't get handled as an option */ - list non_option_arguments; - - for( unsigned i = 1; i < argc; i++ ) - { - if( argv[i][0] != '-' ) - { - non_option_arguments.push_back( argv[i] ); - continue; - } - - if( argv[i][1] == 0 ) - { - /* a lone single dash is an argument (usually signifying stdin) */ - non_option_arguments.push_back( argv[i] ); - continue; - } - - if( argv[i][1] != '-' ) - { - /* handle short (single dash) options */ -#if 0 - i += parsePOSIX(opts, argc - i, &argv[i]); -#else - i += parseSHORT( opts, argc - i, &argv[i] ); -#endif - continue; - } - - if( argv[i][2] == 0 ) - { - /* a lone double dash ends option processing */ - while( ++i < argc ) - non_option_arguments.push_back( argv[i] ); - break; - } - - /* handle long (double dash) options */ - i += parseGNU( opts, argc - i, &argv[i] ); - } - - return non_option_arguments; -} - -void scanLine( Options& opts, string& line ) -{ - /* strip any leading whitespace */ - size_t start = line.find_first_not_of( " \t\n\r" ); - if( start == string::npos ) - { - /* blank line */ - return; - } - if( line[start] == '#' ) - { - /* comment line */ - return; - } - /* look for first whitespace or ':' after the option end */ - size_t option_end = line.find_first_of( ": \t\n\r", start ); - string option = line.substr( start, option_end - start ); - - /* look for ':', eat up any whitespace first */ - start = line.find_first_not_of( " \t\n\r", option_end ); - if( start == string::npos ) - { - /* error: badly formatted line */ - return; - } - if( line[start] != ':' ) - { - /* error: badly formatted line */ - return; - } - - /* look for start of value string -- eat up any leading whitespace */ - start = line.find_first_not_of( " \t\n\r", ++start ); - if( start == string::npos ) - { - /* error: badly formatted line */ - return; - } - - /* extract the value part, which may contain embedded spaces - * by searching for a word at a time, until we hit a comment or end of line */ - size_t value_end = start; - do - { - if( line[value_end] == '#' ) - { - /* rest of line is a comment */ - value_end--; - break; - } - value_end = line.find_first_of( " \t\n\r", value_end ); - /* consume any white space, incase there is another word. - * any trailing whitespace will be removed shortly */ - value_end = line.find_first_not_of( " \t\n\r", value_end ); - } - while( value_end != string::npos ); - /* strip any trailing space from value*/ - value_end = line.find_last_not_of( " \t\n\r", value_end ); - - string value; - if( value_end >= start ) - { - value = line.substr( start, value_end + 1 - start ); - } - else - { - /* error: no value */ - return; - } - - /* store the value in option */ - storePair( opts, true, false, option, value ); -} - -void scanFile( Options& opts, istream& in ) -{ - do - { - string line; - getline( in, line ); - scanLine( opts, line ); - } - while( !!in ); -} - -/* for all options in opts, set their storage to their specified - * default value */ -void setDefaults( Options& opts ) -{ -// for( Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++ ) -// { -// ( *it )->opt->setDefault(); -// } -} - -void parseConfigFile( Options& opts, const string& filename ) -{ - ifstream cfgstream( filename.c_str(), ifstream::in ); - if( !cfgstream ) - { - cerr << "Failed to open config file: `" - << filename - << "'" - << endl; - exit( EXIT_FAILURE ); - } - scanFile( opts, cfgstream ); -} - } // NAMESPACE diff --git a/lib/ProgramOptions.h b/lib/ProgramOptions.h index 0007cc1..b27ae47 100644 --- a/lib/ProgramOptions.h +++ b/lib/ProgramOptions.h @@ -74,17 +74,6 @@ struct ParseFailure: public std::exception } }; -void doHelp( std::ostream& out, Options& opts, unsigned columns = 80 ); -unsigned parseGNU( Options& opts, unsigned argc, const char* argv[] ); -unsigned parseSHORT( Options& opts, unsigned argc, const char* argv[] ); -std::list scanArgv( Options& opts, unsigned argc, const char* argv[] ); -void scanLine( Options& opts, std::string& line ); -void scanFile( Options& opts, std::istream& in ); -void setDefaults( Options& opts ); -void setDefaults( Options* opts ); -void parseConfigFile( Options& opts, const std::string& filename ); -bool storePair( Options& opts, const std::string& name, const std::string& value ); - /** OptionBase: Virtual base class for storing information relating to a * specific option This base class describes common elements. Type specific * information should be stored in a derived class. */ @@ -106,7 +95,6 @@ struct OptionBase virtual void parse( const std::string& arg ) = 0; /* set the argument to the default value */ //virtual void setDefault() = 0; - int count() { return arg_count; @@ -143,9 +131,9 @@ struct FlagOpt: public OptionBase /** Type specific option storage */ template -struct Option: public OptionBase +struct StandardOpt: public OptionBase { - Option( const std::string& name, T& storage, const std::string& desc ) : + StandardOpt( const std::string& name, T& storage, const std::string& desc ) : OptionBase( name, desc ), opt_storage( storage ) { @@ -163,7 +151,7 @@ struct Option: public OptionBase /* Generic parsing */ template -inline void Option::parse( const std::string& arg ) +inline void StandardOpt::parse( const std::string& arg ) { std::istringstream arg_ss( arg, std::istringstream::in ); arg_ss.exceptions( std::ios::failbit ); @@ -181,7 +169,7 @@ inline void Option::parse( const std::string& arg ) /* string parsing is specialized -- copy the whole string, not just the * first word */ template<> -inline void Option::parse( const std::string& arg ) +inline void StandardOpt::parse( const std::string& arg ) { opt_storage = arg; arg_count++; @@ -190,7 +178,7 @@ inline void Option::parse( const std::string& arg ) /* string parsing is specialized -- copy the whole string, not just the * first word */ template<> -inline void Option >::parse( const std::string& arg ) +inline void StandardOpt >::parse( const std::string& arg ) { opt_storage.push_back( arg ); arg_count++; @@ -225,21 +213,18 @@ private: }; class OptionSpecific; -struct Options +class Options { - ~Options(); +public: - OptionSpecific addOptions(); - Void setDefaults(); - - struct Names + struct Option { - Names() : + Option() : opt( 0 ) { } ; - ~Names() + ~Option() { if( opt ) delete opt; @@ -248,19 +233,44 @@ struct Options std::list opt_short; OptionBase* opt; }; + typedef std::list OptionsList; + + Options( const std::string& name = "" ); + ~Options(); + + std::list scanArgv( unsigned argc, const char* argv[] ); + Void scanArgs( std::vector args_array); + Void doHelp( std::ostream& out, unsigned columns = 80 ); + + OptionSpecific addOptions(); + Void setDefaults(); OptionBase* operator[]( const std::string& optName ); OptionBase* getOption( const std::string& optName ); + OptionsList& getOptionList() + { + return opt_list; + } + void addOption( OptionBase *opt ); - typedef std::list NamesPtrList; - NamesPtrList opt_list; +private: - typedef std::map NamesMap; - NamesMap opt_long_map; - NamesMap opt_short_map; + typedef std::map OptionMap; + OptionMap opt_long_map; + OptionMap opt_short_map; + OptionsList opt_list; + + std::string m_cOptionGroupName; + Bool m_bAllowUnkonw; + + Bool storePair( Bool allow_long, Bool allow_short, const std::string& name, const std::string& value ); + Bool storePair( const std::string& name, const std::string& value ); + UInt parseLONG( unsigned argc, const char* argv[] ); + UInt parseLONG( std::string arg ); + unsigned parseSHORT( unsigned argc, const char* argv[] ); }; /* Class with templated overloaded operator(), for use by Options::addOptions() */ @@ -282,24 +292,10 @@ public: OptionSpecific& operator()( const std::string& name, T& storage, const std::string& desc ) { - parent.addOption( new Option( name, storage, desc ) ); + parent.addOption( new StandardOpt( name, storage, desc ) ); return *this; } -// /** -// * Add option described by name to the parent Options list, -// * with storage for the option's value -// * with default_val as the default value -// * with desc as an optional help description -// */ -// template -// OptionSpecific& -// operator()( const std::string& name, T& storage, const std::string& desc ) -// { -// parent.addOption( new Option( name, storage, desc ) ); -// return *this; -// } - /** * Add option described by name to the parent Options list, * with storage for the option's value diff --git a/modules/AbsoluteFrameDifference.cpp b/modules/AbsoluteFrameDifference.cpp index 8af3b45..5dac1ac 100644 --- a/modules/AbsoluteFrameDifference.cpp +++ b/modules/AbsoluteFrameDifference.cpp @@ -31,24 +31,27 @@ namespace plaYUVer AbsoluteFrameDifference::AbsoluteFrameDifference() { /* Module Definition */ + m_iModuleAPI = MODULE_API_2; m_iModuleType = FRAME_PROCESSING_MODULE; m_pchModuleCategory = "Measurements"; m_pchModuleName = "AbsoluteFrameDifference"; m_pchModuleTooltip = "Measure the absolute difference between two images (Y plane), e. g., abs( Y1 - Y2 )"; m_uiModuleRequirements = MODULE_REQUIRES_NEW_WINDOW; m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES; - m_bApplyWhilePlaying = APPLY_WHILE_PLAYING; - m_pcFrameDifference = NULL; } -Void AbsoluteFrameDifference::create( PlaYUVerFrame* Input ) +Bool AbsoluteFrameDifference::create( std::vector apcFrameList ) { - m_pcFrameDifference = new PlaYUVerFrame( Input->getWidth(), Input->getHeight(), PlaYUVerFrame::GRAY ); + _BASIC_MODULE_API_2_CHECK_ + m_pcFrameDifference = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), PlaYUVerFrame::GRAY ); + return true; } -PlaYUVerFrame* AbsoluteFrameDifference::process( PlaYUVerFrame* Input1, PlaYUVerFrame* Input2 ) +PlaYUVerFrame* AbsoluteFrameDifference::process( std::vector apcFrameList ) { + PlaYUVerFrame* Input1 = apcFrameList[0]; + PlaYUVerFrame* Input2 = apcFrameList[1]; Pel* pInput1PelYUV = Input1->getPelBufferYUV()[0][0]; Pel* pInput2PelYUV = Input2->getPelBufferYUV()[0][0]; Pel* pOutputPelYUV = m_pcFrameDifference->getPelBufferYUV()[0][0]; diff --git a/modules/AbsoluteFrameDifference.h b/modules/AbsoluteFrameDifference.h index 6f4c543..434d61a 100644 --- a/modules/AbsoluteFrameDifference.h +++ b/modules/AbsoluteFrameDifference.h @@ -34,7 +34,7 @@ namespace plaYUVer class AbsoluteFrameDifference: public PlaYUVerModuleIf { - REGISTER_CLASS_FACTORY( AbsoluteFrameDifference ) +REGISTER_CLASS_FACTORY( AbsoluteFrameDifference ) private: PlaYUVerFrame* m_pcFrameDifference; @@ -44,8 +44,8 @@ public: virtual ~AbsoluteFrameDifference() { } - Void create( PlaYUVerFrame* Input ); - PlaYUVerFrame* process( PlaYUVerFrame* Input1, PlaYUVerFrame* Input2 ); + Bool create( std::vector apcFrameList ); + PlaYUVerFrame* process( std::vector apcFrameList ); Void destroy(); }; diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 1dce7dd..ac7afdd 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -37,8 +37,13 @@ ADD_MODULE( FilterComponentChromaU "FilterComponent" ) ADD_MODULE( FilterComponentChromaV "FilterComponent" ) ADD_MODULE( FrameDifference "FrameDifference" ) ADD_MODULE( AbsoluteFrameDifference "AbsoluteFrameDifference" ) +ADD_MODULE( FrameBinarization "FrameBinarization" ) +ADD_MODULE( SetChromaHalfScale "SetChromaHalfScale" ) +ADD_MODULE( EightBitsSampling "EightBitsSampling" ) +ADD_MODULE( FrameCrop "FrameCrop" ) ADD_MODULE( LumaAverage "LumaAverage" ) IF( USE_OPENCV ) + ADD_MODULE( DisparityStereoBM "DisparityStereoBM" ) ADD_MODULE( DisparityStereoVar "DisparityStereoVar" ) ENDIF() @@ -48,4 +53,7 @@ ENDIF() # file( APPEND ${CMAKE_CURRENT_BINARY_DIR}/ModulesListHeader.h "#endif // __MODULESLISTHEADER_H__\n" ) +INCLUDE_DIRECTORIES( ${OpenCV_INCLUDE_DIRS} ) ADD_LIBRARY( PlaYUVerModules ${plaYUver_Mod_SRCS} ) +TARGET_LINK_LIBRARIES( PlaYUVerModules PlaYUVerLib ${OpenCV_LIBRARIES} ) + diff --git a/modules/DisparityStereoBM.cpp b/modules/DisparityStereoBM.cpp new file mode 100644 index 0000000..e950391 --- /dev/null +++ b/modules/DisparityStereoBM.cpp @@ -0,0 +1,94 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file DisparityStereoBM.cpp + * \brief Measure the disparity between two images using the Stereo Var method (OpenCV) + */ + +#include + +#include "DisparityStereoBM.h" + +namespace plaYUVer +{ + +DisparityStereoBM::DisparityStereoBM() +{ + /* Module Definition */ + m_iModuleAPI = MODULE_API_2; + m_iModuleType = FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Disparity"; + m_pchModuleName = "BlockMatching"; + m_pchModuleTooltip = "Measure the disparity between two images using the Stereo BM method (OpenCV)"; + m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES; + m_uiModuleRequirements = MODULE_REQUIRES_SKIP_WHILE_PLAY | MODULE_REQUIRES_NEW_WINDOW | MODULE_REQUIRES_OPTIONS; + + m_cModuleOptions.addOptions()/**/ + ( "block_size", m_cStereoBM.state->SADWindowSize, "Block Size (positive odd number) [9]" ); + + m_pcDisparityFrame = NULL; + + m_cStereoBM.state->preFilterCap = 31; + m_cStereoBM.state->SADWindowSize = 9; + m_cStereoBM.state->minDisparity = 0; + m_cStereoBM.state->textureThreshold = 10; + m_cStereoBM.state->uniquenessRatio = 15; + m_cStereoBM.state->speckleWindowSize = 100; + m_cStereoBM.state->speckleRange = 32; + m_cStereoBM.state->disp12MaxDiff = 1; + +} + +Bool DisparityStereoBM::create( std::vector apcFrameList ) +{ + _BASIC_MODULE_API_2_CHECK_ + m_pcDisparityFrame = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), PlaYUVerFrame::GRAY ); + if( ( m_cStereoBM.state->SADWindowSize % 2 ) == 0 ) + { + m_cStereoBM.state->SADWindowSize++; + } + m_cStereoBM.state->numberOfDisparities = ( ( ( apcFrameList[0]->getWidth() / 8 ) + 15 ) & -16 ); + return true; +} +PlaYUVerFrame* DisparityStereoBM::process( std::vector apcFrameList ) +{ + PlaYUVerFrame* InputLeft = apcFrameList[0]; + PlaYUVerFrame* InputRight = apcFrameList[1]; + + cv::Mat* leftImage = InputLeft->getCvMat( true ); + cv::Mat* rightImage = InputRight->getCvMat( true ); + cv::Mat disparityImage, disparityImage8; + + m_cStereoBM( *leftImage, *rightImage, disparityImage ); + disparityImage.convertTo( disparityImage8, CV_8U ); + + m_pcDisparityFrame->fromCvMat( &disparityImage8 ); + return m_pcDisparityFrame; +} + +Void DisparityStereoBM::destroy() +{ + if( m_pcDisparityFrame ) + delete m_pcDisparityFrame; + m_pcDisparityFrame = NULL; +} + +} // NAMESPACE + diff --git a/modules/DisparityStereoBM.h b/modules/DisparityStereoBM.h new file mode 100644 index 0000000..5c40fe6 --- /dev/null +++ b/modules/DisparityStereoBM.h @@ -0,0 +1,58 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file DisparityStereoBM.h + * \brief Measure the disparity between two images using the Stereo Var method (OpenCV) + */ + +#ifndef __DISPARITYSTEREOBM_H__ +#define __DISPARITYSTEREOBM_H__ + +#include +#include "PlaYUVerModuleIf.h" +#include + +#include + +namespace plaYUVer +{ + +class DisparityStereoBM: public PlaYUVerModuleIf +{ +REGISTER_CLASS_FACTORY( DisparityStereoBM ) + +private: + PlaYUVerFrame* m_pcDisparityFrame; + cv::StereoBM m_cStereoBM; +public: + DisparityStereoBM(); + virtual ~DisparityStereoBM() + { + } + + Bool create( std::vector apcFrameList ); + PlaYUVerFrame* process( std::vector apcFrameList ); + Void destroy(); +}; + +} // NAMESPACE + +#endif // __DISPARITYSTEREOBM_H__ + diff --git a/modules/DisparityStereoVar.cpp b/modules/DisparityStereoVar.cpp index 1dee936..6099935 100644 --- a/modules/DisparityStereoVar.cpp +++ b/modules/DisparityStereoVar.cpp @@ -32,13 +32,13 @@ namespace plaYUVer DisparityStereoVar::DisparityStereoVar() { /* Module Definition */ + m_iModuleAPI = MODULE_API_2; m_iModuleType = FRAME_PROCESSING_MODULE; m_pchModuleCategory = "Disparity"; m_pchModuleName = "StereoVar"; m_pchModuleTooltip = "Measure the disparity between two images using the Stereo Var method (OpenCV)"; m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES; - m_uiModuleRequirements = MODULE_REQUIRES_NEW_WINDOW; - m_bApplyWhilePlaying = !APPLY_WHILE_PLAYING; + m_uiModuleRequirements = MODULE_REQUIRES_SKIP_WHILE_PLAY | MODULE_REQUIRES_NEW_WINDOW; m_pcDisparityFrame = NULL; m_cStereoVar.levels = 3; // ignored with USE_AUTO_PARAMS @@ -55,24 +55,26 @@ DisparityStereoVar::DisparityStereoVar() m_cStereoVar.flags = m_cStereoVar.USE_SMART_ID | m_cStereoVar.USE_AUTO_PARAMS | m_cStereoVar.USE_INITIAL_DISPARITY | m_cStereoVar.USE_MEDIAN_FILTERING; } -Void DisparityStereoVar::create( PlaYUVerFrame* InputFrame ) +Bool DisparityStereoVar::create( std::vector apcFrameList ) { - m_pcDisparityFrame = new PlaYUVerFrame( InputFrame->getWidth(), InputFrame->getHeight(), PlaYUVerFrame::GRAY ); - m_cStereoVar.minDisp = -( ( ( InputFrame->getWidth() / 8 ) + 15 ) & -16 ); + _BASIC_MODULE_API_2_CHECK_ + m_pcDisparityFrame = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), PlaYUVerFrame::GRAY ); + m_cStereoVar.minDisp = -( ( ( apcFrameList[0]->getWidth() / 8 ) + 15 ) & -16 ); + return true; } - -PlaYUVerFrame* DisparityStereoVar::process( PlaYUVerFrame* InputLeft, PlaYUVerFrame* InputRight ) +PlaYUVerFrame* DisparityStereoVar::process( std::vector apcFrameList ) { - cv::Mat* leftImage; - InputLeft->getCvMat( (Void**)&leftImage ); - cv::Mat* rightImage; - InputRight->getCvMat( (Void**)&rightImage ); + PlaYUVerFrame* InputLeft = apcFrameList[0]; + PlaYUVerFrame* InputRight = apcFrameList[1]; + + cv::Mat* leftImage = InputLeft->getCvMat(); + cv::Mat* rightImage = InputRight->getCvMat(); cv::Mat disparityImage, disparityImage8; - m_cStereoVar(*leftImage,*rightImage,disparityImage); - disparityImage.convertTo(disparityImage8,CV_8U); + m_cStereoVar( *leftImage, *rightImage, disparityImage ); + disparityImage.convertTo( disparityImage8, CV_8U ); - m_pcDisparityFrame->fromCvMat( (Void*)&disparityImage8); + m_pcDisparityFrame->fromCvMat( &disparityImage8 ); return m_pcDisparityFrame; } diff --git a/modules/DisparityStereoVar.h b/modules/DisparityStereoVar.h index 3c3b6be..3f7d3e1 100644 --- a/modules/DisparityStereoVar.h +++ b/modules/DisparityStereoVar.h @@ -47,8 +47,8 @@ public: { } - Void create( PlaYUVerFrame* InputFrame ); - PlaYUVerFrame* process( PlaYUVerFrame* InputLeft, PlaYUVerFrame* InputRight ); + Bool create( std::vector apcFrameList ); + PlaYUVerFrame* process( std::vector apcFrameList ); Void destroy(); }; diff --git a/modules/EightBitsSampling.cpp b/modules/EightBitsSampling.cpp new file mode 100644 index 0000000..4ed2f20 --- /dev/null +++ b/modules/EightBitsSampling.cpp @@ -0,0 +1,86 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file EightBitsSampling.cpp + * \brief Binarize frame module + */ + +#include "EightBitsSampling.h" + +namespace plaYUVer +{ + +EightBitsSampling::EightBitsSampling() +{ + /* Module Definition */ + m_iModuleAPI = MODULE_API_2; + m_iModuleType = FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Conversions"; + m_pchModuleName = "EightBitsSampling"; + m_pchModuleTooltip = "Sub-sampling frame to 8bpp"; + m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; + m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; + + m_pcSubSampledFrame = NULL; +} + +Bool EightBitsSampling::create( std::vector apcFrameList ) +{ + if( apcFrameList[0]->getBitsPel() > 8 ) + { + m_pcSubSampledFrame = NULL; + m_pcSubSampledFrame = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), apcFrameList[0]->getPelFormat(), 8 ); + return true; + } + return false; +} + +PlaYUVerFrame* EightBitsSampling::process( std::vector apcFrameList ) +{ + PlaYUVerFrame* pcFrame = apcFrameList[0]; + UInt uiShiftBits = pcFrame->getBitsPel() - 8; + Pel* pPelInput = pcFrame->getPelBufferYUV()[0][0]; + Pel* pPelSubSampled = m_pcSubSampledFrame->getPelBufferYUV()[0][0]; + Pel pelValue; + + for( UInt i = 0; i < pcFrame->getHeight() * pcFrame->getWidth(); i++ ) + { + pelValue = *pPelInput++; + pelValue = pelValue >> uiShiftBits; + *pPelSubSampled++ = pelValue; + } + for( UInt i = 0; i < pcFrame->getChromaLength() * 2; i++ ) + { + pelValue = *pPelInput++; + pelValue = pelValue >> uiShiftBits; + *pPelSubSampled++ = pelValue; + } + return m_pcSubSampledFrame; +} + +Void EightBitsSampling::destroy() +{ + if( m_pcSubSampledFrame ) + delete m_pcSubSampledFrame; + m_pcSubSampledFrame = NULL; +} + +} // NAMESPACE + diff --git a/modules/EightBitsSampling.h b/modules/EightBitsSampling.h new file mode 100644 index 0000000..98045b6 --- /dev/null +++ b/modules/EightBitsSampling.h @@ -0,0 +1,53 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file EightBitsSampling.h + * \brief Binarize frame module + */ + +#ifndef __EIGHTBITSSAMPLING_H__ +#define __EIGHTBITSSAMPLING_H__ + +#include "PlaYUVerModuleIf.h" + +namespace plaYUVer +{ + +class EightBitsSampling: public PlaYUVerModuleIf +{ +REGISTER_CLASS_FACTORY( EightBitsSampling ) + +private: + PlaYUVerFrame* m_pcSubSampledFrame; +public: + EightBitsSampling(); + virtual ~EightBitsSampling() + { + } + Bool create( std::vector apcFrameList ); + PlaYUVerFrame* process( std::vector apcFrameList ); + Void destroy(); + +}; + +} // NAMESPACE + +#endif // __EIGHTBITSSAMPLING_H__ + diff --git a/modules/FilterComponent.cpp b/modules/FilterComponent.cpp index 6102704..2fb6a58 100644 --- a/modules/FilterComponent.cpp +++ b/modules/FilterComponent.cpp @@ -34,10 +34,10 @@ FilterComponentModule::FilterComponentModule() m_pcFilteredFrame = NULL; } -Void FilterComponentModule::createFilter( UInt uiWidth, UInt uiHeight ) +Void FilterComponentModule::createFilter( UInt uiWidth, UInt uiHeight, UInt bitsPixel ) { m_pcFilteredFrame = NULL; - m_pcFilteredFrame = new PlaYUVerFrame( uiWidth, uiHeight, PlaYUVerFrame::GRAY ); + m_pcFilteredFrame = new PlaYUVerFrame( uiWidth, uiHeight, PlaYUVerFrame::GRAY, bitsPixel ); } PlaYUVerFrame* FilterComponentModule::filterComponent( PlaYUVerFrame* InputFrame, Int Component ) @@ -60,18 +60,17 @@ FilterComponentLuma::FilterComponentLuma() /* Module Definition */ m_iModuleType = FRAME_PROCESSING_MODULE; // Apply module to the frames or to the whole sequence. // Currently only support for frame - m_pchModuleCategory = "FilterComponent"; // Category (sub-menu) + m_pchModuleCategory = "FilterComponent"; // Category (sub-menu) m_pchModuleName = "Luma"; // Name m_pchModuleTooltip = "Filter Y matrix of YUV frame"; // Description m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; // Number of Frames required (ONE_FRAME, TWO_FRAMES, THREE_FRAMES) m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; // Module requirements (check PlaYUVerModulesIf.h). // Several requirements should be "or" between each others. - m_bApplyWhilePlaying = APPLY_WHILE_PLAYING; // Apply module while playing } Void FilterComponentLuma::create( PlaYUVerFrame* InputFrame ) { - createFilter( InputFrame->getWidth(), InputFrame->getHeight() ); + createFilter( InputFrame->getWidth(), InputFrame->getHeight(), InputFrame->getBitsPel() ); } PlaYUVerFrame* FilterComponentLuma::process( PlaYUVerFrame* InputFrame ) @@ -88,12 +87,11 @@ FilterComponentChromaU::FilterComponentChromaU() m_pchModuleTooltip = "Filter U matrix of YUV frame"; m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; - m_bApplyWhilePlaying = !APPLY_WHILE_PLAYING; } Void FilterComponentChromaU::create( PlaYUVerFrame* InputFrame ) { - createFilter( InputFrame->getChromaWidth(), InputFrame->getChromaHeight() ); + createFilter( InputFrame->getChromaWidth(), InputFrame->getChromaHeight(), InputFrame->getBitsPel() ); } PlaYUVerFrame* FilterComponentChromaU::process( PlaYUVerFrame* InputFrame ) @@ -110,12 +108,11 @@ FilterComponentChromaV::FilterComponentChromaV() m_pchModuleTooltip = "Filter V matrix of YUV frame"; m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; - m_bApplyWhilePlaying = !APPLY_WHILE_PLAYING; } Void FilterComponentChromaV::create( PlaYUVerFrame* InputFrame ) { - createFilter( InputFrame->getChromaWidth(), InputFrame->getChromaHeight() ); + createFilter( InputFrame->getChromaWidth(), InputFrame->getChromaHeight(), InputFrame->getBitsPel() ); } PlaYUVerFrame* FilterComponentChromaV::process( PlaYUVerFrame* InputFrame ) diff --git a/modules/FilterComponent.h b/modules/FilterComponent.h index 70e0352..9bc0a89 100644 --- a/modules/FilterComponent.h +++ b/modules/FilterComponent.h @@ -43,7 +43,7 @@ public: PlaYUVerFrame* process( PlaYUVerFrame* ) = 0; Void destroy(); - Void createFilter( UInt uiWidth, UInt uiHeight ); + Void createFilter( UInt uiWidth, UInt uiHeight, UInt bitsPixel ); PlaYUVerFrame* filterComponent( PlaYUVerFrame* InputFrame, Int Component ); }; diff --git a/modules/FrameBinarization.cpp b/modules/FrameBinarization.cpp new file mode 100644 index 0000000..ed8662b --- /dev/null +++ b/modules/FrameBinarization.cpp @@ -0,0 +1,73 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file FrameBinarization.cpp + * \brief Binarize frame module + */ + +#include "FrameBinarization.h" + +namespace plaYUVer +{ + +FrameBinarization::FrameBinarization() +{ + /* Module Definition */ + m_iModuleType = FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Utilities"; + m_pchModuleName = "FrameBinarization"; + m_pchModuleTooltip = "Binarize frame"; + m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; + m_uiModuleRequirements = MODULE_REQUIRES_OPTIONS; + + m_cModuleOptions.addOptions()/**/ + ( "threshold", m_uiThreshold, "Threshold level for binarization (0-255) [128]" ); + + m_pcBinFrame = NULL; + m_uiThreshold = 128; +} + +Void FrameBinarization::create( PlaYUVerFrame* frame ) +{ + m_pcBinFrame = NULL; + m_pcBinFrame = new PlaYUVerFrame( frame->getWidth(), frame->getHeight(), PlaYUVerFrame::GRAY, 8 ); +} + +PlaYUVerFrame* FrameBinarization::process( PlaYUVerFrame* frame ) +{ + Pel* pPelInput = frame->getPelBufferYUV()[0][0]; + Pel* pPelBin = m_pcBinFrame->getPelBufferYUV()[0][0]; + for( UInt y = 0; y < frame->getHeight(); y++ ) + for( UInt x = 0; x < frame->getWidth(); x++ ) + { + *pPelBin++ = *pPelInput++ >= m_uiThreshold ? 255 : 0; + } + return m_pcBinFrame; +} + +Void FrameBinarization::destroy() +{ + if( m_pcBinFrame ) + delete m_pcBinFrame; + m_pcBinFrame = NULL; +} + +} // NAMESPACE + diff --git a/modules/FrameBinarization.h b/modules/FrameBinarization.h new file mode 100644 index 0000000..aa6439c --- /dev/null +++ b/modules/FrameBinarization.h @@ -0,0 +1,54 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file FrameBinarization.h + * \brief Binarize frame module + */ + +#ifndef __FRAMEBINARIZATION_H__ +#define __FRAMEBINARIZATION_H__ + +#include "PlaYUVerModuleIf.h" + +namespace plaYUVer +{ + +class FrameBinarization: public PlaYUVerModuleIf +{ +REGISTER_CLASS_FACTORY( FrameBinarization ) + +private: + PlaYUVerFrame* m_pcBinFrame; + UInt m_uiThreshold; +public: + FrameBinarization(); + virtual ~FrameBinarization() + { + } + Void create( PlaYUVerFrame* ); + PlaYUVerFrame* process( PlaYUVerFrame* ); + Void destroy(); + +}; + +} // NAMESPACE + +#endif // __FRAMEBINARIZATION_H__ + diff --git a/modules/FrameCrop.cpp b/modules/FrameCrop.cpp new file mode 100644 index 0000000..23c210f --- /dev/null +++ b/modules/FrameCrop.cpp @@ -0,0 +1,81 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file FrameCrop.cpp + * \brief Crop a region of an image + */ + +#include "FrameCrop.h" + +namespace plaYUVer +{ + +FrameCrop::FrameCrop() +{ + /* Module Definition */ + m_iModuleType = FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Utilities"; + m_pchModuleName = "FrameCrop"; + m_pchModuleTooltip = "Crop a region of a frame"; + m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; + m_uiModuleRequirements = MODULE_REQUIRES_OPTIONS; + + m_cModuleOptions.addOptions()/**/ + ( "xPosition", m_uiXPosition, "X cordinate of the left-top corner of the crop region [0]" )/**/ + ( "yPosition", m_uiYPosition, "Y cordinate of the left-top corner of the crop region [0]" )/**/ + ( "width", m_iXSize, "Width of the crop region [-1]" )/**/ + ( "height", m_iYSize, "Height of the crop region [-1]" ); + + m_pcCropedFrame = NULL; + m_uiXPosition = 0; + m_uiYPosition = 0; + m_iXSize = -1; + m_iYSize = -1; +} + +Void FrameCrop::create( PlaYUVerFrame* frame ) +{ + m_pcCropedFrame = NULL; + if( m_iXSize == -1 ) + { + m_iXSize = frame->getWidth() - m_uiXPosition; + } + if( m_iYSize == -1 ) + { + m_iYSize = frame->getHeight() - m_uiYPosition; + } + m_pcCropedFrame = new PlaYUVerFrame( m_iXSize, m_iYSize, frame->getPelFormat(), frame->getBitsPel() ); +} + +PlaYUVerFrame* FrameCrop::process( PlaYUVerFrame* frame ) +{ + m_pcCropedFrame->copyFrom( frame, m_uiXPosition, m_uiYPosition ); + return m_pcCropedFrame; +} + +Void FrameCrop::destroy() +{ + if( m_pcCropedFrame ) + delete m_pcCropedFrame; + m_pcCropedFrame = NULL; +} + +} // NAMESPACE + diff --git a/modules/FrameCrop.h b/modules/FrameCrop.h new file mode 100644 index 0000000..eee1f60 --- /dev/null +++ b/modules/FrameCrop.h @@ -0,0 +1,57 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file FrameCrop.h + * \brief Crop a region of an image + */ + +#ifndef __FRAMECROP_H__ +#define __FRAMECROP_H__ + +#include "PlaYUVerModuleIf.h" + +namespace plaYUVer +{ + +class FrameCrop: public PlaYUVerModuleIf +{ +REGISTER_CLASS_FACTORY( FrameCrop ) + +private: + PlaYUVerFrame* m_pcCropedFrame; + UInt m_uiXPosition; + UInt m_uiYPosition; + Int m_iXSize; + Int m_iYSize; +public: + FrameCrop(); + virtual ~FrameCrop() + { + } + Void create( PlaYUVerFrame* ); + PlaYUVerFrame* process( PlaYUVerFrame* ); + Void destroy(); + +}; + +} // NAMESPACE + +#endif // __FRAMECROP_H__ + diff --git a/modules/FrameDifference.cpp b/modules/FrameDifference.cpp index f3b8dd1..b524811 100644 --- a/modules/FrameDifference.cpp +++ b/modules/FrameDifference.cpp @@ -31,26 +31,30 @@ namespace plaYUVer FrameDifference::FrameDifference() { /* Module Definition */ + m_iModuleAPI = MODULE_API_2; m_iModuleType = FRAME_PROCESSING_MODULE; m_pchModuleCategory = "Measurements"; m_pchModuleName = "FrameDifference"; m_pchModuleTooltip = "Measure the difference between two images (Y plane), Y1 - Y2, with max absolute diff of 128"; m_uiModuleRequirements = MODULE_REQUIRES_NEW_WINDOW; m_uiNumberOfFrames = MODULE_REQUIRES_TWO_FRAMES; - m_bApplyWhilePlaying = APPLY_WHILE_PLAYING; m_pcFrameDifference = NULL; } -Void FrameDifference::create( PlaYUVerFrame* Input ) +Bool FrameDifference::create( std::vector apcFrameList ) { - m_pcFrameDifference = new PlaYUVerFrame( Input->getWidth(), Input->getHeight(), PlaYUVerFrame::GRAY ); + _BASIC_MODULE_API_2_CHECK_ + UInt bitsPixel = ( apcFrameList[0]->getBitsPel() + 1 ) & 0x0F; + m_iMaxDiffValue = ( 1 << ( bitsPixel - 1 ) ); + m_pcFrameDifference = new PlaYUVerFrame( apcFrameList[0]->getWidth(), apcFrameList[0]->getHeight(), PlaYUVerFrame::GRAY, bitsPixel ); + return true; } -PlaYUVerFrame* FrameDifference::process( PlaYUVerFrame* Input1, PlaYUVerFrame* Input2 ) +PlaYUVerFrame* FrameDifference::process( std::vector apcFrameList ) { - Pel* pInput1PelYUV = Input1->getPelBufferYUV()[0][0]; - Pel* pInput2PelYUV = Input2->getPelBufferYUV()[0][0]; + Pel* pInput1PelYUV = apcFrameList[0]->getPelBufferYUV()[0][0]; + Pel* pInput2PelYUV = apcFrameList[1]->getPelBufferYUV()[0][0]; Pel* pOutputPelYUV = m_pcFrameDifference->getPelBufferYUV()[0][0]; Int aux_pel_1, aux_pel_2; Int diff = 0; @@ -61,8 +65,9 @@ PlaYUVerFrame* FrameDifference::process( PlaYUVerFrame* Input1, PlaYUVerFrame* I aux_pel_1 = *pInput1PelYUV++; aux_pel_2 = *pInput2PelYUV++; diff = aux_pel_1 - aux_pel_2; - diff = std::min( diff, 127 ); - diff = std::max( diff, -128 ); + diff = std::min( diff, m_iMaxDiffValue ); + diff = std::max( diff, -m_iMaxDiffValue ); + diff += m_iMaxDiffValue + 1; *pOutputPelYUV++ = diff; } return m_pcFrameDifference; diff --git a/modules/FrameDifference.h b/modules/FrameDifference.h index 93bf9c8..9b01b0c 100644 --- a/modules/FrameDifference.h +++ b/modules/FrameDifference.h @@ -34,9 +34,10 @@ namespace plaYUVer class FrameDifference: public PlaYUVerModuleIf { - REGISTER_CLASS_FACTORY( FrameDifference ) +REGISTER_CLASS_FACTORY( FrameDifference ) private: + Int m_iMaxDiffValue; PlaYUVerFrame* m_pcFrameDifference; public: @@ -44,8 +45,8 @@ public: virtual ~FrameDifference() { } - Void create( PlaYUVerFrame* Input ); - PlaYUVerFrame* process( PlaYUVerFrame* Input1, PlaYUVerFrame* Input2 ); + Bool create( std::vector apcFrameList ); + PlaYUVerFrame* process( std::vector apcFrameList ); Void destroy(); }; diff --git a/modules/LumaAverage.cpp b/modules/LumaAverage.cpp index c32a79d..3636a72 100644 --- a/modules/LumaAverage.cpp +++ b/modules/LumaAverage.cpp @@ -30,13 +30,14 @@ namespace plaYUVer LumaAverage::LumaAverage() { /* Module Definition */ - m_iModuleType = FRAME_MEASUREMENT_MODULE; - m_pchModuleCategory = "Measurements"; - m_pchModuleName = "LumaAverage"; - m_pchModuleTooltip = "Measure the average of luma component"; - m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; - m_uiModuleRequirements = MODULE_REQUIRES_SIDEBAR; - m_bApplyWhilePlaying = APPLY_WHILE_PLAYING; + m_iModuleType = FRAME_MEASUREMENT_MODULE; // Apply module to the frames or to the whole sequence. + // Currently only support for frame + m_pchModuleCategory = "Measurements"; // Category (sub-menu) + m_pchModuleName = "LumaAverage"; // Name + m_pchModuleTooltip = "Measure the average of luma component"; // Description + m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; // Number of Frames required (ONE_FRAME, TWO_FRAMES, THREE_FRAMES) + m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; // Module requirements (check PlaYUVerModulesIf.h). + // Several requirements should be "or" between each others. } Void LumaAverage::create( PlaYUVerFrame* frame ) @@ -61,5 +62,6 @@ Void LumaAverage::destroy() } -} // NAMESPACE +} +// NAMESPACE diff --git a/modules/PlaYUVerModuleFactory.cpp b/modules/PlaYUVerModuleFactory.cpp index 3007499..db28eee 100644 --- a/modules/PlaYUVerModuleFactory.cpp +++ b/modules/PlaYUVerModuleFactory.cpp @@ -38,9 +38,14 @@ PlaYUVerModuleFactory::PlaYUVerModuleFactory() Register( "FilterComponentChromaV", &FilterComponentChromaV::Create ); Register( "FrameDifference", &FrameDifference::Create ); Register( "AbsoluteFrameDifference", &AbsoluteFrameDifference::Create ); + Register( "SetChromaHalfScale", &SetChromaHalfScale::Create ); + Register( "FrameCrop", &FrameCrop::Create ); + Register( "FrameBinarization", &FrameBinarization::Create ); + Register( "EightBitsSampling", &EightBitsSampling::Create ); Register( "LumaAverage", &LumaAverage::Create ); #ifdef USE_OPENCV Register( "DisparityStereoVar", &DisparityStereoVar::Create ); + Register( "DisparityStereoBM", &DisparityStereoBM::Create ); #endif } @@ -59,7 +64,7 @@ PlaYUVerModuleIf *PlaYUVerModuleFactory::CreateModule( const char* moduleName ) { PlaYUVerModuleFactoryMap& PlaYUVerModuleFactoryMap = PlaYUVerModuleFactory::Get()->getMap(); PlaYUVerModuleFactoryMap::iterator it = PlaYUVerModuleFactoryMap.begin(); - for( ; it != PlaYUVerModuleFactoryMap.end(); ++it) + for( ; it != PlaYUVerModuleFactoryMap.end(); ++it ) { if( !strcmp( it->first, moduleName ) ) { diff --git a/modules/PlaYUVerModuleIf.h b/modules/PlaYUVerModuleIf.h index 54d886f..f6e85a6 100644 --- a/modules/PlaYUVerModuleIf.h +++ b/modules/PlaYUVerModuleIf.h @@ -28,6 +28,8 @@ #include "lib/PlaYUVerDefs.h" #include "lib/PlaYUVerFrame.h" #include "lib/PlaYUVerStream.h" +#include "lib/ProgramOptions.h" +#include namespace plaYUVer { @@ -37,7 +39,20 @@ public: \ static PlaYUVerModuleIf* Create() { return new X(); } \ void Delete() { delete this; } -enum // Module type +#define _BASIC_MODULE_API_2_CHECK_ \ +if( apcFrameList.size() != m_uiNumberOfFrames ) \ + return false; \ +for( UInt i = 0; i < apcFrameList.size(); i++ ) \ + if( !apcFrameList[i] ) \ + return false; + +enum // Module API +{ + MODULE_API_1, + MODULE_API_2, +}; + +enum // Module type { FRAME_PROCESSING_MODULE, FRAME_MEASUREMENT_MODULE, @@ -46,59 +61,75 @@ enum // Module type #define APPLY_WHILE_PLAYING true #define MAX_NUMBER_FRAMES 3 -enum // Number of frames +enum Module_NumberOfFrames { MODULE_REQUIRES_ONE_FRAME = 1, - MODULE_REQUIRES_TWO_FRAMES = 2, - MODULE_REQUIRES_THREE_FRAMES = 3, + MODULE_REQUIRES_TWO_FRAMES, + MODULE_REQUIRES_THREE_FRAMES, + MODULE_REQUIRES_FOUR_FRAMES, + MODULE_REQUIRES_FIVE_FRAMES, + MODULE_REQUIRES_SIX_FRAMES, }; -enum // Requirements +enum Module_Requirements { MODULE_REQUIRES_NOTHING = 0, - MODULE_REQUIRES_NEW_WINDOW = 2, - MODULE_REQUIRES_SIDEBAR = 4, - MODULES_REQUIREMENTS_TOTAL, + MODULE_REQUIRES_SKIP_WHILE_PLAY = 1, + MODULE_REQUIRES_OPTIONS = 2, + MODULE_REQUIRES_NEW_WINDOW = 4, }; -typedef struct -{ - Int m_iModuleType; - const Char* m_pchModuleCategory; - const Char* m_pchModuleName; - const Char* m_pchModuleTooltip; - UInt m_uiNumberOfFrames; - UInt m_uiModuleRequirements; - Bool m_bApplyWhilePlaying; -} PlaYUVerModuleDefinition; - class PlaYUVerModuleIf { public: + Int m_iModuleAPI; Int m_iModuleType; const Char* m_pchModuleCategory; const Char* m_pchModuleName; const Char* m_pchModuleTooltip; - UInt m_uiNumberOfFrames; + enum Module_NumberOfFrames m_uiNumberOfFrames; UInt m_uiModuleRequirements; - Bool m_bApplyWhilePlaying; - PlaYUVerModuleIf() {} - virtual ~PlaYUVerModuleIf() {} + Options m_cModuleOptions; + + PlaYUVerModuleIf() + { + m_iModuleAPI = MODULE_API_1; + m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; + } + virtual ~PlaYUVerModuleIf() + { + } virtual void Delete() = 0; - virtual Void create() {} - virtual Void create( PlaYUVerFrame* ) {} - - virtual PlaYUVerFrame* process( PlaYUVerFrame* ) { return NULL; } - virtual PlaYUVerFrame* process( PlaYUVerFrame*, PlaYUVerFrame* ) { return NULL; } - virtual PlaYUVerFrame* process( PlaYUVerFrame*, PlaYUVerFrame*, PlaYUVerFrame* ) { return NULL; } - - virtual Double measure( PlaYUVerFrame* ) { return 0; } - virtual Double measure( PlaYUVerFrame*, PlaYUVerFrame* ) { return 0; } - virtual Double measure( PlaYUVerFrame*, PlaYUVerFrame*, PlaYUVerFrame* ) { return 0; } + virtual Void create() + { + } + virtual Void create( PlaYUVerFrame* ) + { + } + virtual Bool create( std::vector apcFrameList ) + { + return false; + } + virtual PlaYUVerFrame* process( PlaYUVerFrame* ) + { + return NULL; + } + virtual PlaYUVerFrame* process( std::vector ) + { + return NULL; + } + virtual Double measure( PlaYUVerFrame* ) + { + return 0; + } + virtual Double measure( std::vector ) + { + return 0; + } virtual Void destroy() = 0; diff --git a/modules/SetChromaHalfScale.cpp b/modules/SetChromaHalfScale.cpp new file mode 100644 index 0000000..7b8dc56 --- /dev/null +++ b/modules/SetChromaHalfScale.cpp @@ -0,0 +1,75 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file SetChromaHalfScale.cpp + * \brief Binarize frame module + */ + +#include "SetChromaHalfScale.h" + +namespace plaYUVer +{ + +SetChromaHalfScale::SetChromaHalfScale() +{ + /* Module Definition */ + m_iModuleType = FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Conversions"; + m_pchModuleName = "SetChromaHalfScale"; + m_pchModuleTooltip = "Copy frame only keeping luma component"; + m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; + m_uiModuleRequirements = MODULE_REQUIRES_NOTHING; + + m_pcProcessedFrame = NULL; + +} + +Void SetChromaHalfScale::create( PlaYUVerFrame* frame ) +{ + m_pcProcessedFrame = NULL; + m_pcProcessedFrame = new PlaYUVerFrame( frame->getWidth(), frame->getHeight(), frame->getPelFormat(), frame->getBitsPel() ); +} + +PlaYUVerFrame* SetChromaHalfScale::process( PlaYUVerFrame* frame ) +{ + Pel* pPelInput = frame->getPelBufferYUV()[LUMA][0]; + Pel* pPelOut = m_pcProcessedFrame->getPelBufferYUV()[0][0]; + Pel halfScaleValue = 1 << ( frame->getBitsPel() - 1 ); + for( UInt i = 0; i < frame->getHeight() * frame->getWidth(); i++ ) + { + *pPelOut++ = *pPelInput++; + } + pPelInput = frame->getPelBufferYUV()[CHROMA_U][0]; + for( UInt i = 0; i < m_pcProcessedFrame->getChromaLength() * 2; i++ ) + { + *pPelOut++ = halfScaleValue; + } + return m_pcProcessedFrame; +} + +Void SetChromaHalfScale::destroy() +{ + if( m_pcProcessedFrame ) + delete m_pcProcessedFrame; + m_pcProcessedFrame = NULL; +} + +} // NAMESPACE + diff --git a/modules/SetChromaHalfScale.h b/modules/SetChromaHalfScale.h new file mode 100644 index 0000000..4a36c17 --- /dev/null +++ b/modules/SetChromaHalfScale.h @@ -0,0 +1,53 @@ +/* This file is a part of plaYUVer project + * Copyright (C) 2014-2015 by Luis Lucas (luisfrlucas@gmail.com) + * Joao Carreira (jfmcarreira@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * \file SetChromaHalfScale.h + * \brief Binarize frame module + */ + +#ifndef __CHROMA128_H__ +#define __CHROMA128_H__ + +#include "PlaYUVerModuleIf.h" + +namespace plaYUVer +{ + +class SetChromaHalfScale: public PlaYUVerModuleIf +{ +REGISTER_CLASS_FACTORY( SetChromaHalfScale ) + +private: + PlaYUVerFrame* m_pcProcessedFrame; +public: + SetChromaHalfScale(); + virtual ~SetChromaHalfScale() + { + } + Void create( PlaYUVerFrame* ); + PlaYUVerFrame* process( PlaYUVerFrame* ); + Void destroy(); + +}; + +} // NAMESPACE + +#endif // __CHROMA128_H__ + diff --git a/tools/CommandLineHandle.cpp b/tools/CommandLineHandle.cpp index f6b2b70..33055ce 100644 --- a/tools/CommandLineHandle.cpp +++ b/tools/CommandLineHandle.cpp @@ -70,29 +70,33 @@ Int CommandLineHandle::parseToolsArgs( Int argc, Char *argv[] ) ( "output,o", m_strOutput, "output file" ) /**/ ( "size,s", m_strResolution, "size (WxH)" ) /**/ ( "pel_fmt", m_strPelFmt, "pixel format" ) /**/ + ( "bits_pel", m_uiBitsPerPixel, "bits per pixel" ) /**/ ( "frames,f", m_iFrames, "number of frames to parse" ); Opts().addOptions()/**/ ( "quality", m_strQualityMetric, "select a quality metric" ) /**/ ( "module", m_strModule, "select a module (use internal name)" ); - if( !parse( argc, argv ) ) + config( argc, argv ); + if( !parse() ) { iRet = 1; } if( m_bQuiet ) { - m_uiLogLevel = RESULT; + m_uiLogLevel = LOG_RESULT; } - if( Opts()["quality_metrics"]->count() ) + if( Opts()["module"]->count() && Opts()["help"]->count() ) { - printf( "PlaYUVer supported quality metrics: \n" ); - for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ ) - { - printf( " %s\n", PlaYUVerFrame::supportedQualityMetricsList()[i].c_str() ); - } + listModuleHelp(); + iRet = 1; + } + else if( Opts()["help"]->count() ) + { + printf( "Usage: %s modules/quality [options] -input=input_file [--output=output_file]\n", argv[0] ); + Opts().doHelp( std::cout ); iRet = 1; } @@ -101,7 +105,6 @@ Int CommandLineHandle::parseToolsArgs( Int argc, Char *argv[] ) listModules(); iRet = 1; } - return iRet; } @@ -159,7 +162,28 @@ Void CommandLineHandle::listModules() } printf( "\n" ); } +} +Void CommandLineHandle::listModuleHelp() +{ + std::string moduleName = m_strModule; + PlaYUVerModuleIf* pcCurrModuleIf = NULL; + + PlaYUVerModuleFactoryMap& PlaYUVerModuleFactoryMap = PlaYUVerModuleFactory::Get()->getMap(); + PlaYUVerModuleFactoryMap::iterator it = PlaYUVerModuleFactoryMap.begin(); + for( UInt i = 0; it != PlaYUVerModuleFactoryMap.end(); ++it, i++ ) + { + if( strcmp( it->first, moduleName.c_str() ) == 0 ) + { + pcCurrModuleIf = it->second(); + break; + } + } + if( pcCurrModuleIf ) + { + printf( "Usage: playuverTools --module=%s options:\n", it->first ); + pcCurrModuleIf->m_cModuleOptions.doHelp( std::cout ); + } } } // NAMESPACE diff --git a/tools/CommandLineHandle.h b/tools/CommandLineHandle.h index e1a0942..afc9871 100644 --- a/tools/CommandLineHandle.h +++ b/tools/CommandLineHandle.h @@ -42,13 +42,6 @@ public: CommandLineHandle(); ~CommandLineHandle(); - enum LOG_LEVEL - { - INFO = 0, - WARNINGS = 1, - RESULT = 2, - ERROR = 3, - }; Void setLogLevel( enum LOG_LEVEL level ) { m_uiLogLevel = level; @@ -85,6 +78,7 @@ private: std::string m_strOutput; std::string m_strResolution; std::string m_strPelFmt; + UInt m_uiBitsPerPixel; Bool m_bListPelFmts; Int m_iFrames; @@ -94,6 +88,7 @@ private: std::string m_strModule; Void listModules(); + Void listModuleHelp(); }; diff --git a/tools/PlaYUVerTools.cpp b/tools/PlaYUVerTools.cpp index 6562ab4..a28aa5e 100644 --- a/tools/PlaYUVerTools.cpp +++ b/tools/PlaYUVerTools.cpp @@ -70,6 +70,11 @@ Int PlaYUVerTools::openInputs() { fmtString = m_cCmdLineHandler.m_strPelFmt; } + UInt uiBitPerPixel = 8; + if( m_cCmdLineHandler.Opts()["bits_pel"]->count() ) + { + uiBitPerPixel = m_cCmdLineHandler.m_uiBitsPerPixel; + } std::vector inputFileNames = m_cCmdLineHandler.m_apcInputs; @@ -79,16 +84,16 @@ Int PlaYUVerTools::openInputs() pcStream = new PlaYUVerStream; try { - if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, 1 ) ) + if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, uiBitPerPixel, 1 ) ) { - m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Cannot open input stream %s! ", inputFileNames[i].c_str() ); + m_cCmdLineHandler.log( LOG_ERROR, "Cannot open input stream %s! ", inputFileNames[i].c_str() ); return 2; } m_apcInputStreams.push_back( pcStream ); } catch( const char *msg ) { - m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Cannot open input stream %s with the following error: \n%s\n", inputFileNames[i].c_str(), msg ); + m_cCmdLineHandler.log( LOG_ERROR, "Cannot open input stream %s with the following error: \n%s\n", inputFileNames[i].c_str(), msg ); return 2; } } @@ -132,11 +137,11 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) if( m_cCmdLineHandler.Opts()["quality"]->count() ) { std::string qualityMetric = m_cCmdLineHandler.m_strQualityMetric; - if( m_apcInputStreams.size() != 2 ) - { - m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Invalid number of inputs! " ); - return 2; - } +// if( m_apcInputStreams.size() != 2 ) +// { +// m_cCmdLineHandler.log( LOG_ERROR, "Invalid number of inputs! " ); +// return 2; +// } for( UInt i = 0; i < PlaYUVerFrame::supportedQualityMetricsList().size(); i++ ) { if( lowercase( PlaYUVerFrame::supportedQualityMetricsList()[i] ) == lowercase( qualityMetric ) ) @@ -146,12 +151,12 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) } if( m_uiQualityMetric == -1 ) { - m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Invalid quality metric! " ); + m_cCmdLineHandler.log( LOG_ERROR, "Invalid quality metric! " ); return 2; } m_uiOperation = QUALITY_OPERATION; m_fpProcess = &PlaYUVerTools::QualityOperation; - m_cCmdLineHandler.log( CommandLineHandle::INFO, "PlaYUVer Quality\n" ); + m_cCmdLineHandler.log( LOG_INFO, "PlaYUVer Quality\n" ); } /** @@ -174,11 +179,33 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) if( m_apcInputStreams.size() != m_pcCurrModuleIf->m_uiNumberOfFrames ) { - m_cCmdLineHandler.log( CommandLineHandle::ERROR, "Invalid number of inputs! " ); + m_cCmdLineHandler.log( LOG_ERROR, "Invalid number of inputs! " ); return 2; } - m_pcCurrModuleIf->create( m_apcInputStreams[0]->getCurrFrame() ); + m_pcCurrModuleIf->m_cModuleOptions.scanArgv( argc, ( const Char** )argv ); + + // Create Module + Bool moduleCreated = false; + std::vector apcFrameList; + for( UInt i = 0; i < m_pcCurrModuleIf->m_uiNumberOfFrames; i++ ) + { + apcFrameList.push_back( m_apcInputStreams[i]->getCurrFrame() ); + } + if( m_pcCurrModuleIf->m_iModuleAPI == MODULE_API_2 ) + { + moduleCreated = m_pcCurrModuleIf->create( apcFrameList ); + } + else if( m_pcCurrModuleIf->m_iModuleAPI == MODULE_API_1 ) + { + m_pcCurrModuleIf->create( m_apcInputStreams[0]->getCurrFrame() ); + moduleCreated = true; + } + if( !moduleCreated ) + { + m_cCmdLineHandler.log( LOG_ERROR, "Module is not supported with the selected inputs! " ); + return 2; + } if( m_pcCurrModuleIf->m_iModuleType == FRAME_PROCESSING_MODULE ) { @@ -186,13 +213,20 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) std::vector outputFileNames; if( m_cCmdLineHandler.Opts()["output"]->count() ) outputFileNames.push_back( m_cCmdLineHandler.m_strOutput ); - ; if( outputFileNames.size() == 1 ) { - PlaYUVerFrame* pcModFrame = applyFrameModule(); + PlaYUVerFrame* pcModFrame; + if( m_pcCurrModuleIf->m_iModuleAPI == MODULE_API_2 ) + { + pcModFrame = m_pcCurrModuleIf->process( apcFrameList ); + } + else + { + pcModFrame = applyFrameModule(); + } PlaYUVerStream* pcModStream = new PlaYUVerStream; - if( !pcModStream->open( outputFileNames[0], pcModFrame->getWidth(), pcModFrame->getHeight(), pcModFrame->getPelFormat(), 1, false ) ) + if( !pcModStream->open( outputFileNames[0], pcModFrame->getWidth(), pcModFrame->getHeight(), pcModFrame->getPelFormat(), 8, 1, false ) ) { delete pcModStream; pcModStream = NULL; @@ -202,19 +236,19 @@ Int PlaYUVerTools::Open( Int argc, Char *argv[] ) } else { - m_cCmdLineHandler.log( CommandLineHandle::ERROR, "One output is required! " ); + m_cCmdLineHandler.log( LOG_ERROR, "One output is required! " ); return 2; } } m_uiOperation = MODULE_OPERATION; m_fpProcess = &PlaYUVerTools::ModuleOperation; - m_cCmdLineHandler.log( CommandLineHandle::INFO, "PlaYUVer Module\n" ); + m_cCmdLineHandler.log( LOG_INFO, "PlaYUVer Module\n" ); } if( m_uiOperation == INVALID_OPERATION ) { - m_cCmdLineHandler.log( CommandLineHandle::ERROR, "No operation was selected! " ); + m_cCmdLineHandler.log( LOG_ERROR, "No operation was selected! " ); return 2; } return iRet; @@ -238,8 +272,7 @@ Int PlaYUVerTools::QualityOperation() Double adAverageQuality[MAX_NUMBER_INPUTS - 1][MAX_NUMBER_COMPONENTS]; Double dQuality; - m_cCmdLineHandler.log( CommandLineHandle::INFO, " Measuring Quality using %s ... \n", - PlaYUVerFrame::supportedQualityMetricsList()[m_uiQualityMetric].c_str() ); + m_cCmdLineHandler.log( LOG_INFO, " Measuring Quality using %s ... \n", PlaYUVerFrame::supportedQualityMetricsList()[m_uiQualityMetric].c_str() ); for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) { @@ -251,21 +284,21 @@ Int PlaYUVerTools::QualityOperation() } for( UInt frame = 0; frame < m_uiNumberOfFrames; frame++ ) { - m_cCmdLineHandler.log( CommandLineHandle::INFO, " %3d", frame ); + m_cCmdLineHandler.log( LOG_INFO, " %3d", frame ); for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) apcCurrFrame[s] = m_apcInputStreams[s]->getCurrFrame(); for( UInt s = 1; s < m_apcInputStreams.size(); s++ ) { - m_cCmdLineHandler.log( CommandLineHandle::RESULT, " " ); + m_cCmdLineHandler.log( LOG_RESULT, " " ); for( UInt c = 0; c < m_uiNumberOfComponents; c++ ) { dQuality = apcCurrFrame[s]->getQuality( m_uiQualityMetric, apcCurrFrame[0], c ); adAverageQuality[s - 1][c] = ( adAverageQuality[s - 1][c] * Double( frame ) + dQuality ) / Double( frame + 1 ); - m_cCmdLineHandler.log( CommandLineHandle::RESULT, " %5.3f", dQuality ); + m_cCmdLineHandler.log( LOG_RESULT, " %5.3f", dQuality ); } } - m_cCmdLineHandler.log( CommandLineHandle::RESULT, "\n" ); + m_cCmdLineHandler.log( LOG_RESULT, "\n" ); for( UInt s = 0; s < m_apcInputStreams.size(); s++ ) { abEOF[s] = m_apcInputStreams[s]->setNextFrame(); @@ -275,15 +308,15 @@ Int PlaYUVerTools::QualityOperation() } } } - m_cCmdLineHandler.log( CommandLineHandle::INFO, "\n Mean Values: \n " ); + m_cCmdLineHandler.log( LOG_INFO, "\n Mean Values: \n " ); for( UInt s = 0; s < m_apcInputStreams.size() - 1; s++ ) { for( UInt c = 0; c < m_uiNumberOfComponents; c++ ) { - m_cCmdLineHandler.log( CommandLineHandle::INFO, " %5.3f", adAverageQuality[s][c] ); + m_cCmdLineHandler.log( LOG_INFO, " %5.3f", adAverageQuality[s][c] ); } } - m_cCmdLineHandler.log( CommandLineHandle::INFO, "\n" ); + m_cCmdLineHandler.log( LOG_INFO, "\n" ); return 0; } @@ -292,22 +325,15 @@ PlaYUVerFrame* PlaYUVerTools::applyFrameModule() PlaYUVerFrame* pcProcessedFrame = NULL; if( m_pcCurrModuleIf->m_iModuleType == FRAME_PROCESSING_MODULE ) { - switch( m_pcCurrModuleIf->m_uiNumberOfFrames ) - { - case MODULE_REQUIRES_ONE_FRAME: - pcProcessedFrame = m_pcCurrModuleIf->process( m_apcInputStreams[0]->getCurrFrame() ); - break; - case MODULE_REQUIRES_TWO_FRAMES: - pcProcessedFrame = m_pcCurrModuleIf->process( m_apcInputStreams[0]->getCurrFrame(), m_apcInputStreams[1]->getCurrFrame() ); - break; - } + pcProcessedFrame = m_pcCurrModuleIf->process( m_apcInputStreams[0]->getCurrFrame() ); } return pcProcessedFrame; } Int PlaYUVerTools::ModuleOperation() { - m_cCmdLineHandler.log( CommandLineHandle::INFO, " Applying Module %s/%s ...\n", m_pcCurrModuleIf->m_pchModuleCategory, m_pcCurrModuleIf->m_pchModuleName ); + std::vector apcFrameList; + m_cCmdLineHandler.log( LOG_INFO, " Applying Module %s/%s ...\n", m_pcCurrModuleIf->m_pchModuleCategory, m_pcCurrModuleIf->m_pchModuleName ); PlaYUVerFrame* pcProcessedFrame = NULL; Double dMeasurementResult = 0.0; @@ -321,25 +347,35 @@ Int PlaYUVerTools::ModuleOperation() for( UInt frame = 0; frame < m_uiNumberOfFrames; frame++ ) { - + apcFrameList.clear(); + for( UInt i = 0; i < m_pcCurrModuleIf->m_uiNumberOfFrames; i++ ) + { + apcFrameList.push_back( m_apcInputStreams[i]->getCurrFrame() ); + } if( m_pcCurrModuleIf->m_iModuleType == FRAME_PROCESSING_MODULE ) { - pcProcessedFrame = applyFrameModule(); + if( m_pcCurrModuleIf->m_iModuleAPI == MODULE_API_2 ) + { + pcProcessedFrame = m_pcCurrModuleIf->process( apcFrameList ); + } + else + { + pcProcessedFrame = applyFrameModule(); + } m_apcOutputStreams[0]->writeFrame( pcProcessedFrame ); } else if( m_pcCurrModuleIf->m_iModuleType == FRAME_MEASUREMENT_MODULE ) { - switch( m_pcCurrModuleIf->m_uiNumberOfFrames ) + if( m_pcCurrModuleIf->m_iModuleAPI == MODULE_API_2 ) { - case MODULE_REQUIRES_ONE_FRAME: - dMeasurementResult = m_pcCurrModuleIf->measure( m_apcInputStreams[0]->getCurrFrame() ); - break; - case MODULE_REQUIRES_TWO_FRAMES: - dMeasurementResult = m_pcCurrModuleIf->measure( m_apcInputStreams[0]->getCurrFrame(), m_apcInputStreams[1]->getCurrFrame() ); - break; + dMeasurementResult = m_pcCurrModuleIf->measure( apcFrameList ); } - m_cCmdLineHandler.log( CommandLineHandle::INFO, " %3d", frame ); - m_cCmdLineHandler.log( CommandLineHandle::RESULT, " %8.3f \n", dMeasurementResult ); + else + { + dMeasurementResult = m_pcCurrModuleIf->measure( m_apcInputStreams[0]->getCurrFrame() ); + } + m_cCmdLineHandler.log( LOG_INFO, " %3d", frame ); + m_cCmdLineHandler.log( LOG_RESULT, " %8.3f \n", dMeasurementResult ); dAveragedMeasurementResult = ( dAveragedMeasurementResult * Double( frame ) + dMeasurementResult ) / Double( frame + 1 ); } @@ -355,7 +391,7 @@ Int PlaYUVerTools::ModuleOperation() if( m_pcCurrModuleIf->m_iModuleType == FRAME_MEASUREMENT_MODULE ) { - m_cCmdLineHandler.log( CommandLineHandle::INFO, "\n Mean Value: \n %8.3f\n", dAveragedMeasurementResult ); + m_cCmdLineHandler.log( LOG_INFO, "\n Mean Value: \n %8.3f\n", dAveragedMeasurementResult ); } return 0;