Proper check for rawzor libraries.
[rawtherapee-fixes.git] / rtgui / whitebalance.cc
blob70df5e36b7a5d3dda68db180555115595e6e6b05
1 /*
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>
20 #include <iomanip>
21 #include "config.h"
23 #define MINTEMP 1200
24 #define MAXTEMP 12000
25 #define MINGREEN 0.02
26 #define MAXGREEN 5.0
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 ());
36 hbox->show ();
37 Gtk::Label* lab = Gtk::manage (new Gtk::Label (M("TP_WBALANCE_METHOD")));
38 lab->show ();
39 method = Gtk::manage (new Gtk::ComboBoxText ());
40 method->show ();
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);
48 opt = 0;
50 Gtk::HBox* spotbox = Gtk::manage (new Gtk::HBox ());
51 spotbox->show ();
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"));
55 spotimg->show ();
56 spotbutton->set_image (*spotimg);
57 spotbutton->show ();
59 spotbox->pack_start (*spotbutton);
61 Gtk::Label* slab = Gtk::manage (new Gtk::Label (M("TP_WBALANCE_SIZE")));
62 slab->show ();
64 spotsize = Gtk::manage (new Gtk::ComboBoxText ());
65 spotsize->show ();
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));
80 temp->show ();
81 green->show ();
83 pack_start (*temp);
84 pack_start (*green);
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) {
97 disableListener ();
98 method->set_active (2);
99 enableListener ();
102 if (listener) {
103 if (a==temp)
104 listener->panelChanged (EvWBTemp, Glib::ustring::format ((int)a->getValue()));
105 else if (a==green)
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");
115 if (opt==0 && wbp) {
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");
121 if (batchMode) {
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");
132 if (batchMode) {
133 temp->setEditedState (UnEdited);
134 green->setEditedState (UnEdited);
137 else if (opt==3) {
138 meth = "(Unchanged)";
139 temp->setEditedState (UnEdited);
140 green->setEditedState (UnEdited);
142 if (listener)
143 listener->panelChanged (EvWBMethod, meth);
147 void WhiteBalance::spotPressed () {
149 if (wblistener)
150 wblistener->spotWBRequested (getSize());
153 void WhiteBalance::spotSizeChanged () {
155 if (wblistener)
156 wblistener->spotWBRequested (getSize());
159 void WhiteBalance::read (const ProcParams* pp, const ParamsEdited* pedited) {
161 disableListener ();
162 methconn.block (true);
164 if (pedited) {
165 temp->setEditedState (UnEdited);
166 green->setEditedState (UnEdited);
169 if (pedited && !pedited->wb.method) {
170 method->set_active (3);
171 opt = 3;
173 else {
174 if (pp->wb.method == "Camera") {
175 method->set_active (0);
176 if (wbp) {
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);
182 opt = 0;
184 else if (pp->wb.method == "Auto") {
185 method->set_active (1);
186 if (wbp) {
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);
192 opt = 1;
194 else if (pp->wb.method == "Custom") {
195 method->set_active (2);
196 temp->setValue (pp->wb.temperature);
197 green->setValue (pp->wb.green);
198 opt = 2;
199 if (pedited) {
200 temp->setEditedState (pedited->wb.temperature ? Edited : UnEdited);
201 green->setEditedState (pedited->wb.green ? Edited : UnEdited);
205 methconn.block (false);
206 enableListener ();
209 void WhiteBalance::write (ProcParams* pp, ParamsEdited* pedited) {
211 if (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);
247 if (pedited) {
248 temp->setDefaultEditedState (pedited->wb.temperature ? Edited : UnEdited);
249 green->setDefaultEditedState (pedited->wb.green ? Edited : UnEdited);
251 else {
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) {
272 disableListener ();
273 temp->setValue (vtemp);
274 green->setValue (vgreen);
275 method->set_active (2);
276 temp->setEditedState (Edited);
277 green->setEditedState (Edited);
278 enableListener ();
280 if (listener)
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);
295 tempAdd = btempadd;
296 greenAdd = bgreenadd;