4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcdisplayinfo.h"
28 #include "mainprogress.h"
29 #include "pluginvclient.h"
30 #include "transportque.inc"
36 #define TOP_FIELD_FIRST 0
37 #define BOTTOM_FIELD_FIRST 1
40 class FieldFrameWindow;
48 class FieldFrameConfig
52 int equivalent(FieldFrameConfig &src);
60 class FieldFrameTop : public BC_Radial
63 FieldFrameTop(FieldFrame *plugin, FieldFrameWindow *gui, int x, int y);
66 FieldFrameWindow *gui;
70 class FieldFrameBottom : public BC_Radial
73 FieldFrameBottom(FieldFrame *plugin, FieldFrameWindow *gui, int x, int y);
76 FieldFrameWindow *gui;
79 // class FieldFrameFirst : public BC_Radial
82 // FieldFrameFirst(FieldFrame *plugin, FieldFrameWindow *gui, int x, int y);
83 // int handle_event();
84 // FieldFrame *plugin;
85 // FieldFrameWindow *gui;
88 // class FieldFrameSecond : public BC_Radial
91 // FieldFrameSecond(FieldFrame *plugin, FieldFrameWindow *gui, int x, int y);
92 // int handle_event();
93 // FieldFrame *plugin;
94 // FieldFrameWindow *gui;
97 class FieldFrameWindow : public PluginClientWindow
100 FieldFrameWindow(FieldFrame *plugin);
101 void create_objects();
104 FieldFrameBottom *bottom;
105 // FieldFrameFirst *first;
106 // FieldFrameSecond *second;
114 class FieldFrame : public PluginVClient
117 FieldFrame(PluginServer *server);
120 PLUGIN_CLASS_MEMBERS(FieldFrameConfig);
122 int process_buffer(VFrame *frame,
123 int64_t start_position,
126 void save_data(KeyFrame *keyframe);
127 void read_data(KeyFrame *keyframe);
129 void apply_field(VFrame *output, VFrame *input, int field);
142 REGISTER_PLUGIN(FieldFrame)
147 FieldFrameConfig::FieldFrameConfig()
149 field_dominance = TOP_FIELD_FIRST;
153 int FieldFrameConfig::equivalent(FieldFrameConfig &src)
155 return src.field_dominance == field_dominance &&
156 src.first_frame == first_frame;
166 FieldFrameWindow::FieldFrameWindow(FieldFrame *plugin)
167 : PluginClientWindow(plugin,
174 this->plugin = plugin;
177 void FieldFrameWindow::create_objects()
180 add_subwindow(top = new FieldFrameTop(plugin, this, x, y));
182 add_subwindow(bottom = new FieldFrameBottom(plugin, this, x, y));
184 // add_subwindow(first = new FieldFrameFirst(plugin, this, x, y));
186 // add_subwindow(second = new FieldFrameSecond(plugin, this, x, y));
204 FieldFrameTop::FieldFrameTop(FieldFrame *plugin,
205 FieldFrameWindow *gui,
210 plugin->config.field_dominance == TOP_FIELD_FIRST,
211 _("Top field first"))
213 this->plugin = plugin;
217 int FieldFrameTop::handle_event()
219 plugin->config.field_dominance = TOP_FIELD_FIRST;
220 gui->bottom->update(0);
221 plugin->send_configure_change();
229 FieldFrameBottom::FieldFrameBottom(FieldFrame *plugin,
230 FieldFrameWindow *gui,
235 plugin->config.field_dominance == BOTTOM_FIELD_FIRST,
236 _("Bottom field first"))
238 this->plugin = plugin;
242 int FieldFrameBottom::handle_event()
244 plugin->config.field_dominance = BOTTOM_FIELD_FIRST;
246 plugin->send_configure_change();
254 // FieldFrameFirst::FieldFrameFirst(FieldFrame *plugin,
255 // FieldFrameWindow *gui,
260 // plugin->config.first_frame == 0,
261 // _("First frame is first field"))
263 // this->plugin = plugin;
267 // int FieldFrameFirst::handle_event()
269 // plugin->config.first_frame = 0;
270 // gui->second->update(0);
271 // plugin->send_configure_change();
278 // FieldFrameSecond::FieldFrameSecond(FieldFrame *plugin,
279 // FieldFrameWindow *gui,
284 // plugin->config.first_frame == 1,
285 // _("Second frame is first field"))
287 // this->plugin = plugin;
291 // int FieldFrameSecond::handle_event()
293 // plugin->config.first_frame = 1;
294 // gui->first->update(0);
295 // plugin->send_configure_change();
320 FieldFrame::FieldFrame(PluginServer *server)
321 : PluginVClient(server)
328 FieldFrame::~FieldFrame()
332 if(input) delete input;
335 const char* FieldFrame::plugin_title() { return _("Fields to frames"); }
336 int FieldFrame::is_realtime() { return 1; }
339 NEW_WINDOW_MACRO(FieldFrame, FieldFrameWindow)
341 int FieldFrame::load_configuration()
343 KeyFrame *prev_keyframe;
344 FieldFrameConfig old_config = config;
346 prev_keyframe = get_prev_keyframe(get_source_position());
347 read_data(prev_keyframe);
349 return !old_config.equivalent(config);
354 void FieldFrame::save_data(KeyFrame *keyframe)
358 // cause data to be stored directly in text
359 output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
360 output.tag.set_title("FIELD_FRAME");
361 output.tag.set_property("DOMINANCE", config.field_dominance);
362 output.tag.set_property("FIRST_FRAME", config.first_frame);
364 output.tag.set_title("/FIELD_FRAME");
366 output.append_newline();
367 output.terminate_string();
370 void FieldFrame::read_data(KeyFrame *keyframe)
374 input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
376 while(!input.read_tag())
378 if(input.tag.title_is("FIELD_FRAME"))
380 config.field_dominance = input.tag.get_property("DOMINANCE", config.field_dominance);
381 config.first_frame = input.tag.get_property("FIRST_FRAME", config.first_frame);
387 void FieldFrame::update_gui()
391 if(load_configuration())
393 thread->window->lock_window();
394 ((FieldFrameWindow*)thread->window)->top->update(config.field_dominance == TOP_FIELD_FIRST);
395 ((FieldFrameWindow*)thread->window)->bottom->update(config.field_dominance == BOTTOM_FIELD_FIRST);
396 // thread->window->first->update(config.first_frame == 0);
397 // thread->window->second->update(config.first_frame == 1);
398 thread->window->unlock_window();
404 int FieldFrame::process_buffer(VFrame *frame,
405 int64_t start_position,
409 load_configuration();
411 if(input && !input->equivalent(frame, 0))
419 input = new VFrame(0,
423 frame->get_color_model(),
428 int64_t field1_position = start_position * 2;
429 int64_t field2_position = start_position * 2 + 1;
431 if (get_direction() == PLAY_REVERSE)
433 field1_position -= 1;
434 field2_position -= 1;
438 // printf("FieldFrame::process_buffer %d %lld %lld\n",
439 // config.field_dominance,
449 config.field_dominance == TOP_FIELD_FIRST ? 0 : 1);
457 config.field_dominance == TOP_FIELD_FIRST ? 1 : 0);
467 void FieldFrame::apply_field(VFrame *output, VFrame *input, int field)
469 unsigned char **input_rows = input->get_rows();
470 unsigned char **output_rows = output->get_rows();
471 int row_size = VFrame::calculate_bytes_per_pixel(output->get_color_model()) * output->get_w();
472 for(int i = field; i < output->get_h(); i += 2)
474 memcpy(output_rows[i], input_rows[i], row_size);