5 #include "bcdisplayinfo.h"
8 #include "mainprogress.h"
16 REGISTER_PLUGIN(_720to480Main)
22 _720to480Config::_720to480Config()
32 _720to480Window::_720to480Window(_720to480Main *client, int x, int y)
33 : BC_Window(client->gui_string,
44 this->client = client;
48 _720to480Window::~_720to480Window()
52 int _720to480Window::create_objects()
56 add_tool(odd_first = new _720to480Order(client, this, 1, x, y, _("Odd field first")));
58 add_tool(even_first = new _720to480Order(client, this, 0, x, y, _("Even field first")));
61 // add_tool(forward = new _720to480Direction(client, this, FORWARD, x, y, _("Downsample")));
63 // add_tool(reverse = new _720to480Direction(client, this, REVERSE, x, y, _("Upsample")));
65 add_subwindow(new BC_OKButton(this));
66 add_subwindow(new BC_CancelButton(this));
73 WINDOW_CLOSE_EVENT(_720to480Window)
75 int _720to480Window::set_first_field(int first_field)
77 odd_first->update(first_field == 1);
78 even_first->update(first_field == 0);
80 client->config.first_field = first_field;
84 int _720to480Window::set_direction(int direction)
86 forward->update(direction == FORWARD);
87 reverse->update(direction == REVERSE);
90 client->config.direction = direction;
96 _720to480Order::_720to480Order(_720to480Main *client,
97 _720to480Window *window,
104 client->config.first_field == output,
107 this->client = client;
108 this->window = window;
109 this->output = output;
112 int _720to480Order::handle_event()
114 window->set_first_field(output);
122 _720to480Direction::_720to480Direction(_720to480Main *client,
123 _720to480Window *window,
130 client->config.direction == output,
133 this->client = client;
134 this->window = window;
135 this->output = output;
138 int _720to480Direction::handle_event()
140 window->set_direction(output);
159 _720to480Main::_720to480Main(PluginServer *server)
160 : PluginVClient(server)
166 _720to480Main::~_720to480Main()
171 if(temp) delete temp;
174 char* _720to480Main::plugin_title() { return N_("720 to 480"); }
175 int _720to480Main::is_realtime() { return 0; }
177 double _720to480Main::get_framerate()
179 return project_frame_rate / 2;
186 int _720to480Main::load_defaults()
188 char directory[BCTEXTLEN], string[BCTEXTLEN];
189 sprintf(directory, "%s720to480.rc", BCASTDIR);
191 defaults = new BC_Hash(directory);
193 config.first_field = defaults->get("FIRST_FIELD", config.first_field);
194 config.direction = defaults->get("DIRECTION", config.direction);
199 int _720to480Main::save_defaults()
201 defaults->update("FIRST_FIELD", config.first_field);
202 defaults->update("DIRECTION", config.direction);
207 int _720to480Main::get_parameters()
210 _720to480Window window(this,
211 info.get_abs_cursor_x(),
212 info.get_abs_cursor_y());
213 window.create_objects();
214 int result = window.run_window();
218 int _720to480Main::start_loop()
220 if(PluginClient::interactive)
222 char string[BCTEXTLEN];
223 sprintf(string, "%s...", plugin_title());
224 progress = start_progress(string,
225 PluginClient::end - PluginClient::start);
228 input_position = PluginClient::start;
233 int _720to480Main::stop_loop()
235 if(PluginClient::interactive)
237 progress->stop_progress();
248 void _720to480Main::reduce_field(VFrame *output, VFrame *input, int dest_row)
250 int in_w = input->get_w();
251 int in_h = input->get_h();
252 int out_w = output->get_w();
253 int out_h = output->get_h();
255 #define REDUCE_MACRO(type, temp, components) \
256 for(int i = 0; i < DST_H; i++) \
258 int output_number = dest_row + i * 2; \
259 if(output_number >= out_h) break; \
261 int in1 = i * 3 + dest_row * 2; \
262 int in2 = i * 3 + 1 + dest_row * 2; \
263 int in3 = i * 3 + 2 + dest_row * 2; \
265 if(in1 >= in_h) in1 = in_h - 1; \
266 if(in2 >= in_h) in2 = in_h - 1; \
267 if(in3 >= in_h) in3 = in_h - 1; \
269 type *out_row = (type*)output->get_rows()[output_number]; \
270 type *in_row1 = (type*)input->get_rows()[in1]; \
271 type *in_row2 = (type*)input->get_rows()[in2]; \
272 type *in_row3 = (type*)input->get_rows()[in3]; \
274 int w = MIN(out_w, in_w) * components; \
275 for(int j = 0; j < w; j++) \
277 *out_row++ = ((temp)*in_row1++ + \
279 (temp)*in_row3++) / 3; \
283 switch(input->get_color_model())
287 REDUCE_MACRO(unsigned char, int64_t, 3);
290 REDUCE_MACRO(float, float, 3);
294 REDUCE_MACRO(unsigned char, int64_t, 4);
297 REDUCE_MACRO(float, float, 4);
301 REDUCE_MACRO(uint16_t, int64_t, 3);
303 case BC_RGBA16161616:
304 case BC_YUVA16161616:
305 REDUCE_MACRO(uint16_t, int64_t, 4);
310 int _720to480Main::process_loop(VFrame *output)
318 output->get_color_model());
320 if(config.direction == FORWARD)
322 // Step 1: Reduce vertically and put in desired fields of output
323 read_frame(temp, input_position);
324 reduce_field(output, temp, config.first_field == 0 ? 0 : 1);
327 read_frame(temp, input_position);
328 reduce_field(output, temp, config.first_field == 0 ? 1 : 0);
332 if(PluginClient::interactive)
333 result = progress->update(input_position - PluginClient::start);
335 if(input_position >= PluginClient::end) result = 1;
345 void _720to480Main::save_data(KeyFrame *keyframe)
348 output.set_shared_string(keyframe->data, MESSAGESIZE);
349 output.tag.set_title("720TO480");
350 output.tag.set_property("FIRST_FIELD", config.first_field);
351 output.tag.set_property("DIRECTION", config.direction);
353 output.terminate_string();
356 void _720to480Main::read_data(KeyFrame *keyframe)
359 input.set_shared_string(keyframe->data, strlen(keyframe->data));
361 while(!input.read_tag())
363 if(input.tag.title_is("720TO480"))
365 config.first_field = input.tag.get_property("FIRST_FIELD", config.first_field);
366 config.direction = input.tag.get_property("DIRECTION", config.direction);