5 #include "bcdisplayinfo.h"
7 #include "mainprogress.h"
11 #define _(String) gettext(String)
12 #define gettext_noop(String) String
13 #define N_(String) gettext_noop (String)
20 REGISTER_PLUGIN(_720to480Main)
26 _720to480Config::_720to480Config()
36 _720to480Window::_720to480Window(_720to480Main *client, int x, int y)
37 : BC_Window(client->gui_string,
48 this->client = client;
52 _720to480Window::~_720to480Window()
56 int _720to480Window::create_objects()
60 add_tool(odd_first = new _720to480Order(client, this, 1, x, y, _("Odd field first")));
62 add_tool(even_first = new _720to480Order(client, this, 0, x, y, _("Even field first")));
65 // add_tool(forward = new _720to480Direction(client, this, FORWARD, x, y, _("Downsample")));
67 // add_tool(reverse = new _720to480Direction(client, this, REVERSE, x, y, _("Upsample")));
69 add_subwindow(new BC_OKButton(this));
70 add_subwindow(new BC_CancelButton(this));
77 WINDOW_CLOSE_EVENT(_720to480Window)
79 int _720to480Window::set_first_field(int first_field)
81 odd_first->update(first_field == 1);
82 even_first->update(first_field == 0);
84 client->config.first_field = first_field;
88 int _720to480Window::set_direction(int direction)
90 forward->update(direction == FORWARD);
91 reverse->update(direction == REVERSE);
94 client->config.direction = direction;
100 _720to480Order::_720to480Order(_720to480Main *client,
101 _720to480Window *window,
108 client->config.first_field == output,
111 this->client = client;
112 this->window = window;
113 this->output = output;
116 int _720to480Order::handle_event()
118 window->set_first_field(output);
126 _720to480Direction::_720to480Direction(_720to480Main *client,
127 _720to480Window *window,
134 client->config.direction == output,
137 this->client = client;
138 this->window = window;
139 this->output = output;
142 int _720to480Direction::handle_event()
144 window->set_direction(output);
163 _720to480Main::_720to480Main(PluginServer *server)
164 : PluginVClient(server)
170 _720to480Main::~_720to480Main()
175 if(temp) delete temp;
178 char* _720to480Main::plugin_title() { return _("720 to 480"); }
179 int _720to480Main::is_realtime() { return 0; }
181 double _720to480Main::get_framerate()
183 return project_frame_rate / 2;
190 int _720to480Main::load_defaults()
192 char directory[BCTEXTLEN], string[BCTEXTLEN];
193 sprintf(directory, "%s720to480.rc", BCASTDIR);
195 defaults = new Defaults(directory);
197 config.first_field = defaults->get("FIRST_FIELD", config.first_field);
198 config.direction = defaults->get("DIRECTION", config.direction);
203 int _720to480Main::save_defaults()
205 defaults->update("FIRST_FIELD", config.first_field);
206 defaults->update("DIRECTION", config.direction);
211 int _720to480Main::get_parameters()
214 _720to480Window window(this,
215 info.get_abs_cursor_x(),
216 info.get_abs_cursor_y());
217 window.create_objects();
218 int result = window.run_window();
222 int _720to480Main::start_loop()
224 if(PluginClient::interactive)
226 char string[BCTEXTLEN];
227 sprintf(string, "%s...", plugin_title());
228 progress = start_progress(string,
229 PluginClient::end - PluginClient::start);
232 input_position = PluginClient::start;
237 int _720to480Main::stop_loop()
239 if(PluginClient::interactive)
241 progress->stop_progress();
252 void _720to480Main::reduce_field(VFrame *output, VFrame *input, int dest_row)
254 int in_w = input->get_w();
255 int in_h = input->get_h();
256 int out_w = output->get_w();
257 int out_h = output->get_h();
259 #define REDUCE_MACRO(type, components) \
260 for(int i = 0; i < DST_H; i++) \
262 int output_number = dest_row + i * 2; \
263 if(output_number >= out_h) break; \
265 int in1 = i * 3 + dest_row * 2; \
266 int in2 = i * 3 + 1 + dest_row * 2; \
267 int in3 = i * 3 + 2 + dest_row * 2; \
269 if(in1 >= in_h) in1 = in_h - 1; \
270 if(in2 >= in_h) in2 = in_h - 1; \
271 if(in3 >= in_h) in3 = in_h - 1; \
273 type *out_row = (type*)output->get_rows()[output_number]; \
274 type *in_row1 = (type*)input->get_rows()[in1]; \
275 type *in_row2 = (type*)input->get_rows()[in2]; \
276 type *in_row3 = (type*)input->get_rows()[in3]; \
278 int w = MIN(out_w, in_w) * components; \
279 for(int j = 0; j < w; j++) \
281 *out_row++ = ((int64_t)*in_row1++ + (int64_t)*in_row2++ + (int64_t)*in_row3++) / 3; \
285 switch(input->get_color_model())
289 REDUCE_MACRO(unsigned char, 3);
293 REDUCE_MACRO(unsigned char, 4);
297 REDUCE_MACRO(uint16_t, 3);
299 case BC_RGBA16161616:
300 case BC_YUVA16161616:
301 REDUCE_MACRO(uint16_t, 4);
306 int _720to480Main::process_loop(VFrame *output)
314 output->get_color_model());
316 if(config.direction == FORWARD)
318 // Step 1: Reduce vertically and put in desired fields of output
319 read_frame(temp, input_position);
320 reduce_field(output, temp, config.first_field == 0 ? 0 : 1);
323 read_frame(temp, input_position);
324 reduce_field(output, temp, config.first_field == 0 ? 1 : 0);
328 if(PluginClient::interactive)
329 result = progress->update(input_position - PluginClient::start);
331 if(input_position >= PluginClient::end) result = 1;
341 void _720to480Main::save_data(KeyFrame *keyframe)
344 output.set_shared_string(keyframe->data, MESSAGESIZE);
345 output.tag.set_title("720TO480");
346 output.tag.set_property("FIRST_FIELD", config.first_field);
347 output.tag.set_property("DIRECTION", config.direction);
349 output.terminate_string();
352 void _720to480Main::read_data(KeyFrame *keyframe)
355 input.set_shared_string(keyframe->data, strlen(keyframe->data));
357 while(!input.read_tag())
359 if(input.tag.title_is("720TO480"))
361 config.first_field = input.tag.get_property("FIRST_FIELD", config.first_field);
362 config.direction = input.tag.get_property("DIRECTION", config.direction);