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 "rawcacorrection.h"
20 #include "eventmapper.h"
21 #include "guiutils.h"
22 #include "rtimage.h"
23
24 using namespace rtengine;
25 using namespace rtengine::procparams;
26
RAWCACorr()27 RAWCACorr::RAWCACorr () : FoldableToolPanel(this, "rawcacorrection", M("TP_RAWCACORR_LABEL"), false, true, true)
28 {
29 EvToolEnabled.set_action(DARKFRAME);
30 EvToolReset.set_action(DARKFRAME);
31
32 auto m = ProcEventMapper::getInstance();
33 EvPreProcessCAAutoiterations = m->newEvent(DARKFRAME, "HISTORY_MSG_RAWCACORR_AUTOIT");
34 EvPreProcessCAColourshift = m->newEvent(DARKFRAME, "HISTORY_MSG_RAWCACORR_COLORSHIFT");
35 EvPreProcessCAColourshiftHistory = m->newEvent(M_VOID, "HISTORY_MSG_RAWCACORR_COLORSHIFT");
36
37 Gtk::Image* icaredL = Gtk::manage (new RTImage ("circle-red-cyan-small.png"));
38 Gtk::Image* icaredR = Gtk::manage (new RTImage ("circle-cyan-red-small.png"));
39 Gtk::Image* icablueL = Gtk::manage (new RTImage ("circle-blue-yellow-small.png"));
40 Gtk::Image* icablueR = Gtk::manage (new RTImage ("circle-yellow-blue-small.png"));
41
42 caAutocorrect = Gtk::manage (new CheckBox(M("TP_RAWCACORR_AUTO")));
43 caAutocorrect->setCheckBoxListener (this);
44
45 caAutoiterations = Gtk::manage(new Adjuster (M("TP_RAWCACORR_AUTOIT"), 1, 5, 1, 2));
46 caAutoiterations->setAdjusterListener (this);
47 caAutoiterations->set_tooltip_markup(M("TP_RAWCACORR_AUTOIT_TOOLTIP"));
48
49 if (caAutoiterations->delay < options.adjusterMaxDelay) {
50 caAutoiterations->delay = options.adjusterMaxDelay;
51 }
52
53 caRed = Gtk::manage(new Adjuster (M("TP_RAWCACORR_CARED"), -4.0, 4.0, 0.1, 0, icaredL, icaredR));
54 caRed->setAdjusterListener (this);
55
56 if (caRed->delay < options.adjusterMaxDelay) {
57 caRed->delay = options.adjusterMaxDelay;
58 }
59
60 caRed->show();
61 caBlue = Gtk::manage(new Adjuster (M("TP_RAWCACORR_CABLUE"), -8.0, 8.0, 0.1, 0, icablueL, icablueR));
62 caBlue->setAdjusterListener (this);
63
64 if (caBlue->delay < options.adjusterMaxDelay) {
65 caBlue->delay = options.adjusterMaxDelay;
66 }
67
68 caBlue->show();
69
70 caRed->setLogScale(10, 0);
71 caBlue->setLogScale(10, 0);
72
73 pack_start( *caAutocorrect, Gtk::PACK_SHRINK, 4);
74 pack_start( *caAutoiterations, Gtk::PACK_SHRINK, 4);
75 pack_start( *caRed, Gtk::PACK_SHRINK, 4);
76 pack_start( *caBlue, Gtk::PACK_SHRINK, 4);
77
78 caAvoidcolourshift = Gtk::manage (new CheckBox(M("TP_RAWCACORR_AVOIDCOLORSHIFT")));
79 caAvoidcolourshift->setCheckBoxListener (this);
80 pack_start( *caAvoidcolourshift, Gtk::PACK_SHRINK, 4);
81
82
83 }
84
read(const rtengine::procparams::ProcParams * pp)85 void RAWCACorr::read(const rtengine::procparams::ProcParams* pp)
86 {
87 disableListener ();
88
89 setEnabled(pp->raw.enable_ca);
90 // disable Red and Blue sliders when caAutocorrect is enabled
91 caAutoiterations->set_sensitive(pp->raw.ca_autocorrect);
92 caRed->set_sensitive(!pp->raw.ca_autocorrect);
93 caBlue->set_sensitive(!pp->raw.ca_autocorrect);
94 caAutocorrect->setValue(pp->raw.ca_autocorrect);
95 caAvoidcolourshift->setValue(pp->raw.ca_avoidcolourshift);
96 caAutoiterations->setValue (pp->raw.caautoiterations);
97 caRed->setValue (pp->raw.cared);
98 caBlue->setValue (pp->raw.cablue);
99
100 enableListener ();
101 }
102
write(rtengine::procparams::ProcParams * pp)103 void RAWCACorr::write(rtengine::procparams::ProcParams* pp)
104 {
105 pp->raw.enable_ca = getEnabled();
106 pp->raw.ca_autocorrect = caAutocorrect->getLastActive();
107 pp->raw.ca_avoidcolourshift = caAvoidcolourshift->getLastActive();
108 pp->raw.caautoiterations = caAutoiterations->getValue();
109 pp->raw.cared = caRed->getValue();
110 pp->raw.cablue = caBlue->getValue();
111 }
112
adjusterChanged(Adjuster * a,double newval)113 void RAWCACorr::adjusterChanged(Adjuster* a, double newval)
114 {
115 if (listener && getEnabled()) {
116
117 Glib::ustring value = a->getTextValue();
118
119 if (a == caAutoiterations) {
120 listener->panelChanged (EvPreProcessCAAutoiterations, value );
121 } else if (a == caRed) {
122 listener->panelChanged (EvPreProcessCARed, value );
123 } else if (a == caBlue) {
124 listener->panelChanged (EvPreProcessCABlue, value );
125 }
126 }
127 }
128
adjusterAutoToggled(Adjuster * a,bool newval)129 void RAWCACorr::adjusterAutoToggled(Adjuster* a, bool newval)
130 {
131 }
132
checkBoxToggled(CheckBox * c,CheckValue newval)133 void RAWCACorr::checkBoxToggled (CheckBox* c, CheckValue newval)
134 {
135 if (c == caAutocorrect) {
136 // disable Red and Blue sliders when caAutocorrect is enabled
137 caAutoiterations->set_sensitive(caAutocorrect->getLastActive ());
138 caRed->set_sensitive(!caAutocorrect->getLastActive ());
139 caBlue->set_sensitive(!caAutocorrect->getLastActive ());
140 if (listener) {
141 listener->panelChanged (EvPreProcessAutoCA, caAutocorrect->getLastActive() ? M("GENERAL_ENABLED") : M("GENERAL_DISABLED"));
142 }
143 }
144 else if (c == caAvoidcolourshift) {
145 if (listener) {
146 listener->panelChanged ((caAutocorrect->getLastActive() || caRed->getValue() != 0 || caBlue->getValue() != 0) ? EvPreProcessCAColourshift : EvPreProcessCAColourshiftHistory, caAvoidcolourshift->getLastActive() ? M("GENERAL_ENABLED") : M("GENERAL_DISABLED"));
147 }
148 }
149 }
150
151
setDefaults(const rtengine::procparams::ProcParams * defParams)152 void RAWCACorr::setDefaults(const rtengine::procparams::ProcParams* defParams)
153 {
154 caAutoiterations->setDefault( defParams->raw.caautoiterations);
155 caRed->setDefault( defParams->raw.cared);
156 caBlue->setDefault( defParams->raw.cablue);
157
158 initial_params = defParams->raw;
159 }
160
161
trimValues(rtengine::procparams::ProcParams * pp)162 void RAWCACorr::trimValues (rtengine::procparams::ProcParams* pp)
163 {
164
165 caAutoiterations->trimValue(pp->raw.caautoiterations);
166 caRed->trimValue(pp->raw.cared);
167 caBlue->trimValue(pp->raw.cablue);
168 }
169
170
toolReset(bool to_initial)171 void RAWCACorr::toolReset(bool to_initial)
172 {
173 ProcParams pp;
174 if (to_initial) {
175 pp.raw = initial_params;
176 }
177 pp.raw.enable_ca = getEnabled();
178 read(&pp);
179 }
180