add new av-opts files from andrew, fix copy/paste segv for clip folder, fix deinterla...
[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  *
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 "deinterwindow-cv.h"
24 #include "language.h"
25 #include <string.h>
26
27
28 DeInterlaceWindow::DeInterlaceWindow(DeInterlaceMain *client)
29  : PluginClientWindow(client,
30         xS(400),
31         yS(200),
32         xS(400),
33         yS(200),
34         0)
35 {
36         this->client = client;
37         adaptive=0; dominance_top=0; dominance_bottom=0; threshold=0;
38
39 }
40
41 DeInterlaceWindow::~DeInterlaceWindow()
42 {
43 }
44
45 void DeInterlaceWindow::create_objects()
46 {
47         int xs10 = xS(10);
48         int ys10 = yS(10), ys25 = yS(25);
49         int x = xs10, y = ys10;
50         add_tool(new BC_Title(x, y, _("Select deinterlacing mode")));
51         y += ys25;
52         add_tool(mode = new DeInterlaceMode(client, this, x, y));
53         mode->create_objects();
54         y += ys25;
55         optional_controls_x=x;
56         optional_controls_y=y;
57         y += yS(125);
58         char string[BCTEXTLEN];
59         get_status_string(string, 0);
60         add_tool(status = new BC_Title(x, y, string));
61         flash();
62         show_window();
63         set_mode(client->config.mode, 1);
64 }
65
66 void DeInterlaceWindow::get_status_string(char *string, int changed_rows)
67 {
68         sprintf(string, _("Changed rows: %d\n"), changed_rows);
69 }
70
71 int DeInterlaceWindow::set_mode(int mode, int recursive)
72 {
73         int x,y;
74         client->config.mode = mode;
75
76 /* Restore position of controls */
77         x=optional_controls_x;
78         y=optional_controls_y;
79         if (adaptive) { delete adaptive; adaptive=0; }
80         if (threshold) { delete threshold; threshold=0; }
81         if (dominance_top) { delete dominance_top; dominance_top=0; }
82         if (dominance_bottom) { delete dominance_bottom; dominance_bottom=0; }
83
84 /* Display Dominance controls */
85         switch (mode)
86         {
87                 case DEINTERLACE_KEEP:
88                 case DEINTERLACE_BOBWEAVE:
89                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Keep top field")));
90                         y+=yS(25);
91                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Keep bottom field")));
92                         y+=yS(25);
93                         break;
94                 case DEINTERLACE_AVG_1F:
95                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Average top fields")));
96                         y+=yS(25);
97                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y,_("Average bottom fields")));
98                         y+=yS(25);
99                         break;
100                 case DEINTERLACE_SWAP:
101                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Top field first")));
102                         y+=yS(25);
103                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Bottom field first")));
104                         y+=yS(25);
105                         break;
106                 case DEINTERLACE_TEMPORALSWAP:
107                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Top field first")));
108                         y+=yS(25);
109                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Bottom field first")));
110                         y+=yS(25);
111                         break;
112                 case DEINTERLACE_NONE:
113                 case  DEINTERLACE_AVG:
114                 default:
115                         ;
116         }
117
118         if (dominance_top&&dominance_bottom)  {
119                 dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
120                 dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
121         }
122
123 /* Display Threshold and adaptive controls */
124         switch (mode) {
125                 case  DEINTERLACE_AVG_1F:
126                         add_subwindow(adaptive = new DeInterlaceAdaptive(client, x, y));
127
128                         add_subwindow(threshold = new DeInterlaceThreshold(client, x + xS(150), y));
129                         add_subwindow(threshold->title_caption=new BC_Title(x+xS(150), y + yS(50), _("Threshold")));
130                         threshold->show_window(0);
131                         adaptive->update(client->config.adaptive?BC_Toggle::TOGGLE_CHECKED:0);
132                         break;
133                 case DEINTERLACE_BOBWEAVE:
134                         add_subwindow(threshold = new DeInterlaceThreshold(client, x + xS(150), y));
135                         add_subwindow(threshold->title_caption=new BC_Title(x+xS(150), y + yS(50), _("Bob Threshold")));
136                         threshold->show_window(0);
137                         break;
138                 case DEINTERLACE_NONE:
139                 case DEINTERLACE_KEEP:
140                 case DEINTERLACE_AVG:
141                 case DEINTERLACE_SWAP:
142                 case DEINTERLACE_TEMPORALSWAP:
143                 default:
144
145                 break;
146         }
147
148
149         if(!recursive)
150                 client->send_configure_change();
151         return 0;
152 }
153
154
155 DeInterlaceOption::DeInterlaceOption(DeInterlaceMain *client,
156                 DeInterlaceWindow *window,
157                 int output,
158                 int x,
159                 int y,
160                 char *text)
161  : BC_Radial(x, y, client->config.mode == output, text)
162 {
163         this->client = client;
164         this->window = window;
165         this->output = output;
166 }
167
168 DeInterlaceOption::~DeInterlaceOption()
169 {
170 }
171 int DeInterlaceOption::handle_event()
172 {
173         window->set_mode(output, 0);
174         return 1;
175 }
176
177
178 DeInterlaceAdaptive::DeInterlaceAdaptive(DeInterlaceMain *client, int x, int y)
179  : BC_CheckBox(x, y, client->config.adaptive, _("Adaptive"))
180 {
181         this->client = client;
182 }
183 int DeInterlaceAdaptive::handle_event()
184 {
185         client->config.adaptive = get_value();
186         client->send_configure_change();
187         return 1;
188 }
189
190 DeInterlaceDominanceTop::DeInterlaceDominanceTop(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, char * title)
191  : BC_Radial(x, y, client->config.dominance, title)
192 {
193         this->client = client;
194         this->window = window;
195
196 }
197 int DeInterlaceDominanceTop::handle_event()
198 {
199         client->config.dominance = (get_value()==0);
200         window->dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
201         client->send_configure_change();
202         return 1;
203 }
204
205
206 DeInterlaceDominanceBottom::DeInterlaceDominanceBottom(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, const char * title)
207  : BC_Radial(x, y, client->config.dominance, title)
208 {
209         this->client = client;
210         this->window = window;
211 }
212 int DeInterlaceDominanceBottom::handle_event()
213 {
214
215         client->config.dominance = (get_value() != 0 );
216         window->dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
217         client->send_configure_change();
218         return 1;
219 }
220
221
222 DeInterlaceThreshold::DeInterlaceThreshold(DeInterlaceMain *client, int x, int y)
223  : BC_IPot(x, y, client->config.threshold, 0, 100)
224 {
225         this->client = client;
226         title_caption=NULL;
227 }
228 int DeInterlaceThreshold::handle_event()
229 {
230         client->config.threshold = get_value();
231         client->send_configure_change();
232         return 1;
233 }
234
235 DeInterlaceThreshold::~DeInterlaceThreshold()
236 {
237   if (title_caption) delete title_caption;
238 }
239
240 DeInterlaceMode::DeInterlaceMode(DeInterlaceMain*plugin,
241         DeInterlaceWindow *gui,
242         int x,
243         int y)
244  : BC_PopupMenu(x, y, xS(200), to_text(plugin->config.mode), 1)
245 {
246         this->plugin = plugin;
247         this->gui = gui;
248 }
249 void DeInterlaceMode::create_objects()
250 {
251         add_item(new BC_MenuItem(to_text(DEINTERLACE_NONE)));
252         add_item(new BC_MenuItem(to_text(DEINTERLACE_KEEP)));
253         add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG)));
254         add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG_1F)));
255         add_item(new BC_MenuItem(to_text(DEINTERLACE_BOBWEAVE)));
256         add_item(new BC_MenuItem(to_text(DEINTERLACE_SWAP)));
257         add_item(new BC_MenuItem(to_text(DEINTERLACE_TEMPORALSWAP)));
258 }
259
260 char* DeInterlaceMode::to_text(int mode)
261 {
262         switch(mode)
263         {
264                 case DEINTERLACE_KEEP:
265                         return _("Duplicate one field");
266                 case DEINTERLACE_AVG_1F:
267                         return _("Average one field");
268                 case DEINTERLACE_AVG:
269                         return _("Average both fields");
270                 case DEINTERLACE_BOBWEAVE:
271                         return _("Bob & Weave");
272                 case DEINTERLACE_SWAP:
273                         return _("Spatial field swap");
274                 case DEINTERLACE_TEMPORALSWAP:
275                         return _("Temporal field swap");
276                 default:
277                         return _("Do Nothing");
278         }
279 }
280 int DeInterlaceMode::from_text(char *text)
281 {
282         if(!strcmp(text, to_text(DEINTERLACE_KEEP)))
283                 return DEINTERLACE_KEEP;
284         if(!strcmp(text, to_text(DEINTERLACE_AVG)))
285                 return DEINTERLACE_AVG;
286         if(!strcmp(text, to_text(DEINTERLACE_AVG_1F)))
287                 return DEINTERLACE_AVG_1F;
288         if(!strcmp(text, to_text(DEINTERLACE_BOBWEAVE)))
289                 return DEINTERLACE_BOBWEAVE;
290         if(!strcmp(text, to_text(DEINTERLACE_SWAP)))
291                 return DEINTERLACE_SWAP;
292         if(!strcmp(text, to_text(DEINTERLACE_TEMPORALSWAP)))
293                 return DEINTERLACE_TEMPORALSWAP;
294         return DEINTERLACE_NONE;
295 }
296
297 int DeInterlaceMode::handle_event()
298 {
299         plugin->config.mode = from_text(get_text());
300         gui->set_mode(plugin->config.mode,0);
301         plugin->send_configure_change();
302         return 1;
303 }
304
305
306