add layout_scale preference, scaling cleanup, rework init bc_resources, init tip_info...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / denoiseseltempavg / seltempavgwindow.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program 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 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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 this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "language.h"
24 #include "seltempavgwindow.h"
25
26
27
28 #define MAX_FRAMES 1024
29
30
31 SelTempAvgWindow::SelTempAvgWindow(SelTempAvgMain *client)
32  : PluginClientWindow(client,
33         xS(310),
34         yS(480),
35         xS(310),
36         yS(480),
37         0)
38 {
39         this->client = client;
40 }
41
42 SelTempAvgWindow::~SelTempAvgWindow()
43 {
44 }
45
46 void SelTempAvgWindow::create_objects()
47 {
48         int xs10 = xS(10), xs20 = xS(20), xs40 = xS(40), xs80 = xS(80), xs175=xS(175), xs260=xS(260);
49         int ys10 = yS(10), ys20 = yS(20), ys25 = yS(25), ys30 = yS(30), ys35 = yS(35);
50         int x1 = xs10, x2 = xs40, x3 = xs80, x4 = xs175, x5 = xs260, y = ys10;
51
52         add_tool(new BC_Title(x1, y, _("Frames to average")));
53         y += ys20;
54         add_tool(total_frames = new SelTempAvgSlider(client, x1, y));
55         y += ys20;
56
57         add_tool(new BC_Title(x1, y, _("Use Method:")));
58         y += ys20;
59
60         add_tool(method_none = new SelTempAvgMethodRadial(client, this, x1, y, SelTempAvgConfig::METHOD_NONE, _("None ")));
61         y += ys20;
62
63         add_tool(method_seltempavg = new SelTempAvgMethodRadial(client, this, x1, y, SelTempAvgConfig::METHOD_SELTEMPAVG, _("Selective Temporal Averaging: ")));
64         y += ys25;
65
66         add_tool(new BC_Title(x3, y, _("Av. Thres.")));
67         add_tool(new BC_Title(x4, y, _("S.D. Thres.")));
68         add_tool(new BC_Title(x5, y, _("Mask")));
69         y += ys25;
70
71         add_tool(new BC_Title(x2, y, _("R / Y")));
72         add_tool(avg_threshold_RY = new SelTempAvgThreshSlider(client, x3, y, AVG_RY,client->config.avg_threshold_RY));
73         add_tool(std_threshold_RY = new SelTempAvgThreshSlider(client, x4, y, STD_RY,client->config.std_threshold_RY));
74         add_tool(mask_RY = new SelTempAvgMask(client, x5, y, MASK_RY, client->config.mask_RY));
75
76         y += ys25;
77         add_tool(new BC_Title(x2, y, _("G / U")));
78         add_tool(avg_threshold_GU = new SelTempAvgThreshSlider(client, x3, y, AVG_GU,client->config.avg_threshold_GU));
79         add_tool(std_threshold_GU = new SelTempAvgThreshSlider(client, x4, y, STD_GU,client->config.std_threshold_GU));
80         add_tool(mask_GU = new SelTempAvgMask(client, x5, y, MASK_GU,client->config.mask_GU));
81
82         y += ys25;
83         add_tool(new BC_Title(x2, y, _("B / V")));
84         add_tool(avg_threshold_BV = new SelTempAvgThreshSlider(client, x3, y, AVG_BV,client->config.avg_threshold_BV));
85         add_tool(std_threshold_BV = new SelTempAvgThreshSlider(client, x4, y, STD_BV,client->config.std_threshold_BV));
86         add_tool(mask_BV = new SelTempAvgMask(client, x5, y, MASK_BV,client->config.mask_BV));
87
88         y += ys30;
89         add_tool(method_average = new SelTempAvgMethodRadial(client, this, x1, y, SelTempAvgConfig::METHOD_AVERAGE, _("Average")));
90         y += ys20;
91         add_tool(method_stddev = new SelTempAvgMethodRadial(client, this, x1, y, SelTempAvgConfig::METHOD_STDDEV, _("Standard Deviation")));
92
93         y += ys35;
94         add_tool(new BC_Title(x1, y, _("First frame in average:")));
95         y += ys20;
96         add_tool(offset_fixed = new SelTempAvgOffsetRadial(client, this, x1, y, SelTempAvgConfig::OFFSETMODE_FIXED, _("Fixed offset: ")));
97         add_tool(offset_fixed_value = new SelTempAvgOffsetValue(client, x4, y));
98         y += ys25;
99
100         add_tool(offset_restartmarker = new SelTempAvgOffsetRadial(client, this, x1, y, SelTempAvgConfig::OFFSETMODE_RESTARTMARKERSYS, _("Restart marker system:")));
101         add_tool(offset_restartmarker_pos = new BC_TextBox(x4+xs20, y, 100, 1, ""));
102         offset_restartmarker_pos->disable();
103         y += ys20;
104         add_tool(offset_restartmarker_keyframe = new SelTempAvgStartKeyframe(client, x2 + xs10, y));
105
106         y += ys35;
107
108         add_tool(new BC_Title(x1, y, _("Other Options:")));
109         y += ys20;
110         add_tool(paranoid = new SelTempAvgParanoid(client, x1, y));
111         y += ys25;
112         add_tool(no_subtract = new SelTempAvgNoSubtract(client, x1, y));
113         y += ys30;
114         add_tool(new BC_Title(x2, y, _("Gain:")));
115         add_tool(gain = new SelTempAvgGainValue(client, x3, y));
116
117         show_window();
118         flush();
119 }
120
121
122
123
124
125 SelTempAvgThreshSlider::SelTempAvgThreshSlider(SelTempAvgMain *client, int x, int y, int id, float currentval)
126   : BC_TextBox(x,y, xS(80), 1, currentval)
127 {
128   //    float val;
129   //    int   ival;
130         this->type = id;
131         this->client = client;
132 }
133 SelTempAvgThreshSlider::~SelTempAvgThreshSlider()
134 {
135 }
136 int SelTempAvgThreshSlider::handle_event()
137 {
138         float val = atof(get_text());
139
140         if(val < 0) val = 0;
141
142         switch (type) {
143         case AVG_RY:
144                 client->config.avg_threshold_RY = val;
145                 break;
146         case AVG_GU:
147                 client->config.avg_threshold_GU = val;
148                 break;
149         case AVG_BV:
150                 client->config.avg_threshold_BV = val;
151                 break;
152         case STD_RY:
153                 client->config.std_threshold_RY = val;
154                 break;
155         case STD_GU:
156                 client->config.std_threshold_GU = val;
157                 break;
158         case STD_BV:
159                 client->config.std_threshold_BV = val;
160                 break;
161         }
162
163         client->send_configure_change();
164         return 1;
165 }
166
167
168 SelTempAvgOffsetValue::SelTempAvgOffsetValue(SelTempAvgMain *client, int x, int y)
169   : BC_TextBox(x,y, xS(80), 1, client->config.offset_fixed_value)
170 {
171         this->client = client;
172 }
173 SelTempAvgOffsetValue::~SelTempAvgOffsetValue()
174 {
175 }
176 int SelTempAvgOffsetValue::handle_event()
177 {
178         int val = atoi(get_text());
179
180         client->config.offset_fixed_value = val;
181         client->send_configure_change();
182         return 1;
183 }
184
185
186 SelTempAvgGainValue::SelTempAvgGainValue(SelTempAvgMain *client, int x, int y)
187   : BC_TextBox(x,y, xS(80), 1, client->config.gain)
188 {
189         this->client = client;
190 }
191 SelTempAvgGainValue::~SelTempAvgGainValue()
192 {
193 }
194 int SelTempAvgGainValue::handle_event()
195 {
196         float val = atof(get_text());
197
198         if(val < 0) val = 0;
199         client->config.gain = val;
200         client->send_configure_change();
201         return 1;
202 }
203
204
205
206
207
208 SelTempAvgSlider::SelTempAvgSlider(SelTempAvgMain *client, int x, int y)
209  : BC_ISlider(x, y, 0, xS(280), yS(200), 1, MAX_FRAMES, client->config.frames)
210 {
211         this->client = client;
212 }
213 SelTempAvgSlider::~SelTempAvgSlider()
214 {
215 }
216 int SelTempAvgSlider::handle_event()
217 {
218         int result = get_value();
219         if(result < 1) result = 1;
220         client->config.frames = result;
221         client->send_configure_change();
222         return 1;
223 }
224
225
226
227 SelTempAvgOffsetRadial::SelTempAvgOffsetRadial(SelTempAvgMain *client, SelTempAvgWindow *gui, int x, int y, int type, char *caption)
228  : BC_Radial(x, y, client->config.offsetmode == type, caption)
229 {
230         this->client = client;
231         this->gui = gui;
232         this->type = type;
233 }
234 int SelTempAvgOffsetRadial::handle_event()
235 {
236         int result = get_value();
237         client->config.offsetmode = result;
238
239         gui->offset_fixed->update(client->config.offsetmode == SelTempAvgConfig::OFFSETMODE_FIXED);
240         gui->offset_restartmarker->update(client->config.offsetmode == SelTempAvgConfig::OFFSETMODE_RESTARTMARKERSYS);
241
242         client->send_configure_change();
243         return 1;
244 }
245
246
247
248 SelTempAvgMethodRadial::SelTempAvgMethodRadial(SelTempAvgMain *client,
249         SelTempAvgWindow *gui, int x, int y, int type, char *caption)
250  : BC_Radial(x,
251         y,
252         client->config.method == type,
253         caption)
254 {
255         this->client = client;
256         this->gui = gui;
257         this->type = type;
258 }
259 int SelTempAvgMethodRadial::handle_event()
260 {
261         int result = get_value();
262         client->config.method = result;
263
264         gui->method_none->update(client->config.method       == SelTempAvgConfig::METHOD_NONE);
265         gui->method_seltempavg->update(client->config.method == SelTempAvgConfig::METHOD_SELTEMPAVG);
266         gui->method_average->update(client->config.method    == SelTempAvgConfig::METHOD_AVERAGE);
267         gui->method_stddev->update(client->config.method     == SelTempAvgConfig::METHOD_STDDEV);
268
269         client->send_configure_change();
270         return 1;
271 }
272
273
274 SelTempAvgParanoid::SelTempAvgParanoid(SelTempAvgMain *client, int x, int y)
275  : BC_CheckBox(x, y, client->config.paranoid, _("Reprocess frame again"))
276 {
277         this->client = client;
278 }
279 int SelTempAvgParanoid::handle_event()
280 {
281         int result = get_value();
282         client->config.paranoid = result;
283         client->send_configure_change();
284         return 1;
285 }
286
287
288 SelTempAvgNoSubtract::SelTempAvgNoSubtract(SelTempAvgMain *client, int x, int y)
289  : BC_CheckBox(x, y, client->config.nosubtract, _("Disable subtraction"))
290 {
291         this->client = client;
292 }
293 int SelTempAvgNoSubtract::handle_event()
294 {
295         int result = get_value();
296         client->config.nosubtract = result;
297         client->send_configure_change();
298         return 1;
299 }
300
301 SelTempAvgMask::SelTempAvgMask(SelTempAvgMain *client, int x, int y, int type, int val)
302  : BC_CheckBox(x, y, val, "")
303 {
304         this->client = client;
305         this->type = type;
306 }
307 int SelTempAvgMask::handle_event()
308 {
309         int result = get_value();
310         switch (type) {
311         case MASK_RY:
312                 client->config.mask_RY = result;
313                 break;
314         case MASK_GU:
315                 client->config.mask_GU = result;
316                 break;
317         case MASK_BV:
318                 client->config.mask_BV = result;
319                 break;
320         }
321         client->send_configure_change();
322         return 1;
323 }
324
325
326
327 SelTempAvgStartKeyframe::SelTempAvgStartKeyframe(SelTempAvgMain *client, int x, int y)
328  : BC_CheckBox(x, y, client->config.nosubtract, _("This Frame is a start of a section"))
329 {
330         this->client = client;
331 }
332 int SelTempAvgStartKeyframe::handle_event()
333 {
334         int result = get_value();
335         client->config.offset_restartmarker_keyframe = result;
336         client->send_configure_change();
337         return 1;
338 }