1 #include "bcdisplayinfo.h"
6 #include "swapchannels.h"
15 #define _(String) gettext(String)
16 #define gettext_noop(String) String
17 #define N_(String) gettext_noop (String)
24 REGISTER_PLUGIN(SwapMain)
33 SwapConfig::SwapConfig()
42 int SwapConfig::equivalent(SwapConfig &that)
44 return (red == that.red &&
45 green == that.green &&
50 void SwapConfig::copy_from(SwapConfig &that)
65 SwapWindow::SwapWindow(SwapMain *plugin, int x, int y)
66 : BC_Window(plugin->gui_string,
77 this->plugin = plugin;
80 SwapWindow::~SwapWindow()
85 void SwapWindow::create_objects()
90 add_subwindow(new BC_Title(x, y, _("Swap channels")));
92 add_subwindow(new BC_Title(x + 160, y + 5, _("-> Red")));
93 add_subwindow(red = new SwapMenu(plugin, &(plugin->config.red), x, y));
94 red->create_objects();
96 add_subwindow(new BC_Title(x + 160, y + 5, _("-> Green")));
97 add_subwindow(green = new SwapMenu(plugin, &(plugin->config.green), x, y));
98 green->create_objects();
100 add_subwindow(new BC_Title(x + 160, y + 5, _("-> Blue")));
101 add_subwindow(blue = new SwapMenu(plugin, &(plugin->config.blue), x, y));
102 blue->create_objects();
104 add_subwindow(new BC_Title(x + 160, y + 5, _("-> Alpha")));
105 add_subwindow(alpha = new SwapMenu(plugin, &(plugin->config.alpha), x, y));
106 alpha->create_objects();
112 int SwapWindow::close_event()
114 // Set result to 1 to indicate a client side close
123 SwapMenu::SwapMenu(SwapMain *client, int *output, int x, int y)
124 : BC_PopupMenu(x, y, 150, client->output_to_text(*output))
126 this->client = client;
127 this->output = output;
130 int SwapMenu::handle_event()
132 client->send_configure_change();
136 int SwapMenu::create_objects()
138 add_item(new SwapItem(this, client->output_to_text(RED_SRC)));
139 add_item(new SwapItem(this, client->output_to_text(GREEN_SRC)));
140 add_item(new SwapItem(this, client->output_to_text(BLUE_SRC)));
141 add_item(new SwapItem(this, client->output_to_text(ALPHA_SRC)));
142 add_item(new SwapItem(this, client->output_to_text(NO_SRC)));
143 add_item(new SwapItem(this, client->output_to_text(MAX_SRC)));
150 SwapItem::SwapItem(SwapMenu *menu, char *title)
156 int SwapItem::handle_event()
158 menu->set_text(get_text());
159 *(menu->output) = menu->client->text_to_output(get_text());
160 menu->handle_event();
172 PLUGIN_THREAD_OBJECT(SwapMain, SwapThread, SwapWindow)
183 SwapMain::SwapMain(PluginServer *server)
184 : PluginVClient(server)
187 PLUGIN_CONSTRUCTOR_MACRO
190 SwapMain::~SwapMain()
192 PLUGIN_DESTRUCTOR_MACRO
194 if(temp) delete temp;
197 void SwapMain::reset()
202 int SwapMain::is_realtime()
207 char* SwapMain::plugin_title()
209 return _("Swap channels");
212 int SwapMain::is_synthesis()
217 SHOW_GUI_MACRO(SwapMain, SwapThread)
218 NEW_PICON_MACRO(SwapMain)
219 SET_STRING_MACRO(SwapMain)
220 RAISE_WINDOW_MACRO(SwapMain)
222 int SwapMain::load_defaults()
224 char directory[1024], string[1024];
225 // set the default directory
226 sprintf(directory, "%sswapchannels.rc", BCASTDIR);
229 defaults = new Defaults(directory);
232 config.red = defaults->get("RED", config.red);
233 config.green = defaults->get("GREEN", config.green);
234 config.blue = defaults->get("BLUE", config.blue);
235 config.alpha = defaults->get("ALPHA", config.alpha);
239 int SwapMain::save_defaults()
241 defaults->update("RED", config.red);
242 defaults->update("GREEN", config.green);
243 defaults->update("BLUE", config.blue);
244 defaults->update("ALPHA", config.alpha);
249 void SwapMain::save_data(KeyFrame *keyframe)
253 // cause data to be stored directly in text
254 output.set_shared_string(keyframe->data, MESSAGESIZE);
255 output.tag.set_title("SWAPCHANNELS");
256 output.tag.set_property("RED", config.red);
257 output.tag.set_property("GREEN", config.green);
258 output.tag.set_property("BLUE", config.blue);
259 output.tag.set_property("ALPHA", config.alpha);
261 output.append_newline();
262 output.terminate_string();
263 // data is now in *text
266 void SwapMain::read_data(KeyFrame *keyframe)
270 input.set_shared_string(keyframe->data, strlen(keyframe->data));
276 result = input.read_tag();
280 if(input.tag.title_is("SWAPCHANNELS"))
282 config.red = input.tag.get_property("RED", config.red);
283 config.green = input.tag.get_property("GREEN", config.green);
284 config.blue = input.tag.get_property("BLUE", config.blue);
285 config.alpha = input.tag.get_property("ALPHA", config.alpha);
291 void SwapMain::update_gui()
295 load_configuration();
296 thread->window->lock_window();
297 thread->window->red->set_text(output_to_text(config.red));
298 thread->window->green->set_text(output_to_text(config.green));
299 thread->window->blue->set_text(output_to_text(config.blue));
300 thread->window->alpha->set_text(output_to_text(config.alpha));
301 thread->window->unlock_window();
306 void SwapMain::load_configuration()
308 KeyFrame *prev_keyframe;
309 prev_keyframe = get_prev_keyframe(get_source_position());
311 read_data(prev_keyframe);
337 #define MAXMINSRC(src, max) \
338 (src == MAX_SRC ? max : 0)
340 #define SWAP_CHANNELS(type, max, components) \
342 int h = input_ptr->get_h(); \
343 int w = input_ptr->get_w(); \
344 int red = config.red; \
345 int green = config.green; \
346 int blue = config.blue; \
347 int alpha = config.alpha; \
349 if(components == 3) \
351 if(red == ALPHA_SRC) red = MAX_SRC; \
352 if(green == ALPHA_SRC) green = MAX_SRC; \
353 if(blue == ALPHA_SRC) blue = MAX_SRC; \
357 for(int i = 0; i < h; i++) \
359 type *inrow = (type*)input_ptr->get_rows()[i]; \
360 type *outrow = (type*)temp->get_rows()[i]; \
362 for(int j = 0; j < w; j++) \
365 *outrow++ = *(inrow + red); \
367 *outrow++ = MAXMINSRC(red, max); \
370 *outrow++ = *(inrow + green); \
372 *outrow++ = MAXMINSRC(green, max); \
375 *outrow++ = *(inrow + blue); \
377 *outrow++ = MAXMINSRC(blue, max); \
379 if(components == 4) \
382 *outrow++ = *(inrow + alpha); \
384 *outrow++ = MAXMINSRC(alpha, max); \
387 inrow += components; \
391 output_ptr->copy_from(temp); \
396 int SwapMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
398 load_configuration();
405 input_ptr->get_color_model());
407 switch(input_ptr->get_color_model())
411 SWAP_CHANNELS(unsigned char, 0xff, 3);
415 SWAP_CHANNELS(unsigned char, 0xff, 4);
419 SWAP_CHANNELS(uint16_t, 0xffff, 3);
421 case BC_RGBA16161616:
422 case BC_YUVA16161616:
423 SWAP_CHANNELS(uint16_t, 0xffff, 4);
432 char* SwapMain::output_to_text(int value)
460 int SwapMain::text_to_output(char *text)
462 if(!strcmp(text, _("Red"))) return RED_SRC;
463 if(!strcmp(text, _("Green"))) return GREEN_SRC;
464 if(!strcmp(text, _("Blue"))) return BLUE_SRC;
465 if(!strcmp(text, _("Alpha"))) return ALPHA_SRC;
466 if(!strcmp(text, _("0%"))) return NO_SRC;
467 if(!strcmp(text, _("100%"))) return MAX_SRC;