r745: Updated deinterlace patch by Jerome Cornet <jerome.cornet@gmail.com>
[cinelerra_cv/mob.git] / plugins / deinterlace / deinterwindow.C
blobc4691313dbae11c8a8ce658accc90cf2b1355b84
1 #include "bcdisplayinfo.h"
2 #include "deinterwindow.h"
3 #include <string.h>
5 #include <libintl.h>
6 #define _(String) gettext(String)
7 #define gettext_noop(String) String
8 #define N_(String) gettext_noop (String)
12 PLUGIN_THREAD_OBJECT(DeInterlaceMain, DeInterlaceThread, DeInterlaceWindow)
17 DeInterlaceWindow::DeInterlaceWindow(DeInterlaceMain *client, int x, int y)
18  : BC_Window(client->gui_string, 
19         x, 
20         y, 
21         400, 
22         200, 
23         400, 
24         200, 
25         0, 
26         0,
27         1)
28
29         this->client = client; 
30         adaptive=0; dominance_top=0; dominance_bottom=0; threshold=0;
34 DeInterlaceWindow::~DeInterlaceWindow()
38 int DeInterlaceWindow::create_objects()
40         int x = 10, y = 10;
41         add_tool(new BC_Title(x, y, _("Select deinterlacing mode")));
42         y += 25;
43         add_tool(mode = new DeInterlaceMode(client, this, x, y));
44         mode->create_objects();
45         y += 25;
46         optional_controls_x=x;
47         optional_controls_y=y;
48         y += 125;
49         char string[BCTEXTLEN];
50         get_status_string(string, 0);
51         add_tool(status = new BC_Title(x, y, string));
52         flash();
53         show_window();
54         set_mode(client->config.mode,0);
55         flush();
56         return 0;
59 WINDOW_CLOSE_EVENT(DeInterlaceWindow)
61 void DeInterlaceWindow::get_status_string(char *string, int changed_rows)
63         sprintf(string, _("Changed rows: %d\n"), changed_rows);
66 int DeInterlaceWindow::set_mode(int mode, int recursive)
68         int x,y;
69         client->config.mode = mode;
70         
71 /* Restore position of controls */
72         x=optional_controls_x;
73         y=optional_controls_y;
74         if (adaptive) { delete adaptive; adaptive=0; }
75         if (threshold) { delete threshold; threshold=0; }
76         if (dominance_top) { delete dominance_top; dominance_top=0; }
77         if (dominance_bottom) { delete dominance_bottom; dominance_bottom=0; }
79 /* Display Dominance controls */
80         switch (mode) 
81         {
82                 case DEINTERLACE_KEEP:
83                 case DEINTERLACE_BOBWEAVE:
84                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Keep top field")));
85                         y+=25;
86                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Keep bottom field")));
87                         y+=25;
88                         break;
89                 case DEINTERLACE_AVG_1F: 
90                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Average top fields")));
91                         y+=25;
92                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y,"Average bottom fields"));
93                         y+=25;
94                         break;
95                 case DEINTERLACE_SWAP:
96                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Top field first")));
97                         y+=25;
98                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Bottom field first")));
99                         y+=25;
100                         break;
101                 case DEINTERLACE_TEMPORALSWAP:
102                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Top field first")));
103                         y+=25;
104                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Bottom field first")));
105                         y+=25;
106                         break;
107                 case DEINTERLACE_NONE:
108                 case  DEINTERLACE_AVG:
109                 default:
110                         ;
111         }
113         if (dominance_top&&dominance_bottom)  {
114                 dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
115                 dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
116         }
117         
118 /* Display Threshold and adaptive controls */
119         switch (mode) {
120                 case  DEINTERLACE_AVG_1F:
121                         add_subwindow(adaptive = new DeInterlaceAdaptive(client, x, y));
123                         add_subwindow(threshold = new DeInterlaceThreshold(client, x + 150, y));
124                         add_subwindow(threshold->title_caption=new BC_Title(x+150, y + 50, _("Threshold")));
125                         adaptive->update(client->config.adaptive?BC_Toggle::TOGGLE_CHECKED:0);
126                         break;
127                 case DEINTERLACE_BOBWEAVE:
128                         add_subwindow(threshold = new DeInterlaceThreshold(client, x + 150, y));
129                         add_subwindow(threshold->title_caption=new BC_Title(x+150, y + 50, _("Bob Threshold")));
130                         break;
131                 case DEINTERLACE_NONE:
132                 case DEINTERLACE_KEEP:
133                 case DEINTERLACE_AVG:
134                 case DEINTERLACE_SWAP:
135                 case DEINTERLACE_TEMPORALSWAP:
136                 default:
138                 break;
139         }       
142         if(!recursive)
143                 client->send_configure_change();
144         return 0;
148 DeInterlaceOption::DeInterlaceOption(DeInterlaceMain *client, 
149                 DeInterlaceWindow *window, 
150                 int output, 
151                 int x, 
152                 int y, 
153                 char *text)
154  : BC_Radial(x, y, client->config.mode == output, text)
156         this->client = client;
157         this->window = window;
158         this->output = output;
161 DeInterlaceOption::~DeInterlaceOption()
164 int DeInterlaceOption::handle_event()
166         window->set_mode(output, 0); 
167         return 1;
171 DeInterlaceAdaptive::DeInterlaceAdaptive(DeInterlaceMain *client, int x, int y)
172  : BC_CheckBox(x, y, client->config.adaptive, _("Adaptive") )
174         this->client = client;
176 int DeInterlaceAdaptive::handle_event()
178         client->config.adaptive = get_value();
179         client->send_configure_change();
180         return 1;
183 DeInterlaceDominanceTop::DeInterlaceDominanceTop(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, char * title)
184  : BC_Radial(x, y, client->config.dominance, title)
186         this->client = client;
187         this->window = window;
190 int DeInterlaceDominanceTop::handle_event()
192         client->config.dominance = (get_value()==0);
193         window->dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
194         client->send_configure_change();
195         return 1;
199 DeInterlaceDominanceBottom::DeInterlaceDominanceBottom(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, char * title)
200  : BC_Radial(x, y, client->config.dominance, title)
202         this->client = client;
203         this->window = window;
205 int DeInterlaceDominanceBottom::handle_event()
208         client->config.dominance = (get_value() != 0 );
209         window->dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
210         client->send_configure_change();
211         return 1;
215 DeInterlaceThreshold::DeInterlaceThreshold(DeInterlaceMain *client, int x, int y)
216  : BC_IPot(x, y, client->config.threshold, 0, 100)
218         this->client = client;
219         title_caption=NULL;
221 int DeInterlaceThreshold::handle_event()
223         client->config.threshold = get_value();
224         client->send_configure_change();
225         return 1;
228 DeInterlaceThreshold::~DeInterlaceThreshold()
230   if (title_caption) delete title_caption;
233 DeInterlaceMode::DeInterlaceMode(DeInterlaceMain*plugin, 
234         DeInterlaceWindow *gui, 
235         int x, 
236         int y)
237  : BC_PopupMenu(x, y, 200, to_text(plugin->config.mode), 1)
239         this->plugin = plugin;
240         this->gui = gui;
242 void DeInterlaceMode::create_objects()
244         add_item(new BC_MenuItem(to_text(DEINTERLACE_NONE)));
245         add_item(new BC_MenuItem(to_text(DEINTERLACE_KEEP)));
246         add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG)));
247         add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG_1F)));
248         add_item(new BC_MenuItem(to_text(DEINTERLACE_BOBWEAVE)));
249         add_item(new BC_MenuItem(to_text(DEINTERLACE_SWAP)));
250         add_item(new BC_MenuItem(to_text(DEINTERLACE_TEMPORALSWAP)));
253 char* DeInterlaceMode::to_text(int mode)
255         switch(mode)
256         {
257                 case DEINTERLACE_KEEP:
258                         return _("Duplicate one field");
259                 case DEINTERLACE_AVG_1F:
260                         return _("Average one field");
261                 case DEINTERLACE_AVG:
262                         return _("Average both fields");
263                 case DEINTERLACE_BOBWEAVE:
264                         return _("Bob & Weave");
265                 case DEINTERLACE_SWAP:
266                         return _("Spatial field swap");
267                 case DEINTERLACE_TEMPORALSWAP:
268                         return _("Temporal field swap");
269                 default:
270                         return _("Do Nothing");
271         }
273 int DeInterlaceMode::from_text(char *text)
275         if(!strcmp(text, to_text(DEINTERLACE_KEEP))) 
276                 return DEINTERLACE_KEEP;
277         if(!strcmp(text, to_text(DEINTERLACE_AVG))) 
278                 return DEINTERLACE_AVG;
279         if(!strcmp(text, to_text(DEINTERLACE_AVG_1F))) 
280                 return DEINTERLACE_AVG_1F;
281         if(!strcmp(text, to_text(DEINTERLACE_BOBWEAVE))) 
282                 return DEINTERLACE_BOBWEAVE;
283         if(!strcmp(text, to_text(DEINTERLACE_SWAP))) 
284                 return DEINTERLACE_SWAP;
285         if(!strcmp(text, to_text(DEINTERLACE_TEMPORALSWAP))) 
286                 return DEINTERLACE_TEMPORALSWAP;
287         return DEINTERLACE_NONE;
290 int DeInterlaceMode::handle_event()
292         plugin->config.mode = from_text(get_text());
293         gui->set_mode(plugin->config.mode,0);
294         plugin->send_configure_change();