diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index bd2475c..c29aac2 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -9,24 +9,25 @@ set(plaYUver_App_SRCS # Main main.cpp plaYUVerApp.cpp - ViewArea.cpp - ModulesHandle.cpp - PlaYUVerAppModuleIf.cpp - QualityMeasurement.cpp - GridManager.cpp - Settings.cpp -# Sub Window SubWindowHandle.cpp + Settings.cpp +# Module Video VideoSubWindow.cpp + ViewArea.cpp + VideoHandle.cpp + FramePropertiesSidebar.cpp +# Module Quality + QualityHandle.cpp + QualityMeasurementSidebar.cpp +# Module Plugins + ModulesHandle.cpp + ModuleHandleDock.cpp + PlaYUVerAppModuleIf.cpp + GridManager.cpp # Dialogs AboutDialog.cpp ConfigureFormatDialog.cpp DialogSubWindowSelector.cpp -# Docks / Sidebars - ModuleHandleDock.cpp - PropertiesSidebar.cpp - PlaYUVerFrameStatistics.cpp - QualityMeasurementSidebar.cpp # Widgets HistogramWidget.cpp WidgetFrameNumber.cpp diff --git a/app/ConfigureFormatDialog.cpp b/app/ConfigureFormatDialog.cpp index a72e561..ca73973 100644 --- a/app/ConfigureFormatDialog.cpp +++ b/app/ConfigureFormatDialog.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/ConfigureFormatDialog.h b/app/ConfigureFormatDialog.h index 74f1458..a6084cb 100644 --- a/app/ConfigureFormatDialog.h +++ b/app/ConfigureFormatDialog.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/DialogSubWindowSelector.cpp b/app/DialogSubWindowSelector.cpp index a4e2653..fc1c3fc 100644 --- a/app/DialogSubWindowSelector.cpp +++ b/app/DialogSubWindowSelector.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/DialogSubWindowSelector.h b/app/DialogSubWindowSelector.h index f7cc093..b4505f7 100644 --- a/app/DialogSubWindowSelector.h +++ b/app/DialogSubWindowSelector.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/PropertiesSidebar.cpp b/app/FramePropertiesSidebar.cpp similarity index 79% rename from app/PropertiesSidebar.cpp rename to app/FramePropertiesSidebar.cpp index ccb8926..205ed42 100644 --- a/app/PropertiesSidebar.cpp +++ b/app/FramePropertiesSidebar.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -18,164 +18,18 @@ */ /** - * \file PropertiesSidebar.cpp + * \file FramePropertiesSideBar.cpp * \brief Main side bar definition */ #include #include #include -#include "PropertiesSidebar.h" +#include "FramePropertiesSidebar.h" namespace plaYUVer { -static inline QSize bestSize( QSize currSize ) -{ - QSize bestSize( 180, currSize.height() ); - if( currSize.width() < bestSize.width() ) - return bestSize; - else - return currSize; -} - -//////////////////////////////////////////////////////////////////////////////// -// StreamPropertiesSideBar -//////////////////////////////////////////////////////////////////////////////// - -StreamPropertiesSideBar::StreamPropertiesSideBar( QWidget* parent ) : - QWidget( parent ) -{ - // -------------- Variables definition -------------- - m_pcStream = NULL; - - // ----------------- GUI definition ----------------- - - QLabel *streamNameLabel = new QLabel( tr( "Name:" ) ); - streamNameLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); - labelNameValue = new QLabel; - labelNameValue->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); - labelNameValue->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); - - QLabel *formatLabel = new QLabel( tr( "File Format:" ) ); - formatLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); - labelFormatValue = new QLabel; - labelFormatValue->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); - - QLabel *codecLabel = new QLabel( tr( "Codec:" ) ); - codecLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); - labelCodecValue = new QLabel; - labelCodecValue->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); - - QLabel *durationLabel = new QLabel( tr( "Duration:" ) ); - durationLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); - labelDurationValueTime = new QLabel; - labelDurationValueTime->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); - - labelDurationValueFrames = new QLabel; - labelDurationValueFrames->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); - - QLabel *sizeLabel = new QLabel( tr( "Resolution:" ) ); - sizeLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); - labelSizeValue = new QLabel; - labelSizeValue->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); - - QLabel *colorSpaceLabel = new QLabel( tr( "Color Space:" ) ); - colorSpaceLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); - labelColorSpaceValue = new QLabel; - labelColorSpaceValue->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); - - QGridLayout *propertiesLayout = new QGridLayout; - Int layout_line = 0; -// propertiesLayout->addWidget( streamNameLabel, layout_line, 0 ); -// propertiesLayout->addWidget( labelNameValue, layout_line, 1 ); -// layout_line++; - propertiesLayout->addWidget( formatLabel, layout_line, 0 ); - propertiesLayout->addWidget( labelFormatValue, layout_line, 1 ); - layout_line++; - propertiesLayout->addWidget( codecLabel, layout_line, 0 ); - propertiesLayout->addWidget( labelCodecValue, layout_line, 1 ); - layout_line++; - propertiesLayout->addWidget( durationLabel, layout_line, 0 ); - propertiesLayout->addWidget( labelDurationValueTime, layout_line, 1 ); - layout_line++; - propertiesLayout->addWidget( labelDurationValueFrames, layout_line, 1 ); - layout_line++; - propertiesLayout->addWidget( sizeLabel, layout_line, 0 ); - propertiesLayout->addWidget( labelSizeValue, layout_line, 1 ); - layout_line++; - propertiesLayout->addWidget( colorSpaceLabel, layout_line, 0 ); - propertiesLayout->addWidget( labelColorSpaceValue, layout_line, 1 ); - - propertiesLayout->setRowStretch( 8, 10 ); - setLayout( propertiesLayout ); - - //QGroupBox *propertiesGroup = new QGroupBox; - //propertiesGroup->setLayout( propertiesLayout ); - //QGridLayout *mainLayout = new QGridLayout; - //mainLayout->addWidget( propertiesGroup ); - //mainLayout->setRowStretch( 8, 10 ); - //setLayout( mainLayout ); - - setEnabled( false ); -} - -StreamPropertiesSideBar::~StreamPropertiesSideBar() -{ - -} - -QSize StreamPropertiesSideBar::sizeHint() const -{ - return bestSize( size() ); -} - -Void StreamPropertiesSideBar::setData( PlaYUVerStream* pcStream ) -{ - // Clear information. - labelNameValue->clear(); - labelFormatValue->clear(); - labelCodecValue->clear(); - labelDurationValueTime->clear(); - labelDurationValueFrames->clear(); - labelSizeValue->clear(); - labelColorSpaceValue->clear(); - - if( !pcStream || !pcStream->getCurrFrame() ) - { - setEnabled( false ); - return; - } - else - { - m_pcStream = pcStream; - setEnabled( true ); - - - labelNameValue->setText( QFileInfo( m_pcStream->getFileName() ).fileName() ); - labelFormatValue->setText( m_pcStream->getFormatName() ); - labelCodecValue->setText( m_pcStream->getCodecName() ); - Int duration[3]; - m_pcStream->getDuration( duration ); - QString value; - value = QString( tr( "%1h:%2m:%3s" ) ).arg( duration[0] ).arg( duration[1] ).arg( duration[2] ); - labelDurationValueTime->setText( value ); - value = QString( tr( "%1 frms" ) ).arg( m_pcStream->getFrameNum() ); - labelDurationValueFrames->setText( value ); - UInt width = m_pcStream->getWidth(); - UInt height = m_pcStream->getHeight(); - UInt fps = m_pcStream->getFrameRate(); - value = QString( tr( "%1 x %2 @ %3 Hz" ) ).arg( width ).arg( height ).arg( fps ); - labelSizeValue->setText( value ); - value = QString( PlaYUVerFrame::supportedPixelFormatListNames().at( m_pcStream->getCurrFrame()->getPelFormat() ) ); - labelColorSpaceValue->setText( value ); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// FramePropertiesSideBar -//////////////////////////////////////////////////////////////////////////////// - FramePropertiesSideBar::FramePropertiesSideBar( QWidget* parent, Bool* pbMainPlaySwitch ) : QWidget( parent ), pbMainPlaySwitch( pbMainPlaySwitch ) @@ -399,7 +253,11 @@ FramePropertiesSideBar::~FramePropertiesSideBar() QSize FramePropertiesSideBar::sizeHint() const { - return bestSize( size() ); + QSize currSize = size(); + QSize bestSize( 180, currSize.height() ); + if( currSize.width() < bestSize.width() ) + return bestSize; + return currSize; } Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame, Bool isPlaying ) @@ -482,7 +340,7 @@ Void FramePropertiesSideBar::setData( PlaYUVerFrame* pcFrame, Bool isPlaying ) } } setEnabled( true ); - if( m_pcFrame != pcFrame || !(*pbMainPlaySwitch) ) + if( m_pcFrame || !(*pbMainPlaySwitch) ) { m_pcFrame = pcFrame; updateDataHistogram(); @@ -529,7 +387,7 @@ Void FramePropertiesSideBar::updateDataHistogram() // image is the same in Image Viewer, then compute too the histogram // for this selection. // New frame required to separate from the thread - histogramWidget->updateData( new PlaYUVerFrame(m_pcFrame), NULL ); + histogramWidget->updateData( m_pcFrame, NULL ); fullImageButton->hide(); selectionImageButton->hide(); } @@ -558,7 +416,7 @@ Void FramePropertiesSideBar::updateStatistiques() if( channel == HistogramWidget::ColorChannelsHistogram ) channel = colorsCB->currentIndex() + 1; - PlaYUVerFrameStatistics *histogram; + PlaYUVerFrameStats* histogram; if( histogramWidget->m_renderingType == HistogramWidget::FullImageHistogram ) histogram = histogramWidget->m_imageHistogram; diff --git a/app/PropertiesSidebar.h b/app/FramePropertiesSidebar.h similarity index 80% rename from app/PropertiesSidebar.h rename to app/FramePropertiesSidebar.h index a7c165a..3baf683 100644 --- a/app/PropertiesSidebar.h +++ b/app/FramePropertiesSidebar.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -18,12 +18,12 @@ */ /** - * \file PropertiesSidebar.h + * \file FramePropertiesSidebar.h * \brief Main side bar definition */ -#ifndef __PROPERTIESSIDEBAR_H__ -#define __PROPERTIESSIDEBAR_H__ +#ifndef __FRAMEPROPERTIESSIDEBAR_H__ +#define __FRAMEPROPERTIESSIDEBAR_H__ #include "config.h" #include "lib/PlaYUVerDefs.h" @@ -40,30 +40,6 @@ namespace plaYUVer { -class StreamPropertiesSideBar: public QWidget -{ -Q_OBJECT -public: - StreamPropertiesSideBar( QWidget* parent ); - ~StreamPropertiesSideBar(); - - QSize sizeHint() const; - - Void setData( PlaYUVerStream* m_pcStream ); - -private: - PlaYUVerStream* m_pcStream; - - Bool m_bIsVisible; - QLabel* labelNameValue; - QLabel* labelFormatValue; - QLabel* labelCodecValue; - QLabel* labelDurationValueTime; - QLabel* labelDurationValueFrames; - QLabel* labelSizeValue; - QLabel* labelColorSpaceValue; -}; - class FramePropertiesSideBar: public QWidget { Q_OBJECT @@ -156,4 +132,4 @@ private Q_SLOTS: } // NAMESPACE -#endif // __PROPERTIESSIDEBAR_H__ +#endif // __FRAMEPROPERTIESSIDEBAR_H__ diff --git a/app/GridManager.cpp b/app/GridManager.cpp index fd233c6..c90a277 100644 --- a/app/GridManager.cpp +++ b/app/GridManager.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/GridManager.h b/app/GridManager.h index d2092a6..d9d0fdd 100644 --- a/app/GridManager.h +++ b/app/GridManager.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/HistogramWidget.cpp b/app/HistogramWidget.cpp index 6ec8b83..d1502bf 100644 --- a/app/HistogramWidget.cpp +++ b/app/HistogramWidget.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -25,29 +25,88 @@ //TODO: // - Optimizar paintEvent. Parece haver codigo redundante !! - #include "config.h" #include #include #include #include "HistogramWidget.h" -#include "PlaYUVerFrameStatistics.h" namespace plaYUVer { +class HistogramWorker: public QThread +{ +private: + QObject* m_parent; + PlaYUVerFrameStats* m_histogram; + +public: + + HistogramWorker( QObject* parent ) + { + m_histogram = NULL; + m_parent = parent; + } + + Void setup( PlaYUVerFrameStats* hist ) + { + m_histogram = hist; + run(); + } + Void run() + { + if( m_histogram && m_parent ) + { + EventData *eventData = new EventData(); +// eventData->starting = true; +// eventData->success = false; +// eventData->histogram = m_histogram; +// QCoreApplication::postEvent( m_parent, eventData ); + + m_histogram->calcHistogram(); + + eventData->starting = false; + eventData->success = m_histogram->getHasHistogram(); + eventData->histogram = m_histogram; + QCoreApplication::postEvent( m_parent, eventData ); + } + } + + /** + * Custom Event + */ + class EventData: public QEvent + { + + public: + + EventData() : + QEvent( QEvent::User ) + { + starting = false; + success = false; + histogram = 0; + } + + bool starting; + bool success; + PlaYUVerFrameStats *histogram; + }; + +}; + const QBrush g_eColorPallet[][3] = { - { - Qt::darkGray, // Luma - Qt::blue, // Cb - Qt::red, // Cr - }, - { - Qt::red, // Channel Red - Qt::green, // Channel Green - Qt::blue, // Channel Blue - }, }; + { + Qt::darkGray, // Luma + Qt::blue, // Cb + Qt::red, // Cr + }, + { + Qt::red, // Channel Red + Qt::green, // Channel Green + Qt::blue, // Channel Blue + }, }; class HistogramWidgetPrivate { @@ -123,6 +182,9 @@ HistogramWidget::HistogramWidget( Int width, Int height, QWidget *parent ) : m_imageHistogram = 0; m_selectionHistogram = 0; + m_imageWorker = new HistogramWorker( this ); + m_selectionWorker = new HistogramWorker( this ); + update(); } @@ -139,6 +201,9 @@ HistogramWidget::~HistogramWidget() if( m_selectionHistogram ) delete m_selectionHistogram; + delete m_imageWorker; + delete m_selectionWorker; + delete d; } //////////////////////////////////////////////////////////////////////////////// @@ -182,16 +247,8 @@ Void HistogramWidget::reset() d->guideVisible = false; d->clearFlag = HistogramWidgetPrivate::HistogramNone; // Remove histogram data from memory. - if( m_imageHistogram ) - { - delete m_imageHistogram; - m_imageHistogram = 0; - } - if( m_selectionHistogram ) - { - delete m_selectionHistogram; - m_selectionHistogram = 0; - } + m_imageHistogram = NULL; + m_selectionHistogram = NULL; update(); } @@ -206,7 +263,7 @@ Void HistogramWidget::customEvent( QEvent *event ) return; } - PlaYUVerFrameStatistics::EventData *ed = ( PlaYUVerFrameStatistics::EventData* )event; + HistogramWorker::EventData *ed = ( HistogramWorker::EventData* )event; if( !ed ) { @@ -325,11 +382,11 @@ Void HistogramWidget::setLoadingFailed() Void HistogramWidget::stopHistogramComputation() { - if( m_imageHistogram ) - m_imageHistogram->stopCalcHistogramValues(); - - if( m_selectionHistogram ) - m_selectionHistogram->stopCalcHistogramValues(); +// if( m_imageHistogram ) +// m_imageHistogram->setRunningFlag( false ); +// +// if( m_selectionHistogram ) +// m_selectionHistogram->setRunningFlag( false ); d->blinkTimer->stop(); } @@ -338,59 +395,12 @@ Void HistogramWidget::stopHistogramComputation() // Update Data Methods //////////////////////////////////////////////////////////////////////////////// -Void HistogramWidget::updateData( Pel ***imageData, UInt imageWidth, UInt imageHeight, Int bitsPerChannel, Int colorSpace, UInt chroma_size, Pel ***selData, - UInt selWidth, UInt selHeight ) -{ - d->sixteenBits = ( bool )( bitsPerChannel == 16 ); - d->imageColorSpace = colorSpace; - - switch( colorSpace ) - { - case PlaYUVerFrame::COLOR_GRAY: - d->imageChannels = 1; - break; - case PlaYUVerFrame::COLOR_YUV: - case PlaYUVerFrame::COLOR_RGB: - d->imageChannels = 3; - break; - case PlaYUVerFrame::COLOR_ARGB: - d->imageChannels = 4; - break; - default: - d->imageChannels = 1; - } - - // We are deleting the histogram data, - // so we must not use it to draw any more. - d->clearFlag = HistogramWidgetPrivate::HistogramNone; - - // Do not using PlaYUVerFrameStatistics::getHistogramSegment() - // method here because histogram hasn't yet been computed. - d->range = d->sixteenBits ? 65535 : 255; - emit signalMaximumValueChanged( d->range ); - - // Remove old histogram data from memory. - if( m_imageHistogram ) - delete m_imageHistogram; - - if( m_selectionHistogram ) - delete m_selectionHistogram; - - // Calc new histogram data - m_imageHistogram = new PlaYUVerFrameStatistics( imageData, imageWidth, imageHeight, bitsPerChannel, colorSpace, chroma_size, this ); - - if( selData && selWidth && selHeight ) - m_selectionHistogram = new PlaYUVerFrameStatistics( selData, selWidth, selHeight, bitsPerChannel, colorSpace, chroma_size, this ); - else - m_selectionHistogram = 0L; -} - -Void HistogramWidget::updateData( const PlaYUVerFrame *playuver_frame, const PlaYUVerFrame *playuver_selection ) +Void HistogramWidget::updateData( const PlaYUVerFrame *pcFrame, const PlaYUVerFrame *pcFrameSelection ) { d->sixteenBits = false; //d->imageColorSpace = image.getPelFormat(); - d->imageColorSpace = playuver_frame->getColorSpace(); - d->imageChannels = playuver_frame->getNumberChannels(); + d->imageColorSpace = pcFrame->getColorSpace(); + d->imageChannels = pcFrame->getNumberChannels(); // We are deleting the histogram data, // so we must not use it to draw any more. @@ -402,43 +412,18 @@ Void HistogramWidget::updateData( const PlaYUVerFrame *playuver_frame, const Pla d->range = d->sixteenBits ? 65535 : 255; emit signalMaximumValueChanged( d->range ); - // Remove old histogram data from memory. - if( m_imageHistogram ) - delete m_imageHistogram; + m_imageHistogram = ( PlaYUVerFrameStats* )pcFrame; + m_imageWorker->setup( m_imageHistogram ); - if( m_selectionHistogram ) - delete m_selectionHistogram; - - // Calc new histogram data - m_imageHistogram = new PlaYUVerFrameStatistics( playuver_frame, this ); - - if( playuver_selection ) - m_selectionHistogram = new PlaYUVerFrameStatistics( playuver_selection, this ); - else - m_selectionHistogram = NULL; + m_selectionHistogram = ( PlaYUVerFrameStats* )pcFrameSelection; + m_selectionWorker->setup( m_selectionHistogram ); } -Void HistogramWidget::updateSelectionData( Pel ***selData, UInt selWidth, UInt selHeight, Int bitsPerChannel, Int colorSpace, UInt chroma_size ) +Void HistogramWidget::updateSelectionData( const PlaYUVerFrame *pcFrameSelection ) { - // Remove old histogram data from memory. - - if( m_selectionHistogram ) - delete m_selectionHistogram; - - // Calc new histogram data - m_selectionHistogram = new PlaYUVerFrameStatistics( selData, selWidth, selHeight, bitsPerChannel, colorSpace, chroma_size, this ); -} - -Void HistogramWidget::updateSelectionData( const PlaYUVerFrame *selection ) -{ - // Remove old histogram data from memory. - - if( m_selectionHistogram ) - delete m_selectionHistogram; - - m_selectionHistogram = new PlaYUVerFrameStatistics( selection, this ); - + m_selectionHistogram = ( PlaYUVerFrame* )pcFrameSelection; + m_selectionWorker->setup( m_selectionHistogram ); } //////////////////////////////////////////////////////////////////////////////// @@ -522,7 +507,7 @@ Void HistogramWidget::paintEvent( QPaintEvent * ) int wWidth = width() - 1; int wHeight = height() - 1; double max; - class PlaYUVerFrameStatistics *histogram; + PlaYUVerFrameStats *histogram; if( m_renderingType == ImageSelectionHistogram && m_selectionHistogram ) histogram = m_selectionHistogram; @@ -542,24 +527,24 @@ Void HistogramWidget::paintEvent( QPaintEvent * ) switch( m_channelType ) { case HistogramWidget::FirstChannelHistogram: // Y channel. - max = histogram->getMaximum( PlaYUVerFrameStatistics::YChannel ); + max = histogram->getMaximum( PlaYUVerFrameStats::YChannel ); break; case HistogramWidget::SecondChannelHistogram: // Cb channel. - max = histogram->getMaximum( PlaYUVerFrameStatistics::CbChannel ); + max = histogram->getMaximum( PlaYUVerFrameStats::CbChannel ); break; case HistogramWidget::ThirdChannelHistogram: // Cr channel. - max = histogram->getMaximum( PlaYUVerFrameStatistics::CrChannel ); + max = histogram->getMaximum( PlaYUVerFrameStats::CrChannel ); break; case HistogramWidget::AlphaChannelHistogram: // Alpha channel. - max = histogram->getMaximum( PlaYUVerFrameStatistics::AlphaChannel ); + max = histogram->getMaximum( PlaYUVerFrameStats::AlphaChannel ); break; case HistogramWidget::ColorChannelsHistogram: // All color channels. - max = qMax( qMax( histogram->getMaximum( PlaYUVerFrameStatistics::YChannel ), histogram->getMaximum( PlaYUVerFrameStatistics::CbChannel ) ), - histogram->getMaximum( PlaYUVerFrameStatistics::CrChannel ) ); + max = qMax( qMax( histogram->getMaximum( PlaYUVerFrameStats::YChannel ), histogram->getMaximum( PlaYUVerFrameStats::CbChannel ) ), + histogram->getMaximum( PlaYUVerFrameStats::CrChannel ) ); break; case HistogramWidget::LumaHistogram: // Luminance. - max = histogram->getMaximum( PlaYUVerFrameStatistics::LumaChannel ); + max = histogram->getMaximum( PlaYUVerFrameStats::LumaChannel ); break; } @@ -606,24 +591,24 @@ Void HistogramWidget::paintEvent( QPaintEvent * ) switch( m_channelType ) { case HistogramWidget::FirstChannelHistogram: // Y channel. - v = histogram->getValue( PlaYUVerFrameStatistics::YChannel, i++ ); + v = histogram->getHistogramValue( PlaYUVerFrameStats::YChannel, i++ ); break; case HistogramWidget::SecondChannelHistogram: // Cb channel. - v = histogram->getValue( PlaYUVerFrameStatistics::CbChannel, i++ ); + v = histogram->getHistogramValue( PlaYUVerFrameStats::CbChannel, i++ ); break; case HistogramWidget::ThirdChannelHistogram: // Cr channel. - v = histogram->getValue( PlaYUVerFrameStatistics::CrChannel, i++ ); + v = histogram->getHistogramValue( PlaYUVerFrameStats::CrChannel, i++ ); break; case HistogramWidget::AlphaChannelHistogram: // Alpha channel. - v = histogram->getValue( PlaYUVerFrameStatistics::AlphaChannel, i++ ); + v = histogram->getHistogramValue( PlaYUVerFrameStats::AlphaChannel, i++ ); break; case HistogramWidget::ColorChannelsHistogram: // All color. - vr = histogram->getValue( PlaYUVerFrameStatistics::YChannel, i ); - vg = histogram->getValue( PlaYUVerFrameStatistics::CbChannel, i ); - vb = histogram->getValue( PlaYUVerFrameStatistics::CrChannel, i++ ); + vr = histogram->getHistogramValue( PlaYUVerFrameStats::YChannel, i ); + vg = histogram->getHistogramValue( PlaYUVerFrameStats::CbChannel, i ); + vb = histogram->getHistogramValue( PlaYUVerFrameStats::CrChannel, i++ ); break; case HistogramWidget::LumaHistogram: // Luminance. - v = histogram->getValue( PlaYUVerFrameStatistics::LumaChannel, i++ ); + v = histogram->getHistogramValue( PlaYUVerFrameStats::LumaChannel, i++ ); break; } diff --git a/app/HistogramWidget.h b/app/HistogramWidget.h index a9c437c..a0a8019 100644 --- a/app/HistogramWidget.h +++ b/app/HistogramWidget.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -31,14 +31,13 @@ #include #include #include "lib/PlaYUVerFrame.h" -#include "PlaYUVerFrameStatistics.h" class QEvent; namespace plaYUVer { -class PlaYUVerFrameStatistics; +class HistogramWorker; class HistogramWidgetPrivate; class HistogramWidget: public QWidget @@ -118,20 +117,11 @@ public : /** Stop current histogram computations.*/ Void stopHistogramComputation(); - /** Update full image histogram data methods.*/ - Void updateData( Pel ***imageData, UInt imageWidth, UInt imageHeight, - Int bitsPerChannel, Int colorSpace, UInt chroma_size, - Pel ***selData = 0, UInt selWidth = 0, UInt selHeight = 0); - /** Update full image histogram data from SImage.*/ - Void updateData( const PlaYUVerFrame *playuver_frame, const PlaYUVerFrame *playuver_selection ); - - /** Update image selection histogram data methods.*/ - Void updateSelectionData( Pel ***selData, uint selWidth, uint selHeight, - Int bitsPerChannel, Int colorSpace, UInt chroma_size ); + Void updateData( const PlaYUVerFrame *pcFrame, const PlaYUVerFrame *pcFrameSelection ); /** Update image selection histogram data from SImage.*/ - Void updateSelectionData( const PlaYUVerFrame *imageSelection ); + Void updateSelectionData( const PlaYUVerFrame *pcFrameSelection ); /** @see @p HistogramOption */ Void setOptions( HistogramOptions options = AllOptions ); @@ -153,9 +143,11 @@ public: Int m_renderingType; /** Full image */ - PlaYUVerFrameStatistics *m_imageHistogram; + HistogramWorker* m_imageWorker; + PlaYUVerFrameStats* m_imageHistogram; /** Histogram area selection */ - PlaYUVerFrameStatistics *m_selectionHistogram; + HistogramWorker* m_selectionWorker; + PlaYUVerFrameStats* m_selectionHistogram; Q_SIGNALS: void signalIntervalChanged( int min, int max ); diff --git a/app/ModuleHandleDock.cpp b/app/ModuleHandleDock.cpp index 6d0557e..59f1224 100644 --- a/app/ModuleHandleDock.cpp +++ b/app/ModuleHandleDock.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -34,13 +34,10 @@ ModuleHandleDock::ModuleHandleDock( QWidget* parent, PlaYUVerAppModuleIf* module QWidget( parent ), m_pcCurrModuleIf( moduleIf ) { - - PlaYUVerModuleDefinition ModuleDef = moduleIf->m_pcModule->getModuleDefinition(); - // ----------------- Dock definition ----------------- QString labelStr; - labelStr.append( ModuleDef.m_pchModuleName ); + labelStr.append( moduleIf->m_pcModule->m_pchModuleName ); labelStr.append( " Result:" ); labelModulueValueLabel = new QLabel( labelStr ); labelModulueValueLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); diff --git a/app/ModuleHandleDock.h b/app/ModuleHandleDock.h index b2f87b4..e1f9963 100644 --- a/app/ModuleHandleDock.h +++ b/app/ModuleHandleDock.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/ModulesHandle.cpp b/app/ModulesHandle.cpp index ef2c2aa..8f0a6f4 100644 --- a/app/ModulesHandle.cpp +++ b/app/ModulesHandle.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -25,8 +25,7 @@ #include #include "ModulesHandle.h" -#include "ModulesListHeader.h" -#include "ModulesListMacro.h" +#include "PlaYUVerModuleFactory.h" #include "DialogSubWindowSelector.h" #include "SubWindowHandle.h" #include "VideoSubWindow.h" @@ -35,83 +34,216 @@ namespace plaYUVer { ModulesHandle::ModulesHandle( QMainWindow * parent, QMdiArea *mdiArea ) : - QObject( parent ), + QWidget( parent ), m_pcParent( parent ), - m_pcMdiArea( mdiArea ), - m_uiModulesCount( 0 ), - m_iOptionSelected( INVALID_OPT ) + m_pcMdiArea( mdiArea ) { - // configure class setParent( m_pcParent ); - // Register Modules - REGISTER_ALL_MODULES } ModulesHandle::~ModulesHandle() { } -Void ModulesHandle::appendModule( PlaYUVerModuleIf* pModuleIf ) +Void ModulesHandle::createActions() { - m_pcPlaYUVerModulesIf.append( pModuleIf ); - PlaYUVerAppModuleIf* pcAppModuleIf = new PlaYUVerAppModuleIf; - pcAppModuleIf->m_pcModule = pModuleIf; - pcAppModuleIf->setParent( this ); - m_pcPlaYUVerModules.append( pcAppModuleIf ); - m_uiModulesCount++; + m_arrayActions.resize( MODULES_TOTAL_ACT ); + + m_pcActionMapper = new QSignalMapper( this ); + connect( m_pcActionMapper, SIGNAL( mapped(int) ), this, SLOT( processOpt(int) ) ); + + m_arrayActions[FORCE_NEW_WINDOW_ACT] = new QAction( "Use New Window", parent() ); + m_arrayActions[FORCE_NEW_WINDOW_ACT]->setStatusTip( "Show module result in a new window. Some modules already force this feature" ); + m_arrayActions[FORCE_NEW_WINDOW_ACT]->setCheckable( true ); + m_arrayActions[FORCE_PLAYING_REFRESH_ACT] = new QAction( "Refresh while playing", parent() ); + m_arrayActions[FORCE_PLAYING_REFRESH_ACT]->setStatusTip( "Force module refreshing while playing" ); + m_arrayActions[FORCE_PLAYING_REFRESH_ACT]->setCheckable( true ); + + m_arrayActions[APPLY_ALL_ACT] = new QAction( "Apply to All", parent() ); + m_arrayActions[APPLY_ALL_ACT]->setStatusTip( "Apply module to all frames and save the result" ); + connect( m_arrayActions[APPLY_ALL_ACT], SIGNAL( triggered() ), m_pcActionMapper, SLOT( map() ) ); + m_pcActionMapper->setMapping( m_arrayActions[APPLY_ALL_ACT], APPLY_ALL_ACT ); + + m_arrayActions[SWAP_FRAMES_ACT] = new QAction( "Swap frames", parent() ); + m_arrayActions[SWAP_FRAMES_ACT]->setStatusTip( "Swap Sub Window order" ); + connect( m_arrayActions[SWAP_FRAMES_ACT], SIGNAL( triggered() ), m_pcActionMapper, SLOT( map() ) ); + m_pcActionMapper->setMapping( m_arrayActions[SWAP_FRAMES_ACT], SWAP_FRAMES_ACT ); + + m_arrayActions[DISABLE_ALL_ACT] = new QAction( "Disable All Modules", parent() ); + connect( m_arrayActions[DISABLE_ALL_ACT], SIGNAL( triggered() ), this, SLOT( destroyAllModulesIf() ) ); + } -Void ModulesHandle::selectModule( Int index ) +QMenu* ModulesHandle::createMenu() { - m_iOptionSelected = index; -} + PlaYUVerModuleIf* pcCurrModuleIf; + QString ModuleIfInternalName; + QAction* currAction; + QMenu* currSubMenu; -SubWindowHandle* ModulesHandle::processModuleHandlingOpt() -{ - if( m_iOptionSelected >= 0 ) + m_pcModulesMenu = new QMenu( "&Modules", this ); + + m_pcModulesActionMapper = new QSignalMapper( this ); + //connect( m_pcModulesActionMapper, SIGNAL( mapped(int) ), this, SLOT( activateModule(int) ) ); + + UInt i = 0; + PlaYUVerModuleFactoryMap& PlaYUVerModuleFactoryMap = PlaYUVerModuleFactory::Get()->getMap(); + PlaYUVerModuleFactoryMap::iterator it = PlaYUVerModuleFactoryMap.begin(); + for( ; it != PlaYUVerModuleFactoryMap.end(); ++it, i++ ) { - PlaYUVerAppModuleIf* pcCurrModuleIf = m_pcPlaYUVerModules.at( m_iOptionSelected ); - m_iOptionSelected = INVALID_OPT; - if( pcCurrModuleIf->m_pcAction->isChecked() ) + pcCurrModuleIf = it->second(); + ModuleIfInternalName = QString::fromLocal8Bit( it->first ); + + currSubMenu = NULL; + if( pcCurrModuleIf->m_pchModuleCategory ) { - return enableModuleIf( pcCurrModuleIf ); + for( Int j = 0; j < m_pcModulesSubMenuList.size(); j++ ) + { + if( m_pcModulesSubMenuList.at( j )->title() == QString( pcCurrModuleIf->m_pchModuleCategory ) ) + { + currSubMenu = m_pcModulesSubMenuList.at( j ); + break; + } + } + if( !currSubMenu ) + { + currSubMenu = m_pcModulesMenu->addMenu( pcCurrModuleIf->m_pchModuleCategory ); + m_pcModulesSubMenuList.append( currSubMenu ); + } + } + + currAction = new QAction( pcCurrModuleIf->m_pchModuleName, parent() ); + currAction->setStatusTip( pcCurrModuleIf->m_pchModuleTooltip ); + currAction->setData( ModuleIfInternalName ); + currAction->setCheckable( true ); + connect( currAction, SIGNAL( triggered() ), this, SLOT( activateModule() ) ); + //connect( currAction, SIGNAL( triggered() ), m_pcModulesActionMapper, SLOT( map() ) ); + m_pcModulesActionMapper->setMapping( currAction, i ); + m_arrayModulesActions.append( currAction ); + + if( currSubMenu ) + currSubMenu->addAction( currAction ); + else + m_pcModulesMenu->addAction( currAction ); + + pcCurrModuleIf->Delete(); + } + + m_pcModulesMenu->addSeparator(); + m_pcModulesMenu->addAction( m_arrayActions[APPLY_ALL_ACT] ); + m_pcModulesMenu->addAction( m_arrayActions[SWAP_FRAMES_ACT] ); + m_pcModulesMenu->addAction( m_arrayActions[DISABLE_ALL_ACT] ); + m_pcModulesMenu->addAction( m_arrayActions[FORCE_NEW_WINDOW_ACT] ); + + return m_pcModulesMenu; +} + +Void ModulesHandle::updateMenus() +{ + VideoSubWindow* pcSubWindow = qobject_cast( m_pcMdiArea->activeSubWindow() ); + Bool hasSubWindow = pcSubWindow ? true : false; + QAction* currModuleAction; + + for( Int i = 0; i < m_arrayModulesActions.size(); i++ ) + { + currModuleAction = m_arrayModulesActions.at( i ); + currModuleAction->setEnabled( hasSubWindow ); + currModuleAction->setChecked( false ); + } + for( Int i = 0; i < m_arrayActions.size(); i++ ) + { + m_arrayActions.at( i )->setEnabled( false ); + } + m_arrayActions[DISABLE_ALL_ACT]->setEnabled( hasSubWindow ); + m_arrayActions[FORCE_NEW_WINDOW_ACT]->setEnabled( hasSubWindow ); + if( pcSubWindow ) + { + QList apcCurrentModule = pcSubWindow->getModuleArray(); + for( Int i = 0; i < apcCurrentModule.size(); i++ ) + { + currModuleAction = apcCurrentModule.at( i )->m_pcModuleAction; + currModuleAction->setChecked( true ); + } + if( apcCurrentModule.size() ) + { + m_arrayActions[APPLY_ALL_ACT]->setEnabled( true ); + m_arrayActions[SWAP_FRAMES_ACT]->setEnabled( true ); + } + } +} + +Void ModulesHandle::readSettings() +{ + QSettings appSettings; + m_arrayActions[FORCE_NEW_WINDOW_ACT]->setChecked( appSettings.value( "ModulesHandle/UseNewWindow", false ).toBool() ); +} + +Void ModulesHandle::writeSettings() +{ + QSettings appSettings; + appSettings.setValue( "ModulesHandle/UseNewWindow", m_arrayActions[FORCE_NEW_WINDOW_ACT]->isChecked() ); +} + +Void ModulesHandle::processOpt( Int index ) +{ + VideoSubWindow* pcSubWindow = qobject_cast( m_pcMdiArea->activeSubWindow() ); + if( pcSubWindow ) + { + QList apcCurrentModule = pcSubWindow->getModuleArray(); + if( apcCurrentModule.size() > 1 ) + { + PlaYUVerAppModuleIf* pcCurrModule = apcCurrentModule.at( 0 ); + switch( index ) + { + case INVALID_OPT: + break; + case SWAP_FRAMES_ACT: + swapModulesWindowsIf( pcCurrModule ); + break; + case APPLY_ALL_ACT: + applyAllModuleIf( pcCurrModule ); + break; + default: + Q_ASSERT( 0 ); + } + } + emit changed(); + } +} + +Void ModulesHandle::activateModule() +{ + QAction *pcAction = qobject_cast( sender() ); + VideoSubWindow* pcVideoSubWindow = qobject_cast( m_pcMdiArea->activeSubWindow() ); + if( pcVideoSubWindow ) + { + if( pcAction->isChecked() ) + { + QString ModuleIfName = pcAction->data().toString(); + PlaYUVerModuleIf* pcCurrModuleIf = PlaYUVerModuleFactory::Get()->CreateModule( ModuleIfName.toLocal8Bit().constData() ); + + PlaYUVerAppModuleIf* pcCurrAppModuleIf = new PlaYUVerAppModuleIf( this, pcAction, pcCurrModuleIf ); + enableModuleIf( pcCurrAppModuleIf ); + m_pcPlaYUVerAppModuleIfList.append( pcCurrAppModuleIf ); } else { - destroyModuleIf( pcCurrModuleIf ); + pcVideoSubWindow->disableModule(); } } - else - { - VideoSubWindow* pcSubWindow = qobject_cast( m_pcMdiArea->activeSubWindow() ); - switch( m_iOptionSelected ) - { - case INVALID_OPT: - break; - case SWAP_FRAMES_OPT: - pcSubWindow->swapModuleFrames(); - break; - case APPLY_ALL_OPT: - openModuleIfStream( pcSubWindow->getModule() ); - pcSubWindow->applyModuleAllFrames(); - break; - default: - Q_ASSERT( 0 ); - } - } - m_iOptionSelected = INVALID_OPT; - return NULL; + emit changed(); } -SubWindowHandle* ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf ) +Void ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf ) { + VideoSubWindow* pcModuleSubWindow = NULL; Bool bShowModulesNewWindow = m_arrayActions[FORCE_NEW_WINDOW_ACT]->isChecked(); VideoSubWindow* pcVideoSubWindow = qobject_cast( m_pcMdiArea->activeSubWindow() ); QString windowName; QVector subWindowList; - UInt numberOfFrames = pcCurrModuleIf->m_pcModule->m_cModuleDef.m_uiNumberOfFrames; + UInt numberOfFrames = pcCurrModuleIf->m_pcModule->m_uiNumberOfFrames; if( numberOfFrames > MODULE_REQUIRES_ONE_FRAME ) // Show dialog to select sub windows { DialogSubWindowSelector dialogWindowsSelection( m_pcParent, m_pcMdiArea, numberOfFrames, numberOfFrames ); @@ -136,7 +268,7 @@ SubWindowHandle* ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModul // Check for same fmt in more than one frame modules for( Int i = 1; i < subWindowList.size(); i++ ) { - if( !subWindowList.at( i )->getCurrFrame()->haveSameFmt( subWindowList.at( 0 )->getCurrFrame()) ) + if( !subWindowList.at( i )->getCurrFrame()->haveSameFmt( subWindowList.at( 0 )->getCurrFrame() ) ) { subWindowList.clear(); break; @@ -151,48 +283,45 @@ SubWindowHandle* ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModul if( subWindowList.size() == 0 ) { - pcCurrModuleIf->m_pcAction->setChecked( false ); m_pcParent->statusBar()->showMessage( "Error! Module cannot be applied", 2000 ); - return NULL; + destroyModuleIf( pcCurrModuleIf ); + return; } windowName.append( " <" ); - windowName.append( pcCurrModuleIf->m_pcModule->m_cModuleDef.m_pchModuleName ); + windowName.append( pcCurrModuleIf->m_pcModule->m_pchModuleName ); windowName.append( ">" ); for( Int i = 0; i < subWindowList.size(); i++ ) { pcCurrModuleIf->m_pcSubWindow[i] = subWindowList.at( i ); - pcCurrModuleIf->m_pcSubWindow[i]->disableModule(); } pcCurrModuleIf->m_pcDisplaySubWindow = NULL; - VideoSubWindow* interfaceChild = NULL; - if( pcCurrModuleIf->m_pcModule->m_cModuleDef.m_iModuleType == FRAME_PROCESSING_MODULE ) + if( pcCurrModuleIf->m_pcModule->m_iModuleType == FRAME_PROCESSING_MODULE ) { - if( ( pcCurrModuleIf->m_pcModule->m_cModuleDef.m_uiModuleRequirements & MODULE_REQUIRES_NEW_WINDOW ) || bShowModulesNewWindow ) + if( ( pcCurrModuleIf->m_pcModule->m_uiModuleRequirements & MODULE_REQUIRES_NEW_WINDOW ) || bShowModulesNewWindow ) { - interfaceChild = new VideoSubWindow( m_pcParent, true ); - interfaceChild->setWindowName( windowName ); + pcModuleSubWindow = new VideoSubWindow( this , true ); + pcModuleSubWindow->setWindowShortName( windowName ); + pcModuleSubWindow->setWindowName( windowName ); - // connect( interfaceChild->getViewArea(), SIGNAL( positionChanged(const QPoint &, PlaYUVerFrame *) ), m_pcParent, -// SLOT( updatePixelValueStatusBar(const QPoint &, PlaYUVerFrame *) ) ); + connect( pcModuleSubWindow, SIGNAL( updateStatusBar( const QString& ) ), m_pcParent, SLOT( updateStatusBar( const QString& ) ) ); + connect( pcModuleSubWindow, SIGNAL( zoomChanged() ), m_pcParent, SLOT( updateZoomFactorSBox() ) ); - connect( interfaceChild, SIGNAL( updateStatusBar( const QString& ) ), m_pcParent, SLOT( updateStatusBar( const QString& ) ) ); - connect( interfaceChild, SIGNAL( zoomChanged() ), m_pcParent, SLOT( updateZoomFactorSBox() ) ); - - pcCurrModuleIf->m_pcDisplaySubWindow = interfaceChild; - pcCurrModuleIf->m_pcDisplaySubWindow->setModule( pcCurrModuleIf ); + pcCurrModuleIf->m_pcDisplaySubWindow = pcModuleSubWindow; + pcCurrModuleIf->m_pcDisplaySubWindow->enableModule( pcCurrModuleIf, true ); + //m_pcMdiArea->addSubWindow( pcModuleSubWindow ); } } - else if( pcCurrModuleIf->m_pcModule->m_cModuleDef.m_iModuleType == FRAME_MEASUREMENT_MODULE ) + else if( pcCurrModuleIf->m_pcModule->m_iModuleType == FRAME_MEASUREMENT_MODULE ) { - if( pcCurrModuleIf->m_pcModule->m_cModuleDef.m_uiModuleRequirements & MODULE_REQUIRES_SIDEBAR ) + 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_cModuleDef.m_pchModuleName ); + 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 ); @@ -202,74 +331,89 @@ SubWindowHandle* ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModul } } - // Create Module - pcCurrModuleIf->m_pcModule->create( pcCurrModuleIf->m_pcSubWindow[0]->getCurrFrame() ); - // Associate module with subwindows for( UInt i = 0; i < numberOfFrames; i++ ) { pcCurrModuleIf->m_pcSubWindow[i]->enableModule( pcCurrModuleIf ); } - applyModuleIf( pcCurrModuleIf, false ); - return interfaceChild; + // Create Module + pcCurrModuleIf->m_pcModule->create( pcCurrModuleIf->m_pcSubWindow[0]->getCurrFrame() ); + + applyModuleIf( pcCurrModuleIf, false ); + QCoreApplication::processEvents(); + + if( pcModuleSubWindow ) + { + QMdiSubWindow* window = m_pcMdiArea->addSubWindow( pcModuleSubWindow ); + window->show(); + } + + return; } Void ModulesHandle::destroyModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf ) { - if( pcCurrModuleIf->m_pcModuleDock ) + if( pcCurrModuleIf ) { - pcCurrModuleIf->m_pcModuleDock->close(); - pcCurrModuleIf->m_pcModuleDock = NULL; - } - if( pcCurrModuleIf->m_pcDockWidget ) - { - pcCurrModuleIf->m_pcDockWidget->close(); - pcCurrModuleIf->m_pcDockWidget = NULL; - } - if( pcCurrModuleIf->m_pcDisplaySubWindow ) - pcCurrModuleIf->m_pcDisplaySubWindow->close(); - pcCurrModuleIf->m_pcDisplaySubWindow = NULL; - - for( Int i = 0; i < MAX_NUMBER_FRAMES; i++ ) - { - if( pcCurrModuleIf->m_pcSubWindow[i] ) + if( pcCurrModuleIf->m_pcModuleDock ) { - pcCurrModuleIf->m_pcSubWindow[i]->disableModule(); - pcCurrModuleIf->m_pcSubWindow[i] = NULL; + pcCurrModuleIf->m_pcModuleDock->close(); + pcCurrModuleIf->m_pcModuleDock = NULL; + } + if( pcCurrModuleIf->m_pcDockWidget ) + { + pcCurrModuleIf->m_pcDockWidget->close(); + pcCurrModuleIf->m_pcDockWidget = NULL; + } + if( pcCurrModuleIf->m_pcDisplaySubWindow ) + pcCurrModuleIf->m_pcDisplaySubWindow->close(); + pcCurrModuleIf->m_pcDisplaySubWindow = NULL; + + for( Int i = 0; i < MAX_NUMBER_FRAMES; i++ ) + { + if( pcCurrModuleIf->m_pcSubWindow[i] ) + { + pcCurrModuleIf->m_pcSubWindow[i]->disableModule( pcCurrModuleIf ); + pcCurrModuleIf->m_pcSubWindow[i] = NULL; + } + } + if( pcCurrModuleIf->m_pcModuleStream ) + { + pcCurrModuleIf->m_pcModuleStream->close(); + delete pcCurrModuleIf->m_pcModuleStream; + pcCurrModuleIf->m_pcModuleStream = NULL; + } + if( pcCurrModuleIf->m_pcModule ) + { + pcCurrModuleIf->m_pcModule->destroy(); + pcCurrModuleIf->m_pcModule->Delete(); + pcCurrModuleIf->m_pcModule = NULL; } } - if( pcCurrModuleIf->m_pcModuleStream ) - { - pcCurrModuleIf->m_pcModuleStream->close(); - delete pcCurrModuleIf->m_pcModuleStream; - pcCurrModuleIf->m_pcModuleStream = NULL; - } - pcCurrModuleIf->m_pcAction->setChecked( false ); - pcCurrModuleIf->m_pcModule->destroy(); } Void ModulesHandle::destroyAllModulesIf() { - for( Int i = 0; i < m_pcPlaYUVerModules.size(); i++ ) + for( Int i = 0; i < m_pcPlaYUVerAppModuleIfList.size(); i++ ) { - destroyModuleIf( m_pcPlaYUVerModules.at( i ) ); + destroyModuleIf( m_pcPlaYUVerAppModuleIfList.at( i ) ); } } Bool ModulesHandle::applyModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf, Bool isPlaying, Bool disableThreads ) { Bool bRet = false; - if( !isPlaying || ( isPlaying && pcCurrModuleIf->m_pcModule->m_cModuleDef.m_bApplyWhilePlaying ) ) + if( !isPlaying || ( isPlaying && pcCurrModuleIf->m_pcModule->m_bApplyWhilePlaying ) ) { #ifdef PLAYUVER_THREADED_MODULES if( !disableThreads ) - pcCurrModuleIf->start(); + pcCurrModuleIf->start(); else #endif - pcCurrModuleIf->run(); + pcCurrModuleIf->run(); - if( pcCurrModuleIf->m_pcDisplaySubWindow || pcCurrModuleIf->m_pcModule->m_cModuleDef.m_iModuleType == FRAME_MEASUREMENT_MODULE ) + if( pcCurrModuleIf->m_pcDisplaySubWindow || pcCurrModuleIf->m_pcModule->m_iModuleType == FRAME_MEASUREMENT_MODULE ) { bRet = true; } @@ -282,40 +426,6 @@ Bool ModulesHandle::applyModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf, Bool isP } Void ModulesHandle::applyAllModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf ) -{ - if( pcCurrModuleIf->m_pcModuleStream ) - { - UInt numberOfWindows = pcCurrModuleIf->m_pcModule->m_cModuleDef.m_uiNumberOfFrames; - UInt64 currFrames = 0; - UInt64 numberOfFrames = INT_MAX; - for( UInt i = 0; i < numberOfWindows; i++ ) - { - currFrames = pcCurrModuleIf->m_pcSubWindow[i]->getInputStream()->getFrameNum(); - if( currFrames < numberOfFrames ) - numberOfFrames = currFrames; - pcCurrModuleIf->m_pcSubWindow[i]->stop(); - } - QApplication::setOverrideCursor( Qt::WaitCursor ); - for( UInt f = 1; f < numberOfFrames; f++ ) - { - applyModuleIf( pcCurrModuleIf, false, true ); - QCoreApplication::processEvents(); - pcCurrModuleIf->m_pcModuleStream->writeFrame( pcCurrModuleIf->m_pcProcessedFrame ); - for( UInt i = 0; i < numberOfWindows; i++ ) - { - pcCurrModuleIf->m_pcSubWindow[i]->play(); - pcCurrModuleIf->m_pcSubWindow[i]->playEvent(); - } - } - for( UInt i = 0; i < numberOfWindows; i++ ) - { - pcCurrModuleIf->m_pcSubWindow[i]->stop(); - } - QApplication::restoreOverrideCursor(); - } -} - -Void ModulesHandle::openModuleIfStream( PlaYUVerAppModuleIf *pcCurrModuleIf ) { if( pcCurrModuleIf ) { @@ -363,6 +473,36 @@ Void ModulesHandle::openModuleIfStream( PlaYUVerAppModuleIf *pcCurrModuleIf ) } } } + if( pcCurrModuleIf->m_pcModuleStream ) + { + UInt numberOfWindows = pcCurrModuleIf->m_pcModule->m_uiNumberOfFrames; + UInt64 currFrames = 0; + UInt64 numberOfFrames = INT_MAX; + for( UInt i = 0; i < numberOfWindows; i++ ) + { + currFrames = pcCurrModuleIf->m_pcSubWindow[i]->getInputStream()->getFrameNum(); + if( currFrames < numberOfFrames ) + numberOfFrames = currFrames; + pcCurrModuleIf->m_pcSubWindow[i]->stop(); + } + QApplication::setOverrideCursor( Qt::WaitCursor ); + for( UInt f = 1; f < numberOfFrames; f++ ) + { + applyModuleIf( pcCurrModuleIf, false, true ); + QCoreApplication::processEvents(); + pcCurrModuleIf->m_pcModuleStream->writeFrame( pcCurrModuleIf->m_pcProcessedFrame ); + for( UInt i = 0; i < numberOfWindows; i++ ) + { + pcCurrModuleIf->m_pcSubWindow[i]->play(); + pcCurrModuleIf->m_pcSubWindow[i]->playEvent(); + } + } + for( UInt i = 0; i < numberOfWindows; i++ ) + { + pcCurrModuleIf->m_pcSubWindow[i]->stop(); + } + QApplication::restoreOverrideCursor(); + } } Bool ModulesHandle::showModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf, PlaYUVerFrame* processedFrame ) @@ -392,11 +532,12 @@ Bool ModulesHandle::showModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf, Double mo Void ModulesHandle::swapModulesWindowsIf( PlaYUVerAppModuleIf *pcCurrModuleIf ) { - if( pcCurrModuleIf->m_pcModule->m_cModuleDef.m_uiNumberOfFrames == MODULE_REQUIRES_TWO_FRAMES ) + if( pcCurrModuleIf->m_pcModule->m_uiNumberOfFrames == MODULE_REQUIRES_TWO_FRAMES ) { VideoSubWindow* auxWindowHandle = pcCurrModuleIf->m_pcSubWindow[0]; pcCurrModuleIf->m_pcSubWindow[0] = pcCurrModuleIf->m_pcSubWindow[1]; pcCurrModuleIf->m_pcSubWindow[1] = auxWindowHandle; + applyModuleIf( pcCurrModuleIf ); } } @@ -409,7 +550,7 @@ Void ModulesHandle::customEvent( QEvent *event ) PlaYUVerAppModuleIf::EventData *eventData = ( PlaYUVerAppModuleIf::EventData* )event; if( eventData->m_bSuccess ) { - switch( eventData->m_pcModule->m_pcModule->m_cModuleDef.m_iModuleType ) + switch( eventData->m_pcModule->m_pcModule->m_iModuleType ) { case FRAME_PROCESSING_MODULE: showModuleIf( eventData->m_pcModule, eventData->m_pcModule->m_pcProcessedFrame ); @@ -421,96 +562,5 @@ Void ModulesHandle::customEvent( QEvent *event ) } } -QMenu* ModulesHandle::createMenus( QMenuBar *MainAppMenuBar ) -{ - PlaYUVerModuleIf* pcCurrModuleIf; - QAction* currAction; - QMenu* currSubMenu; - - m_arrayActions.resize( MODULES_TOTAL_ACT ); - - m_pcActionMapper = new QSignalMapper( this ); - connect( m_pcActionMapper, SIGNAL( mapped(int) ), this, SLOT( selectModule(int) ) ); - - m_pcModulesMenu = MainAppMenuBar->addMenu( "&Modules" ); - - for( Int i = 0; i < m_pcPlaYUVerModulesIf.size(); i++ ) - { - pcCurrModuleIf = m_pcPlaYUVerModulesIf.at( i ); - - currSubMenu = NULL; - if( pcCurrModuleIf->m_cModuleDef.m_pchModuleCategory ) - { - for( Int j = 0; j < m_pcModulesSubMenuList.size(); j++ ) - { - if( m_pcModulesSubMenuList.at( j )->title() == QString( pcCurrModuleIf->m_cModuleDef.m_pchModuleCategory ) ) - { - currSubMenu = m_pcModulesSubMenuList.at( j ); - break; - } - } - if( !currSubMenu ) - { - currSubMenu = m_pcModulesMenu->addMenu( pcCurrModuleIf->m_cModuleDef.m_pchModuleCategory ); - m_pcModulesSubMenuList.append( currSubMenu ); - } - } - - currAction = new QAction( pcCurrModuleIf->m_cModuleDef.m_pchModuleName, parent() ); - currAction->setStatusTip( pcCurrModuleIf->m_cModuleDef.m_pchModuleTooltip ); - currAction->setCheckable( true ); - connect( currAction, SIGNAL( triggered() ), m_pcActionMapper, SLOT( map() ) ); - m_pcActionMapper->setMapping( currAction, i ); - m_arrayModulesActions.append( currAction ); - - if( currSubMenu ) - currSubMenu->addAction( currAction ); - else - m_pcModulesMenu->addAction( currAction ); - - m_pcPlaYUVerModules.at( i )->m_pcAction = currAction; - } - - m_arrayActions[FORCE_NEW_WINDOW_ACT] = new QAction( "Use New Window", parent() ); - m_arrayActions[FORCE_NEW_WINDOW_ACT]->setStatusTip( "Show module result in a new window. Some modules already force this feature" ); - m_arrayActions[FORCE_NEW_WINDOW_ACT]->setCheckable( true ); - m_arrayActions[FORCE_PLAYING_REFRESH_ACT] = new QAction( "Refresh while playing", parent() ); - m_arrayActions[FORCE_PLAYING_REFRESH_ACT]->setStatusTip( "Force module refreshing while playing" ); - m_arrayActions[FORCE_PLAYING_REFRESH_ACT]->setCheckable( true ); - - m_arrayActions[APPLY_ALL_ACT] = new QAction( "Apply to All", parent() ); - m_arrayActions[APPLY_ALL_ACT]->setStatusTip( "Apply module to all frames and save the result" ); - connect( m_arrayActions[APPLY_ALL_ACT], SIGNAL( triggered() ), m_pcActionMapper, SLOT( map() ) ); - m_pcActionMapper->setMapping( m_arrayActions[APPLY_ALL_ACT], APPLY_ALL_OPT ); - - m_arrayActions[SWAP_FRAMES_ACT] = new QAction( "Swap frames", parent() ); - m_arrayActions[SWAP_FRAMES_ACT]->setStatusTip( "Swap Sub Window order" ); - connect( m_arrayActions[SWAP_FRAMES_ACT], SIGNAL( triggered() ), m_pcActionMapper, SLOT( map() ) ); - m_pcActionMapper->setMapping( m_arrayActions[SWAP_FRAMES_ACT], SWAP_FRAMES_OPT ); - - m_arrayActions[DISABLE_ALL_ACT] = new QAction( "Disable All Modules", parent() ); - connect( m_arrayActions[DISABLE_ALL_ACT], SIGNAL( triggered() ), this, SLOT( destroyAllModulesIf() ) ); - - m_pcModulesMenu->addSeparator(); - m_pcModulesMenu->addAction( m_arrayActions[APPLY_ALL_ACT] ); - m_pcModulesMenu->addAction( m_arrayActions[SWAP_FRAMES_ACT] ); - m_pcModulesMenu->addAction( m_arrayActions[DISABLE_ALL_ACT] ); - m_pcModulesMenu->addAction( m_arrayActions[FORCE_NEW_WINDOW_ACT] ); - - return m_pcModulesMenu; -} - -Void ModulesHandle::updateMenus( Bool hasSubWindow ) -{ - QAction* currModuleAction; - for( Int i = 0; i < m_pcPlaYUVerModules.size(); i++ ) - { - currModuleAction = m_arrayModulesActions.at( i ); - currModuleAction->setEnabled( hasSubWindow ); - } - m_arrayActions[APPLY_ALL_ACT]->setEnabled( hasSubWindow ); - m_arrayActions[SWAP_FRAMES_ACT]->setEnabled( hasSubWindow ); -} - } // NAMESPACE diff --git a/app/ModulesHandle.h b/app/ModulesHandle.h index 99a9b4c..a07c0f8 100644 --- a/app/ModulesHandle.h +++ b/app/ModulesHandle.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -45,43 +45,45 @@ namespace plaYUVer class PlaYUVerAppModuleIf; class SubWindowHandle; -class ModulesHandle: public QObject +class ModulesHandle: public QWidget { Q_OBJECT public: ModulesHandle( QMainWindow* parent = 0, QMdiArea *mdiArea = 0 ); ~ModulesHandle(); - QMenu* createMenus( QMenuBar* MainAppMenuBar ); - Void updateMenus( Bool hasSubWindow ); - SubWindowHandle* processModuleHandlingOpt(); + Void createActions(); + QMenu* createMenu(); + //QDockWidget* createDock(); + Void updateMenus(); + + Void readSettings(); + Void writeSettings(); static Void destroyModuleIf( PlaYUVerAppModuleIf* pcCurrModuleIf ); - static Bool applyModuleIf( PlaYUVerAppModuleIf* pcCurrModuleIf, Bool isPlaying, Bool disableThreads = false ); - static Void swapModulesWindowsIf( PlaYUVerAppModuleIf *pcCurrModuleIf ); + static Bool applyModuleIf( PlaYUVerAppModuleIf* pcCurrModuleIf, Bool isPlaying = false, Bool disableThreads = false ); + static Bool showModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf, PlaYUVerFrame* processedFrame ); static Bool showModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf, Double moduleResult ); - static Void applyAllModuleIf( PlaYUVerAppModuleIf* pcCurrModuleIf ); private: QMainWindow *m_pcParent; QMdiArea *m_pcMdiArea; - UInt m_uiModulesCount; - Int m_iOptionSelected; enum { INVALID_OPT = -1, - SWAP_FRAMES_OPT = -2, - APPLY_ALL_OPT = -3, + SWAP_FRAMES_OPT = 0, + APPLY_ALL_OPT = 1, }; QMenu* m_pcModulesMenu; QList m_pcModulesSubMenuList; - QList m_pcPlaYUVerModulesIf; - QList m_pcPlaYUVerModules; - QSignalMapper* m_pcActionMapper; + QList m_pcPlaYUVerModulesIfList; + QList m_pcPlaYUVerAppModuleIfList; + QVector m_arrayModulesActions; + QSignalMapper* m_pcModulesActionMapper; enum MODULES_ACTION_LIST { @@ -93,15 +95,20 @@ private: MODULES_TOTAL_ACT }; QVector m_arrayActions; + QSignalMapper* m_pcActionMapper; - Void appendModule( PlaYUVerModuleIf* pModuleIf ); - SubWindowHandle* enableModuleIf( PlaYUVerAppModuleIf* pcCurrModuleIf ); - Void openModuleIfStream( PlaYUVerAppModuleIf *pcCurrModuleIf ); + Void enableModuleIf( PlaYUVerAppModuleIf* pcCurrModuleIf ); + Void applyAllModuleIf( PlaYUVerAppModuleIf* pcCurrModuleIf ); + Void swapModulesWindowsIf( PlaYUVerAppModuleIf *pcCurrModuleIf ); Void customEvent( QEvent *event ); +Q_SIGNALS: + void changed(); + private Q_SLOTS: - void selectModule( int index ); + void activateModule(); + void processOpt( int index ); void destroyAllModulesIf(); }; diff --git a/app/PlaYUVerAppAdaptor.cpp b/app/PlaYUVerAppAdaptor.cpp index f72540f..f82e686 100644 --- a/app/PlaYUVerAppAdaptor.cpp +++ b/app/PlaYUVerAppAdaptor.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/PlaYUVerAppAdaptor.h b/app/PlaYUVerAppAdaptor.h index 4888a55..4210724 100644 --- a/app/PlaYUVerAppAdaptor.h +++ b/app/PlaYUVerAppAdaptor.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/PlaYUVerAppModuleIf.cpp b/app/PlaYUVerAppModuleIf.cpp index 92d5753..5145312 100644 --- a/app/PlaYUVerAppModuleIf.cpp +++ b/app/PlaYUVerAppModuleIf.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -28,8 +28,9 @@ namespace plaYUVer { -PlaYUVerAppModuleIf::PlaYUVerAppModuleIf() : - m_pcAction( NULL ), +PlaYUVerAppModuleIf::PlaYUVerAppModuleIf( QObject* parent, QAction* action, PlaYUVerModuleIf* module ) : + m_pcModuleAction( action ), + m_pcModule( module ), m_pcDisplaySubWindow( NULL ), m_pcDockWidget( NULL ), m_pcModuleDock( NULL ), @@ -37,6 +38,7 @@ PlaYUVerAppModuleIf::PlaYUVerAppModuleIf() : m_pcProcessedFrame( NULL ), m_dMeasurementResult( 0 ) { + setParent( parent ); for( Int i = 0; i < MAX_NUMBER_FRAMES; i++ ) { m_pcSubWindow[i] = NULL; @@ -48,9 +50,9 @@ void PlaYUVerAppModuleIf::run() m_pcProcessedFrame = NULL; m_dMeasurementResult = 0; - if( m_pcModule->m_cModuleDef.m_iModuleType == FRAME_PROCESSING_MODULE ) + if( m_pcModule->m_iModuleType == FRAME_PROCESSING_MODULE ) { - switch( m_pcModule->m_cModuleDef.m_uiNumberOfFrames ) + switch( m_pcModule->m_uiNumberOfFrames ) { case MODULE_REQUIRES_ONE_FRAME: m_pcProcessedFrame = m_pcModule->process( m_pcSubWindow[0]->getCurrFrame() ); @@ -63,9 +65,9 @@ void PlaYUVerAppModuleIf::run() break; } } - else if( m_pcModule->m_cModuleDef.m_iModuleType == FRAME_MEASUREMENT_MODULE ) + else if( m_pcModule->m_iModuleType == FRAME_MEASUREMENT_MODULE ) { - switch( m_pcModule->m_cModuleDef.m_uiNumberOfFrames ) + switch( m_pcModule->m_uiNumberOfFrames ) { case MODULE_REQUIRES_ONE_FRAME: m_dMeasurementResult = m_pcModule->measure( m_pcSubWindow[0]->getCurrFrame() ); diff --git a/app/PlaYUVerAppModuleIf.h b/app/PlaYUVerAppModuleIf.h index 6a41c4d..cc73748 100644 --- a/app/PlaYUVerAppModuleIf.h +++ b/app/PlaYUVerAppModuleIf.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -53,9 +53,10 @@ class PlaYUVerAppModuleIf private: + QAction* m_pcModuleAction; PlaYUVerModuleIf* m_pcModule; - QAction* m_pcAction; + VideoSubWindow* m_pcSubWindow[MAX_NUMBER_FRAMES]; VideoSubWindow* m_pcDisplaySubWindow; @@ -82,7 +83,7 @@ public: PlaYUVerAppModuleIf* m_pcModule; }; - PlaYUVerAppModuleIf(); + PlaYUVerAppModuleIf( QObject* parent, QAction* action, PlaYUVerModuleIf* module ); virtual ~PlaYUVerAppModuleIf() {} protected: diff --git a/app/PlaYUVerFrameStatistics.cpp b/app/PlaYUVerFrameStatistics.cpp deleted file mode 100644 index c199fcc..0000000 --- a/app/PlaYUVerFrameStatistics.cpp +++ /dev/null @@ -1,571 +0,0 @@ -/* This file is a part of plaYUVer project - * Copyright (C) 2014 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 PlaYUVerFrameStatistics.cpp - * \brief Measure PlaYUVerFrame statistics - * Based on the work of Ricardo N. Rocha Sardo in SCode project - */ - -#include -#include -#include - -#include -#include "PlaYUVerFrameStatistics.h" -#include "lib/LibMemory.h" - -namespace plaYUVer -{ - -//////////////////////////////////////////////////////////////////////////////// -// Private Data Class -//////////////////////////////////////////////////////////////////////////////// -class PlaYUVerFrameStatisticsPrivate -{ - -public: - /* - // Using a structure instead a class is more fast - // (access with memset() and bytes manipulation). - - struct double_packet - { - double luma; - double red; - double green; - double blue; - double alpha; - }; - */ -public: - - PlaYUVerFrameStatisticsPrivate() - { - parent = 0; - imageData = 0; - histogram = 0; - runningFlag = true; - } - - /** The histogram data.*/ - Double *histogram; - - /** If true, calc the luminosity channel histogram when the image is RGB */ - Bool calcLuma; - - /** If the image is RGB and calcLuma is true, we have 1 more channel */ - Int histoChannels; - - /** Image information.*/ - Pel ***imageData; - UInt imageWidth; - UInt imageHeight; - Int imageChannels; - Int imageColorSpace; - UInt imageChromaSize; - - /** Numbers of histogram segments dependaing of image bytes depth*/ - Int histoSegments; - - /** To post event from thread to parent.*/ - QObject *parent; - - /** Used to stop thread during calculations.*/ - Bool runningFlag; -}; - -//////////////////////////////////////////////////////////////////////////////// -// Constructors and Destructor -//////////////////////////////////////////////////////////////////////////////// - -PlaYUVerFrameStatistics::PlaYUVerFrameStatistics( const PlaYUVerFrame *playuver_frame, QObject *parent, Options options ) : - QThread() -{ - setup( playuver_frame->getPelBufferYUV(), playuver_frame->getWidth(), playuver_frame->getHeight(), playuver_frame->getBitsChannel(), - playuver_frame->getColorSpace(), playuver_frame->getChromaLength(), parent, options ); -} - -PlaYUVerFrameStatistics::PlaYUVerFrameStatistics( Pel ***data, UInt width, UInt height, Int bitsPerChannel, Int colorSpace, UInt chroma_size, QObject *parent, - Options options ) : - QThread() -{ - setup( data, width, height, bitsPerChannel, colorSpace, chroma_size, parent, options ); -} - -PlaYUVerFrameStatistics::~PlaYUVerFrameStatistics() -{ - stopCalcHistogramValues(); - - if( d->histogram ) - delete[] d->histogram; - - delete d; -} - -//////////////////////////////////////////////////////////////////////////////// -// Setup Function -//////////////////////////////////////////////////////////////////////////////// -void PlaYUVerFrameStatistics::setup( Pel ***data, UInt width, UInt height, Int bitsPerChannel, Int colorSpace, UInt chroma_size, QObject *parent, - Options options ) -{ - d = new PlaYUVerFrameStatisticsPrivate; - d->imageData = data; - d->imageWidth = width; - d->imageHeight = height; - d->parent = parent; - d->histoSegments = ( bitsPerChannel == 16 ) ? 65536 : 256; - d->imageColorSpace = colorSpace; - d->imageChromaSize = chroma_size; - - if( options == CalcLumaWhenRGB ) - d->calcLuma = true; - else - d->calcLuma = false; - - switch( d->imageColorSpace ) - { - case PlaYUVerFrame::COLOR_GRAY: - d->imageChannels = 1; - break; - case PlaYUVerFrame::COLOR_RGB: - case PlaYUVerFrame::COLOR_YUV: - d->imageChannels = 3; - break; - case PlaYUVerFrame::COLOR_ARGB: - d->imageChannels = 4; - break; - default: - d->imageChannels = 1; - } - - if( d->calcLuma && ( d->imageColorSpace == PlaYUVerFrame::COLOR_RGB ) ) - d->histoChannels = d->imageChannels + 1; - else - d->histoChannels = d->imageChannels; - - if( d->imageData && d->imageWidth && d->imageHeight ) - { - if( d->parent ) - start(); - else - run(); //Lukas - substitui calcHistogramValues por run() - } - else - { - if( d->parent ) - postProgress( false, false ); - } -} -//////////////////////////////////////////////////////////////////////////////// -// Accessing Properties -//////////////////////////////////////////////////////////////////////////////// -int PlaYUVerFrameStatistics::getHistogramSegment( void ) -{ - return d->histoSegments; -} - -int PlaYUVerFrameStatistics::getRealHistoChannel( int channel ) -{ - int histoChannel; - - switch( d->imageColorSpace ) - { - case PlaYUVerFrame::COLOR_GRAY: - if( channel != LumaChannel ) - { - return -1; - } - histoChannel = 0; - break; - case PlaYUVerFrame::COLOR_RGB: - if( channel != RedChannel && channel != GreenChannel && channel != BlueChannel && ( channel != LumaChannel && d->calcLuma ) ) - { - return -1; - } - else - { - if( channel == RedChannel ) - histoChannel = 0; - - if( channel == GreenChannel ) - histoChannel = 1; - - if( channel == BlueChannel ) - histoChannel = 2; - - if( channel == LumaChannel ) - histoChannel = 3; - } - break; - case PlaYUVerFrame::COLOR_ARGB: - if( channel != RedChannel && channel != GreenChannel && channel != BlueChannel && channel != AlphaChannel && ( channel != LumaChannel && d->calcLuma ) ) - { - return -1; - } - else - { - if( channel == AlphaChannel ) - histoChannel = 0; - - if( channel == RedChannel ) - histoChannel = 1; - - if( channel == GreenChannel ) - histoChannel = 2; - - if( channel == BlueChannel ) - histoChannel = 3; - - if( channel == LumaChannel ) - histoChannel = 4; - } - break; - case PlaYUVerFrame::COLOR_YUV: - if( channel != LumaChannel && channel != YChannel && channel != CbChannel && channel != CrChannel ) - { - return -1; - } - else - { - if( channel == YChannel || channel == LumaChannel) - histoChannel = 0; - - if( channel == CbChannel ) - histoChannel = 1; - - if( channel == CrChannel ) - histoChannel = 2; - } - break; - default: - histoChannel = -1; - } - return histoChannel; -} -//////////////////////////////////////////////////////////////////////////////// -// Progress Indicators -//////////////////////////////////////////////////////////////////////////////// -void PlaYUVerFrameStatistics::postProgress( bool starting, bool success ) -{ - EventData *eventData = new EventData(); - eventData->starting = starting; - eventData->success = success; - eventData->histogram = this; - QCoreApplication::postEvent( d->parent, eventData ); -} - -void PlaYUVerFrameStatistics::stopCalcHistogramValues( void ) -{ - d->runningFlag = false; - wait(); -} - -//////////////////////////////////////////////////////////////////////////////// -// List of threaded operations -//////////////////////////////////////////////////////////////////////////////// -void PlaYUVerFrameStatistics::run() -{ - calcHistogramValues(); -} - -void PlaYUVerFrameStatistics::calcHistogramValues() -{ - register uint i; - register int j; - - if( d->parent ) - postProgress( true, false ); - - getMem1D( &( d->histogram ), d->histoSegments * d->histoChannels ); - - if( !d->histogram ) - { - qWarning( ) << "PlaYUVerFrameStatistics::calcHistogramValuess: " - "Unable to allocate memory!" - << endl; - - if( d->parent ) - postProgress( false, false ); - - return; - } - - if( d->imageColorSpace == PlaYUVerFrame::COLOR_YUV ) - { - Pel *data[3]; - data[LUMA] = d->imageData[LUMA][0]; - data[CHROMA_U] = d->imageData[CHROMA_U][0]; - data[CHROMA_V] = d->imageData[CHROMA_V][0]; - for( i = 0; ( i < d->imageHeight * d->imageWidth ) && d->runningFlag; i++ ) - { - d->histogram[*( data[LUMA] ) + LUMA * d->histoSegments]++; - data[LUMA] += 1; - } - for( i = 0; ( i < d->imageChromaSize ) && d->runningFlag; i++ ) - { - for( j = 1; j < d->imageChannels; j++ ) - { - d->histogram[*( data[j] ) + j * d->histoSegments]++; - } - for( j = 1; j < d->imageChannels; j++ ) - data[j] += 1; - } - } - else - { - Pel *data[3], luma; - data[COLOR_R] = d->imageData[COLOR_R][0]; - data[COLOR_G] = d->imageData[COLOR_G][0]; - data[COLOR_B] = d->imageData[COLOR_B][0]; - - for( i = 0; ( i < d->imageHeight * d->imageWidth ) && d->runningFlag; i++ ) - { - for( j = 0; j < d->imageChannels; j++ ) - { - d->histogram[*( data[j] ) + j * d->histoSegments]++; - } - if( d->calcLuma && ( d->imageColorSpace == PlaYUVerFrame::COLOR_RGB || d->imageColorSpace == PlaYUVerFrame::COLOR_ARGB ) ) - { - PlaYUVerFrame::Pixel currPixel( d->imageColorSpace, *( data[COLOR_R] ), *( data[COLOR_G] ), *( data[COLOR_B] ) ); - luma = PlaYUVerFrame::ConvertPixel( currPixel, PlaYUVerFrame::COLOR_YUV ).Y(); - d->histogram[luma + j * d->histoSegments]++; - } - for( j = 0; j < d->imageChannels; j++ ) - data[j] += 1; - } - } - - if( d->parent && d->runningFlag ) - postProgress( false, true ); - -} - -double PlaYUVerFrameStatistics::getCount( int channel, int start, int end ) -{ - int i; - int histoChannel; - int indexStart; - double count = 0.0; - - if( !d->histogram || start < 0 || end > d->histoSegments - 1 || start > end ) - { - return 0.0; - } - - histoChannel = getRealHistoChannel( channel ); - - if( histoChannel == -1 ) - { - return 0.0; - } - - indexStart = histoChannel * d->histoSegments; - - for( i = start; i <= end; i++ ) - { - count += d->histogram[indexStart + i]; - } - return count; -} - -double PlaYUVerFrameStatistics::getPixels() -{ - if( !d->histogram ) - { - return 0.0; - } - - return ( d->imageWidth * d->imageHeight ); -} - -double PlaYUVerFrameStatistics::getMean( int channel, int start, int end ) -{ - int i; - int indexStart; - int histoChannel; - double mean = 0.0; - double count; - - if( !d->histogram || start < 0 || end > d->histoSegments - 1 || start > end ) - { - return 0.0; - } - - histoChannel = getRealHistoChannel( channel ); - - if( histoChannel == -1 ) - { - return 0.0; - } - - indexStart = histoChannel * d->histoSegments; - - for( i = start; i <= end; i++ ) - { - mean += i * d->histogram[indexStart + i]; - } - - count = getCount( channel, start, end ); - - if( count > 0.0 ) - { - return mean / count; - } - - return mean; -} - -int PlaYUVerFrameStatistics::getMedian( int channel, int start, int end ) -{ - int i; - int histoChannel; - int indexStart; - double sum = 0.0; - double count; - - if( !d->histogram || start < 0 || end > d->histoSegments - 1 || start > end ) - { - return 0; - } - - histoChannel = getRealHistoChannel( channel ); - - if( histoChannel == -1 ) - { - return 0; - } - - indexStart = histoChannel * d->histoSegments; - - count = getCount( channel, start, end ); - - for( i = start; i <= end; i++ ) - { - sum += d->histogram[indexStart + i]; - if( sum * 2 > count ) - return i; - } - - return 0; -} - -double PlaYUVerFrameStatistics::getStdDev( int channel, int start, int end ) -{ - int i; - int histoChannel; - int indexStart; - double dev = 0.0; - double count; - double mean; - - if( !d->histogram || start < 0 || end > d->histoSegments - 1 || start > end ) - { - return 0.0; - } - - histoChannel = getRealHistoChannel( channel ); - - if( histoChannel == -1 ) - { - return 0.0; - } - - indexStart = histoChannel * d->histoSegments; - mean = getMean( channel, start, end ); - count = getCount( channel, start, end ); - - if( count == 0.0 ) - count = 1.0; - - /*------------ original - - for ( i = start ; i <= end ; i++ ) - { - dev += ( i - mean ) * ( i - mean ) * d->histogram[indexStart +i]; - } - - return sqrt( dev / count ); - - -----------------------*/ - - for( i = start; i <= end; i++ ) - { - dev += ( i * i ) * d->histogram[indexStart + i]; - } - - return sqrt( ( dev - count * mean * mean ) / ( count - 1 ) ); - -} - -double PlaYUVerFrameStatistics::getValue( int channel, int bin ) -{ - double value; - int histoChannel; - int indexStart; - - if( !d->histogram || bin < 0 || bin > d->histoSegments - 1 ) - return 0.0; - - histoChannel = getRealHistoChannel( channel ); - - if( histoChannel == -1 ) - { - return 0.0; - } - - indexStart = histoChannel * d->histoSegments; - - value = d->histogram[indexStart + bin]; - - return value; -} - -double PlaYUVerFrameStatistics::getMaximum( int channel ) -{ - double max = 0.0; - int x; - int histoChannel; - int indexStart; - - if( !d->histogram ) - return 0.0; - - histoChannel = getRealHistoChannel( channel ); - - if( histoChannel == -1 ) - { - return 0.0; - } - - indexStart = histoChannel * d->histoSegments; - - for( x = 0; x < d->histoSegments; x++ ) - { - if( d->histogram[indexStart + x] > max ) - { - max = d->histogram[indexStart + x]; - } - } - - return max; -} - -} // NAMESPACE - diff --git a/app/PlaYUVerFrameStatistics.h b/app/PlaYUVerFrameStatistics.h deleted file mode 100644 index 1b93eb7..0000000 --- a/app/PlaYUVerFrameStatistics.h +++ /dev/null @@ -1,137 +0,0 @@ -/* This file is a part of plaYUVer project - * Copyright (C) 2014 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 PlaYUVerFrameStatistics.h - * \brief Measure PlaYUVerFrame statistics - * Based on the work of Ricardo N. Rocha Sardo in SCode project - */ - -#ifndef __PLAYUVERFRAMESTATISTICS_H_ -#define __PLAYUVERFRAMESTATISTICS_H_ - -#include -#include "lib/PlaYUVerFrame.h" -#include "lib/PlaYUVerDefs.h" - -class QObject; - -namespace plaYUVer -{ - -class PlaYUVerFrameStatisticsPrivate; - -/** - * Esta classe permite obter o histograma de uma imagem assim como algumas - * estatísticas. - */ -class PlaYUVerFrameStatistics: public QThread -{ - -public: - - enum StatisticsChannel - { - LumaChannel = 0, - RedChannel = 1, - GreenChannel = 2, - BlueChannel = 3, - AlphaChannel = 4, - YChannel = 1, - CbChannel = 2, - CrChannel = 3 - }; - - enum Options - { - CalcLumaWhenRGB = 0 - }; - - /** - * Custom Event - */ - class EventData: public QEvent - { - - public: - - EventData() : - QEvent( QEvent::User ) - { - starting = false; - success = false; - histogram = 0; - } - - bool starting; - bool success; - PlaYUVerFrameStatistics *histogram; - }; - -public: - - PlaYUVerFrameStatistics( Pel ***data, UInt width, UInt height, Int bitsPerChannel, Int pixel_format, UInt chroma_size, - QObject *parent = 0, Options options = CalcLumaWhenRGB ); - - PlaYUVerFrameStatistics( const PlaYUVerFrame *playuver_frame, QObject *parent = 0, Options options = CalcLumaWhenRGB ); - - ~PlaYUVerFrameStatistics(); - - void setup( Pel ***data, UInt width, UInt height, Int bitsPerChannel, Int colorSpace, UInt chroma_size, QObject *parent = 0, Options options = CalcLumaWhenRGB ); - - /** Method to stop threaded computations.*/ - void stopCalcHistogramValues( void ); - - // Methods for to manipulate the histogram data. - - double getCount( int channel, int start, int end ); - double getMean( int channel, int start, int end ); - /** - * @return Number of image pixels - */ - double getPixels(); - double getStdDev( int channel, int start, int end ); - double getValue( int channel, int bin ); - double getMaximum( int channel ); - - /** - * @return Number of histogram segments: 256 or 65536 for 8 or 16 bits per - * sample. - */ - int getHistogramSegment( void ); - int getMedian( int channel, int start, int end ); - -private: - - PlaYUVerFrameStatisticsPrivate *d; - -private: - - int getRealHistoChannel( int channel ); - void calcHistogramValues(); - void postProgress( bool starting, bool success ); - -protected: - - virtual void run(); -}; - -} // NAMESPACE - -#endif // __PLAYUVERFRAMESTATISTICS_H_ diff --git a/app/QualityMeasurement.cpp b/app/QualityHandle.cpp similarity index 66% rename from app/QualityMeasurement.cpp rename to app/QualityHandle.cpp index 4d70466..ba99ec1 100644 --- a/app/QualityMeasurement.cpp +++ b/app/QualityHandle.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -18,31 +18,31 @@ */ /** - * \file QualityMeasurement.cpp + * \file QualityHandle.cpp * \brief Definition of the quality measurement sidebar */ #include "lib/PlaYUVerDefs.h" #include -#include "QualityMeasurement.h" +#include "QualityHandle.h" #include "DialogSubWindowSelector.h" namespace plaYUVer { -QualityMeasurement::QualityMeasurement( QWidget* parent, QMdiArea* mdiArea ) : +QualityHandle::QualityHandle( QWidget* parent, QMdiArea* mdiArea ) : m_pcParet( parent ), m_pcMainWindowMdiArea( mdiArea ) { } -QualityMeasurement::~QualityMeasurement() +QualityHandle::~QualityHandle() { } -Void QualityMeasurement::createActions() +Void QualityHandle::createActions() { m_actionGroupQualityMetric = new QActionGroup( this ); m_actionGroupQualityMetric->setExclusive( true ); @@ -65,7 +65,7 @@ Void QualityMeasurement::createActions() connect( m_arrayActions[SELECT_REF_ACT], SIGNAL( triggered() ), this, SLOT( slotSelectReference() ) ); } -QMenu* QualityMeasurement::createMenu() +QMenu* QualityHandle::createMenu() { m_pcMenuQuality = new QMenu( "Quality", this ); QMenu* metricsSubMenu = m_pcMenuQuality->addMenu( "Quality Metrics" ); @@ -76,38 +76,53 @@ QMenu* QualityMeasurement::createMenu() return m_pcMenuQuality; } -QDockWidget* QualityMeasurement::createDock() +QDockWidget* QualityHandle::createDock() { - m_pcQualityMeasurementSideBar = new QualityMeasurementSidebar( m_pcParet, m_pcMainWindowMdiArea ); - m_pcQualityMeasurementDock = new QDockWidget( tr( "Quality Measurement" ), this ); - m_pcQualityMeasurementDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); - m_pcQualityMeasurementDock->setWidget( m_pcQualityMeasurementSideBar ); + m_pcQualityHandleSideBar = new QualityMeasurementSidebar( m_pcParet, m_pcMainWindowMdiArea ); + m_pcQualityHandleDock = new QDockWidget( tr( "Quality Measurement" ), this ); + m_pcQualityHandleDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); + m_pcQualityHandleDock->setWidget( m_pcQualityHandleSideBar ); - connect( m_pcQualityMeasurementSideBar, SIGNAL( signalQualityMetricChanged(int) ), this, SLOT( slotQualityMetricChanged(int) ) ); + connect( m_pcQualityHandleSideBar, SIGNAL( signalQualityMetricChanged(int) ), this, SLOT( slotQualityMetricChanged(int) ) ); connect( m_mapperQualityMetric, SIGNAL( mapped(int) ), this, SLOT( slotQualityMetricChanged(int) ) ); - return m_pcQualityMeasurementDock; + slotQualityMetricChanged( 0 ); + + return m_pcQualityHandleDock; } -Void QualityMeasurement::updateMenus() +Void QualityHandle::updateMenus() { } -Void QualityMeasurement::update( VideoSubWindow* currSubWindow ) +Void QualityHandle::readSettings() { - m_pcQualityMeasurementSideBar->updateSubWindowList(); - m_pcQualityMeasurementSideBar->updateCurrentWindow( currSubWindow ); + QSettings appSettings; + Int metric = appSettings.value( "QualityHandle/Metric", 0 ).toInt(); + slotQualityMetricChanged( metric ); } -Void QualityMeasurement::slotQualityMetricChanged( Int idx ) +Void QualityHandle::writeSettings() +{ + QSettings appSettings; + appSettings.setValue( "QualityHandle/Metric", m_iQualityMetricIdx ); +} + +Void QualityHandle::update( VideoSubWindow* currSubWindow ) +{ + m_pcQualityHandleSideBar->updateCurrentWindow( currSubWindow ); +} + +Void QualityHandle::slotQualityMetricChanged( Int idx ) { m_actionGroupQualityMetric->actions().at( idx )->setChecked( true ); - m_pcQualityMeasurementSideBar->updateQualityMetric( idx ); - m_pcQualityMeasurementDock->show(); + m_pcQualityHandleSideBar->updateQualityMetric( idx ); + m_pcQualityHandleDock->show(); + m_iQualityMetricIdx = idx; } -Void QualityMeasurement::slotSelectReference() +Void QualityHandle::slotSelectReference() { DialogSubWindowSelector dialogWindowSelection( this, m_pcMainWindowMdiArea, 1, 1 ); if( dialogWindowSelection.exec() == QDialog::Accepted ) @@ -130,8 +145,8 @@ Void QualityMeasurement::slotSelectReference() pcVideoSubWindow = subWindowList.at( i ); pcVideoSubWindow->setRefSubWindow( pcRefSubWindow ); } - m_pcQualityMeasurementSideBar->updateSidebarData(); - m_pcQualityMeasurementDock->show(); + m_pcQualityHandleSideBar->updateSidebarData(); + m_pcQualityHandleDock->show(); } } diff --git a/app/QualityMeasurement.h b/app/QualityHandle.h similarity index 79% rename from app/QualityMeasurement.h rename to app/QualityHandle.h index 0e0d39b..d2f59c4 100644 --- a/app/QualityMeasurement.h +++ b/app/QualityHandle.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -18,7 +18,7 @@ */ /** - * \file QualityMeasurement.h + * \file QualityHandle.h * \brief Definition of the quality measurement sidebar */ @@ -40,18 +40,21 @@ namespace plaYUVer class VideoSubWindow; -class QualityMeasurement: public QWidget +class QualityHandle: public QWidget { Q_OBJECT public: - QualityMeasurement( QWidget*, QMdiArea * ); - ~QualityMeasurement(); + QualityHandle( QWidget*, QMdiArea * ); + ~QualityHandle(); Void createActions(); QMenu* createMenu(); QDockWidget* createDock(); Void updateMenus(); + Void readSettings(); + Void writeSettings(); + Void update( VideoSubWindow* currSubWindow ); private: @@ -65,11 +68,15 @@ private: QVector m_arrayActions; QActionGroup* m_actionGroupQualityMetric; QSignalMapper* m_mapperQualityMetric; + Int m_iQualityMetricIdx; QMenu* m_pcMenuQuality; - QDockWidget* m_pcQualityMeasurementDock; - QualityMeasurementSidebar* m_pcQualityMeasurementSideBar; + QDockWidget* m_pcQualityHandleDock; + QualityMeasurementSidebar* m_pcQualityHandleSideBar; + +Q_SIGNALS: + void changed(); private Q_SLOTS: void slotQualityMetricChanged( int ); diff --git a/app/QualityMeasurementSidebar.cpp b/app/QualityMeasurementSidebar.cpp index d9253ed..ad32a24 100644 --- a/app/QualityMeasurementSidebar.cpp +++ b/app/QualityMeasurementSidebar.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -167,13 +167,14 @@ Void QualityMeasurementSidebar::updateCurrentWindow( VideoSubWindow *subWindow ) index = m_pcVideoWindowList.indexOf( refSubWindow ); } m_comboBoxRef->setCurrentIndex( index ); + updateSubWindowList(); updateSidebarData(); } } Void QualityMeasurementSidebar::updateSidebarData() { - QString value( "0.00" ); + QString value( "0.0000" ); if( m_pcCurrentVideoSubWindow ) { VideoSubWindow* refSubWindow = m_pcCurrentVideoSubWindow->getRefSubWindow(); @@ -186,7 +187,7 @@ Void QualityMeasurementSidebar::updateSidebarData() for( Int component = 0; component < 3; component++ ) { quality = currFrame->getQuality( m_comboBoxMetric->currentIndex(), refFrame, component ); - m_ppcLabelQualityValue[component]->setText( value.setNum( quality, 'f', 2 ) ); + m_ppcLabelQualityValue[component]->setText( value.setNum( quality, 'f', 4 ) ); } return; } diff --git a/app/QualityMeasurementSidebar.h b/app/QualityMeasurementSidebar.h index 861f09a..15533b1 100644 --- a/app/QualityMeasurementSidebar.h +++ b/app/QualityMeasurementSidebar.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/Settings.cpp b/app/Settings.cpp index cf8458f..d44947c 100644 --- a/app/Settings.cpp +++ b/app/Settings.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -27,89 +27,9 @@ namespace plaYUVer { -Settings::Settings() : - m_settings( "pixLRA", "plaYUVer" ) +Settings::Settings() { } -// - - - - - - - - - - - - Main Window Settings - - - - - - - - - - - - - - - - - -QPoint Settings::mainWindowPos() -{ - return m_settings.value( "MainWindow/pos", QPoint( 200, 200 ) ).toPoint(); -} - -Void Settings::setMainWindowPos( const QPoint & pos ) -{ - m_settings.setValue( "MainWindow/pos", pos ); -} - -QSize Settings::mainWindowSize() -{ - return m_settings.value( "MainWindow/size", QSize( 500, 400 ) ).toSize(); -} - -Void Settings::setMainWindowSize( const QSize & size ) -{ - m_settings.setValue( "MainWindow/size", size ); -} - -QString Settings::lastOpenPath() -{ - return m_settings.value( "MainWindow/lastOpenPath", QDir::homePath() ).toString(); -} - -Void Settings::setLastOpenPath( const QString & path ) -{ - m_settings.setValue( "MainWindow/lastOpenPath", path ); -} - -Int Settings::getSelectedTool() -{ - return m_settings.value( "MainWindow/SelectedTool", ViewArea::NavigationTool ).toInt(); -} - -Void Settings::setSelectedTool( Int tool ) -{ - m_settings.setValue( "MainWindow/SelectedTool", tool ); -} - -Void Settings::setDockVisibility( Bool statusStreamProperties, Bool statusFrameProperties, Bool statusQualityMeasurement ) -{ - m_settings.setValue( "Dock/StreamProperties", statusStreamProperties ); - m_settings.setValue( "Dock/FrameProperties", statusFrameProperties ); - m_settings.setValue( "Dock/QualityMeasurement", statusQualityMeasurement ); -} - -Void Settings::getDockVisibility( Bool& statusStreamProperties, Bool& statusFrameProperties, Bool& statusQualityMeasurement ) -{ - statusStreamProperties = m_settings.value( "Dock/StreamProperties", true ).toBool(); - statusFrameProperties = m_settings.value( "Dock/FrameProperties", true ).toBool(); - statusQualityMeasurement = m_settings.value( "Dock/QualityMeasurement", true ).toBool(); -} - -// - - - - - - - - - - - - PLaying Settings - - - - - - - - - - - - - - - - - -Bool Settings::getRepeat() -{ - return m_settings.value( "Playing/Repeat", false ).toBool(); -} -Void Settings::setPlayingSettings( Bool repeat) -{ - m_settings.setValue( "Playing/Repeat", repeat ); -} - -Void Settings::setRecentFileList( PlaYUVerStreamInfoVector recentFileList ) -{ - QVariant var; - var.setValue( recentFileList ); - m_settings.setValue("MainWindow/RecentFileList", var ); -} - -QVector Settings::getRecentFileList() -{ - QVariant value = m_settings.value("MainWindow/RecentFileList"); - return value.value(); -} // - - - - - - - - - - - - - - Grid Settings - - - - - - - - - - - - - - - - - - diff --git a/app/Settings.h b/app/Settings.h index d460022..f666474 100644 --- a/app/Settings.h +++ b/app/Settings.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -40,29 +40,6 @@ class Settings public: Settings(); - // - - - - - - - - - - Main Window Settings - - - - - - - - - - - - - - QPoint mainWindowPos(); - Void setMainWindowPos( const QPoint &v ); - - QSize mainWindowSize(); - Void setMainWindowSize( const QSize &v ); - - QString lastOpenPath(); - Void setLastOpenPath( const QString &v ); - - Int getSelectedTool(); - Void setSelectedTool( Int); - - Bool getRepeat(); - Void setPlayingSettings( Bool repeat ); - - Void setDockVisibility( Bool statusStreamProperties, Bool statusFrameProperties, Bool statusQualityMeasurement ); - Void getDockVisibility( Bool& statusStreamProperties, Bool& statusFrameProperties, Bool& statusQualityMeasurement ); - - // - - - - - - - - - - Recent Files Settings - - - - - - - - - - - - - - Void setRecentFileList( PlaYUVerStreamInfoVector recentFileList ); - PlaYUVerStreamInfoVector getRecentFileList(); - // - - - - - - - - - - - - Grid Settings - - - - - - - - - - - - - - - GridManager::Style gridStyle(); Void setGridStyle( GridManager::Style v ); diff --git a/app/SubWindowHandle.cpp b/app/SubWindowHandle.cpp index 7d9149c..12279ea 100644 --- a/app/SubWindowHandle.cpp +++ b/app/SubWindowHandle.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -39,14 +39,16 @@ SubWindowHandle::~SubWindowHandle() } Void SubWindowHandle::setWindowName( QString name ) - { - m_cWindowName = name; - setWindowTitle( m_cWindowName ); - } - QString SubWindowHandle::getWindowName() - { - return m_cWindowName; - } +{ + m_cWindowName = name; + setWindowTitle( m_cWindowName ); +} + +QString SubWindowHandle::getWindowName() +{ + return m_cWindowName; +} + Bool SubWindowHandle::mayClose() { return true; diff --git a/app/SubWindowHandle.h b/app/SubWindowHandle.h index 3a7050a..64596bf 100644 --- a/app/SubWindowHandle.h +++ b/app/SubWindowHandle.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -82,6 +82,9 @@ public: return m_uiCategory; } +protected: + virtual void closeEvent( QCloseEvent *event ) = 0; + Q_SIGNALS: void zoomChanged(); void updateStatusBar( const QString& ); diff --git a/app/VideoHandle.cpp b/app/VideoHandle.cpp new file mode 100644 index 0000000..3d60e5b --- /dev/null +++ b/app/VideoHandle.cpp @@ -0,0 +1,537 @@ +/* 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 VideoHandle.h + * \brief Class to handle video playback + */ + +#include "lib/PlaYUVerDefs.h" +#include +#include "VideoHandle.h" +#include "DialogSubWindowSelector.h" + +namespace plaYUVer +{ + +VideoHandle::VideoHandle( QWidget* parent, QMdiArea* mdiArea ) : + m_pcParet( parent ), + m_pcMainWindowMdiArea( mdiArea ) +{ + m_pcCurrentVideoSubWindow = NULL; + m_bIsPlaying = false; + m_pcPlayingTimer = new QTimer; +#if( QT_VERSION_PLAYUVER == 5 ) + m_pcPlayingTimer->setTimerType( Qt::CoarseTimer ); +#endif + connect( m_pcPlayingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) ); + m_acPlayingSubWindows.clear(); +} + +VideoHandle::~VideoHandle() +{ + +} + +Void VideoHandle::createActions() +{ + + m_arrayActions.resize( TOTAL_ACT ); + m_arrayActions[PLAY_ACT] = new QAction( "Play", this ); + m_arrayActions[PLAY_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaPlay ) ) ); + m_arrayActions[PLAY_ACT]->setShortcut( Qt::Key_Space ); + connect( m_arrayActions[PLAY_ACT], SIGNAL( triggered() ), this, SLOT( play() ) ); + + m_arrayActions[STOP_ACT] = new QAction( "Stop", this ); + m_arrayActions[STOP_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaStop ) ) ); + connect( m_arrayActions[STOP_ACT], SIGNAL( triggered() ), this, SLOT( stop() ) ); + + m_mapperVideoSeek = new QSignalMapper( this ); + connect( m_mapperVideoSeek, SIGNAL( mapped(int) ), this, SLOT( seekEvent(int) ) ); + + m_arrayActions[VIDEO_BACKWARD_ACT] = new QAction( "Video Backward", this ); + m_arrayActions[VIDEO_BACKWARD_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaSeekBackward ) ) ); + m_arrayActions[VIDEO_BACKWARD_ACT]->setShortcut( Qt::Key_Left ); + connect( m_arrayActions[VIDEO_BACKWARD_ACT], SIGNAL( triggered() ), m_mapperVideoSeek, SLOT( map() ) ); + m_mapperVideoSeek->setMapping( m_arrayActions[VIDEO_BACKWARD_ACT], 0 ); + + m_arrayActions[VIDEO_FORWARD_ACT] = new QAction( "Video Forward", this ); + m_arrayActions[VIDEO_FORWARD_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaSeekForward ) ) ); + m_arrayActions[VIDEO_FORWARD_ACT]->setShortcut( Qt::Key_Right ); + connect( m_arrayActions[VIDEO_FORWARD_ACT], SIGNAL( triggered() ), m_mapperVideoSeek, SLOT( map() ) ); + m_mapperVideoSeek->setMapping( m_arrayActions[VIDEO_FORWARD_ACT], 1 ); + + m_arrayActions[VIDEO_LOOP_ACT] = new QAction( "Repeat", this ); + m_arrayActions[VIDEO_LOOP_ACT]->setCheckable( true ); + m_arrayActions[VIDEO_LOOP_ACT]->setChecked( false ); + + m_arrayActions[VIDEO_LOCK_SELECTION_ACT] = new QAction( "Video Lock Window Selection", this ); + m_arrayActions[VIDEO_FORWARD_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaSeekForward ) ) ); + connect( m_arrayActions[VIDEO_LOCK_SELECTION_ACT], SIGNAL( triggered() ), this, SLOT( videoSelectionButtonEvent() ) ); + + m_pcFrameSlider = new QSlider; + m_pcFrameSlider->setOrientation( Qt::Horizontal ); + m_pcFrameSlider->setMaximumWidth( 100 ); + m_pcFrameSlider->setMaximumWidth( /* 300 */2000 ); + m_pcFrameSlider->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ) ); + m_pcFrameSlider->setEnabled( false ); + connect( m_pcFrameSlider, SIGNAL( sliderMoved(int) ), this, SLOT( seekSliderEvent(int) ) ); +} + +QMenu* VideoHandle::createMenu() +{ + m_pcMenuVideo = new QMenu( "Video", this ); + m_pcMenuVideo->addAction( m_arrayActions[PLAY_ACT] ); + m_pcMenuVideo->addAction( m_arrayActions[STOP_ACT] ); + m_pcMenuVideo->addAction( m_arrayActions[VIDEO_BACKWARD_ACT] ); + m_pcMenuVideo->addAction( m_arrayActions[VIDEO_FORWARD_ACT] ); + m_pcMenuVideo->addAction( m_arrayActions[VIDEO_LOOP_ACT] ); + m_pcMenuVideo->addAction( m_arrayActions[VIDEO_LOCK_SELECTION_ACT] ); + return m_pcMenuVideo; +} + +QToolBar* VideoHandle::createToolBar() +{ + m_toolbarVideo = new QToolBar( tr( "Video" ) ); + m_toolbarVideo->setAllowedAreas( Qt::TopToolBarArea | Qt::BottomToolBarArea ); + m_toolbarVideo->addAction( m_arrayActions[PLAY_ACT] ); + m_toolbarVideo->addAction( m_arrayActions[STOP_ACT] ); + + QLabel* pcLockLabel = new QLabel( "PlayingLock", this ); + m_arrayActions[VIDEO_LOCK_ACT] = m_toolbarVideo->addWidget( pcLockLabel ); + m_arrayActions[VIDEO_LOCK_ACT]->setVisible( false ); + + m_toolbarVideo->addAction( m_arrayActions[VIDEO_BACKWARD_ACT] ); + m_toolbarVideo->addWidget( m_pcFrameSlider ); + m_toolbarVideo->addAction( m_arrayActions[VIDEO_FORWARD_ACT] ); + m_toolbarVideo->addWidget( new QLabel ); + m_pcFrameNumInfo = new WidgetFrameNumber; + m_toolbarVideo->addWidget( m_pcFrameNumInfo ); + + return m_toolbarVideo; +} + +QDockWidget* VideoHandle::createDock() +{ + m_pcFramePropertiesSideBar = new FramePropertiesSideBar( this, &m_bIsPlaying ); + m_pcFramePropertiesDock = new QDockWidget( tr( "Frame Information" ), this ); + m_pcFramePropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); + m_pcFramePropertiesDock->setWidget( m_pcFramePropertiesSideBar ); + connect( m_pcFramePropertiesDock, SIGNAL( visibilityChanged(bool) ), this, SLOT( update() ) ); + + return m_pcFramePropertiesDock; +} + +QWidget* VideoHandle::createStatusBarMessage() +{ + QWidget* statusBarWidget = new QWidget; + QHBoxLayout* mainlayout = new QHBoxLayout; + + m_pcFormatCodeLabel = new QLabel; + m_pcFormatCodeLabel->setText( " " ); + m_pcFormatCodeLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + m_pcFormatCodeLabel->setMinimumWidth( 100 ); + m_pcFormatCodeLabel->setAlignment( Qt::AlignCenter ); + + m_pcResolutionLabel = new QLabel; + m_pcResolutionLabel->setText( " " ); + m_pcResolutionLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + m_pcResolutionLabel->setMinimumWidth( 90 ); + m_pcResolutionLabel->setAlignment( Qt::AlignCenter ); + + m_pcColorSpace = new QLabel; + m_pcColorSpace->setText( " " ); + m_pcColorSpace->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + m_pcColorSpace->setMinimumWidth( 60 ); + m_pcColorSpace->setAlignment( Qt::AlignCenter ); + + mainlayout->addWidget( m_pcFormatCodeLabel ); + mainlayout->addWidget( m_pcResolutionLabel ); + mainlayout->addWidget( m_pcColorSpace ); + statusBarWidget->setLayout( mainlayout ); + + return statusBarWidget; +} + +Void VideoHandle::updateMenus() +{ + VideoSubWindow* pcSubWindow = qobject_cast( m_pcMainWindowMdiArea->activeSubWindow() ); + Bool hasSubWindow = pcSubWindow ? true : false; + + m_arrayActions[PLAY_ACT]->setEnabled( hasSubWindow ); + //m_arrayActions[PAUSE_ACT]->setEnabled( hasSubWindow ); + m_arrayActions[STOP_ACT]->setEnabled( hasSubWindow ); + m_arrayActions[VIDEO_BACKWARD_ACT]->setEnabled( hasSubWindow ); + m_arrayActions[VIDEO_FORWARD_ACT]->setEnabled( hasSubWindow ); + m_arrayActions[VIDEO_LOOP_ACT]->setEnabled( hasSubWindow ); + m_arrayActions[VIDEO_LOCK_SELECTION_ACT]->setEnabled( hasSubWindow ); + m_pcFrameSlider->setEnabled( hasSubWindow ); + if( !hasSubWindow ) + { + m_pcFrameSlider->setValue( 0 ); + m_pcFrameNumInfo->clear(); + } +} + +Void VideoHandle::readSettings() +{ + QSettings appSettings; + m_arrayActions[VIDEO_LOOP_ACT]->setChecked( appSettings.value( "VideoHandle/Repeat", false ).toBool() ); + if( !appSettings.value( "VideoHandle/FrameProperties", true ).toBool() ) + m_pcFramePropertiesDock->close(); +} + +Void VideoHandle::writeSettings() +{ + QSettings appSettings; + appSettings.setValue( "VideoHandle/Repeat", m_arrayActions[VIDEO_LOOP_ACT]->isChecked() ); + appSettings.setValue( "VideoHandle/FrameProperties", m_pcFramePropertiesSideBar->isVisible() ); +} + +Void VideoHandle::update() +{ + if( m_pcCurrentVideoSubWindow ) + { + PlaYUVerStream* pcStream = m_pcCurrentVideoSubWindow->getInputStream(); + PlaYUVerFrame* pcFrame = m_pcCurrentVideoSubWindow->getCurrFrame(); + + Int frame_num = 0; + UInt64 total_frame_num = 1; + + QString resolution; + if( pcFrame ) + { + m_pcColorSpace->setText( PlaYUVerFrame::supportedPixelFormatListNames().at( pcFrame->getPelFormat() ) ); + resolution.append( QString( "%1x%2" ).arg( pcFrame->getWidth() ).arg( pcFrame->getHeight() ) ); + } + + if( pcStream ) + { + frame_num = pcStream->getCurrFrameNum(); + m_pcFrameNumInfo->setCurrFrameNum( frame_num ); + total_frame_num = getMaxFrameNumber(); + + resolution.append( QString( "@%1" ).arg( pcStream->getFrameRate() ) ); + m_pcFormatCodeLabel->setText( QString( "%1 | %2" ).arg( pcStream->getFormatName() ).arg( pcStream->getCodecName() ) ); + } + else + { + //m_pcStreamProperties->setData( NULL ); + m_pcFrameNumInfo->setCurrFrameNum( 0 ); + m_pcFormatCodeLabel->clear(); + } + + if( pcFrame ) + 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 ); + + if( m_pcCurrentVideoSubWindow->isPlaying() ) + m_arrayActions[PLAY_ACT]->setIcon( style()->standardIcon( QStyle::SP_MediaPause ) ); + else + m_arrayActions[PLAY_ACT]->setIcon( style()->standardIcon( QStyle::SP_MediaPlay ) ); + + //m_appModuleQuality->update( m_pcCurrentVideoSubWindow ); + return; + } + //m_pcStreamProperties->setData( NULL ); + m_pcFramePropertiesSideBar->setData( NULL, false ); + m_pcFrameSlider->setValue( 0 ); + m_pcFrameNumInfo->setCurrFrameNum( 0 ); + m_pcFrameNumInfo->setTotalFrameNum( 0 ); +} + +Void VideoHandle::update( VideoSubWindow* currSubWindow ) +{ + m_pcCurrentVideoSubWindow = currSubWindow; + update(); +} + +Void VideoHandle::updateSelectionArea( QRect area ) +{ + if( m_pcCurrentVideoSubWindow ) + { + m_pcFramePropertiesSideBar->setSelection( area ); + } +} + +Void VideoHandle::closeSubWindow( VideoSubWindow* currSubWindow ) +{ + if( m_acPlayingSubWindows.contains( currSubWindow ) ) + { + Int pos = m_acPlayingSubWindows.indexOf( currSubWindow ); + m_acPlayingSubWindows.at( pos )->stop(); + m_acPlayingSubWindows.remove( pos ); + if( m_acPlayingSubWindows.size() < 2 ) + { + m_arrayActions[VIDEO_LOCK_ACT]->setVisible( false ); + } + } +} + +UInt64 VideoHandle::getMaxFrameNumber() +{ + UInt currFrames; + UInt64 maxFrames = INT_MAX; + if( m_pcCurrentVideoSubWindow ) + { + if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) + { + for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) + { + currFrames = m_acPlayingSubWindows.at( i )->getInputStream()->getFrameNum(); + if( currFrames < maxFrames ) + maxFrames = currFrames; + } + } + else + { + maxFrames = m_pcCurrentVideoSubWindow->getInputStream()->getFrameNum(); + } + } + return maxFrames; +} + +Void VideoHandle::setTimerStatus() +{ + Bool status = false; + for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) + { + status |= m_acPlayingSubWindows.at( i )->isPlaying(); + } + if( m_pcCurrentVideoSubWindow ) + { + status |= m_pcCurrentVideoSubWindow->isPlaying(); + } + if( status ) + { + if( !m_bIsPlaying ) + { + m_pcPlayingTimer->start(); + m_bIsPlaying = true; + } + } + else + { + m_pcPlayingTimer->stop(); + m_bIsPlaying = false; + } +} + +Void VideoHandle::play() +{ + if( !m_pcCurrentVideoSubWindow ) + return; + + if( !m_pcCurrentVideoSubWindow->getInputStream() ) + return; + + if( !m_pcCurrentVideoSubWindow->isPlaying() ) // Not playing + { + UInt frameRate; + UInt timeInterval; + if( m_acPlayingSubWindows.size() < 2 ) + { + for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) + { + m_acPlayingSubWindows.at( i )->pause(); + } + m_acPlayingSubWindows.clear(); + m_acPlayingSubWindows.append( m_pcCurrentVideoSubWindow ); + } + if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) + { + for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) + { + m_acPlayingSubWindows.at( i )->play(); + } + frameRate = m_acPlayingSubWindows.at( 0 )->getInputStream()->getFrameRate(); + timeInterval = ( UInt )( 1000.0 / frameRate + 0.5 ); + m_pcPlayingTimer->setInterval( timeInterval ); + } + } + else + { + if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) + { + for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) + { + m_acPlayingSubWindows.at( i )->pause(); + } + } + else + { + m_pcCurrentVideoSubWindow->pause(); + } + } + setTimerStatus(); + emit changed(); + //update(); +} + +Void VideoHandle::stop() +{ + if( m_acPlayingSubWindows.size() > 0 ) + { + for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) + { + m_acPlayingSubWindows.at( i )->stop(); + } + m_acPlayingSubWindows.clear(); + setTimerStatus(); + } + else + { + if( m_pcCurrentVideoSubWindow ) + { + m_pcCurrentVideoSubWindow->stop(); + } + } + emit changed(); + //update(); + m_arrayActions[VIDEO_LOCK_ACT]->setVisible( false ); +} + +Void VideoHandle::playEvent() +{ + Bool bEndOfSequence = false; + try + { + for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) + { + bEndOfSequence |= m_acPlayingSubWindows.at( i )->playEvent(); + } + if( bEndOfSequence && !m_arrayActions[VIDEO_LOOP_ACT]->isChecked() ) + { + stop(); + } + } + catch( const char *msg ) + { + QString warningMsg = "Error while playing " + QFileInfo( m_pcCurrentVideoSubWindow->getCurrentFileName() ).fileName() + " with the following error: \n" + + msg; + QMessageBox::warning( this, QApplication::applicationName(), warningMsg ); + //statusBar()->showMessage( warningMsg, 2000 ); + qDebug( ) << warningMsg; + stop(); + m_pcCurrentVideoSubWindow->close(); + } + emit changed(); + //update(); +} + +Void VideoHandle::seekEvent( Int direction ) +{ + if( m_pcCurrentVideoSubWindow ) + { + if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) + { + if( !( ( UInt )( m_pcCurrentVideoSubWindow->getInputStream()->getCurrFrameNum() + 1 ) >= getMaxFrameNumber() && direction > 0 ) ) + { + for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) + { + m_acPlayingSubWindows.at( i )->seekRelativeEvent( direction > 0 ? true : false ); + } + } + } + else + { + m_pcCurrentVideoSubWindow->seekRelativeEvent( direction > 0 ? true : false ); + } + emit changed(); + //update(); + } +} + +Void VideoHandle::seekSliderEvent( Int new_frame_num ) +{ + if( m_pcCurrentVideoSubWindow ) + { + if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) + { + for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) + { + m_acPlayingSubWindows.at( i )->seekAbsoluteEvent( ( UInt )new_frame_num ); + } + } + else + { + m_pcCurrentVideoSubWindow->seekAbsoluteEvent( ( UInt )new_frame_num ); + } + emit changed(); + //update(); + } +} + +Void VideoHandle::videoSelectionButtonEvent() +{ + DialogSubWindowSelector dialogWindowsSelection( this, m_pcMainWindowMdiArea ); + QStringList cWindowListNames; + for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) + { + cWindowListNames.append( m_acPlayingSubWindows.at( i )->getWindowName() ); + dialogWindowsSelection.setSubWindowList( cWindowListNames ); + } + if( dialogWindowsSelection.exec() == QDialog::Accepted ) + { + QStringList selectedWindows = dialogWindowsSelection.getSelectedWindows(); + m_acPlayingSubWindows.clear(); + SubWindowHandle *subWindow; + QString windowName; + QList subWindowList = m_pcMainWindowMdiArea->findChildren(); + for( Int i = 0; i < subWindowList.size(); i++ ) + { + subWindow = subWindowList.at( i ); + windowName = subWindow->getWindowName(); + if( selectedWindows.contains( windowName ) ) + { + VideoSubWindow* pcVideoSubWinodw = qobject_cast( subWindow ); + m_acPlayingSubWindows.append( pcVideoSubWinodw ); + pcVideoSubWinodw->seekAbsoluteEvent( m_acPlayingSubWindows.at( 0 )->getInputStream()->getCurrFrameNum() ); + } + } + if( m_acPlayingSubWindows.size() > 0 ) + { + m_acPlayingSubWindows.at( 0 )->activateWindow(); + if( m_acPlayingSubWindows.size() > 1 ) + { + m_arrayActions[VIDEO_LOCK_ACT]->setVisible( true ); + } + if( m_bIsPlaying ) + { + for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) + { + m_acPlayingSubWindows.at( i )->play(); + } + } + } + else + { + stop(); + } + return; + } +} + +} // NAMESPACE + diff --git a/app/VideoHandle.h b/app/VideoHandle.h new file mode 100644 index 0000000..33e2d56 --- /dev/null +++ b/app/VideoHandle.h @@ -0,0 +1,122 @@ +/* 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 VideoHandle.h + * \brief Class to handle video playback + */ + +#ifndef __VIDEOHANDLE_H__ +#define __VIDEOHANDLE_H__ + +#include "config.h" +#include +#if( QT_VERSION_PLAYUVER == 5 ) +#include +#elif( QT_VERSION_PLAYUVER == 4 ) +#include +#endif +#include "VideoSubWindow.h" +#include "WidgetFrameNumber.h" +#include "FramePropertiesSidebar.h" + +namespace plaYUVer +{ + +class VideoSubWindow; + +class VideoHandle: public QWidget +{ +Q_OBJECT +public: + VideoHandle( QWidget*, QMdiArea * ); + ~VideoHandle(); + + Void createActions(); + QMenu* createMenu(); + QToolBar* createToolBar(); + QDockWidget* createDock(); + QWidget* createStatusBarMessage(); + Void updateMenus(); + + Void readSettings(); + Void writeSettings(); + + Void update( VideoSubWindow* currSubWindow ); + + Void closeSubWindow( VideoSubWindow* currSubWindow ); + +private: + QWidget* m_pcParet; + QMdiArea* m_pcMainWindowMdiArea; + enum + { + PLAY_ACT, + STOP_ACT, + VIDEO_FORWARD_ACT, + VIDEO_BACKWARD_ACT, + VIDEO_LOOP_ACT, + VIDEO_LOCK_ACT, + VIDEO_LOCK_SELECTION_ACT, + TOTAL_ACT, + }; + QVector m_arrayActions; + QSignalMapper* m_mapperVideoSeek; + + QSlider* m_pcFrameSlider; + WidgetFrameNumber* m_pcFrameNumInfo; + + QMenu* m_pcMenuVideo; + QToolBar* m_toolbarVideo; + + QDockWidget* m_pcFramePropertiesDock; + FramePropertiesSideBar* m_pcFramePropertiesSideBar; + + QLabel* m_pcFormatCodeLabel; + QLabel* m_pcResolutionLabel; + QLabel* m_pcColorSpace; + + VideoSubWindow* m_pcCurrentVideoSubWindow; + QVector m_acPlayingSubWindows; + + QTimer *m_pcPlayingTimer; + Bool m_bIsPlaying; + + + UInt64 getMaxFrameNumber(); + Void setTimerStatus(); + +Q_SIGNALS: + void changed(); + +private Q_SLOTS: + void update(); + void updateSelectionArea( QRect area ); + void play(); + void stop(); + void playEvent(); + void seekSliderEvent( int new_frame_num ); + void seekEvent( int direction ); + void videoSelectionButtonEvent(); + +}; + +} // NAMESPACE + +#endif // __VIDEOHANDLE_H__ diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index cdabab3..48c6dde 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -75,7 +75,6 @@ VideoSubWindow::VideoSubWindow( QWidget * parent, Bool isModule ) : SubWindowHandle( parent, SubWindowHandle::VIDEO_SUBWINDOW ), m_pCurrStream( NULL ), m_pcCurrFrame( NULL ), - m_pcCurrentModule( NULL ), m_pcReferenceSubWindow( NULL ), m_bIsPlaying( false ), m_bIsModule( isModule ) @@ -104,6 +103,8 @@ VideoSubWindow::VideoSubWindow( QWidget * parent, Bool isModule ) : m_cScrollArea->setWidget( m_cViewArea ); m_cScrollArea->setWidgetResizable( true ); + m_apcCurrentModule.clear(); + m_cLastScroll = QPoint(); } @@ -207,56 +208,50 @@ Void VideoSubWindow::updateSelectedArea( QRect area ) * Functions to enable a module in the * current SubWindow */ -Void VideoSubWindow::enableModule( PlaYUVerAppModuleIf* select_module ) +Void VideoSubWindow::enableModule( PlaYUVerAppModuleIf* pcModule, Bool bThisWindow ) { - if( m_pcCurrentModule ) + if( bThisWindow ) { + m_apcCurrentModule.clear(); disableModule(); } - m_pcCurrentModule = select_module; -// refreshFrame(); + m_apcCurrentModule.append( pcModule ); } -Void VideoSubWindow::disableModule() +Void VideoSubWindow::disableModule( PlaYUVerAppModuleIf* pcModule ) { - if( m_pcCurrentModule ) + if( pcModule ) { - PlaYUVerAppModuleIf* pcCurrentModule = m_pcCurrentModule; - m_pcCurrentModule = NULL; - ModulesHandle::destroyModuleIf( pcCurrentModule ); - refreshFrame(); + Int modIdx = m_apcCurrentModule.indexOf( pcModule ); + if( modIdx != -1 ) + { + m_apcCurrentModule.removeAt( modIdx ); + ModulesHandle::destroyModuleIf( pcModule ); + } } -} - -Void VideoSubWindow::swapModuleFrames() -{ - if( m_pcCurrentModule ) + else { - ModulesHandle::swapModulesWindowsIf( m_pcCurrentModule ); - refreshFrame(); - } -} - -Void VideoSubWindow::applyModuleAllFrames() -{ - if( m_pcCurrentModule ) - { - ModulesHandle::applyAllModuleIf( m_pcCurrentModule ); - stop(); + QList apcCurrentModule = m_apcCurrentModule; + for( Int i = 0; i < apcCurrentModule.size(); i++ ) + { + m_apcCurrentModule.removeOne( apcCurrentModule.at( i ) ); + ModulesHandle::destroyModuleIf( apcCurrentModule.at( i ) ); + } + assert( m_apcCurrentModule.size() == 0 ); } + refreshFrame(); } Void VideoSubWindow::setCurrFrame( PlaYUVerFrame* pcCurrFrame ) { m_pcCurrFrame = pcCurrFrame; m_cViewArea->setImage( m_pcCurrFrame ); - if( !isVisible() ) - { - show(); - resize( sizeHint() ); - zoomToFit(); - - } +// if( !isVisible() ) +// { +// show(); +// resize( sizeHint() ); +// zoomToFit(); +// } } Void VideoSubWindow::refreshFrame() @@ -266,17 +261,10 @@ Void VideoSubWindow::refreshFrame() { m_pcCurrFrame = m_pCurrStream->getCurrFrame(); bSetFrame = true; - if( m_pcCurrentModule ) - { - bSetFrame = ModulesHandle::applyModuleIf( m_pcCurrentModule, m_bIsPlaying ); - } } - else + for( Int i = 0; i < m_apcCurrentModule.size(); i++ ) { - if( m_pcCurrentModule ) - { - bSetFrame = ModulesHandle::applyModuleIf( m_pcCurrentModule, m_bIsPlaying ); - } + bSetFrame = ModulesHandle::applyModuleIf( m_apcCurrentModule.at( i ), m_bIsPlaying ); } if( bSetFrame ) { @@ -547,10 +535,9 @@ QSize VideoSubWindow::sizeHint() const return maxSize; } -void VideoSubWindow::closeEvent( QCloseEvent *event ) +Void VideoSubWindow::closeEvent( QCloseEvent *event ) { - Bool bAccept = mayClose(); - bAccept = m_bIsPlaying ? false : bAccept; + Bool bAccept = m_bIsPlaying ? false : true; if( bAccept ) { event->accept(); diff --git a/app/VideoSubWindow.h b/app/VideoSubWindow.h index 31f5313..59e1b13 100644 --- a/app/VideoSubWindow.h +++ b/app/VideoSubWindow.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -72,7 +72,8 @@ private: QRect m_cSelectedArea; QString m_cFilename; - PlaYUVerAppModuleIf* m_pcCurrentModule; + //PlaYUVerAppModuleIf* m_pcCurrentModule; + QList m_apcCurrentModule; VideoSubWindow* m_pcReferenceSubWindow; @@ -131,15 +132,6 @@ public: return m_cViewArea; } - Void setModule( PlaYUVerAppModuleIf* pcCurrentModule ) - { - m_pcCurrentModule = pcCurrentModule; - } - PlaYUVerAppModuleIf* getModule() - { - return m_pcCurrentModule; - } - Void setRefSubWindow( VideoSubWindow* subWindow ) { m_pcReferenceSubWindow = NULL; @@ -147,6 +139,7 @@ public: if( m_pcCurrFrame->haveSameFmt( subWindow->getCurrFrame() ) ) m_pcReferenceSubWindow = subWindow; } + VideoSubWindow* getRefSubWindow() { return m_pcReferenceSubWindow; @@ -156,10 +149,12 @@ public: * Functions to enable a module in the * current SubWindow */ - Void enableModule( PlaYUVerAppModuleIf* select_module ); - Void disableModule(); - Void swapModuleFrames(); - Void applyModuleAllFrames(); + Void enableModule( PlaYUVerAppModuleIf* pcModule, Bool bThisWindow = true ); + Void disableModule( PlaYUVerAppModuleIf* pcModule = NULL ); + QList getModuleArray() + { + return m_apcCurrentModule; + } /** * Virtual functions from SubWindowHandle @@ -177,6 +172,10 @@ public: QSize sizeHint() const; + Void setWindowShortName( const QString& name) + { + m_cWindowShortName = name; + } QString getWindowShortName() { return m_cWindowShortName; diff --git a/app/ViewArea.cpp b/app/ViewArea.cpp index 3d8dd2e..711821e 100644 --- a/app/ViewArea.cpp +++ b/app/ViewArea.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/ViewArea.h b/app/ViewArea.h index 1e64a65..1dda297 100644 --- a/app/ViewArea.h +++ b/app/ViewArea.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/WidgetFrameNumber.cpp b/app/WidgetFrameNumber.cpp index c17a642..1136b98 100644 --- a/app/WidgetFrameNumber.cpp +++ b/app/WidgetFrameNumber.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/WidgetFrameNumber.h b/app/WidgetFrameNumber.h index e7571ef..7aeed71 100644 --- a/app/WidgetFrameNumber.h +++ b/app/WidgetFrameNumber.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/app/plaYUVerApp.cpp b/app/plaYUVerApp.cpp index 06067b4..4a63a0b 100644 --- a/app/plaYUVerApp.cpp +++ b/app/plaYUVerApp.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -29,7 +29,6 @@ #include "plaYUVerApp.h" #include "DialogSubWindowSelector.h" #include "WidgetFrameNumber.h" -#include "Settings.h" #define SYNCHRONISED_ZOON 1 @@ -46,18 +45,16 @@ plaYUVerApp::plaYUVerApp() m_pDBusAdaptor = new PlaYUVerAppAdaptor( this ); #endif - mdiArea = new PlaYUVerMdiArea; + mdiArea = new PlaYUVerMdiArea( this ); setCentralWidget( mdiArea ); - mdiArea->setActivationOrder( QMdiArea::ActivationHistoryOrder ); - - connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( chageSubWindowSelection() ) ); + //mdiArea->setActivationOrder( QMdiArea::ActivationHistoryOrder ); mapperWindow = new QSignalMapper( this ); connect( mapperWindow, SIGNAL( mapped(QWidget*) ), this, SLOT( setActiveSubWindow(QWidget*) ) ); - m_pcModulesHandle = new ModulesHandle( this, mdiArea ); - - m_appModuleQuality = new QualityMeasurement( this, mdiArea ); + m_appModuleVideo = new VideoHandle( this, mdiArea ); + m_appModuleQuality = new QualityHandle( this, mdiArea ); + m_appModuleExtensions = new ModulesHandle( this, mdiArea ); createActions(); createToolBars(); @@ -72,17 +69,14 @@ plaYUVerApp::plaYUVerApp() setWindowIcon( QIcon( ":/images/playuver.png" ) ); setUnifiedTitleAndToolBarOnMac( true ); - m_bIsPlaying = false; - m_pcPlayingTimer = new QTimer; -#if( QT_VERSION_PLAYUVER == 5 ) - m_pcPlayingTimer->setTimerType( Qt::CoarseTimer ); -#endif - connect( m_pcPlayingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) ); - m_acPlayingSubWindows.clear(); - setAcceptDrops( true ); mdiArea->setAcceptDrops( true ); + connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( update() ) ); + connect( m_appModuleVideo, SIGNAL( changed() ), this, SLOT( update() ) ); + 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; @@ -106,13 +100,6 @@ Void plaYUVerApp::about() if( !m_pcAboutDialog ) m_pcAboutDialog = new AboutDialog( this ); m_pcAboutDialog->exec(); - // QString about_message; - // about_message.append( "The plaYUVer is an open-source raw video player! " ); - // about_message.append( "Developed by " ); - // about_message.append( "João Carreira " ); - // about_message.append( "and " ); - // about_message.append( "Luís Lucas" ); - // QMessageBox::about( this, "About plaYUVer", about_message ); } Void plaYUVerApp::closeEvent( QCloseEvent *event ) @@ -141,7 +128,7 @@ Void plaYUVerApp::closeEvent( QCloseEvent *event ) if( mayCloseAll ) { - m_pcPlayingTimer->stop(); + //m_pcPlayingTimer->stop(); closeAll(); writeSettings(); event->accept(); @@ -157,6 +144,18 @@ Void plaYUVerApp::closeEvent( QCloseEvent *event ) } } +Void plaYUVerApp::closeActiveWindow() +{ + SubWindowHandle *currSubWindow = activeSubWindow(); + m_appModuleVideo->closeSubWindow( qobject_cast( currSubWindow ) ); + mdiArea->closeActiveSubWindow(); +} + +Void plaYUVerApp::closeAll() +{ + mdiArea->closeAllSubWindows(); +} + Void plaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo ) { if( !QFileInfo( fileName ).exists() ) @@ -193,7 +192,7 @@ Void plaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo ) mdiArea->addSubWindow( videoSubWindow ); videoSubWindow->show(); - connect( videoSubWindow->getViewArea(), SIGNAL( selectionChanged( QRect ) ), this, SLOT( updatePropertiesSelectedArea( QRect ) ) ); + connect( videoSubWindow->getViewArea(), SIGNAL( selectionChanged( QRect ) ), m_appModuleVideo, SLOT( updateSelectionArea( QRect ) ) ); connect( subWindow, SIGNAL( updateStatusBar( const QString& ) ), this, SLOT( updateStatusBar( const QString& ) ) ); connect( subWindow, SIGNAL( zoomChanged() ), this, SLOT( updateZoomFactorSBox() ) ); @@ -334,7 +333,7 @@ Void plaYUVerApp::format() m_pcCurrentSubWindow->close(); } m_pcCurrentSubWindow = NULL; - chageSubWindowSelection(); + update(); } } @@ -342,17 +341,15 @@ Void plaYUVerApp::reload() { if( m_pcCurrentVideoSubWindow ) { - VideoSubWindow* pcVideoSubWindow = qobject_cast( m_pcCurrentVideoSubWindow ); - pcVideoSubWindow->reloadFile(); + m_pcCurrentVideoSubWindow->reloadFile(); m_pcCurrentSubWindow = NULL; - chageSubWindowSelection(); + update(); } } Void plaYUVerApp::reloadAll() { VideoSubWindow *subWindow; - QList videoSubWindowList = mdiArea->findChildren(); for( Int i = 0; i < videoSubWindowList.size(); i++ ) { @@ -362,7 +359,10 @@ Void plaYUVerApp::reloadAll() subWindow->reloadFile(); } } + m_pcCurrentSubWindow = NULL; + update(); } + Void plaYUVerApp::loadAll() { if( m_pcCurrentVideoSubWindow ) @@ -377,11 +377,6 @@ Void plaYUVerApp::setTool( Int idxTool ) { m_appTool = ( ViewArea::eTool )idxTool; actionGroupTools->actions().at( m_appTool )->setChecked( true ); - setAllSubWindowTool(); -} - -Void plaYUVerApp::setAllSubWindowTool() -{ QList videoSubWindowList = mdiArea->findChildren(); for( Int i = 0; i < videoSubWindowList.size(); i++ ) { @@ -389,342 +384,6 @@ Void plaYUVerApp::setAllSubWindowTool() } } -Void plaYUVerApp::closeActiveWindow() -{ - SubWindowHandle *currSubWindow = activeSubWindow(); - if( currSubWindow->getCategory() == SubWindowHandle::VIDEO_SUBWINDOW ) - { - VideoSubWindow* pcVideoSubWindow = qobject_cast( currSubWindow ); - if( m_acPlayingSubWindows.contains( pcVideoSubWindow ) ) - { - Int pos = m_acPlayingSubWindows.indexOf( pcVideoSubWindow ); - m_acPlayingSubWindows.at( pos )->stop(); - m_acPlayingSubWindows.remove( pos ); - } - } - mdiArea->closeActiveSubWindow(); -} - -Void plaYUVerApp::closeAll() -{ - mdiArea->closeAllSubWindows(); -} - -// ----------------------- Modules Selection -------------------- - -Void plaYUVerApp::ModuleHandling( QAction *curr_action ) -{ - m_pcFrameProperties->stopHistogram(); - SubWindowHandle *interfaceChild = m_pcModulesHandle->processModuleHandlingOpt(); - if( interfaceChild ) - { - mdiArea->addSubWindow( interfaceChild ); - //interfaceChild->getViewArea()->setTool( m_appTool ); - } - if( activeSubWindow() ) - m_pcCurrentSubWindow = activeSubWindow(); - - updateStreamProperties(); - return; -} - -// ----------------------- Update Properties -------------------- - -UInt64 plaYUVerApp::getMaxFrameNumber() -{ - UInt currFrames; - UInt64 maxFrames = INT_MAX; - if( m_pcCurrentVideoSubWindow ) - { - if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) - { - for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) - { - currFrames = m_acPlayingSubWindows.at( i )->getInputStream()->getFrameNum(); - if( currFrames < maxFrames ) - maxFrames = currFrames; - } - } - else - { - maxFrames = m_pcCurrentVideoSubWindow->getInputStream()->getFrameNum(); - } - } - return maxFrames; -} - -Void plaYUVerApp::updateStreamProperties() -{ - if( m_pcCurrentVideoSubWindow ) - { - Int frame_num = 0; - UInt64 total_frame_num = 1; - if( m_pcCurrentVideoSubWindow->getInputStream() ) - { - frame_num = m_pcCurrentVideoSubWindow->getInputStream()->getCurrFrameNum(); - m_pcFrameNumInfo->setCurrFrameNum( frame_num ); - total_frame_num = getMaxFrameNumber(); - m_pcStreamProperties->setData( m_pcCurrentVideoSubWindow->getInputStream() ); - } - else - { - m_pcStreamProperties->setData( NULL ); - m_pcFrameNumInfo->setCurrFrameNum( 0 ); - } - - m_pcFrameProperties->setData( m_pcCurrentVideoSubWindow->getCurrFrame(), m_pcCurrentVideoSubWindow->isPlaying() ); - - m_pcFrameSlider->setValue( frame_num ); - m_pcFrameSlider->setMaximum( total_frame_num - 1 ); - m_pcFrameNumInfo->setTotalFrameNum( total_frame_num ); - - if( m_pcCurrentVideoSubWindow->isPlaying() ) - m_arrayActions[PLAY_ACT]->setIcon( style()->standardIcon( QStyle::SP_MediaPause ) ); - else - m_arrayActions[PLAY_ACT]->setIcon( style()->standardIcon( QStyle::SP_MediaPlay ) ); - - m_appModuleQuality->update( m_pcCurrentVideoSubWindow ); - return; - } - m_pcStreamProperties->setData( NULL ); - m_pcFrameProperties->setData( NULL, false ); - m_pcFrameNumInfo->setCurrFrameNum( 0 ); - m_pcFrameNumInfo->setTotalFrameNum( 0 ); - m_pcZoomFactorSBox->setValue( 0.0 ); -} - -Void plaYUVerApp::updatePropertiesSelectedArea( QRect area ) -{ - if( m_pcCurrentSubWindow ) - { - if( area.isValid() ) - { - m_pcFrameProperties->setSelection( area ); - } - } - else - { - m_pcFrameProperties->setData( NULL, false ); - } -} - -// ----------------------- Playing Functions -------------------- - -Void plaYUVerApp::setTimerStatus() -{ - Bool status = false; - for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) - { - status |= m_acPlayingSubWindows.at( i )->isPlaying(); - } - if( m_pcCurrentVideoSubWindow ) - { - status |= m_pcCurrentVideoSubWindow->isPlaying(); - } - if( status ) - { - if( !m_bIsPlaying ) - { - m_pcPlayingTimer->start(); - m_bIsPlaying = true; - } - } - else - { - m_pcPlayingTimer->stop(); - m_bIsPlaying = false; - } -} - -Void plaYUVerApp::play() -{ - if( !m_pcCurrentVideoSubWindow ) - return; - - if( !m_pcCurrentVideoSubWindow->getInputStream() ) - return; - - if( !m_pcCurrentVideoSubWindow->isPlaying() ) // Not playing - { - UInt frameRate; - UInt timeInterval; - if( m_acPlayingSubWindows.size() < 2 ) - { - for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) - { - m_acPlayingSubWindows.at( i )->pause(); - } - m_acPlayingSubWindows.clear(); - m_acPlayingSubWindows.append( m_pcCurrentVideoSubWindow ); - } - if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) - { - for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) - { - m_acPlayingSubWindows.at( i )->play(); - } - frameRate = m_acPlayingSubWindows.at( 0 )->getInputStream()->getFrameRate(); - timeInterval = ( UInt )( 1000.0 / frameRate + 0.5 ); - m_pcPlayingTimer->setInterval( timeInterval ); - } - } - else - { - if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) - { - for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) - { - m_acPlayingSubWindows.at( i )->pause(); - } - } - else - { - m_pcCurrentVideoSubWindow->pause(); - } - } - setTimerStatus(); - updateStreamProperties(); -} - -Void plaYUVerApp::stop() -{ - if( m_acPlayingSubWindows.size() > 0 ) - { - for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) - { - m_acPlayingSubWindows.at( i )->stop(); - } - m_acPlayingSubWindows.clear(); - setTimerStatus(); - } - else - { - if( m_pcCurrentVideoSubWindow ) - { - m_pcCurrentVideoSubWindow->stop(); - } - } - updateStreamProperties(); - m_arrayActions[VIDEO_LOCK_ACT]->setVisible( false ); -} - -Void plaYUVerApp::playEvent() -{ - Bool bEndOfSequence = false; - try - { - for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) - { - bEndOfSequence |= m_acPlayingSubWindows.at( i )->playEvent(); - } - if( bEndOfSequence && !m_arrayActions[VIDEO_LOOP_ACT]->isChecked() ) - { - stop(); - } - } - catch( const char *msg ) - { - QString warningMsg = "Error while playing " + QFileInfo( m_pcCurrentVideoSubWindow->getCurrentFileName() ).fileName() + " with the following error: \n" - + msg; - QMessageBox::warning( this, QApplication::applicationName(), warningMsg ); - statusBar()->showMessage( warningMsg, 2000 ); - qDebug( ) << warningMsg; - stop(); - m_pcCurrentVideoSubWindow->close(); - } - updateStreamProperties(); -} - -Void plaYUVerApp::seekEvent( Int direction ) -{ - if( m_pcCurrentVideoSubWindow ) - { - if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) - { - if( !( ( UInt )( m_pcCurrentVideoSubWindow->getInputStream()->getCurrFrameNum() + 1 ) >= getMaxFrameNumber() && direction > 0 ) ) - { - for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) - { - m_acPlayingSubWindows.at( i )->seekRelativeEvent( direction > 0 ? true : false ); - } - } - } - else - { - m_pcCurrentVideoSubWindow->seekRelativeEvent( direction > 0 ? true : false ); - } - updateStreamProperties(); - } -} - -Void plaYUVerApp::seekSliderEvent( Int new_frame_num ) -{ - if( m_pcCurrentVideoSubWindow ) - { - if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) ) - { - for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) - { - m_acPlayingSubWindows.at( i )->seekAbsoluteEvent( ( UInt )new_frame_num ); - } - } - else - { - m_pcCurrentVideoSubWindow->seekAbsoluteEvent( ( UInt )new_frame_num ); - } - updateStreamProperties(); - } -} - -Void plaYUVerApp::videoSelectionButtonEvent() -{ - DialogSubWindowSelector dialogWindowsSelection( this, mdiArea ); - QStringList cWindowListNames; - for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) - { - cWindowListNames.append( m_acPlayingSubWindows.at( i )->getWindowName() ); - dialogWindowsSelection.setSubWindowList( cWindowListNames ); - } - if( dialogWindowsSelection.exec() == QDialog::Accepted ) - { - QStringList selectedWindows = dialogWindowsSelection.getSelectedWindows(); - m_acPlayingSubWindows.clear(); - SubWindowHandle *subWindow; - QString windowName; - for( Int i = 0; i < mdiArea->subWindowList().size(); i++ ) - { - subWindow = qobject_cast( mdiArea->subWindowList().at( i ) ); - windowName = subWindow->getWindowName(); - if( selectedWindows.contains( windowName ) ) - { - VideoSubWindow* pcVideoSubWinodw = qobject_cast( subWindow ); - m_acPlayingSubWindows.append( pcVideoSubWinodw ); - pcVideoSubWinodw->seekAbsoluteEvent( m_acPlayingSubWindows.at( 0 )->getInputStream()->getCurrFrameNum() ); - } - } - if( m_acPlayingSubWindows.size() > 0 ) - { - m_acPlayingSubWindows.at( 0 )->activateWindow(); - if( m_acPlayingSubWindows.size() > 1 ) - { - m_arrayActions[VIDEO_LOCK_ACT]->setVisible( true ); - } - if( m_bIsPlaying ) - { - for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) - { - m_acPlayingSubWindows.at( i )->play(); - } - } - } - else - { - stop(); - } - return; - } -} - // ----------------------- Zoom Functions ----------------------- Void plaYUVerApp::normalSize() @@ -789,55 +448,6 @@ Void plaYUVerApp::updateZoomFactorSBox() } } -Void plaYUVerApp::chageSubWindowSelection() -{ - SubWindowHandle *new_window = activeSubWindow(); - if( activeSubWindow() != m_pcCurrentSubWindow ) - { - m_pcCurrentVideoSubWindow = NULL; - if( activeSubWindow() ) - { - m_pcCurrentSubWindow = new_window; - - m_pcCurrentVideoSubWindow = NULL; - switch( m_pcCurrentSubWindow->getCategory() ) - { - case SubWindowHandle::VIDEO_SUBWINDOW: - m_pcCurrentVideoSubWindow = qobject_cast( m_pcCurrentSubWindow ); - break; - } - - setWindowTitle( QApplication::applicationName() + " - " + m_pcCurrentSubWindow->getWindowName() ); - - if( m_pcCurrentVideoSubWindow ) - { - if( !plaYUVerApp::findSubWindow( mdiArea, m_pcCurrentVideoSubWindow->getRefSubWindow() ) ) - { - m_pcCurrentVideoSubWindow->setRefSubWindow( NULL ); - } - } - updateZoomFactorSBox(); - } - } - updateStreamProperties(); - m_appModuleQuality->update( m_pcCurrentVideoSubWindow ); - updateMenus(); -} - -// ----------------------- Status bar Functions ----------------------- - -Void plaYUVerApp::updateStatusBar( const QString& statusBarString ) -{ - if( !statusBarString.isEmpty() ) - { - statusBar()->showMessage( statusBarString, 5000 ); - } - else - { - statusBar()->showMessage( " " ); - } -} - // ----------------------- Drag and drop functions ---------------------- Void plaYUVerApp::dragEnterEvent( QDragEnterEvent *event ) @@ -859,7 +469,12 @@ Void plaYUVerApp::dropEvent( QDropEvent *event ) } } -// ----------------------- Gui Functions ----------------------- +// ----------------------- Sub Window Functions ----------------------- + +void plaYUVerApp::tileSubWindows() +{ + mdiArea->tileSubWindows(); +} SubWindowHandle *plaYUVerApp::activeSubWindow() { @@ -915,6 +530,56 @@ Void plaYUVerApp::setActiveSubWindow( QWidget *window ) mdiArea->setActiveSubWindow( qobject_cast( window ) ); } +// ----------------------- Update Functions ----------------------- + +Void plaYUVerApp::update() +{ + SubWindowHandle *new_window = activeSubWindow(); + QCoreApplication::processEvents(); + //if( activeSubWindow() != m_pcCurrentSubWindow ) + { + m_pcCurrentSubWindow = NULL; + m_pcCurrentVideoSubWindow = NULL; + if( activeSubWindow() ) + { + m_pcCurrentSubWindow = new_window; + + switch( m_pcCurrentSubWindow->getCategory() ) + { + case SubWindowHandle::VIDEO_SUBWINDOW: + m_pcCurrentVideoSubWindow = qobject_cast( m_pcCurrentSubWindow ); + break; + } + + setWindowTitle( QApplication::applicationName() + " - " + m_pcCurrentSubWindow->getWindowName() ); + + if( m_pcCurrentVideoSubWindow ) + { + if( !plaYUVerApp::findSubWindow( mdiArea, m_pcCurrentVideoSubWindow->getRefSubWindow() ) ) + { + m_pcCurrentVideoSubWindow->setRefSubWindow( NULL ); + } + } + updateZoomFactorSBox(); + } + } + m_appModuleVideo->update( m_pcCurrentVideoSubWindow ); + m_appModuleQuality->update( m_pcCurrentVideoSubWindow ); + updateMenus(); +} + +Void plaYUVerApp::updateStatusBar( const QString& statusBarString ) +{ + if( !statusBarString.isEmpty() ) + { + statusBar()->showMessage( statusBarString, 5000 ); + } + else + { + statusBar()->showMessage( " " ); + } +} + Void plaYUVerApp::updateMenus() { Bool hasSubWindow = ( activeSubWindow() != 0 ); @@ -936,25 +601,15 @@ Void plaYUVerApp::updateMenus() m_arrayActions[ZOOM_OUT_ACT]->setEnabled( hasSubWindow ); m_arrayActions[ZOOM_NORMAL_ACT]->setEnabled( hasSubWindow ); m_arrayActions[ZOOM_FIT_ACT]->setEnabled( hasSubWindow ); + m_arrayActions[ZOOM_FIT_ALL_ACT]->setEnabled( hasSubWindow ); m_pcZoomFactorSBox->setEnabled( hasSubWindow ); - m_arrayActions[PLAY_ACT]->setEnabled( hasSubWindow ); - //m_arrayActions[PAUSE_ACT]->setEnabled( hasSubWindow ); - m_arrayActions[STOP_ACT]->setEnabled( hasSubWindow ); - m_arrayActions[VIDEO_BACKWARD_ACT]->setEnabled( hasSubWindow ); - m_arrayActions[VIDEO_FORWARD_ACT]->setEnabled( hasSubWindow ); - m_arrayActions[VIDEO_LOOP_ACT]->setEnabled( hasSubWindow ); - m_arrayActions[VIDEO_LOCK_SELECTION_ACT]->setEnabled( hasSubWindow ); - m_pcFrameSlider->setEnabled( hasSubWindow ); - if( !hasSubWindow ) - { - m_pcFrameSlider->setValue( 0 ); - m_pcFrameNumInfo->clear(); - } m_arrayActions[NAVIGATION_TOOL_ACT]->setEnabled( hasSubWindow ); m_arrayActions[SELECTION_TOOL_ACT]->setEnabled( hasSubWindow ); - m_pcModulesHandle->updateMenus( hasSubWindow ); + m_appModuleVideo->updateMenus(); + m_appModuleQuality->updateMenus(); + m_appModuleExtensions->updateMenus(); } Void plaYUVerApp::updateWindowMenu() @@ -1008,7 +663,7 @@ Void plaYUVerApp::updateWindowMenu() } } - +// ----------------------- Create Functions ----------------------- Void plaYUVerApp::createActions() { @@ -1100,47 +755,10 @@ Void plaYUVerApp::createActions() m_arrayActions[ZOOM_FIT_ACT]->setStatusTip( tr( "Zoom in or out to fit on the window." ) ); connect( m_arrayActions[ZOOM_FIT_ACT], SIGNAL( triggered() ), this, SLOT( zoomToFit() ) ); - // ------------ Playing ------------ - - m_arrayActions[PLAY_ACT] = new QAction( "Play", this ); - m_arrayActions[PLAY_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaPlay ) ) ); - m_arrayActions[PLAY_ACT]->setShortcut( Qt::Key_Space ); - connect( m_arrayActions[PLAY_ACT], SIGNAL( triggered() ), this, SLOT( play() ) ); - - m_arrayActions[STOP_ACT] = new QAction( "Stop", this ); - m_arrayActions[STOP_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaStop ) ) ); - connect( m_arrayActions[STOP_ACT], SIGNAL( triggered() ), this, SLOT( stop() ) ); - - mapperSeekVideo = new QSignalMapper( this ); - connect( mapperSeekVideo, SIGNAL( mapped(int) ), this, SLOT( seekEvent(int) ) ); - - m_arrayActions[VIDEO_BACKWARD_ACT] = new QAction( "Video Backward", this ); - m_arrayActions[VIDEO_BACKWARD_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaSeekBackward ) ) ); - m_arrayActions[VIDEO_BACKWARD_ACT]->setShortcut( Qt::Key_Left ); - connect( m_arrayActions[VIDEO_BACKWARD_ACT], SIGNAL( triggered() ), mapperSeekVideo, SLOT( map() ) ); - mapperSeekVideo->setMapping( m_arrayActions[VIDEO_BACKWARD_ACT], 0 ); - - m_arrayActions[VIDEO_FORWARD_ACT] = new QAction( "Video Forward", this ); - m_arrayActions[VIDEO_FORWARD_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaSeekForward ) ) ); - m_arrayActions[VIDEO_FORWARD_ACT]->setShortcut( Qt::Key_Right ); - connect( m_arrayActions[VIDEO_FORWARD_ACT], SIGNAL( triggered() ), mapperSeekVideo, SLOT( map() ) ); - mapperSeekVideo->setMapping( m_arrayActions[VIDEO_FORWARD_ACT], 1 ); - - m_arrayActions[VIDEO_LOOP_ACT] = new QAction( "Repeat", this ); - m_arrayActions[VIDEO_LOOP_ACT]->setCheckable( true ); - m_arrayActions[VIDEO_LOOP_ACT]->setChecked( false ); - - m_arrayActions[VIDEO_LOCK_SELECTION_ACT] = new QAction( "Video Lock Window Selection", this ); - m_arrayActions[VIDEO_FORWARD_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaSeekForward ) ) ); - connect( m_arrayActions[VIDEO_LOCK_SELECTION_ACT], SIGNAL( triggered() ), this, SLOT( videoSelectionButtonEvent() ) ); - - m_pcFrameSlider = new QSlider; - m_pcFrameSlider->setOrientation( Qt::Horizontal ); - m_pcFrameSlider->setMaximumWidth( 100 ); - m_pcFrameSlider->setMaximumWidth( /* 300 */2000 ); - m_pcFrameSlider->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ) ); - m_pcFrameSlider->setEnabled( false ); - connect( m_pcFrameSlider, SIGNAL( sliderMoved(int) ), this, SLOT( seekSliderEvent(int) ) ); + m_arrayActions[ZOOM_FIT_ALL_ACT] = new QAction( tr( "Zoom to Fit All" ), this ); + //m_arrayActions[ZOOM_FIT_ALL_ACT]->setIcon( QIcon::fromTheme( "zoom-fit-best", QIcon( ":/images/fittowindow.png" ) ) ); + m_arrayActions[ZOOM_FIT_ALL_ACT]->setStatusTip( tr( "Apply zoom to fit to all windows" ) ); + connect( m_arrayActions[ZOOM_FIT_ALL_ACT], SIGNAL( triggered() ), this, SLOT( zoomToFitAll() ) ); // ------------ Tools ------------ actionGroupTools = new QActionGroup( this ); @@ -1165,14 +783,17 @@ Void plaYUVerApp::createActions() connect( m_arrayActions[SELECTION_TOOL_ACT], SIGNAL( triggered() ), m_mapperTools, SLOT( map() ) ); m_mapperTools->setMapping( m_arrayActions[SELECTION_TOOL_ACT], ViewArea::NormalSelectionTool ); + m_appModuleVideo->createActions(); m_appModuleQuality->createActions(); + m_appModuleExtensions->createActions(); // ------------ Window ------------ 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 ); m_arrayActions[CASCADE_WINDOWS_ACT]->setIcon( QIcon( ":images/windowscascade.png" ) ); @@ -1242,6 +863,7 @@ Void plaYUVerApp::createMenus() m_arrayMenu[VIEW_MENU]->addAction( m_arrayActions[ZOOM_OUT_ACT] ); m_arrayMenu[VIEW_MENU]->addAction( m_arrayActions[ZOOM_NORMAL_ACT] ); m_arrayMenu[VIEW_MENU]->addAction( m_arrayActions[ZOOM_FIT_ACT] ); + m_arrayMenu[VIEW_MENU]->addAction( m_arrayActions[ZOOM_FIT_ALL_ACT] ); m_arrayMenu[VIEW_MENU]->addSeparator(); @@ -1258,20 +880,13 @@ Void plaYUVerApp::createMenus() // m_arrayMenu[TOOLS_MENU]->addAction( m_arrayActions[NAVIGATION_TOOL_ACT] ); // m_arrayMenu[TOOLS_MENU]->addAction( m_arrayActions[SELECTION_TOOL_ACT] ); - m_arrayMenu[VIDEO_MENU] = menuBar()->addMenu( tr( "Video" ) ); - m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[PLAY_ACT] ); - //m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[PAUSE_ACT] ); - m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[STOP_ACT] ); - m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[VIDEO_BACKWARD_ACT] ); - m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[VIDEO_FORWARD_ACT] ); - m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[VIDEO_LOOP_ACT] ); - m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[VIDEO_LOCK_SELECTION_ACT] ); - + QMenu* VideoMenu = m_appModuleVideo->createMenu(); + menuBar()->addMenu( VideoMenu ); QMenu* QualityMenu = m_appModuleQuality->createMenu(); menuBar()->addMenu( QualityMenu ); - - QMenu* modules_menu = m_pcModulesHandle->createMenus( menuBar() ); - connect( modules_menu, SIGNAL( triggered(QAction *) ), this, SLOT( ModuleHandling(QAction *) ) ); + QMenu* ModuleMenu = m_appModuleExtensions->createMenu(); + menuBar()->addMenu( ModuleMenu ); + //connect( ModuleMenu, SIGNAL( triggered(QAction *) ), this, SLOT( ModuleHandling(QAction *) ) ); m_arrayMenu[WINDOW_MENU] = menuBar()->addMenu( tr( "&Window" ) ); updateWindowMenu(); @@ -1319,52 +934,22 @@ Void plaYUVerApp::createToolBars() m_arrayToolBars[FILE_TOOLBAR]->setMovable( false ); addToolBar( Qt::TopToolBarArea, m_arrayToolBars[VIEW_TOOLBAR] ); - m_arrayToolBars[VIDEO_TOOLBAR] = new QToolBar( tr( "Video" ) ); - m_arrayToolBars[VIDEO_TOOLBAR]->setAllowedAreas( Qt::TopToolBarArea | Qt::BottomToolBarArea ); - m_arrayToolBars[VIDEO_TOOLBAR]->addAction( m_arrayActions[PLAY_ACT] ); - m_arrayToolBars[VIDEO_TOOLBAR]->addAction( m_arrayActions[STOP_ACT] ); + addToolBar( Qt::TopToolBarArea, m_appModuleVideo->createToolBar() ); - m_pcLockLabel = new QLabel( "PlayingLock", this ); - m_arrayActions[VIDEO_LOCK_ACT] = m_arrayToolBars[VIDEO_TOOLBAR]->addWidget( m_pcLockLabel ); - - m_arrayToolBars[VIDEO_TOOLBAR]->addAction( m_arrayActions[VIDEO_BACKWARD_ACT] ); - m_arrayToolBars[VIDEO_TOOLBAR]->addWidget( m_pcFrameSlider ); - m_arrayToolBars[VIDEO_TOOLBAR]->addAction( m_arrayActions[VIDEO_FORWARD_ACT] ); - m_arrayToolBars[VIDEO_TOOLBAR]->addWidget( new QLabel ); - m_pcFrameNumInfo = new WidgetFrameNumber; - m_arrayToolBars[VIDEO_TOOLBAR]->addWidget( m_pcFrameNumInfo ); - - addToolBar( Qt::TopToolBarArea, m_arrayToolBars[VIDEO_TOOLBAR] ); - m_arrayActions[VIDEO_LOCK_ACT]->setVisible( false ); } Void plaYUVerApp::createDockWidgets() { // Properties Dock Window m_arraySideBars.resize( TOTAL_DOCK ); - - m_pcStreamProperties = new StreamPropertiesSideBar( this ); - m_arraySideBars[STREAM_DOCK] = new QDockWidget( tr( "Stream Information" ), this ); - m_arraySideBars[STREAM_DOCK]->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); - m_arraySideBars[STREAM_DOCK]->setWidget( m_pcStreamProperties ); - addDockWidget( Qt::RightDockWidgetArea, m_arraySideBars[STREAM_DOCK] ); - connect( m_arraySideBars[STREAM_DOCK], SIGNAL( visibilityChanged(bool) ), this, SLOT( updateStreamProperties() ) ); - - m_pcFrameProperties = new FramePropertiesSideBar( this, &m_bIsPlaying ); - m_arraySideBars[FRAME_DOCK] = new QDockWidget( tr( "Frame Information" ), this ); - m_arraySideBars[FRAME_DOCK]->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); - m_arraySideBars[FRAME_DOCK]->setWidget( m_pcFrameProperties ); - addDockWidget( Qt::RightDockWidgetArea, m_arraySideBars[FRAME_DOCK] ); - connect( m_arraySideBars[FRAME_DOCK], SIGNAL( visibilityChanged(bool) ), this, SLOT( updateStreamProperties() ) ); - - QMainWindow::tabifyDockWidget( m_arraySideBars[FRAME_DOCK], m_arraySideBars[STREAM_DOCK] ); - //QMainWindow::setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); - - addDockWidget( Qt::RightDockWidgetArea, m_appModuleQuality->createDock() ); + addDockWidget( Qt::RightDockWidgetArea, m_appModuleVideo->createDock() ); + addDockWidget( Qt::RightDockWidgetArea, m_appModuleQuality->createDock() ); } Void plaYUVerApp::createStatusBar() { + m_appModuleVideo->createStatusBarMessage(); + //statusBar()->addPermanentWidget( m_appModuleVideo->createStatusBarMessage() ); statusBar()->showMessage( tr( "Ready" ) ); } @@ -1405,40 +990,43 @@ Void plaYUVerApp::updateRecentFileActions() Void plaYUVerApp::readSettings() { - Settings settings; - QPoint pos = settings.mainWindowPos(); - QSize size = settings.mainWindowSize(); + QSettings appSettings; + + QPoint pos = appSettings.value( "MainWindow/Position", QPoint( 200, 200 ) ).toPoint(); + QSize size = appSettings.value( "MainWindow/Size", QSize( 500, 400 ) ).toSize(); move( pos ); resize( size ); - m_cLastOpenPath = settings.lastOpenPath(); - m_appTool = ( ViewArea::eTool )settings.getSelectedTool(); - setTool( m_appTool ); - m_arrayActions[VIDEO_LOOP_ACT]->setChecked( settings.getRepeat() ); - m_aRecentFileStreamInfo = settings.getRecentFileList(); + m_cLastOpenPath = appSettings.value( "MainWindow/LastOpenPath", QDir::homePath() ).toString(); + + m_appTool = ( ViewArea::eTool )appSettings.value( "MainWindow/SelectedTool", ViewArea::NavigationTool ).toInt(); + setTool( m_appTool ); + + QVariant value = appSettings.value( "MainWindow/RecentFileList" ); + m_aRecentFileStreamInfo = value.value(); updateRecentFileActions(); - Bool visibleStreamProp, visibleFrameProp, visibleQualityMeasure; - settings.getDockVisibility( visibleStreamProp, visibleFrameProp, visibleQualityMeasure ); - if( !visibleStreamProp ) - m_arraySideBars[STREAM_DOCK]->close(); - if( !visibleFrameProp ) - m_arraySideBars[FRAME_DOCK]->close(); - if( !visibleQualityMeasure ) - m_arraySideBars[QUALITY_DOCK]->close(); - + m_appModuleVideo->readSettings(); + m_appModuleQuality->readSettings(); + m_appModuleExtensions->readSettings(); } Void plaYUVerApp::writeSettings() { - Settings settings; - settings.setMainWindowPos( pos() ); - settings.setMainWindowSize( size() ); - settings.setLastOpenPath( m_cLastOpenPath ); - settings.setSelectedTool( ( Int )m_appTool ); - settings.setRecentFileList( m_aRecentFileStreamInfo ); - settings.setDockVisibility( m_pcStreamProperties->isVisible(), m_pcFrameProperties->isVisible(), true ); - settings.setPlayingSettings( m_arrayActions[VIDEO_LOOP_ACT]->isChecked() ); + QSettings appSettings; + + appSettings.setValue( "MainWindow/Position", pos() ); + appSettings.setValue( "MainWindow/Size", size() ); + appSettings.setValue( "MainWindow/LastOpenPath", m_cLastOpenPath ); + appSettings.setValue( "MainWindow/SelectedTool", ( Int )m_appTool ); + + QVariant var; + var.setValue( m_aRecentFileStreamInfo ); + appSettings.setValue( "MainWindow/RecentFileList", var ); + + m_appModuleVideo->writeSettings(); + m_appModuleQuality->writeSettings(); + m_appModuleExtensions->writeSettings(); } } // NAMESPACE diff --git a/app/plaYUVerApp.h b/app/plaYUVerApp.h index ce802d6..9354cac 100644 --- a/app/plaYUVerApp.h +++ b/app/plaYUVerApp.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -38,9 +38,9 @@ #include "lib/PlaYUVerDefs.h" #include "SubWindowHandle.h" #include "VideoSubWindow.h" -#include "QualityMeasurement.h" +#include "VideoHandle.h" +#include "QualityHandle.h" #include "ModulesHandle.h" -#include "PropertiesSidebar.h" #include "AboutDialog.h" #include "WidgetFrameNumber.h" @@ -64,6 +64,8 @@ protected: private Q_SLOTS: + void about(); + /** * File functions slots */ @@ -77,19 +79,6 @@ private Q_SLOTS: void closeActiveWindow(); void closeAll(); - /** - * Playing functions slots - */ - void play(); - void stop(); - void playEvent(); - void seekSliderEvent( int new_frame_num ); - void seekEvent( int direction ); - - void videoSelectionButtonEvent(); - - void ModuleHandling( QAction * ); - /** * Scale the image by a given factor * @param factor factor of scale. Ex: 120 scale the image up by 20% and @@ -99,26 +88,22 @@ private Q_SLOTS: void setZoomFromSBox( double ratio ); void normalSize(); void zoomToFit(); + void zoomToFitAll(); - void chageSubWindowSelection(); - void updateWindowMenu(); - void updateZoomFactorSBox(); - void updateStreamProperties(); - - void about(); + void setTool( int idxTool ); void dragEnterEvent( QDragEnterEvent *event ); void dropEvent( QDropEvent *event ); + void tileSubWindows(); void setActiveSubWindow( QWidget *window ); + + void update(); + void updateWindowMenu(); + void updateZoomFactorSBox(); void updateStatusBar( const QString& ); - void updatePropertiesSelectedArea( QRect area ); - - void setAllSubWindowTool(); - void setTool( int idxTool ); - private: class PlaYUVerMdiArea: public QMdiArea @@ -153,28 +138,20 @@ private: /** * Save the current subwindow for every category */ - SubWindowHandle* m_pcCurrentSubWindow; //!< General always set + SubWindowHandle* m_pcCurrentSubWindow; //!< General always set VideoSubWindow* m_pcCurrentVideoSubWindow; - ModulesHandle *m_pcModulesHandle; - QString m_cLastOpenPath; - QTimer *m_pcPlayingTimer; - Bool m_bIsPlaying; - - Void zoomToFitAll(); - - /** - * Playing functions - */ - UInt64 getMaxFrameNumber(); - Void setTimerStatus(); + SubWindowHandle *activeSubWindow(); + template + T findSubWindow( const QMdiArea* mdiArea, const QString& name ); + template + T findSubWindow( const QMdiArea* mdiArea, const T subWindow ); + static VideoSubWindow* findVideoSubWindow( const QMdiArea* mdiArea, const QString& fileName ); Void updateMenus(); - - Void createActions(); Void createMenus(); Void createToolBars(); @@ -187,33 +164,32 @@ private: Void readSettings(); Void writeSettings(); - SubWindowHandle *activeSubWindow(); - template - T findSubWindow( const QMdiArea* mdiArea, const QString& name ); - template - T findSubWindow( const QMdiArea* mdiArea, const T subWindow ); - - static VideoSubWindow* findVideoSubWindow( const QMdiArea* mdiArea, const QString& fileName ); - - QVector m_acPlayingSubWindows; - - QLabel* m_pcLockLabel; - QSlider* m_pcFrameSlider; - WidgetFrameNumber* m_pcFrameNumInfo; QDoubleSpinBox *m_pcZoomFactorSBox; QSignalMapper *mapperZoom; - QSignalMapper *mapperSeekVideo; QSignalMapper *mapperWindow; + // Tools Actions; + QActionGroup *actionGroupTools; + enum APP_TOOLS_ACTION_LIST + { + NAVIGATION_TOOL, + SELECTION_TOOL, + TOTAL_TOOLS, + }; + QSignalMapper *m_mapperTools; + ViewArea::eTool m_appTool; + /** * App modules * Video * Quality * Modules */ - QualityMeasurement* m_appModuleQuality; + VideoHandle* m_appModuleVideo; + QualityHandle* m_appModuleQuality; + ModulesHandle *m_appModuleExtensions; /** * Array of menus for the main app @@ -241,16 +217,10 @@ private: */ enum SIDEBAR_LIST { - STREAM_DOCK = 0, - FRAME_DOCK, - QUALITY_DOCK, TOTAL_DOCK, }; QVector m_arraySideBars; - StreamPropertiesSideBar* m_pcStreamProperties; - FramePropertiesSideBar* m_pcFrameProperties; - /** * Array of tool bars for the main app */ @@ -279,16 +249,9 @@ private: EXIT_ACT, ZOOM_IN_ACT, ZOOM_OUT_ACT, - ZOOM_FIT_ACT, ZOOM_NORMAL_ACT, - PLAY_ACT, - /*PAUSE_ACT,*/ - STOP_ACT, - VIDEO_FORWARD_ACT, - VIDEO_BACKWARD_ACT, - VIDEO_LOOP_ACT, - VIDEO_LOCK_ACT, - VIDEO_LOCK_SELECTION_ACT, + ZOOM_FIT_ACT, + ZOOM_FIT_ALL_ACT, NAVIGATION_TOOL_ACT, SELECTION_TOOL_ACT, TILE_WINDOWS_ACT, @@ -303,26 +266,11 @@ private: }; QVector m_arrayActions; -#define MAX_RECENT_FILES 10 +#define MAX_RECENT_FILES 20 QVector m_arrayRecentFilesActions; - //QAction *actionPopupMenu; - - // Tools Actions; - QActionGroup *actionGroupTools; - enum APP_TOOLS_ACTION_LIST - { - NAVIGATION_TOOL, - SELECTION_TOOL, - TOTAL_TOOLS, - }; - QVector m_arrayTools; - QSignalMapper *m_mapperTools; - ViewArea::eTool m_appTool; - PlaYUVerStreamInfoVector m_aRecentFileStreamInfo; AboutDialog* m_pcAboutDialog; - }; } // NAMESPACE diff --git a/config.h.in b/config.h.in index fd3f5b0..62b33be 100644 --- a/config.h.in +++ b/config.h.in @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index e9a2503..9299568 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -2,7 +2,7 @@ ### CMakeLists for playuver lib component ### -INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ) +INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR} ) set(plaYUver_Lib_SRCS # Frame diff --git a/lib/LibAvContextHandle.cpp b/lib/LibAvContextHandle.cpp index a813359..fe2156f 100644 --- a/lib/LibAvContextHandle.cpp +++ b/lib/LibAvContextHandle.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/lib/LibAvContextHandle.h b/lib/LibAvContextHandle.h index 3fd2eeb..fc33fcd 100644 --- a/lib/LibAvContextHandle.h +++ b/lib/LibAvContextHandle.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/lib/LibMemory.h b/lib/LibMemory.h index c2db691..c245f81 100644 --- a/lib/LibMemory.h +++ b/lib/LibMemory.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/lib/PlaYUVerDefs.h b/lib/PlaYUVerDefs.h index 4ba0fe7..4d89955 100644 --- a/lib/PlaYUVerDefs.h +++ b/lib/PlaYUVerDefs.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/lib/PlaYUVerFrame.cpp b/lib/PlaYUVerFrame.cpp index 817f8bc..f579da0 100644 --- a/lib/PlaYUVerFrame.cpp +++ b/lib/PlaYUVerFrame.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -161,6 +161,7 @@ Void PlaYUVerFrame::frameFromBuffer( Pel *Buff, UInt64 uiBuffSize ) return; m_pcPelFormat->frameFromBuffer( Buff, m_pppcInputPel, m_uiWidth, m_uiHeight ); m_bHasRGBPel = false; + m_bHasHistogram = false; fillRGBBuffer(); } @@ -182,6 +183,7 @@ Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame ) if( m_iPixelFormat != input_frame->getPelFormat() && m_uiWidth == input_frame->getWidth() && m_uiHeight == input_frame->getHeight() ) return; m_bHasRGBPel = false; + m_bHasHistogram = false; memcpy( *m_pppcInputPel[LUMA], input_frame->getPelBufferYUV()[LUMA][0], getBytesPerFrame() * sizeof(Pel) ); } @@ -210,7 +212,6 @@ Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame, UInt xPos, UInt yPos ) { if( m_iPixelFormat != input_frame->getPelFormat() ) return; - m_bHasRGBPel = false; Pel ***pInput = input_frame->getPelBufferYUV(); for( UInt ch = 0; ch < m_pcPelFormat->numberChannels; ch++ ) { @@ -221,6 +222,8 @@ Void PlaYUVerFrame::copyFrom( PlaYUVerFrame* input_frame, UInt xPos, UInt yPos ) memcpy( m_pppcInputPel[ch][i], &( pInput[ch][yPos / ratioH + i][xPos / ratioW] ), m_uiWidth / ratioW * sizeof(Pel) ); } } + m_bHasRGBPel = false; + m_bHasHistogram = false; } PlaYUVerFrame::Pixel PlaYUVerFrame::getPixelValue( Int xPos, Int yPos, Int eColorSpace ) @@ -376,6 +379,7 @@ Void PlaYUVerFrame::fromCvMat( Void* voidFrame ) } m_bHasRGBPel = false; + m_bHasHistogram = false; if( m_iPixelFormat != GRAY ) { diff --git a/lib/PlaYUVerFrame.h b/lib/PlaYUVerFrame.h index f8c50fb..6ae97d9 100644 --- a/lib/PlaYUVerFrame.h +++ b/lib/PlaYUVerFrame.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/lib/PlaYUVerFramePixelFormats.cpp b/lib/PlaYUVerFramePixelFormats.cpp index 6af1a00..ddce223 100644 --- a/lib/PlaYUVerFramePixelFormats.cpp +++ b/lib/PlaYUVerFramePixelFormats.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/lib/PlaYUVerFramePixelFormats.h b/lib/PlaYUVerFramePixelFormats.h index 27951fa..82a2bb2 100644 --- a/lib/PlaYUVerFramePixelFormats.h +++ b/lib/PlaYUVerFramePixelFormats.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/lib/PlaYUVerFrameStats.cpp b/lib/PlaYUVerFrameStats.cpp index fb37bbe..1fd30a8 100644 --- a/lib/PlaYUVerFrameStats.cpp +++ b/lib/PlaYUVerFrameStats.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -43,7 +43,7 @@ PlaYUVerFrameStats::PlaYUVerFrameStats() : PlaYUVerFrameStats::~PlaYUVerFrameStats() { if( m_pdHistogram ) - delete[] m_pdHistogram; + freeMem1D( m_pdHistogram ); } @@ -72,7 +72,10 @@ Void PlaYUVerFrameStats::xSetupStatistics( const PlaYUVerFrame *pcFrame, UInt op Void PlaYUVerFrameStats::calcHistogram() { - m_bHasHistogram = false; + m_bRunningFlag = true; + //m_bHasHistogram = false; + if( m_bHasHistogram ) + return; getMem1D( &( m_pdHistogram ), m_uiHistoSegments * histoChannels ); if( !m_pdHistogram ) @@ -97,7 +100,7 @@ Void PlaYUVerFrameStats::calcHistogram() m_pdHistogram[*( data[LUMA] ) + LUMA * m_uiHistoSegments]++; data[LUMA] += 1; } - for( i = 0; ( i < imageChromaSize ) && runningFlag; i++ ) + for( i = 0; ( i < imageChromaSize ) && m_bRunningFlag; i++ ) { for( j = 1; j < m_uiChannels; j++ ) { @@ -115,7 +118,7 @@ Void PlaYUVerFrameStats::calcHistogram() data[COLOR_G] = m_pppImageData[COLOR_G][0]; data[COLOR_B] = m_pppImageData[COLOR_B][0]; - for( i = 0; ( i < m_uiImageHeight * m_uiImageWidth ) && runningFlag; i++ ) + for( i = 0; ( i < m_uiImageHeight * m_uiImageWidth ) && m_bRunningFlag; i++ ) { for( j = 0; j < m_uiChannels; j++ ) { diff --git a/lib/PlaYUVerFrameStats.h b/lib/PlaYUVerFrameStats.h index 780def7..166e15a 100644 --- a/lib/PlaYUVerFrameStats.h +++ b/lib/PlaYUVerFrameStats.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -80,6 +80,17 @@ public: */ Int getHistogramSegment(); + /** + * Control calculation + */ + Void setRunningFlag( Bool bFlag ) + { + m_bRunningFlag = bFlag; + } + Bool getHasHistogram() + { + return m_bHasHistogram; + } private: /** The histogram data.*/ @@ -103,7 +114,7 @@ private: UInt m_uiHistoSegments; /** Used to stop thread during calculations.*/ - Bool runningFlag; + Bool m_bRunningFlag; Int getRealHistoChannel( Int channel ); diff --git a/lib/PlaYUVerStream.cpp b/lib/PlaYUVerStream.cpp index ee743ff..72663ba 100644 --- a/lib/PlaYUVerStream.cpp +++ b/lib/PlaYUVerStream.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -254,6 +254,7 @@ Void PlaYUVerStream::close() #ifdef USE_FFMPEG if( m_uiStreamHandler == FFMPEG ) m_cLibAvContext->closeAvFormat(); + delete m_cLibAvContext; #endif if( m_ppcFrameBuffer ) diff --git a/lib/PlaYUVerStream.h b/lib/PlaYUVerStream.h index a0e35e4..787c652 100644 --- a/lib/PlaYUVerStream.h +++ b/lib/PlaYUVerStream.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 diff --git a/modules/AbsoluteFrameDifference.cpp b/modules/AbsoluteFrameDifference.cpp index 44b4eeb..a2e0ac9 100644 --- a/modules/AbsoluteFrameDifference.cpp +++ b/modules/AbsoluteFrameDifference.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -27,21 +27,18 @@ namespace plaYUVer { -static PlaYUVerModuleDefinition AbsoluteFrameDifferenceDef = -{ - FRAME_PROCESSING_MODULE, - "Measurements", - "AbsoluteFrameDifference", - "Measure the absolute difference between two images (Y plane), e. g., abs( Y1 - Y2 )", - MODULE_REQUIRES_TWO_FRAMES, - MODULE_REQUIRES_NEW_WINDOW, - APPLY_WHILE_PLAYING, -}; - AbsoluteFrameDifference::AbsoluteFrameDifference() { + /* Module Definition */ + 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; - setModuleDefinition( AbsoluteFrameDifferenceDef ); } Void AbsoluteFrameDifference::create( PlaYUVerFrame* Input ) diff --git a/modules/AbsoluteFrameDifference.h b/modules/AbsoluteFrameDifference.h index 4360790..6f4c543 100644 --- a/modules/AbsoluteFrameDifference.h +++ b/modules/AbsoluteFrameDifference.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -34,6 +34,8 @@ namespace plaYUVer class AbsoluteFrameDifference: public PlaYUVerModuleIf { + REGISTER_CLASS_FACTORY( AbsoluteFrameDifference ) + private: PlaYUVerFrame* m_pcFrameDifference; diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index a024c01..fef8861 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -2,7 +2,11 @@ ### CMakeLists for playuver modules component ### -INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} ) +INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) + +set(plaYUver_Mod_SRCS + PlaYUVerModuleFactory.cpp +) MACRO(ADD_MODULE name file ) set(__modulename "Module${name}") @@ -18,15 +22,6 @@ MACRO(ADD_MODULE name file ) ENDMACRO() - -# -# Init header -# -file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/ModulesListMacro.h "// This files defines the macro to \n" - "// define a list of modules\n" - "#ifndef __MODULESLISTMACRO_H__\n#define __MODULESLISTMACRO_H__\n" - "#define REGISTER_ALL_MODULES ") - file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/ModulesListHeader.h "// This files add the header files of each module\n" "#ifndef __MODULESLISTHEADER_H__\n#define __MODULESLISTHEADER_H__\n" ) @@ -35,13 +30,20 @@ file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/ModulesListHeader.h "// This files add # # Modules List # -INCLUDE( ModulesList.cmake ) +ADD_MODULE( FilterComponentLuma "FilterComponent" ) +ADD_MODULE( FilterComponentChromaU "FilterComponent" ) +ADD_MODULE( FilterComponentChromaV "FilterComponent" ) +ADD_MODULE( FrameDifference "FrameDifference" ) +ADD_MODULE( AbsoluteFrameDifference "AbsoluteFrameDifference" ) +ADD_MODULE( LumaAverage "LumaAverage" ) +IF( USE_OPENCV ) + ADD_MODULE( DisparityStereoVar "DisparityStereoVar" ) +ENDIF() # # Finish header # -file( APPEND ${CMAKE_CURRENT_BINARY_DIR}/ModulesListMacro.h "\n#endif // __MODULESLISTMACRO_H__\n" ) file( APPEND ${CMAKE_CURRENT_BINARY_DIR}/ModulesListHeader.h "#endif // __MODULESLISTHEADER_H__\n" ) ADD_LIBRARY( PlaYUVerModules ${plaYUver_Mod_SRCS} ) diff --git a/modules/DisparityStereoVar.cpp b/modules/DisparityStereoVar.cpp index 2b75788..1dee936 100644 --- a/modules/DisparityStereoVar.cpp +++ b/modules/DisparityStereoVar.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -29,19 +29,9 @@ namespace plaYUVer { -static PlaYUVerModuleDefinition DisparityStereoVarDef = -{ - FRAME_PROCESSING_MODULE, - "Disparity", - "StereoVar", - "Measure the disparity between two images using the Stereo Var method (OpenCV)", - MODULE_REQUIRES_TWO_FRAMES, - MODULE_REQUIRES_NEW_WINDOW, - !APPLY_WHILE_PLAYING, -}; - DisparityStereoVar::DisparityStereoVar() { + /* Module Definition */ m_iModuleType = FRAME_PROCESSING_MODULE; m_pchModuleCategory = "Disparity"; m_pchModuleName = "StereoVar"; @@ -50,7 +40,6 @@ DisparityStereoVar::DisparityStereoVar() m_uiModuleRequirements = MODULE_REQUIRES_NEW_WINDOW; m_bApplyWhilePlaying = !APPLY_WHILE_PLAYING; - setModuleDefinition( DisparityStereoVarDef ); m_pcDisparityFrame = NULL; m_cStereoVar.levels = 3; // ignored with USE_AUTO_PARAMS m_cStereoVar.pyrScale = 0.5; // ignored with USE_AUTO_PARAMS diff --git a/modules/DisparityStereoVar.h b/modules/DisparityStereoVar.h index 6e6457d..3c3b6be 100644 --- a/modules/DisparityStereoVar.h +++ b/modules/DisparityStereoVar.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -36,6 +36,8 @@ namespace plaYUVer class DisparityStereoVar: public PlaYUVerModuleIf { + REGISTER_CLASS_FACTORY( DisparityStereoVar ) + private: PlaYUVerFrame* m_pcDisparityFrame; cv::StereoVar m_cStereoVar; diff --git a/modules/FilterComponent.cpp b/modules/FilterComponent.cpp index cb4ab8e..cf53e0b 100644 --- a/modules/FilterComponent.cpp +++ b/modules/FilterComponent.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -28,18 +28,18 @@ namespace plaYUVer { -FilterComponent::FilterComponent() +FilterComponentModule::FilterComponentModule() { m_pcFilteredFrame = NULL; } -Void FilterComponent::createFilter( UInt uiWidth, UInt uiHeight ) +Void FilterComponentModule::createFilter( UInt uiWidth, UInt uiHeight ) { m_pcFilteredFrame = NULL; m_pcFilteredFrame = new PlaYUVerFrame( uiWidth, uiHeight, PlaYUVerFrame::GRAY ); } -PlaYUVerFrame* FilterComponent::filterComponent( PlaYUVerFrame* InputFrame, Int Component ) +PlaYUVerFrame* FilterComponentModule::filterComponent( PlaYUVerFrame* InputFrame, Int Component ) { Pel*** pppOutputPelYUV = m_pcFilteredFrame->getPelBufferYUV(); Pel*** pppInputPelYUV = InputFrame->getPelBufferYUV(); @@ -47,29 +47,25 @@ PlaYUVerFrame* FilterComponent::filterComponent( PlaYUVerFrame* InputFrame, Int return m_pcFilteredFrame; } -Void FilterComponent::destroy() +Void FilterComponentModule::destroy() { if( m_pcFilteredFrame ) delete m_pcFilteredFrame; m_pcFilteredFrame = NULL; } - -PlaYUVerModuleDefinition FilterComponentLumaDef = { - FRAME_PROCESSING_MODULE, // Apply module to the frames or to the whole sequence. - // Currently only support for frame - "Filter Component", // Category (sub-menu) - "Luma", // Name - "Filter Y matrix of YUV frame", // Description - MODULE_REQUIRES_ONE_FRAME, // Number of Frames required (ONE_FRAME, TWO_FRAMES, THREE_FRAMES) - MODULE_REQUIRES_NOTHING, // Module requirements (check PlaYUVerModulesIf.h). - // Several requirements should be "or" between each others. - APPLY_WHILE_PLAYING, // Apply module while playing -}; - FilterComponentLuma::FilterComponentLuma() { - setModuleDefinition( FilterComponentLumaDef ); + /* Module Definition */ + m_iModuleType = FRAME_PROCESSING_MODULE; // Apply module to the frames or to the whole sequence. + // Currently only support for frame + m_pchModuleCategory = "Filter Component"; // 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 ) @@ -82,21 +78,16 @@ PlaYUVerFrame* FilterComponentLuma::process( PlaYUVerFrame* InputFrame ) return filterComponent( InputFrame, LUMA ); } -PlaYUVerModuleDefinition FilterComponentCbDef = { - FRAME_PROCESSING_MODULE, // Apply module to the frames or to the whole sequence. - // Currently only support for frame - "Filter Component", // Category (sub-menu) - "Chroma U", // Name - "Filter Y matrix of YUV frame", // Description - MODULE_REQUIRES_ONE_FRAME, // Number of Frames required (ONE_FRAME, TWO_FRAMES, THREE_FRAMES) - MODULE_REQUIRES_NOTHING, // Module requirements (check PlaYUVerModulesIf.h). - // Several requirements should be "or" between each others. - APPLY_WHILE_PLAYING, // Apply module while playing -}; - FilterComponentChromaU::FilterComponentChromaU() { - setModuleDefinition( FilterComponentCbDef ); + /* Module Definition */ + m_iModuleType = FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Filter Component"; + m_pchModuleName = "Chroma U"; + 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 ) @@ -109,21 +100,16 @@ PlaYUVerFrame* FilterComponentChromaU::process( PlaYUVerFrame* InputFrame ) return filterComponent( InputFrame, CHROMA_U ); } -PlaYUVerModuleDefinition FilterComponentCrDef = { - FRAME_PROCESSING_MODULE, // Apply module to the frames or to the whole sequence. - // Currently only support for frame - "Filter Component", // Category (sub-menu) - "Chroma R", // Name - "Filter Y matrix of YUV frame", // Description - MODULE_REQUIRES_ONE_FRAME, // Number of Frames required (ONE_FRAME, TWO_FRAMES, THREE_FRAMES) - MODULE_REQUIRES_NOTHING, // Module requirements (check PlaYUVerModulesIf.h). - // Several requirements should be "or" between each others. - APPLY_WHILE_PLAYING, // Apply module while playing -}; - FilterComponentChromaV::FilterComponentChromaV() { - setModuleDefinition( FilterComponentCrDef ); + /* Module Definition */ + m_iModuleType = FRAME_PROCESSING_MODULE; + m_pchModuleCategory = "Filter Component"; + m_pchModuleName = "Chroma V"; + 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 ) diff --git a/modules/FilterComponent.h b/modules/FilterComponent.h index 427ec74..70e0352 100644 --- a/modules/FilterComponent.h +++ b/modules/FilterComponent.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -30,22 +30,26 @@ namespace plaYUVer { -class FilterComponent +class FilterComponentModule: public PlaYUVerModuleIf { private: PlaYUVerFrame* m_pcFilteredFrame; public: - FilterComponent(); - virtual ~FilterComponent() + FilterComponentModule(); + virtual ~FilterComponentModule() { } + Void create( PlaYUVerFrame* ) = 0; + PlaYUVerFrame* process( PlaYUVerFrame* ) = 0; + Void destroy(); + Void createFilter( UInt uiWidth, UInt uiHeight ); PlaYUVerFrame* filterComponent( PlaYUVerFrame* InputFrame, Int Component ); - Void destroy(); }; -class FilterComponentLuma: public FilterComponent, public PlaYUVerModuleIf +class FilterComponentLuma: public FilterComponentModule { + REGISTER_CLASS_FACTORY( FilterComponentLuma ) public: FilterComponentLuma(); virtual ~FilterComponentLuma() @@ -55,8 +59,9 @@ public: PlaYUVerFrame* process( PlaYUVerFrame* InputFrame ); }; -class FilterComponentChromaU: public FilterComponent, public PlaYUVerModuleIf +class FilterComponentChromaU: public FilterComponentModule { + REGISTER_CLASS_FACTORY( FilterComponentChromaU ) public: FilterComponentChromaU(); virtual ~FilterComponentChromaU() @@ -66,8 +71,9 @@ public: PlaYUVerFrame* process( PlaYUVerFrame* InputFrame ); }; -class FilterComponentChromaV: public FilterComponent, public PlaYUVerModuleIf +class FilterComponentChromaV: public FilterComponentModule { + REGISTER_CLASS_FACTORY( FilterComponentChromaV ) public: FilterComponentChromaV(); virtual ~FilterComponentChromaV() diff --git a/modules/FrameDifference.cpp b/modules/FrameDifference.cpp index a08a07c..f3b8dd1 100644 --- a/modules/FrameDifference.cpp +++ b/modules/FrameDifference.cpp @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -28,21 +28,18 @@ namespace plaYUVer { -static PlaYUVerModuleDefinition FrameDifferenceDef = -{ - FRAME_PROCESSING_MODULE, - "Measurements", - "FrameDifference", - "Measure the difference between two images (Y plane), Y1 - Y2, with max absolute diff of 128", - MODULE_REQUIRES_TWO_FRAMES, - MODULE_REQUIRES_NEW_WINDOW, - APPLY_WHILE_PLAYING, -}; - FrameDifference::FrameDifference() { + /* Module Definition */ + 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; - setModuleDefinition( FrameDifferenceDef ); } Void FrameDifference::create( PlaYUVerFrame* Input ) diff --git a/modules/FrameDifference.h b/modules/FrameDifference.h index 88441fa..93bf9c8 100644 --- a/modules/FrameDifference.h +++ b/modules/FrameDifference.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -34,6 +34,8 @@ namespace plaYUVer class FrameDifference: public PlaYUVerModuleIf { + REGISTER_CLASS_FACTORY( FrameDifference ) + private: PlaYUVerFrame* m_pcFrameDifference; diff --git a/modules/LumaAverage.cpp b/modules/LumaAverage.cpp new file mode 100644 index 0000000..7e621f4 --- /dev/null +++ b/modules/LumaAverage.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 LumaAverage.cpp + * \brief Luma frame average + */ + +#include "LumaAverage.h" + +namespace plaYUVer +{ + +LumaAverage::LumaAverage() +{ + /* Module Definition */ + m_iModuleType = FRAME_MEASUREMENT_MODULE; + m_pchModuleCategory = "Measurements"; + m_pchModuleName = "Luma Average"; + m_pchModuleTooltip = "Measure the average of luma component"; + m_uiNumberOfFrames = MODULE_REQUIRES_ONE_FRAME; + m_uiModuleRequirements = MODULE_REQUIRES_SIDEBAR; + m_bApplyWhilePlaying = APPLY_WHILE_PLAYING; +} + +Void LumaAverage::create( PlaYUVerFrame* frame ) +{ +} + +Double LumaAverage::measure( PlaYUVerFrame* frame ) +{ + Double average = 0; + Pel* pPel = frame->getPelBufferYUV()[0][0]; + for( UInt y = 0; y < frame->getHeight(); y++ ) + for( UInt x = 0; x < frame->getWidth(); x++ ) + { + average += *pPel; + } + return average / Double( frame->getHeight() * frame->getWidth() ); +} + +Void LumaAverage::destroy() +{ + +} + +} // NAMESPACE + diff --git a/modules/MeasurePSNR.h b/modules/LumaAverage.h similarity index 65% rename from modules/MeasurePSNR.h rename to modules/LumaAverage.h index 9764d3e..10662cf 100644 --- a/modules/MeasurePSNR.h +++ b/modules/LumaAverage.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -18,35 +18,36 @@ */ /** - * \file MeasurePSNR.h - * \brief Frame Difference module + * \file LumaAverage.h + * \brief Luma frame average */ -#ifndef __MEASUREPSNR_H__ -#define __MEASUREPSNR_H__ + +#ifndef __LUMAAVERAGE_H__ +#define __LUMAAVERAGE_H__ #include "PlaYUVerModuleIf.h" namespace plaYUVer { -class MeasurePSNR: public PlaYUVerModuleIf +class LumaAverage: public PlaYUVerModuleIf { + REGISTER_CLASS_FACTORY( LumaAverage ) + private: public: - MeasurePSNR(); - virtual ~MeasurePSNR() + LumaAverage(); + virtual ~LumaAverage() { } Void create( PlaYUVerFrame* ); - Double measure( PlaYUVerFrame*, PlaYUVerFrame* ); + Double measure( PlaYUVerFrame* ); Void destroy(); - static Double getMSE( PlaYUVerFrame* Org, PlaYUVerFrame* Rec, Int component ); - }; } // NAMESPACE -#endif // __MEASUREPSNR_H__ +#endif // __LUMAAVERAGE_H__ diff --git a/modules/MeasurePSNR.cpp b/modules/MeasurePSNR.cpp deleted file mode 100644 index 065a51d..0000000 --- a/modules/MeasurePSNR.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* This file is a part of plaYUVer project - * Copyright (C) 2014 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 MeasurePSNR.cpp - * \brief Frame Difference module - */ - -#include "MeasurePSNR.h" - -namespace plaYUVer -{ - -static PlaYUVerModuleDefinition MeasurePSNRDef = -{ - FRAME_MEASUREMENT_MODULE, - "Quality", - "PSNR Y", - "Measure the PSNR between two images", - MODULE_REQUIRES_TWO_FRAMES, - MODULE_REQUIRES_SIDEBAR, - APPLY_WHILE_PLAYING, }; - -MeasurePSNR::MeasurePSNR() -{ - setModuleDefinition( MeasurePSNRDef ); -} - -Void MeasurePSNR::create( PlaYUVerFrame* Org ) -{ -} - -Double MeasurePSNR::getMSE( PlaYUVerFrame* Org, PlaYUVerFrame* Rec, Int component ) -{ - Pel* pInput1PelYUV = Org->getPelBufferYUV()[component][0]; - Pel* pInput2PelYUV = Rec->getPelBufferYUV()[component][0]; - - Int aux_pel_1, aux_pel_2; - Int diff = 0; - Double ssd = 0; - - for( UInt y = 0; y < Org->getHeight(); y++ ) - for( UInt x = 0; x < Org->getWidth(); x++ ) - { - aux_pel_1 = *pInput1PelYUV++; - aux_pel_2 = *pInput2PelYUV++; - diff = aux_pel_1 - aux_pel_2; - ssd += ( Double )( diff * diff ); - } - if( ssd == 0.0 ) - { - return 0.0; - } - return ssd / ( Org->getWidth() * Org->getHeight() ); -} - -Double MeasurePSNR::measure( PlaYUVerFrame* Org, PlaYUVerFrame* Rec ) -{ - Double psnrY = 100; - Double mseY = MeasurePSNR::getMSE( Org, Rec, LUMA ); - - if( mseY != 0 ) - psnrY = 10 * log10( 65025 / mseY ); - - return psnrY; -} - -Void MeasurePSNR::destroy() -{ - -} - -} // NAMESPACE - diff --git a/modules/ModulesList.cmake b/modules/ModulesList.cmake deleted file mode 100644 index d70369f..0000000 --- a/modules/ModulesList.cmake +++ /dev/null @@ -1,13 +0,0 @@ -### -### Modules List -### - -ADD_MODULE( FilterComponentLuma "FilterComponent" ) -ADD_MODULE( FilterComponentChromaU "FilterComponent" ) -ADD_MODULE( FilterComponentChromaV "FilterComponent" ) -ADD_MODULE( FrameDifference "FrameDifference" ) -ADD_MODULE( AbsoluteFrameDifference "AbsoluteFrameDifference" ) -#ADD_MODULE( MeasurePSNR "MeasurePSNR" ) -IF( USE_OPENCV ) - ADD_MODULE( DisparityStereoVar "DisparityStereoVar" ) -ENDIF() diff --git a/modules/PlaYUVerModuleFactory.cpp b/modules/PlaYUVerModuleFactory.cpp new file mode 100644 index 0000000..48ecf55 --- /dev/null +++ b/modules/PlaYUVerModuleFactory.cpp @@ -0,0 +1,71 @@ +/* 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 PlaYUVerModuleFactory.cpp + * \brief PlaYUVer modules factory + */ + +#include +#include +#include "PlaYUVerModuleFactory.h" +#include "ModulesListHeader.h" + +namespace plaYUVer +{ + +PlaYUVerModuleFactory::PlaYUVerModuleFactory() +{ + Register( "FilterComponentLuma", &FilterComponentLuma::Create ); + Register( "FilterComponentChromaU", &FilterComponentChromaU::Create ); + Register( "FilterComponentChromaV", &FilterComponentChromaV::Create ); + Register( "FrameDifference", &FrameDifference::Create ); + Register( "AbsoluteFrameDifference", &AbsoluteFrameDifference::Create ); + Register( "LumaAverage", &LumaAverage::Create ); +#ifdef USE_OPENCV + Register( "DisparityStereoVar", &DisparityStereoVar::Create ); +#endif + +} + +PlaYUVerModuleFactory::~PlaYUVerModuleFactory() +{ + m_FactoryMap.clear(); +} + +Void PlaYUVerModuleFactory::Register( const char* moduleName, CreateModuleFn pfnCreate ) +{ + m_FactoryMap[moduleName] = pfnCreate; +} + +PlaYUVerModuleIf *PlaYUVerModuleFactory::CreateModule( const char* moduleName ) +{ + PlaYUVerModuleFactoryMap& PlaYUVerModuleFactoryMap = PlaYUVerModuleFactory::Get()->getMap(); + PlaYUVerModuleFactoryMap::iterator it = PlaYUVerModuleFactoryMap.begin(); + for( ; it != PlaYUVerModuleFactoryMap.end(); ++it) + { + if( !strcmp( it->first, moduleName ) ) + { + return it->second(); + } + } + return NULL; +} + +} // NAMESPACE diff --git a/modules/PlaYUVerModuleFactory.h b/modules/PlaYUVerModuleFactory.h new file mode 100644 index 0000000..8d1f64f --- /dev/null +++ b/modules/PlaYUVerModuleFactory.h @@ -0,0 +1,69 @@ +/* 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 PlaYUVerModuleFactory.h + * \brief PlaYUVer modules factory + */ + +#ifndef __PLAYUVERMODULESFACTORY_H__ +#define __PLAYUVERMODULESFACTORY_H__ + +#include +#include "PlaYUVerModuleIf.h" + +namespace plaYUVer +{ + +#define REGISTER_MODULE(X) Register( "X", &(X::Create) ); + +typedef PlaYUVerModuleIf* (*CreateModuleFn)( void ); +typedef std::map PlaYUVerModuleFactoryMap; + +// Factory for creating instances of IAnimal +class PlaYUVerModuleFactory +{ +private: + PlaYUVerModuleFactory(); + PlaYUVerModuleFactory &operator=( const PlaYUVerModuleFactory & ) { return *this; } + + PlaYUVerModuleFactoryMap m_FactoryMap; +public: + ~PlaYUVerModuleFactory(); + + static PlaYUVerModuleFactory *Get() + { + static PlaYUVerModuleFactory instance; + return &instance; + } + + Void Register( const char* moduleName, CreateModuleFn pfnCreate ); + PlaYUVerModuleIf *CreateModule( const char *animalName ); + PlaYUVerModuleFactoryMap& getMap(){ return m_FactoryMap; } +}; + +//// typedef to make it easier to set up our factory +//typedef PlaYUVerModuleIf *PlaYUVerModuleMaker(); +//// our global factory +//extern std::map > PlaYUVerModuleFactory; + +}// NAMESPACE + +#endif // __PLAYUVERMODULESFACTORY_H__ + diff --git a/modules/PlaYUVerModuleIf.h b/modules/PlaYUVerModuleIf.h index 715491b..54d886f 100644 --- a/modules/PlaYUVerModuleIf.h +++ b/modules/PlaYUVerModuleIf.h @@ -1,6 +1,6 @@ /* This file is a part of plaYUVer project - * Copyright (C) 2014 by Luis Lucas (luisfrlucas@gmail.com) - * Joao Carreira (jfmcarreira@gmail.com) + * 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 @@ -32,11 +32,10 @@ namespace plaYUVer { -#define REGISTER_MODULE(X) \ - { \ - X *pMod = new X(); \ - appendModule( pMod ); \ - } +#define REGISTER_CLASS_FACTORY(X) \ +public: \ + static PlaYUVerModuleIf* Create() { return new X(); } \ + void Delete() { delete this; } enum // Module type { @@ -85,11 +84,11 @@ public: UInt m_uiModuleRequirements; Bool m_bApplyWhilePlaying; - PlaYUVerModuleDefinition m_cModuleDef; - PlaYUVerModuleIf() {} virtual ~PlaYUVerModuleIf() {} + virtual void Delete() = 0; + virtual Void create() {} virtual Void create( PlaYUVerFrame* ) {} @@ -101,10 +100,7 @@ public: virtual Double measure( PlaYUVerFrame*, PlaYUVerFrame* ) { return 0; } virtual Double measure( PlaYUVerFrame*, PlaYUVerFrame*, PlaYUVerFrame* ) { return 0; } - virtual Void destroy() { } - - Void setModuleDefinition( PlaYUVerModuleDefinition def ) { m_cModuleDef = def; } - PlaYUVerModuleDefinition getModuleDefinition() { return m_cModuleDef; } + virtual Void destroy() = 0; };