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()
48 int ShiftInterlaceConfig::equivalent(ShiftInterlaceConfig &that)
50 return (odd_offset == that.odd_offset &&
51 even_offset == that.even_offset);
54 void ShiftInterlaceConfig::copy_from(ShiftInterlaceConfig &that)
56 odd_offset = that.odd_offset;
57 even_offset = that.even_offset;
60 void ShiftInterlaceConfig::interpolate(ShiftInterlaceConfig &prev,
61 ShiftInterlaceConfig &next,
66 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
67 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
69 this->odd_offset = (int)(prev.odd_offset * prev_scale + next.odd_offset * next_scale);
70 this->even_offset = (int)(prev.even_offset * prev_scale + next.even_offset * next_scale);
78 ShiftInterlaceWindow::ShiftInterlaceWindow(ShiftInterlaceMain *plugin)
79 : PluginClientWindow(plugin,
86 this->plugin = plugin;
90 void ShiftInterlaceWindow::create_objects()
95 add_subwindow(new BC_Title(x, y, _("Odd offset:")));
96 add_subwindow(odd_offset = new ShiftInterlaceOdd(plugin, x + 90, y));
98 add_subwindow(new BC_Title(x, y, _("Even offset:")));
99 add_subwindow(even_offset = new ShiftInterlaceEven(plugin, x + 90, y));
101 add_subwindow(reset = new ShiftInterlaceReset(plugin, this, x, y));
107 void ShiftInterlaceWindow::update()
109 odd_offset->update(plugin->config.odd_offset);
110 even_offset->update(plugin->config.even_offset);
115 ShiftInterlaceOdd::ShiftInterlaceOdd(ShiftInterlaceMain *plugin, int x, int y)
123 plugin->config.odd_offset)
125 this->plugin = plugin;
127 int ShiftInterlaceOdd::handle_event()
129 plugin->config.odd_offset = get_value();
130 plugin->send_configure_change();
137 ShiftInterlaceEven::ShiftInterlaceEven(ShiftInterlaceMain *plugin, int x, int y)
145 plugin->config.even_offset)
147 this->plugin = plugin;
151 int ShiftInterlaceEven::handle_event()
153 plugin->config.even_offset = get_value();
154 plugin->send_configure_change();
161 ShiftInterlaceReset::ShiftInterlaceReset(ShiftInterlaceMain *plugin, ShiftInterlaceWindow *gui, int x, int y)
162 : BC_GenericButton(x, y, _("Reset"))
164 this->plugin = plugin;
167 ShiftInterlaceReset::~ShiftInterlaceReset()
170 int ShiftInterlaceReset::handle_event()
172 plugin->config.reset();
174 plugin->send_configure_change();
187 ShiftInterlaceMain::ShiftInterlaceMain(PluginServer *server)
188 : PluginVClient(server)
193 ShiftInterlaceMain::~ShiftInterlaceMain()
199 const char* ShiftInterlaceMain::plugin_title() { return N_("ShiftInterlace"); }
200 int ShiftInterlaceMain::is_realtime() { return 1; }
206 LOAD_CONFIGURATION_MACRO(ShiftInterlaceMain, ShiftInterlaceConfig)
208 NEW_WINDOW_MACRO(ShiftInterlaceMain, ShiftInterlaceWindow)
212 void ShiftInterlaceMain::save_data(KeyFrame *keyframe)
216 // cause data to be stored directly in text
217 output.set_shared_output(keyframe->xbuf);
218 output.tag.set_title("SHIFTINTERLACE");
219 output.tag.set_property("ODD_OFFSET", config.odd_offset);
220 output.tag.set_property("EVEN_OFFSET", config.even_offset);
222 output.tag.set_title("/SHIFTINTERLACE");
224 output.append_newline();
225 output.terminate_string();
226 // data is now in *text
229 void ShiftInterlaceMain::read_data(KeyFrame *keyframe)
233 input.set_shared_input(keyframe->xbuf);
239 result = input.read_tag();
243 if(input.tag.title_is("SHIFTINTERLACE"))
245 config.odd_offset = input.tag.get_property("ODD_OFFSET", config.odd_offset);
246 config.even_offset = input.tag.get_property("EVEN_OFFSET", config.even_offset);
252 void ShiftInterlaceMain::update_gui()
256 load_configuration();
257 thread->window->lock_window();
258 ((ShiftInterlaceWindow*)thread->window)->odd_offset->update(config.odd_offset);
259 ((ShiftInterlaceWindow*)thread->window)->even_offset->update(config.even_offset);
260 thread->window->unlock_window();
265 #define SHIFT_ROW_MACRO(components, type, chroma_offset) \
267 type *input_row = (type*)input_frame->get_rows()[row]; \
268 type *output_row = (type*)output_frame->get_rows()[row]; \
273 for(i = 0, j = -offset; \
277 output_row[i * components + 0] = input_row[j * components + 0]; \
278 output_row[i * components + 1] = input_row[j * components + 1]; \
279 output_row[i * components + 2] = input_row[j * components + 2]; \
280 if(components == 4) output_row[i * components + 3] = input_row[j * components + 3]; \
285 output_row[i * components + 0] = 0; \
286 output_row[i * components + 1] = chroma_offset; \
287 output_row[i * components + 2] = chroma_offset; \
288 if(components == 4) output_row[i * components + 3] = 0; \
294 for(i = w - offset - 1, j = w - 1; \
299 output_row[j * components + 0] = input_row[i * components + 0]; \
300 output_row[j * components + 1] = input_row[i * components + 1]; \
301 output_row[j * components + 2] = input_row[i * components + 2]; \
302 if(components == 4) output_row[j * components + 3] = input_row[i * components + 3]; \
305 for( ; j >= 0; j--) \
307 output_row[j * components + 0] = 0; \
308 output_row[j * components + 1] = chroma_offset; \
309 output_row[j * components + 2] = chroma_offset; \
310 if(components == 4) output_row[j * components + 3] = 0; \
316 void ShiftInterlaceMain::shift_row(VFrame *input_frame,
317 VFrame *output_frame,
321 int w = input_frame->get_w();
322 switch(input_frame->get_color_model())
325 SHIFT_ROW_MACRO(3, unsigned char, 0x0)
328 SHIFT_ROW_MACRO(3, float, 0x0)
331 SHIFT_ROW_MACRO(3, unsigned char, 0x80)
334 SHIFT_ROW_MACRO(4, float, 0x0)
337 SHIFT_ROW_MACRO(4, unsigned char, 0x0)
340 SHIFT_ROW_MACRO(4, unsigned char, 0x80)
343 SHIFT_ROW_MACRO(3, uint16_t, 0x0)
346 SHIFT_ROW_MACRO(3, uint16_t, 0x8000)
348 case BC_RGBA16161616:
349 SHIFT_ROW_MACRO(4, uint16_t, 0x0)
351 case BC_YUVA16161616:
352 SHIFT_ROW_MACRO(4, uint16_t, 0x8000)
357 int ShiftInterlaceMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
359 load_configuration();
361 int h = input_ptr->get_h();
362 for(int i = 0; i < h; i++)
365 shift_row(input_ptr, output_ptr, config.even_offset, i);
367 shift_row(input_ptr, output_ptr, config.odd_offset, i);