1 /*
2  *  This file is part of RawTherapee.
3  *
4  *  Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
5  *
6  *  RawTherapee is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  RawTherapee is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with RawTherapee.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include "saturation.h"
20 #include "adjuster.h"
21 #include <sigc++/slot.h>
22 #include <iomanip>
23 #include "ppversion.h"
24 #include "edit.h"
25 #include "eventmapper.h"
26 
27 using namespace rtengine;
28 using namespace rtengine::procparams;
29 
Saturation()30 Saturation::Saturation():
31     FoldableToolPanel(this, "saturation", M("TP_SATURATION_LABEL"), false, true, true)
32 {
33     auto m = ProcEventMapper::getInstance();
34     EvVibrance = m->newEvent(LUMINANCECURVE, "HISTORY_MSG_SATURATION_VIBRANCE");
35     EvToolEnabled.set_action(LUMINANCECURVE);
36     EvToolReset.set_action(LUMINANCECURVE);
37     // autolevels = nullptr;
38 
39     saturation = Gtk::manage (new Adjuster (M("TP_SATURATION_SATURATION"), -100, 100, 1, 0));
40     pack_start (*saturation);
41     vibrance = Gtk::manage (new Adjuster (M("TP_SATURATION_VIBRANCE"), -100, 100, 1, 0));
42     pack_start(*vibrance);
43 
44     saturation->setLogScale(2, 0, true);
45     vibrance->setLogScale(2, 0, true);
46 
47     saturation->setAdjusterListener(this);
48     vibrance->setAdjusterListener(this);
49 }
50 
51 
~Saturation()52 Saturation::~Saturation ()
53 {
54 }
55 
56 
read(const ProcParams * pp)57 void Saturation::read(const ProcParams* pp)
58 {
59     disableListener ();
60 
61     setEnabled(pp->saturation.enabled);
62     saturation->setValue(pp->saturation.saturation);
63     vibrance->setValue(pp->saturation.vibrance);
64 
65     enableListener ();
66 }
67 
68 
write(ProcParams * pp)69 void Saturation::write(ProcParams* pp)
70 {
71     pp->saturation.enabled = getEnabled();
72     pp->saturation.saturation = (int)saturation->getValue ();
73     pp->saturation.vibrance = (int)vibrance->getValue ();
74 }
75 
76 
setDefaults(const ProcParams * defParams)77 void Saturation::setDefaults (const ProcParams* defParams)
78 {
79     saturation->setDefault(defParams->saturation.saturation);
80     vibrance->setDefault(defParams->saturation.vibrance);
81 }
82 
83 
adjusterChanged(Adjuster * a,double newval)84 void Saturation::adjusterChanged(Adjuster* a, double newval)
85 {
86     if (!listener || !getEnabled()) {
87         return;
88     }
89 
90     Glib::ustring costr = Glib::ustring::format ((int)a->getValue());
91 
92     if (a == saturation) {
93         listener->panelChanged(EvSaturation, costr);
94     } else if (a == vibrance) {
95         listener->panelChanged(EvVibrance, costr);
96     }
97 }
98 
adjusterAutoToggled(Adjuster * a,bool newval)99 void Saturation::adjusterAutoToggled(Adjuster* a, bool newval)
100 {
101 }
102 
103 
trimValues(rtengine::procparams::ProcParams * pp)104 void Saturation::trimValues (rtengine::procparams::ProcParams* pp)
105 {
106     saturation->trimValue(pp->saturation.saturation);
107     vibrance->trimValue(pp->saturation.vibrance);
108 
109     initial_params = pp->saturation;
110 }
111 
112 
toolReset(bool to_initial)113 void Saturation::toolReset(bool to_initial)
114 {
115     ProcParams pp;
116     if (to_initial) {
117         pp.saturation = initial_params;
118     }
119     pp.saturation.enabled = getEnabled();
120     read(&pp);
121 }
122