Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / deinterlace-cv / deinterwindow-cv.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #include "bcdisplayinfo.h"
24 #include "deinterwindow-cv.h"
25 #include "language.h"
26 #include <string.h>
27
28
29 DeInterlaceWindow::DeInterlaceWindow(DeInterlaceMain *client)
30  : PluginClientWindow(client,
31         xS(400),
32         yS(200),
33         xS(400),
34         yS(200),
35         0)
36 {
37         this->client = client;
38         adaptive=0; dominance_top=0; dominance_bottom=0; threshold=0;
39
40 }
41
42 DeInterlaceWindow::~DeInterlaceWindow()
43 {
44 }
45
46 void DeInterlaceWindow::create_objects()
47 {
48         int xs10 = xS(10);
49         int ys10 = yS(10), ys25 = yS(25);
50         int x = xs10, y = ys10;
51         add_tool(new BC_Title(x, y, _("Select deinterlacing mode")));
52         y += ys25;
53         add_tool(mode = new DeInterlaceMode(client, this, x, y));
54         mode->create_objects();
55         y += ys25;
56         optional_controls_x=x;
57         optional_controls_y=y;
58         y += yS(125);
59         char string[BCTEXTLEN];
60         get_status_string(string, 0);
61         add_tool(status = new BC_Title(x, y, string));
62         flash();
63         show_window();
64         set_mode(client->config.mode, 1);
65 }
66
67 void DeInterlaceWindow::get_status_string(char *string, int changed_rows)
68 {
69         sprintf(string, _("Changed rows: %d\n"), changed_rows);
70 }
71
72 int DeInterlaceWindow::set_mode(int mode, int recursive)
73 {
74         int x,y;
75         client->config.mode = mode;
76
77 /* Restore position of controls */
78         x=optional_controls_x;
79         y=optional_controls_y;
80         if (adaptive) { delete adaptive; adaptive=0; }
81         if (threshold) { delete threshold; threshold=0; }
82         if (dominance_top) { delete dominance_top; dominance_top=0; }
83         if (dominance_bottom) { delete dominance_bottom; dominance_bottom=0; }
84
85 /* Display Dominance controls */
86         switch (mode)
87         {
88                 case DEINTERLACE_KEEP:
89                 case DEINTERLACE_BOBWEAVE:
90                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Keep top field")));
91                         y+=yS(25);
92                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Keep bottom field")));
93                         y+=yS(25);
94                         break;
95                 case DEINTERLACE_AVG_1F:
96                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Average top fields")));
97                         y+=yS(25);
98                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y,_("Average bottom fields")));
99                         y+=yS(25);
100                         break;
101                 case DEINTERLACE_SWAP:
102                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Top field first")));
103                         y+=yS(25);
104                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Bottom field first")));
105                         y+=yS(25);
106                         break;
107                 case DEINTERLACE_TEMPORALSWAP:
108                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Top field first")));
109                         y+=yS(25);
110                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Bottom field first")));
111                         y+=yS(25);
112                         break;
113                 case DEINTERLACE_NONE:
114                 case  DEINTERLACE_AVG:
115                 default:
116                         ;
117         }
118
119         if (dominance_top&&dominance_bottom)  {
120                 dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
121                 dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
122         }
123
124 /* Display Threshold and adaptive controls */
125         switch (mode) {
126                 case  DEINTERLACE_AVG_1F:
127                         add_subwindow(adaptive = new DeInterlaceAdaptive(client, x, y));
128
129                         add_subwindow(threshold = new DeInterlaceThreshold(client, x + xS(150), y));
130                         add_subwindow(threshold->title_caption=new BC_Title(x+xS(150), y + yS(50), _("Threshold")));
131                         threshold->show_window(0);
132                         adaptive->update(client->config.adaptive?BC_Toggle::TOGGLE_CHECKED:0);
133                         break;
134                 case DEINTERLACE_BOBWEAVE:
135                         add_subwindow(threshold = new DeInterlaceThreshold(client, x + xS(150), y));
136                         add_subwindow(threshold->title_caption=new BC_Title(x+xS(150), y + yS(50), _("Bob Threshold")));
137                         threshold->show_window(0);
138                         break;
139                 case DEINTERLACE_NONE:
140                 case DEINTERLACE_KEEP:
141                 case DEINTERLACE_AVG:
142                 case DEINTERLACE_SWAP:
143                 case DEINTERLACE_TEMPORALSWAP:
144                 default:
145
146                 break;
147         }
148
149
150         if(!recursive)
151                 client->send_configure_change();
152         return 0;
153 }
154
155
156 DeInterlaceOption::DeInterlaceOption(DeInterlaceMain *client,
157                 DeInterlaceWindow *window,
158                 int output,
159                 int x,
160                 int y,
161                 char *text)
162  : BC_Radial(x, y, client->config.mode == output, text)
163 {
164         this->client = client;
165         this->window = window;
166         this->output = output;
167 }
168
169 DeInterlaceOption::~DeInterlaceOption()
170 {
171 }
172 int DeInterlaceOption::handle_event()
173 {
174         window->set_mode(output, 0);
175         return 1;
176 }
177
178
179 DeInterlaceAdaptive::DeInterlaceAdaptive(DeInterlaceMain *client, int x, int y)
180  : BC_CheckBox(x, y, client->config.adaptive, _("Adaptive"))
181 {
182         this->client = client;
183 }
184 int DeInterlaceAdaptive::handle_event()
185 {
186         client->config.adaptive = get_value();
187         client->send_configure_change();
188         return 1;
189 }
190
191 DeInterlaceDominanceTop::DeInterlaceDominanceTop(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, char * title)
192  : BC_Radial(x, y, client->config.dominance, title)
193 {
194         this->client = client;
195         this->window = window;
196
197 }
198 int DeInterlaceDominanceTop::handle_event()
199 {
200         client->config.dominance = (get_value()==0);
201         window->dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
202         client->send_configure_change();
203         return 1;
204 }
205
206
207 DeInterlaceDominanceBottom::DeInterlaceDominanceBottom(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, const char * title)
208  : BC_Radial(x, y, client->config.dominance, title)
209 {
210         this->client = client;
211         this->window = window;
212 }
213 int DeInterlaceDominanceBottom::handle_event()
214 {
215
216         client->config.dominance = (get_value() != 0 );
217         window->dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
218         client->send_configure_change();
219         return 1;
220 }
221
222
223 DeInterlaceThreshold::DeInterlaceThreshold(DeInterlaceMain *client, int x, int y)
224  : BC_IPot(x, y, client->config.threshold, 0, 100)
225 {
226         this->client = client;
227         title_caption=NULL;
228 }
229 int DeInterlaceThreshold::handle_event()
230 {
231         client->config.threshold = get_value();
232         client->send_configure_change();
233         return 1;
234 }
235
236 DeInterlaceThreshold::~DeInterlaceThreshold()
237 {
238   if (title_caption) delete title_caption;
239 }
240
241 DeInterlaceMode::DeInterlaceMode(DeInterlaceMain*plugin,
242         DeInterlaceWindow *gui,
243         int x,
244         int y)
245  : BC_PopupMenu(x, y, xS(200), to_text(plugin->config.mode), 1)
246 {
247         this->plugin = plugin;
248         this->gui = gui;
249 }
250 void DeInterlaceMode::create_objects()
251 {
252         add_item(new BC_MenuItem(to_text(DEINTERLACE_NONE)));
253         add_item(new BC_MenuItem(to_text(DEINTERLACE_KEEP)));
254         add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG)));
255         add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG_1F)));
256         add_item(new BC_MenuItem(to_text(DEINTERLACE_BOBWEAVE)));
257         add_item(new BC_MenuItem(to_text(DEINTERLACE_SWAP)));
258         add_item(new BC_MenuItem(to_text(DEINTERLACE_TEMPORALSWAP)));
259 }
260
261 char* DeInterlaceMode::to_text(int mode)
262 {
263         switch(mode)
264         {
265                 case DEINTERLACE_KEEP:
266                         return _("Duplicate one field");
267                 case DEINTERLACE_AVG_1F:
268                         return _("Average one field");
269                 case DEINTERLACE_AVG:
270                         return _("Average both fields");
271                 case DEINTERLACE_BOBWEAVE:
272                         return _("Bob & Weave");
273                 case DEINTERLACE_SWAP:
274                         return _("Spatial field swap");
275                 case DEINTERLACE_TEMPORALSWAP:
276                         return _("Temporal field swap");
277                 default:
278                         return _("Do Nothing");
279         }
280 }
281 int DeInterlaceMode::from_text(char *text)
282 {
283         if(!strcmp(text, to_text(DEINTERLACE_KEEP)))
284                 return DEINTERLACE_KEEP;
285         if(!strcmp(text, to_text(DEINTERLACE_AVG)))
286                 return DEINTERLACE_AVG;
287         if(!strcmp(text, to_text(DEINTERLACE_AVG_1F)))
288                 return DEINTERLACE_AVG_1F;
289         if(!strcmp(text, to_text(DEINTERLACE_BOBWEAVE)))
290                 return DEINTERLACE_BOBWEAVE;
291         if(!strcmp(text, to_text(DEINTERLACE_SWAP)))
292                 return DEINTERLACE_SWAP;
293         if(!strcmp(text, to_text(DEINTERLACE_TEMPORALSWAP)))
294                 return DEINTERLACE_TEMPORALSWAP;
295         return DEINTERLACE_NONE;
296 }
297
298 int DeInterlaceMode::handle_event()
299 {
300         plugin->config.mode = from_text(get_text());
301         gui->set_mode(plugin->config.mode,0);
302         plugin->send_configure_change();
303         return 1;
304 }
305
306
307