00001 #include "bcdisplayinfo.h"
00002 #include "deinterwindow.h"
00003 #include <string.h>
00004
00005 #include <libintl.h>
00006 #define _(String) gettext(String)
00007 #define gettext_noop(String) String
00008 #define N_(String) gettext_noop (String)
00009
00010
00011
00012 PLUGIN_THREAD_OBJECT(DeInterlaceMain, DeInterlaceThread, DeInterlaceWindow)
00013
00014
00015
00016
00017 DeInterlaceWindow::DeInterlaceWindow(DeInterlaceMain *client, int x, int y)
00018 : BC_Window(client->gui_string,
00019 x,
00020 y,
00021 400,
00022 200,
00023 400,
00024 200,
00025 0,
00026 0,
00027 1)
00028 {
00029 this->client = client;
00030 adaptive=0; dominance_top=0; dominance_bottom=0; threshold=0;
00031
00032 }
00033
00034 DeInterlaceWindow::~DeInterlaceWindow()
00035 {
00036 }
00037
00038 int DeInterlaceWindow::create_objects()
00039 {
00040 int x = 10, y = 10;
00041 add_tool(new BC_Title(x, y, _("Select deinterlacing mode")));
00042 y += 25;
00043 add_tool(mode = new DeInterlaceMode(client, this, x, y));
00044 mode->create_objects();
00045 y += 25;
00046 optional_controls_x=x;
00047 optional_controls_y=y;
00048 y += 125;
00049 char string[BCTEXTLEN];
00050 get_status_string(string, 0);
00051 add_tool(status = new BC_Title(x, y, string));
00052 flash();
00053 show_window();
00054 set_mode(client->config.mode,0);
00055 return 0;
00056 }
00057
00058 WINDOW_CLOSE_EVENT(DeInterlaceWindow)
00059
00060 void DeInterlaceWindow::get_status_string(char *string, int changed_rows)
00061 {
00062 sprintf(string, _("Changed rows: %d\n"), changed_rows);
00063 }
00064
00065 int DeInterlaceWindow::set_mode(int mode, int recursive)
00066 {
00067 int x,y;
00068 client->config.mode = mode;
00069
00070
00071 x=optional_controls_x;
00072 y=optional_controls_y;
00073 if (adaptive) { delete adaptive; adaptive=0; }
00074 if (threshold) { delete threshold; threshold=0; }
00075 if (dominance_top) { delete dominance_top; dominance_top=0; }
00076 if (dominance_bottom) { delete dominance_bottom; dominance_bottom=0; }
00077
00078
00079 switch (mode)
00080 {
00081 case DEINTERLACE_KEEP:
00082 case DEINTERLACE_BOBWEAVE:
00083 add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Keep top field")));
00084 y+=25;
00085 add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Keep bottom field")));
00086 y+=25;
00087 break;
00088 case DEINTERLACE_AVG_1F:
00089 add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Average top fields")));
00090 y+=25;
00091 add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y,"Average bottom fields"));
00092 y+=25;
00093 break;
00094 case DEINTERLACE_SWAP:
00095 add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Top field first")));
00096 y+=25;
00097 add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Bottom field first")));
00098 y+=25;
00099 break;
00100 case DEINTERLACE_TEMPORALSWAP:
00101 add_subwindow(dominance_top = new DeInterlaceDominanceTop(client, this, x, y, _("Top field first")));
00102 y+=25;
00103 add_subwindow(dominance_bottom = new DeInterlaceDominanceBottom(client, this, x, y, _("Bottom field first")));
00104 y+=25;
00105 break;
00106 case DEINTERLACE_NONE:
00107 case DEINTERLACE_AVG:
00108 default:
00109 ;
00110 }
00111
00112 if (dominance_top&&dominance_bottom) {
00113 dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
00114 dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
00115 }
00116
00117
00118 switch (mode) {
00119 case DEINTERLACE_AVG_1F:
00120 add_subwindow(adaptive = new DeInterlaceAdaptive(client, x, y));
00121
00122 add_subwindow(threshold = new DeInterlaceThreshold(client, x + 150, y));
00123 add_subwindow(threshold->title_caption=new BC_Title(x+150, y + 50, _("Threshold")));
00124 adaptive->update(client->config.adaptive?BC_Toggle::TOGGLE_CHECKED:0);
00125 break;
00126 case DEINTERLACE_BOBWEAVE:
00127 add_subwindow(threshold = new DeInterlaceThreshold(client, x + 150, y));
00128 add_subwindow(threshold->title_caption=new BC_Title(x+150, y + 50, _("Bob Threshold")));
00129 break;
00130 case DEINTERLACE_NONE:
00131 case DEINTERLACE_KEEP:
00132 case DEINTERLACE_AVG:
00133 case DEINTERLACE_SWAP:
00134 case DEINTERLACE_TEMPORALSWAP:
00135 default:
00136
00137 break;
00138 }
00139
00140
00141 if(!recursive)
00142 client->send_configure_change();
00143 return 0;
00144 }
00145
00146
00147 DeInterlaceOption::DeInterlaceOption(DeInterlaceMain *client,
00148 DeInterlaceWindow *window,
00149 int output,
00150 int x,
00151 int y,
00152 char *text)
00153 : BC_Radial(x, y, client->config.mode == output, text)
00154 {
00155 this->client = client;
00156 this->window = window;
00157 this->output = output;
00158 }
00159
00160 DeInterlaceOption::~DeInterlaceOption()
00161 {
00162 }
00163 int DeInterlaceOption::handle_event()
00164 {
00165 window->set_mode(output, 0);
00166 return 1;
00167 }
00168
00169
00170 DeInterlaceAdaptive::DeInterlaceAdaptive(DeInterlaceMain *client, int x, int y)
00171 : BC_CheckBox(x, y, client->config.adaptive, _("Adaptive"))
00172 {
00173 this->client = client;
00174 }
00175 int DeInterlaceAdaptive::handle_event()
00176 {
00177 client->config.adaptive = get_value();
00178 client->send_configure_change();
00179 return 1;
00180 }
00181
00182 DeInterlaceDominanceTop::DeInterlaceDominanceTop(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, char * title)
00183 : BC_Radial(x, y, client->config.dominance, title)
00184 {
00185 this->client = client;
00186 this->window = window;
00187
00188 }
00189 int DeInterlaceDominanceTop::handle_event()
00190 {
00191 client->config.dominance = (get_value()==0);
00192 window->dominance_bottom->update(client->config.dominance?BC_Toggle::TOGGLE_CHECKED:0);
00193 client->send_configure_change();
00194 return 1;
00195 }
00196
00197
00198 DeInterlaceDominanceBottom::DeInterlaceDominanceBottom(DeInterlaceMain *client, DeInterlaceWindow *window, int x, int y, char * title)
00199 : BC_Radial(x, y, client->config.dominance, title)
00200 {
00201 this->client = client;
00202 this->window = window;
00203 }
00204 int DeInterlaceDominanceBottom::handle_event()
00205 {
00206
00207 client->config.dominance = (get_value() != 0 );
00208 window->dominance_top->update(client->config.dominance?0:BC_Toggle::TOGGLE_CHECKED);
00209 client->send_configure_change();
00210 return 1;
00211 }
00212
00213
00214 DeInterlaceThreshold::DeInterlaceThreshold(DeInterlaceMain *client, int x, int y)
00215 : BC_IPot(x, y, client->config.threshold, 0, 100)
00216 {
00217 this->client = client;
00218 title_caption=NULL;
00219 }
00220 int DeInterlaceThreshold::handle_event()
00221 {
00222 client->config.threshold = get_value();
00223 client->send_configure_change();
00224 return 1;
00225 }
00226
00227 DeInterlaceThreshold::~DeInterlaceThreshold()
00228 {
00229 if (title_caption) delete title_caption;
00230 }
00231
00232 DeInterlaceMode::DeInterlaceMode(DeInterlaceMain*plugin,
00233 DeInterlaceWindow *gui,
00234 int x,
00235 int y)
00236 : BC_PopupMenu(x, y, 200, to_text(plugin->config.mode), 1)
00237 {
00238 this->plugin = plugin;
00239 this->gui = gui;
00240 }
00241 void DeInterlaceMode::create_objects()
00242 {
00243 add_item(new BC_MenuItem(to_text(DEINTERLACE_NONE)));
00244 add_item(new BC_MenuItem(to_text(DEINTERLACE_KEEP)));
00245 add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG)));
00246 add_item(new BC_MenuItem(to_text(DEINTERLACE_AVG_1F)));
00247 add_item(new BC_MenuItem(to_text(DEINTERLACE_BOBWEAVE)));
00248 add_item(new BC_MenuItem(to_text(DEINTERLACE_SWAP)));
00249 add_item(new BC_MenuItem(to_text(DEINTERLACE_TEMPORALSWAP)));
00250 }
00251
00252 char* DeInterlaceMode::to_text(int mode)
00253 {
00254 switch(mode)
00255 {
00256 case DEINTERLACE_KEEP:
00257 return _("Duplicate one field");
00258 case DEINTERLACE_AVG_1F:
00259 return _("Average one field");
00260 case DEINTERLACE_AVG:
00261 return _("Average both fields");
00262 case DEINTERLACE_BOBWEAVE:
00263 return _("Bob & Weave");
00264 case DEINTERLACE_SWAP:
00265 return _("Spatial field swap");
00266 case DEINTERLACE_TEMPORALSWAP:
00267 return _("Temporal field swap");
00268 default:
00269 return _("Do Nothing");
00270 }
00271 }
00272 int DeInterlaceMode::from_text(char *text)
00273 {
00274 if(!strcmp(text, to_text(DEINTERLACE_KEEP)))
00275 return DEINTERLACE_KEEP;
00276 if(!strcmp(text, to_text(DEINTERLACE_AVG)))
00277 return DEINTERLACE_AVG;
00278 if(!strcmp(text, to_text(DEINTERLACE_AVG_1F)))
00279 return DEINTERLACE_AVG_1F;
00280 if(!strcmp(text, to_text(DEINTERLACE_BOBWEAVE)))
00281 return DEINTERLACE_BOBWEAVE;
00282 if(!strcmp(text, to_text(DEINTERLACE_SWAP)))
00283 return DEINTERLACE_SWAP;
00284 if(!strcmp(text, to_text(DEINTERLACE_TEMPORALSWAP)))
00285 return DEINTERLACE_TEMPORALSWAP;
00286 return DEINTERLACE_NONE;
00287 }
00288
00289 int DeInterlaceMode::handle_event()
00290 {
00291 plugin->config.mode = from_text(get_text());
00292 gui->set_mode(plugin->config.mode,0);
00293 plugin->send_configure_change();
00294 }
00295
00296
00297