add BC_SCALE env var for hi def monitors, cleanup theme data
[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,0);
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                         adaptive->update(client->config.adaptive?BC_Toggle::TOGGLE_CHECKED:0);
131                         break;
132                 case DEINTERLACE_BOBWEAVE:
133                         add_subwindow(threshold = new DeInterlaceThreshold(client, x + xS(150), y));
134                         add_subwindow(threshold->title_caption=new BC_Title(x+xS(150), y + yS(50), _("Bob Threshold")));
135                         break;
136                 case DEINTERLACE_NONE:
137                 case DEINTERLACE_KEEP:
138                 case DEINTERLACE_AVG:
139                 case DEINTERLACE_SWAP:
140                 case DEINTERLACE_TEMPORALSWAP:
141                 default:
142
143                 break;
144         }
145
146
147         if(!recursive)
148                 client->send_configure_change();
149         return 0;
150 }
151
152
153 DeInterlaceOption::DeInterlaceOption(DeInterlaceMain *client,
154                 DeInterlaceWindow *window,
155                 int output,
156                 int x,
157                 int y,
158                 char *text)
159  : BC_Radial(x, y, client->config.mode == output, text)
160 {
161         this->client = client;
162         this->window = window;
163         this->output = output;
164 }
165
166 DeInterlaceOption::~DeInterlaceOption()
167 {
168 }
169 int DeInterlaceOption::handle_event()
170 {
171         window->set_mode(output, 0);
172         return 1;
173 }
174
175
176 DeInterlaceAdaptive::DeInterlaceAdaptive(DeInterlaceMain *client, int x, int y)
177  : BC_CheckBox(x, y, client->config.adaptive, _("Adaptive"))
178 {
179         this->client = client;
180 }
181 int DeInterlaceAdaptive::handle_event()
182 {
183         client->config.adaptive = get_value();
184         client->send_configure_change();
185         return 1;
186 }
187
188 DeInterlaceDominanceTop::DeInterlaceDominanceTop(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, char * title)
189  : BC_Radial(x, y, client->config.dominance, title)
190 {
191         this->client = client;
192         this->window = window;
193
194 }
195 int DeInterlaceDominanceTop::handle_event()
196 {
197         client->config.dominance = (get_value()==0);
198         window->dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
199         client->send_configure_change();
200         return 1;
201 }
202
203
204 DeInterlaceDominanceBottom::DeInterlaceDominanceBottom(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, const char * title)
205  : BC_Radial(x, y, client->config.dominance, title)
206 {
207         this->client = client;
208         this->window = window;
209 }
210 int DeInterlaceDominanceBottom::handle_event()
211 {
212
213         client->config.dominance = (get_value() != 0 );
214         window->dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
215         client->send_configure_change();
216         return 1;
217 }
218
219
220 DeInterlaceThreshold::DeInterlaceThreshold(DeInterlaceMain *client, int x, int y)
221  : BC_IPot(x, y, client->config.threshold, 0, 100)
222 {
223         this->client = client;
224         title_caption=NULL;
225 }
226 int DeInterlaceThreshold::handle_event()
227 {
228         client->config.threshold = get_value();
229         client->send_configure_change();
230         return 1;
231 }
232
233 DeInterlaceThreshold::~DeInterlaceThreshold()
234 {
235   if (title_caption) delete title_caption;
236 }
237
238 DeInterlaceMode::DeInterlaceMode(DeInterlaceMain*plugin,
239         DeInterlaceWindow *gui,
240         int x,
241         int y)
242  : BC_PopupMenu(x, y, xS(200), to_text(plugin->config.mode), 1)
243 {
244         this->plugin = plugin;
245         this->gui = gui;
246 }
247 void DeInterlaceMode::create_objects()
248 {
249         add_item(new BC_MenuItem(to_text(DEINTERLACE_NONE)));
250         add_item(new BC_MenuItem(to_text(DEINTERLACE_KEEP)));
251         add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG)));
252         add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG_1F)));
253         add_item(new BC_MenuItem(to_text(DEINTERLACE_BOBWEAVE)));
254         add_item(new BC_MenuItem(to_text(DEINTERLACE_SWAP)));
255         add_item(new BC_MenuItem(to_text(DEINTERLACE_TEMPORALSWAP)));
256 }
257
258 char* DeInterlaceMode::to_text(int mode)
259 {
260         switch(mode)
261         {
262                 case DEINTERLACE_KEEP:
263                         return _("Duplicate one field");
264                 case DEINTERLACE_AVG_1F:
265                         return _("Average one field");
266                 case DEINTERLACE_AVG:
267                         return _("Average both fields");
268                 case DEINTERLACE_BOBWEAVE:
269                         return _("Bob & Weave");
270                 case DEINTERLACE_SWAP:
271                         return _("Spatial field swap");
272                 case DEINTERLACE_TEMPORALSWAP:
273                         return _("Temporal field swap");
274                 default:
275                         return _("Do Nothing");
276         }
277 }
278 int DeInterlaceMode::from_text(char *text)
279 {
280         if(!strcmp(text, to_text(DEINTERLACE_KEEP)))
281                 return DEINTERLACE_KEEP;
282         if(!strcmp(text, to_text(DEINTERLACE_AVG)))
283                 return DEINTERLACE_AVG;
284         if(!strcmp(text, to_text(DEINTERLACE_AVG_1F)))
285                 return DEINTERLACE_AVG_1F;
286         if(!strcmp(text, to_text(DEINTERLACE_BOBWEAVE)))
287                 return DEINTERLACE_BOBWEAVE;
288         if(!strcmp(text, to_text(DEINTERLACE_SWAP)))
289                 return DEINTERLACE_SWAP;
290         if(!strcmp(text, to_text(DEINTERLACE_TEMPORALSWAP)))
291                 return DEINTERLACE_TEMPORALSWAP;
292         return DEINTERLACE_NONE;
293 }
294
295 int DeInterlaceMode::handle_event()
296 {
297         plugin->config.mode = from_text(get_text());
298         gui->set_mode(plugin->config.mode,0);
299         plugin->send_configure_change();
300         return 1;
301 }
302
303
304