2 * This file is part of RawTherapee.
4 * Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
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.
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.
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/>.
19 #include <colorboost.h>
23 using namespace rtengine
;
24 using namespace rtengine::procparams
;
26 ColorBoost::ColorBoost () : ToolPanel(), cbAdd(false) {
28 colorboost
= new Adjuster (M("TP_COLORBOOST_AMOUNT"), -100, 300, 1, 0);
30 pack_start (*colorboost
);
31 pack_start (*Gtk::manage (new Gtk::HSeparator()));
33 avoidclip
= Gtk::manage (new Gtk::CheckButton (M("TP_COLORBOOST_AVOIDCOLORCLIP")));
35 pack_start (*avoidclip
);
36 pack_start (*Gtk::manage (new Gtk::HSeparator()));
38 enablelimiter
= Gtk::manage (new Gtk::CheckButton (M("TP_COLORBOOST_ENABLESATLIMITER")));
39 pack_start (*enablelimiter
);
41 saturationlimiter
= new Adjuster (M("TP_COLORBOOST_SATLIMIT"), 0, 200, 0.1, 100);
42 saturationlimiter
->show ();
43 saturationlimiter
->reference ();
45 colorboost
->setAdjusterListener (this);
46 saturationlimiter
->setAdjusterListener (this);
47 acconn
= avoidclip
->signal_toggled().connect( sigc::mem_fun(*this, &ColorBoost::avoidclip_toggled
) );
48 elconn
= enablelimiter
->signal_toggled().connect( sigc::mem_fun(*this, &ColorBoost::enablelimiter_toggled
) );
53 ColorBoost::~ColorBoost () {
55 delete saturationlimiter
;
58 void ColorBoost::read (const ProcParams
* pp
, const ParamsEdited
* pedited
) {
63 colorboost
->setEditedState (pedited
->colorBoost
.amount
? Edited
: UnEdited
);
64 saturationlimiter
->setEditedState (pedited
->colorBoost
.saturationlimit
? Edited
: UnEdited
);
65 avoidclip
->set_inconsistent (!pedited
->colorBoost
.avoidclip
);
66 enablelimiter
->set_inconsistent (!pedited
->colorBoost
.enable_saturationlimiter
);
69 colorboost
->setValue (pp
->colorBoost
.amount
);
70 saturationlimiter
->setValue (pp
->colorBoost
.saturationlimit
);
72 avoidclip
->set_active (pp
->colorBoost
.avoidclip
);
75 enablelimiter
->set_active (pp
->colorBoost
.enable_saturationlimiter
);
78 removeIfThere (this, saturationlimiter
, false);
79 if (enablelimiter
->get_active () || enablelimiter
->get_inconsistent())
80 pack_start (*saturationlimiter
);
82 lastACVal
= pp
->colorBoost
.avoidclip
;
83 lastELVal
= pp
->colorBoost
.enable_saturationlimiter
;
88 void ColorBoost::write (ProcParams
* pp
, ParamsEdited
* pedited
) {
90 pp
->colorBoost
.amount
= (int)colorboost
->getValue();
91 pp
->colorBoost
.avoidclip
= avoidclip
->get_active ();
92 pp
->colorBoost
.enable_saturationlimiter
= enablelimiter
->get_active ();
93 pp
->colorBoost
.saturationlimit
= saturationlimiter
->getValue ();
96 pedited
->colorBoost
.amount
= colorboost
->getEditedState ();
97 pedited
->colorBoost
.avoidclip
= !avoidclip
->get_inconsistent();
98 pedited
->colorBoost
.enable_saturationlimiter
= !enablelimiter
->get_inconsistent();
99 pedited
->colorBoost
.saturationlimit
= saturationlimiter
->getEditedState ();
103 void ColorBoost::setDefaults (const ProcParams
* defParams
, const ParamsEdited
* pedited
) {
105 colorboost
->setDefault (defParams
->colorBoost
.amount
);
106 saturationlimiter
->setDefault (defParams
->colorBoost
.saturationlimit
);
109 colorboost
->setDefaultEditedState (pedited
->colorBoost
.amount
? Edited
: UnEdited
);
110 saturationlimiter
->setDefaultEditedState (pedited
->colorBoost
.saturationlimit
? Edited
: UnEdited
);
113 colorboost
->setDefaultEditedState (Irrelevant
);
114 saturationlimiter
->setDefaultEditedState (Irrelevant
);
118 void ColorBoost::avoidclip_toggled () {
121 if (avoidclip
->get_inconsistent()) {
122 avoidclip
->set_inconsistent (false);
124 avoidclip
->set_active (false);
125 acconn
.block (false);
128 avoidclip
->set_inconsistent (true);
130 lastACVal
= avoidclip
->get_active ();
134 if (avoidclip
->get_active ())
135 listener
->panelChanged (EvCBAvoidClip
, M("GENERAL_ENABLED"));
137 listener
->panelChanged (EvCBAvoidClip
, M("GENERAL_DISABLED"));
141 void ColorBoost::enablelimiter_toggled () {
144 if (enablelimiter
->get_inconsistent()) {
145 enablelimiter
->set_inconsistent (false);
147 enablelimiter
->set_active (false);
148 elconn
.block (false);
151 enablelimiter
->set_inconsistent (true);
153 lastELVal
= enablelimiter
->get_active ();
156 removeIfThere (this, saturationlimiter
, false);
157 if (enablelimiter
->get_active () || enablelimiter
->get_inconsistent())
158 pack_start (*saturationlimiter
);
161 if (enablelimiter
->get_active ())
162 listener
->panelChanged (EvCBSatLimiter
, M("GENERAL_ENABLED"));
164 listener
->panelChanged (EvCBSatLimiter
, M("GENERAL_DISABLED"));
168 void ColorBoost::adjusterChanged (Adjuster
* a
, double newval
) {
171 if (a
!=saturationlimiter
)
172 listener
->panelChanged (EvCBBoost
, Glib::ustring::format ((int)a
->getValue()));
174 listener
->panelChanged (EvCBSatLimit
, Glib::ustring::format (std::setw(2), std::fixed
, std::setprecision(1), a
->getValue()));
178 void ColorBoost::setAdjusterBehavior (bool bcbadd
) {
180 if (!cbAdd
&& bcbadd
|| cbAdd
&& !bcbadd
)
181 colorboost
->setLimits (-100, 100, 1, 0);
186 void ColorBoost::setBatchMode (bool batchMode
) {
188 ToolPanel::setBatchMode (batchMode
);
189 colorboost
->showEditedCB ();
190 saturationlimiter
->showEditedCB ();