1 /** -*- mode: c++ ; c-basic-offset: 2 -*-
2  *
3  *  @file FilterThread.h
4  *
5  *  Copyright 2017 Sebastien Fourey
6  *
7  *  This file is part of G'MIC-Qt, a generic plug-in for raster graphics
8  *  editors, offering hundreds of filters thanks to the underlying G'MIC
9  *  image processing framework.
10  *
11  *  gmic_qt is free software: you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation, either version 3 of the License, or
14  *  (at your option) any later version.
15  *
16  *  gmic_qt is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with gmic_qt.  If not, see <http://www.gnu.org/licenses/>.
23  *
24  */
25 #ifndef GMIC_QT__FILTERTHREAD_H
26 #define GMIC_QT__FILTERTHREAD_H
27 
28 #include <QElapsedTimer>
29 #include <QString>
30 #include <QThread>
31 #include "Common.h"
32 #include "Host/GmicQtHost.h"
33 #include "GmicQt.h"
34 
35 namespace cimg_library
36 {
37 template <typename T> struct CImgList;
38 }
39 
40 namespace GmicQt
41 {
42 
43 class FilterThread : public QThread {
44   Q_OBJECT
45 
46 public:
47   FilterThread(QObject * parent, const QString & command, const QString & arguments, const QString & environment, OutputMessageMode mode);
48 
49   ~FilterThread() override;
50   void setInputImages(const cimg_library::CImgList<float> & list);
51   void setImageNames(const cimg_library::CImgList<char> & imageNames);
52   void swapImages(cimg_library::CImgList<float> & images);
53   const cimg_library::CImgList<float> & images() const;
54   const cimg_library::CImgList<char> & imageNames() const;
55   QStringList gmicStatus() const;
56   QList<int> parametersVisibilityStates() const;
57   QString errorMessage() const;
58   bool failed() const;
59   bool aborted() const;
60   int duration() const;
61   float progress() const;
62   QString fullCommand() const;
63   void setLogSuffix(const QString & text);
64 
65   static QStringList status2StringList(const QString &);
66   static QList<int> status2Visibilities(const QString &);
67 
68 public slots:
69   void abortGmic();
70 
71 signals:
72   void done();
73 
74 protected:
75   void run() override;
76 
77 private:
78   QString _command;
79   const QString _arguments;
80   QString _environment;
81   cimg_library::CImgList<float> * _images;
82   cimg_library::CImgList<char> * _imageNames;
83   bool _gmicAbort;
84   bool _failed;
85   QString _gmicStatus;
86   float _gmicProgress;
87   QString _errorMessage;
88   QString _name;
89   QString _logSuffix;
90   OutputMessageMode _messageMode;
91   QElapsedTimer _startTime;
92 };
93 
94 } // namespace GmicQt
95 
96 #endif // GMIC_QT__FILTERTHREAD_H
97