1 /** -*- mode: c++ ; c-basic-offset: 2 -*- 2 * 3 * @file GmicQt.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_GMIC_QT_H 26 #define GMIC_QT_GMIC_QT_H 27 28 namespace cimg_library 29 { 30 template <typename T> struct CImg; 31 template <typename T> struct CImgList; 32 } // namespace cimg_library 33 34 #ifndef gmic_pixel_type 35 #define gmic_pixel_type float 36 #endif 37 38 #define GMIC_QT_STRINGIFY(X) #X 39 #define GMIC_QT_XSTRINGIFY(X) GMIC_QT_STRINGIFY(X) 40 #define gmic_pixel_type_str GMIC_QT_XSTRINGIFY(gmic_pixel_type) 41 42 #include <list> 43 #include <string> 44 class QString; 45 class QImage; 46 47 namespace GmicQt 48 { 49 50 enum class UserInterfaceMode 51 { 52 Silent, 53 ProgressDialog, 54 Full 55 }; 56 57 enum class InputMode 58 { 59 NoInput, 60 Active, 61 All, 62 ActiveAndBelow, 63 ActiveAndAbove, 64 AllVisible, 65 AllInvisible, 66 AllVisiblesDesc_DEPRECATED, /* Removed since 2.8.2 */ 67 AllInvisiblesDesc_DEPRECATED, /* Removed since 2.8.2 */ 68 AllDesc_DEPRECATED, /* Removed since 2.8.2 */ 69 Unspecified = 100 70 }; 71 extern InputMode DefaultInputMode; 72 73 enum class OutputMode 74 { 75 InPlace, 76 NewLayers, 77 NewActiveLayers, 78 NewImage, 79 Unspecified = 100 80 }; 81 extern OutputMode DefaultOutputMode; 82 83 enum class OutputMessageMode 84 { 85 Quiet, 86 VerboseLayerName_DEPRECATED = Quiet, /* Removed since 2.9.5 */ 87 VerboseConsole = Quiet + 2, 88 VerboseLogFile, 89 VeryVerboseConsole, 90 VeryVerboseLogFile, 91 DebugConsole, 92 DebugLogFile, 93 Unspecified = 100 94 }; 95 extern const OutputMessageMode DefaultOutputMessageMode; 96 97 const QString & gmicVersionString(); 98 99 struct RunParameters { 100 std::string command; 101 std::string filterPath; 102 InputMode inputMode = InputMode::Unspecified; 103 OutputMode outputMode = OutputMode::Unspecified; 104 std::string filterName() const; 105 }; 106 107 /** 108 * A G'MIC filter may update the parameters it has received. This enum must be 109 * used to tell the function lastAppliedFilterRunParameters() whether it 110 * should return the parameters as they where supplied to the last applied 111 * filter, or as they have been "returned" by this filter. If the filter does 112 * not update its parameters, then "After" means the same as "Before". 113 */ 114 enum class ReturnedRunParametersFlag 115 { 116 BeforeFilterExecution, 117 AfterFilterExecution 118 }; 119 120 RunParameters lastAppliedFilterRunParameters(ReturnedRunParametersFlag flag); 121 122 /** 123 * Function that should be called to launch the plugin from the host adaptation code. 124 * @return The exit status of Qt's main event loop (QApplication::exec()). 125 */ 126 int run(UserInterfaceMode interfaceMode = UserInterfaceMode::Full, // 127 RunParameters parameters = RunParameters(), // 128 const std::list<InputMode> & disabledInputModes = std::list<InputMode>(), // 129 const std::list<OutputMode> & disabledOutputModes = std::list<OutputMode>(), // 130 bool * dialogWasAccepted = nullptr); 131 /* 132 * What follows may be helpful for the implementation of a host_something.cpp 133 */ 134 135 /** 136 * Calibrate any image to fit the required number of channels (1:GRAY, 2:GRAYA, 3:RGB or 4:RGBA). 137 * 138 * Instanciated for T in {unsigned char, gmic_pixel_type} 139 */ 140 template <typename T> // 141 void calibrateImage(cimg_library::CImg<T> & img, const int spectrum, const bool isPreview); 142 143 void convertCImgToQImage(const cimg_library::CImg<float> & in, QImage & out); 144 145 void convertQImageToCImg(const QImage & in, cimg_library::CImg<float> & out); 146 147 } // namespace GmicQt 148 149 #endif // GMIC_QT_GMIC_QT_H 150