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 "shiftinterlace.h"
28 PluginClient* new_plugin(PluginServer *server)
30 return new ShiftInterlaceMain(server);
36 ShiftInterlaceConfig::ShiftInterlaceConfig()
41 void ShiftInterlaceConfig::reset(int clear)
44 case RESET_ODD_OFFSET : odd_offset = 0;
46 case RESET_EVEN_OFFSET : even_offset = 0;
57 int ShiftInterlaceConfig::equivalent(ShiftInterlaceConfig &that)
59 return (odd_offset == that.odd_offset &&
60 even_offset == that.even_offset);
63 void ShiftInterlaceConfig::copy_from(ShiftInterlaceConfig &that)
65 odd_offset = that.odd_offset;
66 even_offset = that.even_offset;
69 void ShiftInterlaceConfig::interpolate(ShiftInterlaceConfig &prev,
70 ShiftInterlaceConfig &next,
75 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
76 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
78 this->odd_offset = (int)(prev.odd_offset * prev_scale + next.odd_offset * next_scale);
79 this->even_offset = (int)(prev.even_offset * prev_scale + next.even_offset * next_scale);
87 ShiftInterlaceWindow::ShiftInterlaceWindow(ShiftInterlaceMain *plugin)
88 : PluginClientWindow(plugin,
95 this->plugin = plugin;
99 void ShiftInterlaceWindow::create_objects()
103 int x1 = 0; int clrBtn_w = 50;
105 add_subwindow(new BC_Title(x, y, _("Odd offset:")));
106 add_subwindow(odd_offset = new ShiftInterlaceOdd(plugin, x + 90, y));
107 x1 = x + 90 + odd_offset->get_w() + 10;
108 add_subwindow(odd_offsetClr = new ShiftInterlaceSliderClr(plugin, this, x1, y, clrBtn_w, RESET_ODD_OFFSET));
111 add_subwindow(new BC_Title(x, y, _("Even offset:")));
112 add_subwindow(even_offset = new ShiftInterlaceEven(plugin, x + 90, y));
113 add_subwindow(even_offsetClr = new ShiftInterlaceSliderClr(plugin, this, x1, y, clrBtn_w, RESET_EVEN_OFFSET));
116 add_subwindow(reset = new ShiftInterlaceReset(plugin, this, x, y));
122 void ShiftInterlaceWindow::update_gui(int clear)
125 case RESET_ODD_OFFSET : odd_offset->update(plugin->config.odd_offset);
127 case RESET_EVEN_OFFSET : even_offset->update(plugin->config.even_offset);
131 odd_offset->update(plugin->config.odd_offset);
132 even_offset->update(plugin->config.even_offset);
139 ShiftInterlaceOdd::ShiftInterlaceOdd(ShiftInterlaceMain *plugin, int x, int y)
147 plugin->config.odd_offset)
149 this->plugin = plugin;
151 int ShiftInterlaceOdd::handle_event()
153 plugin->config.odd_offset = get_value();
154 plugin->send_configure_change();
161 ShiftInterlaceEven::ShiftInterlaceEven(ShiftInterlaceMain *plugin, int x, int y)
169 plugin->config.even_offset)
171 this->plugin = plugin;
175 int ShiftInterlaceEven::handle_event()
177 plugin->config.even_offset = get_value();
178 plugin->send_configure_change();
185 ShiftInterlaceReset::ShiftInterlaceReset(ShiftInterlaceMain *plugin, ShiftInterlaceWindow *gui, int x, int y)
186 : BC_GenericButton(x, y, _("Reset"))
188 this->plugin = plugin;
191 ShiftInterlaceReset::~ShiftInterlaceReset()
194 int ShiftInterlaceReset::handle_event()
196 plugin->config.reset(RESET_ALL);
197 gui->update_gui(RESET_ALL);
198 plugin->send_configure_change();
203 ShiftInterlaceSliderClr::ShiftInterlaceSliderClr(ShiftInterlaceMain *plugin, ShiftInterlaceWindow *gui, int x, int y, int w, int clear)
204 : BC_Button(x, y, w, plugin->get_theme()->get_image_set("reset_button"))
206 this->plugin = plugin;
210 ShiftInterlaceSliderClr::~ShiftInterlaceSliderClr()
213 int ShiftInterlaceSliderClr::handle_event()
215 // clear==1 ==> Odd slider
216 // clear==2 ==> Even slider
217 plugin->config.reset(clear);
218 gui->update_gui(clear);
219 plugin->send_configure_change();
231 ShiftInterlaceMain::ShiftInterlaceMain(PluginServer *server)
232 : PluginVClient(server)
237 ShiftInterlaceMain::~ShiftInterlaceMain()
243 const char* ShiftInterlaceMain::plugin_title() { return N_("ShiftInterlace"); }
244 int ShiftInterlaceMain::is_realtime() { return 1; }
250 LOAD_CONFIGURATION_MACRO(ShiftInterlaceMain, ShiftInterlaceConfig)
252 NEW_WINDOW_MACRO(ShiftInterlaceMain, ShiftInterlaceWindow)
256 void ShiftInterlaceMain::save_data(KeyFrame *keyframe)
260 // cause data to be stored directly in text
261 output.set_shared_output(keyframe->xbuf);
262 output.tag.set_title("SHIFTINTERLACE");
263 output.tag.set_property("ODD_OFFSET", config.odd_offset);
264 output.tag.set_property("EVEN_OFFSET", config.even_offset);
266 output.tag.set_title("/SHIFTINTERLACE");
268 output.append_newline();
269 output.terminate_string();
270 // data is now in *text
273 void ShiftInterlaceMain::read_data(KeyFrame *keyframe)
277 input.set_shared_input(keyframe->xbuf);
283 result = input.read_tag();
287 if(input.tag.title_is("SHIFTINTERLACE"))
289 config.odd_offset = input.tag.get_property("ODD_OFFSET", config.odd_offset);
290 config.even_offset = input.tag.get_property("EVEN_OFFSET", config.even_offset);
296 void ShiftInterlaceMain::update_gui()
300 load_configuration();
301 thread->window->lock_window();
302 ((ShiftInterlaceWindow*)thread->window)->odd_offset->update(config.odd_offset);
303 ((ShiftInterlaceWindow*)thread->window)->even_offset->update(config.even_offset);
304 thread->window->unlock_window();
309 #define SHIFT_ROW_MACRO(components, type, chroma_offset) \
311 type *input_row = (type*)input_frame->get_rows()[row]; \
312 type *output_row = (type*)output_frame->get_rows()[row]; \
317 for(i = 0, j = -offset; \
321 output_row[i * components + 0] = input_row[j * components + 0]; \
322 output_row[i * components + 1] = input_row[j * components + 1]; \
323 output_row[i * components + 2] = input_row[j * components + 2]; \
324 if(components == 4) output_row[i * components + 3] = input_row[j * components + 3]; \
329 output_row[i * components + 0] = 0; \
330 output_row[i * components + 1] = chroma_offset; \
331 output_row[i * components + 2] = chroma_offset; \
332 if(components == 4) output_row[i * components + 3] = 0; \
338 for(i = w - offset - 1, j = w - 1; \
343 output_row[j * components + 0] = input_row[i * components + 0]; \
344 output_row[j * components + 1] = input_row[i * components + 1]; \
345 output_row[j * components + 2] = input_row[i * components + 2]; \
346 if(components == 4) output_row[j * components + 3] = input_row[i * components + 3]; \
349 for( ; j >= 0; j--) \
351 output_row[j * components + 0] = 0; \
352 output_row[j * components + 1] = chroma_offset; \
353 output_row[j * components + 2] = chroma_offset; \
354 if(components == 4) output_row[j * components + 3] = 0; \
360 void ShiftInterlaceMain::shift_row(VFrame *input_frame,
361 VFrame *output_frame,
365 int w = input_frame->get_w();
366 switch(input_frame->get_color_model())
369 SHIFT_ROW_MACRO(3, unsigned char, 0x0)
372 SHIFT_ROW_MACRO(3, float, 0x0)
375 SHIFT_ROW_MACRO(3, unsigned char, 0x80)
378 SHIFT_ROW_MACRO(4, float, 0x0)
381 SHIFT_ROW_MACRO(4, unsigned char, 0x0)
384 SHIFT_ROW_MACRO(4, unsigned char, 0x80)
387 SHIFT_ROW_MACRO(3, uint16_t, 0x0)
390 SHIFT_ROW_MACRO(3, uint16_t, 0x8000)
392 case BC_RGBA16161616:
393 SHIFT_ROW_MACRO(4, uint16_t, 0x0)
395 case BC_YUVA16161616:
396 SHIFT_ROW_MACRO(4, uint16_t, 0x8000)
401 int ShiftInterlaceMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
403 load_configuration();
405 int h = input_ptr->get_h();
406 for(int i = 0; i < h; i++)
409 shift_row(input_ptr, output_ptr, config.even_offset, i);
411 shift_row(input_ptr, output_ptr, config.odd_offset, i);