1 /*
2  *  This file is part of RawTherapee.
3  */
4 #pragma once
5 
6 #include <gtkmm.h>
7 
8 #include "adjuster.h"
9 #include "colorprovider.h"
10 #include "curvelistener.h"
11 #include "curveeditorgroup.h"
12 #include "guiutils.h"
13 #include "thresholdadjuster.h"
14 #include "toolpanel.h"
15 
16 class CurveEditor;
17 class CurveEditorGroup;
18 class DiagonalCurveEditor;
19 class FlatCurveEditor;
20 
21 class Retinex final :
22     public ToolParamBlock,
23     public FoldableToolPanel,
24     public rtengine::RetinexListener,
25     public CurveListener,
26     public AdjusterListener,
27     public ColorProvider
28 {
29 private:
30     IdleRegister idle_register;
31 
32 protected:
33     CurveEditorGroup* curveEditorGD;
34     CurveEditorGroup* curveEditorGDH;
35     CurveEditorGroup* curveEditorGH;
36     CurveEditorGroup* curveEditormap;
37     Adjuster* str;
38     Adjuster* scal;
39     Adjuster* grad;
40     Adjuster* grads;
41     Adjuster* iter;
42     Adjuster* neigh;
43     Adjuster* offs;
44     Adjuster* vart;
45     Adjuster* limd;
46     Adjuster* highl;
47     Adjuster* skal;
48     Adjuster* gam;
49     Adjuster* slope;
50     Adjuster* highlights;
51     Adjuster* h_tonalwidth;
52     Adjuster* shadows;
53     Adjuster* s_tonalwidth;
54     Adjuster* radius;
55 
56     MyExpander* expsettings;
57 
58     Gtk::Label* labmdh;
59     Gtk::Grid* dhgrid;
60     Gtk::Grid* mapgrid;
61     Gtk::Label* labmap;
62     Gtk::Grid* viewgrid;
63     Gtk::Label* labview;
64 
65     Gtk::Label* labgam;
66     Gtk::Grid* gamgrid;
67     Gtk::Button* neutral;
68 
69     MyComboBoxText*   retinexMethod;
70     MyComboBoxText*   retinexcolorspace;
71     MyComboBoxText*   gammaretinex;
72     MyComboBoxText*   mapMethod;
73     MyComboBoxText*   viewMethod;
74     Gtk::CheckButton* medianmap;
75     double nextmin;
76     double nextmax;
77     double nextminiT;
78     double nextmaxiT;
79     double nextmeanT;
80     double nextminT;
81     double nextmaxT;
82     double nextsigma;
83 
84     Gtk::Label* mMLabels;
85     Gtk::Label* transLabels;
86     Gtk::Label* transLabels2;
87     Gtk::Frame *gainFrame;
88     Gtk::Frame *tranFrame;
89     Gtk::Frame *iterFrame;
90     Gtk::Frame *equalFrame;
91 
92     DiagonalCurveEditor* cdshape;
93     DiagonalCurveEditor* cdshapeH;
94     DiagonalCurveEditor* mapshape;
95     CurveEditorGroup* transmissionCurveEditorG;
96     CurveEditorGroup* gaintransmissionCurve;
97     sigc::connection retinexMethodConn, neutralconn, mapMethodConn, viewMethodConn;
98     sigc::connection retinexColorSpaceConn;
99     sigc::connection gammaretinexConn;
100     FlatCurveEditor* transmissionShape;
101     FlatCurveEditor* gaintransmissionShape;
102     FlatCurveEditor* lhshape;
103     bool lastmedianmap;
104     sigc::connection medianmapConn;
105 
106 public:
107     Retinex   ();
108     ~Retinex  () override;
109 
110     void read                  (const rtengine::procparams::ProcParams* pp, const ParamsEdited* pedited = nullptr) override;
111     void write                 (rtengine::procparams::ProcParams* pp, ParamsEdited* pedited = nullptr) override;
112     void setBatchMode          (bool batchMode) override;
113     void setDefaults           (const rtengine::procparams::ProcParams* defParams, const ParamsEdited* pedited = nullptr) override;
114     void trimValues            (rtengine::procparams::ProcParams* pp) override;
115     void adjusterChanged       (Adjuster* a, double newval) override;
116     void autoOpenCurve         () override;
117     void medianmapChanged        ();
118     void minmaxChanged (double cdma, double cdmin, double mini, double maxi, double Tmean, double Tsigma, double Tmin, double Tmax) override;
119     void updateLabel      ();
120     void updateTrans      ();
121     void neutral_pressed       ();
122 
123     void enabledChanged        () override;
124     void curveChanged          (CurveEditor* ce) override;
125     void retinexMethodChanged();
126     void mapMethodChanged();
127     void viewMethodChanged();
128     void retinexColorSpaceChanged();
129     void gammaretinexChanged();
130     void ColorSpaceUpdateUI();
131     void writeOptions (std::vector<int> &tpOpen);
132     void updateToolState (std::vector<int> &tpOpen);
133     void setAdjusterBehavior (bool strAdd, bool neighAdd, bool limdAdd, bool offsAdd, bool vartAdd, bool gamAdd, bool slopeAdd);
134     void updateCurveBackgroundHistogram(
135         const LUTu& histToneCurve,
136         const LUTu& histLCurve,
137         const LUTu& histCCurve,
138         const LUTu& histLCAM,
139         const LUTu& histCCAM,
140         const LUTu& histRed,
141         const LUTu& histGreen,
142         const LUTu& histBlue,
143         const LUTu& histLuma,
144         const LUTu& histLRETI
145     );
146 
147     void colorForValue (double valX, double valY, enum ColorCaller::ElemType elemType, int callerId, ColorCaller* caller) override;
148 
149 private:
150     void foldAllButMe (GdkEventButton* event, MyExpander *expander);
151 
152 };
153