1 /*******************************************************************************
2 **
3 ** Photivo
4 **
5 ** Copyright (C) 2012 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_ShadowsHighlights.h"
24 #include "ptCfgItem.h"
25 #include "../ptImage.h"
26 #include "../ptCurve.h"
27 
28 //==============================================================================
29 
30 const QString CShadowsHighlightsId = "ShadowsHighlights";
31 
32 const QString CFineDetail   = "FineDetail";
33 const QString CCoarseDetail = "CoarseDetail";
34 const QString CScale        = "Scale";
35 const QString CCurve        = "Curve";
36 
37 //==============================================================================
38 
ptFilter_ShadowsHighlights()39 ptFilter_ShadowsHighlights::ptFilter_ShadowsHighlights()
40 : ptFilterBase()
41 {
42   internalInit();
43 }
44 
45 //==============================================================================
46 
CreateShadowsHighlights()47 ptFilterBase *ptFilter_ShadowsHighlights::CreateShadowsHighlights() {
48   auto hInstance         = new ptFilter_ShadowsHighlights;
49   hInstance->FFilterName = CShadowsHighlightsId;
50   hInstance->FCaption    = tr("Shadows/Highlights");
51   return hInstance;
52 }
53 
54 //==============================================================================
55 
doDefineControls()56 void ptFilter_ShadowsHighlights::doDefineControls() {
57   FConfig.initStores(TCfgItemList()                                              //--- Combo: list of entries               ---//
58                                                                                  //--- Check: not available                 ---//
59     //            Id                       Type                      Default     Min           Max           Step       Decimals, commonConnect, storeable, caption, tooltip
60     << ptCfgItem({CFineDetail,             ptCfgItem::Slider,        0.0,       -10.0,        10.0,          0.5,       1,        true, true, tr("Fine detail") ,tr("")})
61     << ptCfgItem({CCoarseDetail,           ptCfgItem::Slider,        0.0,       -10.0,        10.0,          0.5,       1,        true, true, tr("Coarse detail") ,tr("")})
62     << ptCfgItem({CScale,                  ptCfgItem::Slider,       10.0,        0.0,         30.0,          4.0,       1,        true, true, tr("Scale") ,tr("")})
63     << ptCfgItem({CCurve,                  ptCfgItem::CurveWin,      std::make_shared<ptCurve>(ptCurve::diagonalNull(),
64                                                                                                ptCurve::NoMask,
65                                                                                                ptCurve::NoMask,
66                                                                                                ptCurve::SplineInterpol),          tr("")})
67   );
68 }
69 
70 //==============================================================================
71 
doCheckHasActiveCfg()72 bool ptFilter_ShadowsHighlights::doCheckHasActiveCfg() {
73   return (FConfig.value(CFineDetail).toFloat()   != 0.0f) ||
74          (FConfig.value(CCoarseDetail).toFloat() != 0.0f) ||
75          (!FConfig.items()[cfgIdx(CCurve)].Curve->isNull());
76 }
77 
78 //==============================================================================
79 
doRunFilter(ptImage * AImage)80 void ptFilter_ShadowsHighlights::doRunFilter(ptImage *AImage) {
81   AImage->toLab();
82   AImage->ShadowsHighlights(FConfig.items()[cfgIdx(CCurve)].Curve.get(),
83                             FConfig.value(CScale).toDouble(),
84                             FConfig.value(CCoarseDetail).toDouble(),
85                             FConfig.value(CFineDetail).toDouble() );
86 }
87 
88 //==============================================================================
89 
90 RegisterHelper ShadowsHighlightsRegister(&ptFilter_ShadowsHighlights::CreateShadowsHighlights, CShadowsHighlightsId);
91 
92 //==============================================================================
93