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