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 <https://www.gnu.org/licenses/>.
18 */
19 #include <cmath>
20 #include <iomanip>
21
22 #include "impulsedenoise.h"
23
24 #include "guiutils.h"
25
26 #include "../rtengine/procparams.h"
27
28 using namespace rtengine;
29 using namespace rtengine::procparams;
30
ImpulseDenoise()31 ImpulseDenoise::ImpulseDenoise () : FoldableToolPanel(this, "impulsedenoise", M("TP_IMPULSEDENOISE_LABEL"), true, true)
32 {
33
34 thresh = Gtk::manage (new Adjuster (M("TP_IMPULSEDENOISE_THRESH"), 0, 100, 1, 50));
35
36 pack_start (*thresh);
37
38 thresh->setAdjusterListener (this);
39
40 show_all_children ();
41 }
42
read(const ProcParams * pp,const ParamsEdited * pedited)43 void ImpulseDenoise::read (const ProcParams* pp, const ParamsEdited* pedited)
44 {
45
46 disableListener ();
47
48 if (pedited) {
49 thresh->setEditedState (pedited->impulseDenoise.thresh ? Edited : UnEdited);
50 set_inconsistent (multiImage && !pedited->impulseDenoise.enabled);
51 }
52
53 setEnabled(pp->impulseDenoise.enabled);
54
55 thresh->setValue (pp->impulseDenoise.thresh);
56
57 enableListener ();
58 }
59
write(ProcParams * pp,ParamsEdited * pedited)60 void ImpulseDenoise::write (ProcParams* pp, ParamsEdited* pedited)
61 {
62
63 pp->impulseDenoise.thresh = thresh->getValue ();
64 pp->impulseDenoise.enabled = getEnabled();
65
66 if (pedited) {
67 pedited->impulseDenoise.thresh = thresh->getEditedState ();
68 pedited->impulseDenoise.enabled = !get_inconsistent();
69 }
70 }
71
setDefaults(const ProcParams * defParams,const ParamsEdited * pedited)72 void ImpulseDenoise::setDefaults (const ProcParams* defParams, const ParamsEdited* pedited)
73 {
74
75 thresh->setDefault (defParams->impulseDenoise.thresh);
76
77 if (pedited) {
78 thresh->setDefaultEditedState (pedited->impulseDenoise.thresh ? Edited : UnEdited);
79 } else {
80 thresh->setDefaultEditedState (Irrelevant);
81 }
82 }
83
adjusterChanged(Adjuster * a,double newval)84 void ImpulseDenoise::adjusterChanged(Adjuster* a, double newval)
85 {
86 if (listener && getEnabled()) {
87 listener->panelChanged (EvIDNThresh, Glib::ustring::format (std::setw(2), std::fixed, std::setprecision(1), a->getValue()));
88 }
89 }
90
enabledChanged()91 void ImpulseDenoise::enabledChanged ()
92 {
93 if (listener) {
94 if (get_inconsistent()) {
95 listener->panelChanged (EvIDNEnabled, M("GENERAL_UNCHANGED"));
96 } else if (getEnabled()) {
97 listener->panelChanged (EvIDNEnabled, M("GENERAL_ENABLED"));
98 } else {
99 listener->panelChanged (EvIDNEnabled, M("GENERAL_DISABLED"));
100 }
101 }
102 }
103
setBatchMode(bool batchMode)104 void ImpulseDenoise::setBatchMode (bool batchMode)
105 {
106
107 ToolPanel::setBatchMode (batchMode);
108 thresh->showEditedCB ();
109 }
110
setAdjusterBehavior(bool threshadd)111 void ImpulseDenoise::setAdjusterBehavior (bool threshadd)
112 {
113
114 thresh->setAddMode(threshadd);
115 }
116
trimValues(rtengine::procparams::ProcParams * pp)117 void ImpulseDenoise::trimValues (rtengine::procparams::ProcParams* pp)
118 {
119
120 thresh->trimValue(pp->impulseDenoise.thresh);
121 }
122