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"
29 #include "pluginvclient.h"
30 #include "swapframes.h"
39 REGISTER_PLUGIN(SwapFrames)
47 SwapFramesConfig::SwapFramesConfig()
53 void SwapFramesConfig::copy_from(SwapFramesConfig &src)
56 swap_even = src.swap_even;
59 int SwapFramesConfig::equivalent(SwapFramesConfig &src)
61 return on == src.on &&
62 swap_even == src.swap_even;
65 void SwapFramesConfig::interpolate(SwapFramesConfig &prev,
66 SwapFramesConfig &next,
69 int64_t current_frame)
72 swap_even = prev.swap_even;
84 SwapFramesOn::SwapFramesOn(SwapFrames *plugin,
91 this->plugin = plugin;
94 int SwapFramesOn::handle_event()
96 plugin->config.on = get_value();
97 plugin->send_configure_change();
106 SwapFramesEven::SwapFramesEven(SwapFrames *plugin,
107 SwapFramesWindow *gui,
112 plugin->config.swap_even,
113 _("Swap 0-1, 2-3, 4-5..."))
115 this->plugin = plugin;
119 int SwapFramesEven::handle_event()
121 plugin->config.swap_even = 1;
122 gui->swap_odd->update(0);
123 plugin->send_configure_change();
132 SwapFramesOdd::SwapFramesOdd(SwapFrames *plugin,
133 SwapFramesWindow *gui,
138 !plugin->config.swap_even,
139 _("Swap 1-2, 3-4, 5-6..."))
141 this->plugin = plugin;
145 int SwapFramesOdd::handle_event()
147 plugin->config.swap_even = 0;
148 gui->swap_even->update(0);
149 plugin->send_configure_change();
158 SwapFramesWindow::SwapFramesWindow(SwapFrames *plugin)
159 : PluginClientWindow(plugin,
166 this->plugin = plugin;
169 void SwapFramesWindow::create_objects()
172 add_subwindow(on = new SwapFramesOn(plugin, x, y));
173 y += on->get_h() + 5;
175 add_subwindow(bar = new BC_Bar(x, y, get_w() - x * 2));
176 y += bar->get_h() + 5;
177 add_subwindow(swap_even = new SwapFramesEven(plugin,
181 y += swap_even->get_h() + 5;
182 add_subwindow(swap_odd = new SwapFramesOdd(plugin,
201 SwapFrames::SwapFrames(PluginServer *server)
202 : PluginVClient(server)
206 buffer_position = -1;
210 SwapFrames::~SwapFrames()
216 const char* SwapFrames::plugin_title() { return N_("Swap Frames"); }
217 int SwapFrames::is_realtime() { return 1; }
219 NEW_WINDOW_MACRO(SwapFrames, SwapFramesWindow)
220 LOAD_CONFIGURATION_MACRO(SwapFrames, SwapFramesConfig)
222 void SwapFrames::update_gui()
226 thread->window->lock_window();
227 if(load_configuration())
229 ((SwapFramesWindow*)thread->window)->on->update(config.on);
230 ((SwapFramesWindow*)thread->window)->swap_even->update(config.swap_even);
231 ((SwapFramesWindow*)thread->window)->swap_odd->update(!config.swap_even);
233 thread->window->unlock_window();
238 void SwapFrames::save_data(KeyFrame *keyframe)
241 output.set_shared_output(keyframe->xbuf);
242 output.tag.set_title("SWAPFRAMES");
243 output.tag.set_property("ON", config.on);
244 output.tag.set_property("SWAP_EVEN", config.swap_even);
246 output.tag.set_title("/SWAPFRAMES");
248 output.append_newline();
249 output.terminate_string();
252 void SwapFrames::read_data(KeyFrame *keyframe)
255 input.set_shared_input(keyframe->xbuf);
256 while(!input.read_tag())
258 if(input.tag.title_is("SWAPFRAMES"))
260 config.on = input.tag.get_property("ON", config.on);
261 config.swap_even = input.tag.get_property("SWAP_EVEN", config.swap_even);
267 int SwapFrames::process_buffer(VFrame *frame,
268 int64_t start_position,
271 load_configuration();
272 int64_t new_position = start_position;
293 //printf("SwapFrames::process_buffer %d new_position=%lld\n", __LINE__, new_position);
294 if(buffer && buffer_position == new_position)
296 //printf("SwapFrames::process_buffer %d\n", __LINE__);
297 frame->copy_from(buffer);
301 if(new_position > prev_frame + 1)
303 //printf("SwapFrames::process_buffer %d\n", __LINE__);
305 buffer = new VFrame(frame->get_w(), frame->get_h(),
306 frame->get_color_model(), 0);
307 buffer_position = new_position - 1;
318 prev_frame = new_position;
323 //printf("SwapFrames::process_buffer %d\n", __LINE__);
329 prev_frame = new_position;