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 <whitebalance.h>
28 extern Glib::ustring argv0
;
30 using namespace rtengine
;
31 using namespace rtengine::procparams
;
33 WhiteBalance::WhiteBalance () : ToolPanel(), wbp(NULL
), wblistener(NULL
), tempAdd(false), greenAdd (false) {
35 Gtk::HBox
* hbox
= Gtk::manage (new Gtk::HBox ());
37 Gtk::Label
* lab
= Gtk::manage (new Gtk::Label (M("TP_WBALANCE_METHOD")));
39 method
= Gtk::manage (new Gtk::ComboBoxText ());
41 method
->append_text (M("TP_WBALANCE_CAMERA"));
42 method
->append_text (M("TP_WBALANCE_AUTO"));
43 method
->append_text (M("TP_WBALANCE_CUSTOM"));
44 method
->set_active (0);
45 hbox
->pack_start (*lab
, Gtk::PACK_SHRINK
, 4);
46 hbox
->pack_start (*method
);
47 pack_start (*hbox
, Gtk::PACK_SHRINK
, 4);
50 Gtk::HBox
* spotbox
= Gtk::manage (new Gtk::HBox ());
53 spotbutton
= Gtk::manage (new Gtk::Button (M("TP_WBALANCE_SPOTWB")));
54 Gtk::Image
* spotimg
= Gtk::manage (new Gtk::Image (GET_DATA_PATH(argv0
)+"/images/wbpicker16.png"));
56 spotbutton
->set_image (*spotimg
);
59 spotbox
->pack_start (*spotbutton
);
61 Gtk::Label
* slab
= Gtk::manage (new Gtk::Label (M("TP_WBALANCE_SIZE")));
64 spotsize
= Gtk::manage (new Gtk::ComboBoxText ());
66 spotsize
->append_text ("2");
67 spotsize
->append_text ("4");
68 spotsize
->append_text ("8");
69 spotsize
->append_text ("16");
70 spotsize
->append_text ("32");
71 spotsize
->set_active (2);
73 spotbox
->pack_end (*spotsize
, Gtk::PACK_SHRINK
, 4);
74 spotbox
->pack_end (*slab
, Gtk::PACK_SHRINK
, 4);
76 pack_start (*spotbox
, Gtk::PACK_SHRINK
, 4);
78 temp
= Gtk::manage (new Adjuster (M("TP_WBALANCE_TEMPERATURE"), MINTEMP
, MAXTEMP
, 1, 4750));
79 green
= Gtk::manage (new Adjuster (M("TP_WBALANCE_GREEN"), MINGREEN
, MAXGREEN
, 0.001, 1.2));
86 temp
->setAdjusterListener (this);
87 green
->setAdjusterListener (this);
89 spotbutton
->signal_pressed().connect( sigc::mem_fun(*this, &WhiteBalance::spotPressed
) );
90 methconn
= method
->signal_changed().connect( sigc::mem_fun(*this, &WhiteBalance::optChanged
) );
91 spotsize
->signal_changed().connect( sigc::mem_fun(*this, &WhiteBalance::spotSizeChanged
) );
94 void WhiteBalance::adjusterChanged (Adjuster
* a
, double newval
) {
96 if (method
->get_active_row_number()!=2) {
98 method
->set_active (2);
104 listener
->panelChanged (EvWBTemp
, Glib::ustring::format ((int)a
->getValue()));
106 listener
->panelChanged (EvWBGreen
, Glib::ustring::format (std::setw(4), std::fixed
, std::setprecision(3), a
->getValue()));
110 void WhiteBalance::optChanged () {
112 if (opt
!=method
->get_active_row_number()) {
113 opt
= method
->get_active_row_number();
114 Glib::ustring meth
= M("TP_WBALANCE_CUSTOM");
116 double ctemp
; double cgreen
;
117 wbp
->getCamWB (ctemp
, cgreen
);
118 temp
->setValue (tempAdd
? 0.0 : (int)ctemp
);
119 green
->setValue (greenAdd
? 0.0 : cgreen
);
120 meth
= M("TP_WBALANCE_CAMERA");
122 temp
->setEditedState (UnEdited
);
123 green
->setEditedState (UnEdited
);
126 else if (opt
==1 && wbp
) {
127 double ctemp
; double cgreen
;
128 wbp
->getAutoWB (ctemp
, cgreen
);
129 temp
->setValue (tempAdd
? 0.0 : (int)ctemp
);
130 green
->setValue (greenAdd
? 0.0 : cgreen
);
131 meth
= M("TP_WBALANCE_AUTO");
133 temp
->setEditedState (UnEdited
);
134 green
->setEditedState (UnEdited
);
138 meth
= "(Unchanged)";
139 temp
->setEditedState (UnEdited
);
140 green
->setEditedState (UnEdited
);
143 listener
->panelChanged (EvWBMethod
, meth
);
147 void WhiteBalance::spotPressed () {
150 wblistener
->spotWBRequested (getSize());
153 void WhiteBalance::spotSizeChanged () {
156 wblistener
->spotWBRequested (getSize());
159 void WhiteBalance::read (const ProcParams
* pp
, const ParamsEdited
* pedited
) {
162 methconn
.block (true);
165 temp
->setEditedState (UnEdited
);
166 green
->setEditedState (UnEdited
);
169 if (pedited
&& !pedited
->wb
.method
) {
170 method
->set_active (3);
174 if (pp
->wb
.method
== "Camera") {
175 method
->set_active (0);
177 double ctemp
; double cgreen
;
178 wbp
->getCamWB (ctemp
, cgreen
);
179 temp
->setValue (tempAdd
? 0.0 : (int)ctemp
);
180 green
->setValue (greenAdd
? 0.0 : cgreen
);
184 else if (pp
->wb
.method
== "Auto") {
185 method
->set_active (1);
187 double ctemp
; double cgreen
;
188 wbp
->getAutoWB (ctemp
, cgreen
);
189 temp
->setValue (tempAdd
? 0.0 : (int)ctemp
);
190 green
->setValue (greenAdd
? 0.0 : cgreen
);
194 else if (pp
->wb
.method
== "Custom") {
195 method
->set_active (2);
196 temp
->setValue (pp
->wb
.temperature
);
197 green
->setValue (pp
->wb
.green
);
200 temp
->setEditedState (pedited
->wb
.temperature
? Edited
: UnEdited
);
201 green
->setEditedState (pedited
->wb
.green
? Edited
: UnEdited
);
205 methconn
.block (false);
209 void WhiteBalance::write (ProcParams
* pp
, ParamsEdited
* pedited
) {
212 pedited
->wb
.temperature
= temp
->getEditedState ();
213 pedited
->wb
.green
= green
->getEditedState ();
214 pedited
->wb
.method
= method
->get_active_row_number()!=3;
217 if (method
->get_active_row_number()==0)
218 pp
->wb
.method
= "Camera";
219 else if (method
->get_active_row_number()==1)
220 pp
->wb
.method
= "Auto";
221 else if (method
->get_active_row_number()>=2)
222 pp
->wb
.method
= "Custom";
224 pp
->wb
.temperature
= (int)temp
->getValue ();
225 pp
->wb
.green
= green
->getValue ();
229 void WhiteBalance::setDefaults (const ProcParams
* defParams
, const ParamsEdited
* pedited
) {
231 if (wbp
&& defParams
->wb
.method
== "Camera") {
232 double ctemp
; double cgreen
;
233 wbp
->getCamWB (ctemp
, cgreen
);
234 temp
->setDefault (tempAdd
? 0 : (int)ctemp
);
235 green
->setDefault (greenAdd
? 0 : cgreen
);
237 else if (wbp
&& defParams
->wb
.method
== "Auto") {
238 double ctemp
; double cgreen
;
239 wbp
->getAutoWB (ctemp
, cgreen
);
240 temp
->setDefault (tempAdd
? 0 : (int)ctemp
);
241 green
->setDefault (greenAdd
? 0 : cgreen
);
243 else if (defParams
->wb
.method
== "Custom") {
244 temp
->setDefault (defParams
->wb
.temperature
);
245 green
->setDefault (defParams
->wb
.green
);
248 temp
->setDefaultEditedState (pedited
->wb
.temperature
? Edited
: UnEdited
);
249 green
->setDefaultEditedState (pedited
->wb
.green
? Edited
: UnEdited
);
252 temp
->setDefaultEditedState (Irrelevant
);
253 green
->setDefaultEditedState (Irrelevant
);
257 void WhiteBalance::setBatchMode (bool batchMode
) {
259 ToolPanel::setBatchMode (batchMode
);
260 temp
->showEditedCB ();
261 green
->showEditedCB ();
262 method
->append_text ("(Unchanged)");
265 int WhiteBalance::getSize () {
267 return atoi(spotsize
->get_active_text().c_str());
270 void WhiteBalance::setWB (int vtemp
, double vgreen
) {
273 temp
->setValue (vtemp
);
274 green
->setValue (vgreen
);
275 method
->set_active (2);
276 temp
->setEditedState (Edited
);
277 green
->setEditedState (Edited
);
281 listener
->panelChanged (EvWBTemp
, Glib::ustring::compose("%1, %2", (int)temp
->getValue(), Glib::ustring::format (std::setw(4), std::fixed
, std::setprecision(3), green
->getValue())));
283
void WhiteBalance::setAdjusterBehavior (bool btempadd
, bool bgreenadd
) {
285 if (!tempAdd
&& btempadd
)
286 temp
->setLimits (-4000, +4000, 1, 0);
287 else if (tempAdd
&& !btempadd
)
288 temp
->setLimits (MINTEMP
, MAXTEMP
, 1, 4750);
290 if (!greenAdd
&& bgreenadd
)
291 green
->setLimits (-1.0, +1.0, 0.001, 0);
292 else if (greenAdd
&& bgreenadd
)
293 green
->setLimits (MINGREEN
, MAXGREEN
, 0.001, 1.2);
296 greenAdd
= bgreenadd
;