1 /*******************************************************************************
2 **
3 ** Photivo
4 **
5 ** Copyright (C) 2015 Bernd Schoeler <brjohn@brother-john.net>
6 **
7 ** This file is part of Photivo.
8 **
9 ** Photivo is free software: you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License version 3
11 ** as published by the Free Software Foundation.
12 **
13 ** Photivo is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with Photivo.  If not, see <http://www.gnu.org/licenses/>.
20 **
21 *******************************************************************************/
22 
23 #include "ptFilter_SoftglowOrton.h"
24 #include "ptCfgItem.h"
25 #include "../ptConstants.h"
26 #include "../ptImage.h"
27 
28 // TODO: Needed for access to m_ScaleFactor. Find a way to avoid when modernising the processor.
29 #include "../ptProcessor.h"
30 extern ptProcessor* TheProcessor;
31 
32 //------------------------------------------------------------------------------
33 
34 const QString CSoftglowOrtonId = "SoftglowOrton";
35 
36 const QString CMode       = "Mode";
37 const QString CStrength   = "Strength";
38 const QString CRadius     = "Radius";
39 const QString CContrast   = "Contrast";
40 const QString CSaturation = "Saturation";
41 
42 //------------------------------------------------------------------------------
43 
ptFilter_SoftglowOrton()44 ptFilter_SoftglowOrton::ptFilter_SoftglowOrton():
45   ptFilterBase()
46 {
47 //  FHelpUri = "http://photivo.org/something";
48   this->internalInit();
49 }
50 
51 //------------------------------------------------------------------------------
52 
createSoftglowOrton()53 ptFilterBase* ptFilter_SoftglowOrton::createSoftglowOrton() {
54   auto instance         = new ptFilter_SoftglowOrton;
55   instance->FFilterName = CSoftglowOrtonId;
56   instance->FCaption    = tr("Softglow/Orton");
57   return instance;
58 }
59 
60 //------------------------------------------------------------------------------
61 
doDefineControls()62 void ptFilter_SoftglowOrton::doDefineControls() {
63   const ptCfgItem::TComboEntryList sgModes({
64     {tr("Disabled"),        static_cast<int>(TSoftglowMode::Disabled),       "Disabled"},
65     {tr("Lighten"),         static_cast<int>(TSoftglowMode::Lighten),        "Lighten"},
66     {tr("Screen"),          static_cast<int>(TSoftglowMode::Screen),         "Screen"},
67     {tr("Softlight"),       static_cast<int>(TSoftglowMode::Softlight),      "Softlight"},
68     {tr("Normal"),          static_cast<int>(TSoftglowMode::Normal),         "Normal"},
69     {tr("Orton screen"),    static_cast<int>(TSoftglowMode::OrtonScreen),    "OrtonScreen"},
70     {tr("Orton softlight"), static_cast<int>(TSoftglowMode::OrtonSoftlight), "OrtonSoftlight"},
71   });
72 
73   FConfig.initStores(TCfgItemList()                                   //--- Combo: list of entries               ---//
74     //            Id            Type                      Default     Min           Max           Step        Decimals, commonConnect, storeable, caption, tooltip
75     << ptCfgItem({CMode,        ptCfgItem::Combo,         static_cast<int>(TSoftglowMode::Disabled), sgModes,           true, true, tr("Mode"), tr("")})
76     << ptCfgItem({CStrength,    ptCfgItem::Slider,        0.5,        0.0,          1.0,          0.1,        1,        true, true, tr("Strength"), tr("")})
77     << ptCfgItem({CRadius,      ptCfgItem::Slider,       10.0,        0.0,         30.0,          1.0,        1,        true, true, tr("Radius"), tr("")})
78     << ptCfgItem({CContrast,    ptCfgItem::Slider,        5.0,        0.0,         20.0,          0.5,        1,        true, true, tr("Contrast"), tr("")})
79     << ptCfgItem({CSaturation,  ptCfgItem::Slider,        -50,       -100,         100,           5,          0,        true, true, tr("Saturation"), tr("")})
80   );
81 }
82 
83 //------------------------------------------------------------------------------
84 
doCheckHasActiveCfg()85 bool ptFilter_SoftglowOrton::doCheckHasActiveCfg() {
86   return
87       (static_cast<TSoftglowMode>(FConfig.value(CMode).toInt()) != TSoftglowMode::Disabled) &&
88       !qFuzzyIsNull(FConfig.value(CStrength).toDouble());
89 }
90 
91 //------------------------------------------------------------------------------
92 
doRunFilter(ptImage * AImage)93 void ptFilter_SoftglowOrton::doRunFilter(ptImage *AImage) {
94   AImage->toRGB();
95   AImage->Softglow(
96       static_cast<TSoftglowMode>(FConfig.value(CMode).toInt()),
97       FConfig.value(CRadius).toDouble() * TheProcessor->m_ScaleFactor,
98       FConfig.value(CStrength).toDouble(),
99       ChMask_RGB,
100       FConfig.value(CContrast).toDouble(),
101       FConfig.value(CSaturation).toDouble() );
102 }
103 
104 //------------------------------------------------------------------------------
105 
106 RegisterHelper SoftglowOrtonRegister(&ptFilter_SoftglowOrton::createSoftglowOrton, CSoftglowOrtonId);
107 
108 //------------------------------------------------------------------------------
109