5 #include "bcdisplayinfo.h"
8 #include "overlayframe.h"
21 REGISTER_PLUGIN(_1080to540Main)
26 _1080to540Config::_1080to540Config()
31 int _1080to540Config::equivalent(_1080to540Config &that)
33 return first_field == that.first_field;
36 void _1080to540Config::copy_from(_1080to540Config &that)
38 first_field = that.first_field;
41 void _1080to540Config::interpolate(_1080to540Config &prev,
42 _1080to540Config &next,
54 _1080to540Window::_1080to540Window(_1080to540Main *client, int x, int y)
55 : BC_Window(client->gui_string,
66 this->client = client;
70 _1080to540Window::~_1080to540Window()
74 int _1080to540Window::create_objects()
78 add_tool(odd_first = new _1080to540Option(client, this, 1, x, y, _("Odd field first")));
80 add_tool(even_first = new _1080to540Option(client, this, 0, x, y, _("Even field first")));
87 WINDOW_CLOSE_EVENT(_1080to540Window)
89 int _1080to540Window::set_first_field(int first_field, int send_event)
91 odd_first->update(first_field == 1);
92 even_first->update(first_field == 0);
97 client->config.first_field = first_field;
98 client->send_configure_change();
106 _1080to540Option::_1080to540Option(_1080to540Main *client,
107 _1080to540Window *window,
114 client->config.first_field == output,
117 this->client = client;
118 this->window = window;
119 this->output = output;
122 int _1080to540Option::handle_event()
124 window->set_first_field(output, 1);
130 PLUGIN_THREAD_OBJECT(_1080to540Main, _1080to540Thread, _1080to540Window)
138 _1080to540Main::_1080to540Main(PluginServer *server)
139 : PluginVClient(server)
141 PLUGIN_CONSTRUCTOR_MACRO
145 _1080to540Main::~_1080to540Main()
147 PLUGIN_DESTRUCTOR_MACRO
148 if(temp) delete temp;
151 char* _1080to540Main::plugin_title() { return N_("1080 to 540"); }
152 int _1080to540Main::is_realtime() { return 1; }
154 SHOW_GUI_MACRO(_1080to540Main, _1080to540Thread)
155 RAISE_WINDOW_MACRO(_1080to540Main)
156 SET_STRING_MACRO(_1080to540Main)
157 NEW_PICON_MACRO(_1080to540Main)
158 LOAD_CONFIGURATION_MACRO(_1080to540Main, _1080to540Config)
165 void _1080to540Main::reduce_field(VFrame *output, VFrame *input, int src_field, int dst_field)
167 int w = input->get_w();
168 int h = input->get_h();
170 if(h > output->get_h()) h = output->get_h();
171 if(w > output->get_w()) h = output->get_w();
173 #define REDUCE_MACRO(type, temp, components) \
174 for(int i = 0; i < OUT_ROWS; i++) \
176 int in_number1 = dst_field * 2 + src_field + (int)(i * 2) * 2; \
177 int in_number2 = in_number1 + 2; \
178 int in_number3 = in_number2 + 2; \
179 int in_number4 = in_number3 + 2; \
180 int out_number = dst_field + i * 2; \
182 if(in_number1 >= h) in_number1 = h - 1; \
183 if(in_number2 >= h) in_number2 = h - 1; \
184 if(in_number3 >= h) in_number3 = h - 1; \
185 if(in_number4 >= h) in_number4 = h - 1; \
186 if(out_number >= h) out_number = h - 1; \
188 type *in_row1 = (type*)input->get_rows()[in_number1]; \
189 type *in_row2 = (type*)input->get_rows()[in_number2]; \
190 type *in_row3 = (type*)input->get_rows()[in_number3]; \
191 type *in_row4 = (type*)input->get_rows()[in_number4]; \
192 type *out_row = (type*)output->get_rows()[out_number]; \
194 for(int j = 0; j < w * components; j++) \
196 *out_row++ = ((temp)*in_row1++ + \
199 (temp)*in_row4++) / 4; \
203 switch(input->get_color_model())
207 REDUCE_MACRO(unsigned char, int64_t, 3);
210 REDUCE_MACRO(float, float, 3);
214 REDUCE_MACRO(unsigned char, int64_t, 4);
217 REDUCE_MACRO(float, float, 4);
221 REDUCE_MACRO(uint16_t, int64_t, 3);
223 case BC_RGBA16161616:
224 case BC_YUVA16161616:
225 REDUCE_MACRO(uint16_t, int64_t, 4);
231 int _1080to540Main::process_realtime(VFrame *input, VFrame *output)
233 load_configuration();
239 input->get_color_model());
243 reduce_field(temp, input, config.first_field == 0 ? 0 : 1, 0);
244 reduce_field(temp, input, config.first_field == 0 ? 1 : 0, 1);
246 output->copy_from(temp);
252 int _1080to540Main::load_defaults()
254 char directory[BCTEXTLEN], string[BCTEXTLEN];
255 sprintf(directory, "%s1080to540.rc", BCASTDIR);
257 defaults = new BC_Hash(directory);
259 config.first_field = defaults->get("FIRST_FIELD", config.first_field);
264 int _1080to540Main::save_defaults()
266 defaults->update("FIRST_FIELD", config.first_field);
271 void _1080to540Main::save_data(KeyFrame *keyframe)
274 output.set_shared_string(keyframe->data, MESSAGESIZE);
275 output.tag.set_title("1080TO540");
276 output.tag.set_property("FIRST_FIELD", config.first_field);
278 output.terminate_string();
281 void _1080to540Main::read_data(KeyFrame *keyframe)
284 input.set_shared_string(keyframe->data, strlen(keyframe->data));
286 while(!input.read_tag())
288 if(input.tag.title_is("1080TO540"))
290 config.first_field = input.tag.get_property("FIRST_FIELD", config.first_field);
295 void _1080to540Main::update_gui()
299 load_configuration();
300 thread->window->lock_window();
301 thread->window->set_first_field(config.first_field, 0);
302 thread->window->unlock_window();