r870: Merge 2.1:
[cinelerra_cv.git] / plugins / deinterlace / deinterwindow.C
blobefee91c933e75a966054945c1e4e63fef5916800
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         return 0;
58 WINDOW_CLOSE_EVENT(DeInterlaceWindow)
60 void DeInterlaceWindow::get_status_string(char *string, int changed_rows)
62         sprintf(string, _("Changed rows: %d\n"), changed_rows);
65 int DeInterlaceWindow::set_mode(int mode, int recursive)
67         int x,y;
68         client->config.mode = mode;
69         
70 /* Restore position of controls */
71         x=optional_controls_x;
72         y=optional_controls_y;
73         if (adaptive) { delete adaptive; adaptive=0; }
74         if (threshold) { delete threshold; threshold=0; }
75         if (dominance_top) { delete dominance_top; dominance_top=0; }
76         if (dominance_bottom) { delete dominance_bottom; dominance_bottom=0; }
78 /* Display Dominance controls */
79         switch (mode) 
80         {
81                 case DEINTERLACE_KEEP:
82                 case DEINTERLACE_BOBWEAVE:
83                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Keep top field")));
84                         y+=25;
85                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Keep bottom field")));
86                         y+=25;
87                         break;
88                 case DEINTERLACE_AVG_1F: 
89                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Average top fields")));
90                         y+=25;
91                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y,"Average bottom fields"));
92                         y+=25;
93                         break;
94                 case DEINTERLACE_SWAP:
95                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Top field first")));
96                         y+=25;
97                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Bottom field first")));
98                         y+=25;
99                         break;
100                 case DEINTERLACE_TEMPORALSWAP:
101                         add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Top field first")));
102                         y+=25;
103                         add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Bottom field first")));
104                         y+=25;
105                         break;
106                 case DEINTERLACE_NONE:
107                 case  DEINTERLACE_AVG:
108                 default:
109                         ;
110         }
112         if (dominance_top&&dominance_bottom)  {
113                 dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
114                 dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
115         }
116         
117 /* Display Threshold and adaptive controls */
118         switch (mode) {
119                 case  DEINTERLACE_AVG_1F:
120                         add_subwindow(adaptive = new DeInterlaceAdaptive(client, x, y));
122                         add_subwindow(threshold = new DeInterlaceThreshold(client, x + 150, y));
123                         add_subwindow(threshold->title_caption=new BC_Title(x+150, y + 50, _("Threshold")));
124                         adaptive->update(client->config.adaptive?BC_Toggle::TOGGLE_CHECKED:0);
125                         break;
126                 case DEINTERLACE_BOBWEAVE:
127                         add_subwindow(threshold = new DeInterlaceThreshold(client, x + 150, y));
128                         add_subwindow(threshold->title_caption=new BC_Title(x+150, y + 50, _("Bob Threshold")));
129                         break;
130                 case DEINTERLACE_NONE:
131                 case DEINTERLACE_KEEP:
132                 case DEINTERLACE_AVG:
133                 case DEINTERLACE_SWAP:
134                 case DEINTERLACE_TEMPORALSWAP:
135                 default:
137                 break;
138         }       
141         if(!recursive)
142                 client->send_configure_change();
143         return 0;
147 DeInterlaceOption::DeInterlaceOption(DeInterlaceMain *client, 
148                 DeInterlaceWindow *window, 
149                 int output, 
150                 int x, 
151                 int y, 
152                 char *text)
153  : BC_Radial(x, y, client->config.mode == output, text)
155         this->client = client;
156         this->window = window;
157         this->output = output;
160 DeInterlaceOption::~DeInterlaceOption()
163 int DeInterlaceOption::handle_event()
165         window->set_mode(output, 0);
166         return 1;
170 DeInterlaceAdaptive::DeInterlaceAdaptive(DeInterlaceMain *client, int x, int y)
171  : BC_CheckBox(x, y, client->config.adaptive, _("Adaptive"))
173         this->client = client;
175 int DeInterlaceAdaptive::handle_event()
177         client->config.adaptive = get_value();
178         client->send_configure_change();
179         return 1;
182 DeInterlaceDominanceTop::DeInterlaceDominanceTop(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, char * title)
183  : BC_Radial(x, y, client->config.dominance, title)
185         this->client = client;
186         this->window = window;
189 int DeInterlaceDominanceTop::handle_event()
191         client->config.dominance = (get_value()==0);
192         window->dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
193         client->send_configure_change();
194         return 1;
198 DeInterlaceDominanceBottom::DeInterlaceDominanceBottom(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, char * title)
199  : BC_Radial(x, y, client->config.dominance, title)
201         this->client = client;
202         this->window = window;
204 int DeInterlaceDominanceBottom::handle_event()
207         client->config.dominance = (get_value() != 0 );
208         window->dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
209         client->send_configure_change();
210         return 1;
214 DeInterlaceThreshold::DeInterlaceThreshold(DeInterlaceMain *client, int x, int y)
215  : BC_IPot(x, y, client->config.threshold, 0, 100)
217         this->client = client;
218         title_caption=NULL;
220 int DeInterlaceThreshold::handle_event()
222         client->config.threshold = get_value();
223         client->send_configure_change();
224         return 1;
227 DeInterlaceThreshold::~DeInterlaceThreshold()
229   if (title_caption) delete title_caption;
232 DeInterlaceMode::DeInterlaceMode(DeInterlaceMain*plugin, 
233         DeInterlaceWindow *gui, 
234         int x, 
235         int y)
236  : BC_PopupMenu(x, y, 200, to_text(plugin->config.mode), 1)
238         this->plugin = plugin;
239         this->gui = gui;
241 void DeInterlaceMode::create_objects()
243         add_item(new BC_MenuItem(to_text(DEINTERLACE_NONE)));
244         add_item(new BC_MenuItem(to_text(DEINTERLACE_KEEP)));
245         add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG)));
246         add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG_1F)));
247         add_item(new BC_MenuItem(to_text(DEINTERLACE_BOBWEAVE)));
248         add_item(new BC_MenuItem(to_text(DEINTERLACE_SWAP)));
249         add_item(new BC_MenuItem(to_text(DEINTERLACE_TEMPORALSWAP)));
252 char* DeInterlaceMode::to_text(int mode)
254         switch(mode)
255         {
256                 case DEINTERLACE_KEEP:
257                         return _("Duplicate one field");
258                 case DEINTERLACE_AVG_1F:
259                         return _("Average one field");
260                 case DEINTERLACE_AVG:
261                         return _("Average both fields");
262                 case DEINTERLACE_BOBWEAVE:
263                         return _("Bob & Weave");
264                 case DEINTERLACE_SWAP:
265                         return _("Spatial field swap");
266                 case DEINTERLACE_TEMPORALSWAP:
267                         return _("Temporal field swap");
268                 default:
269                         return _("Do Nothing");
270         }
272 int DeInterlaceMode::from_text(char *text)
274         if(!strcmp(text, to_text(DEINTERLACE_KEEP))) 
275                 return DEINTERLACE_KEEP;
276         if(!strcmp(text, to_text(DEINTERLACE_AVG))) 
277                 return DEINTERLACE_AVG;
278         if(!strcmp(text, to_text(DEINTERLACE_AVG_1F))) 
279                 return DEINTERLACE_AVG_1F;
280         if(!strcmp(text, to_text(DEINTERLACE_BOBWEAVE))) 
281                 return DEINTERLACE_BOBWEAVE;
282         if(!strcmp(text, to_text(DEINTERLACE_SWAP))) 
283                 return DEINTERLACE_SWAP;
284         if(!strcmp(text, to_text(DEINTERLACE_TEMPORALSWAP))) 
285                 return DEINTERLACE_TEMPORALSWAP;
286         return DEINTERLACE_NONE;
289 int DeInterlaceMode::handle_event()
291         plugin->config.mode = from_text(get_text());
292         gui->set_mode(plugin->config.mode,0);
293         plugin->send_configure_change();