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 "bandslide.h"
23 #include "bcdisplayinfo.h"
28 #include "overlayframe.h"
41 REGISTER_PLUGIN(BandSlideMain)
47 BandSlideCount::BandSlideCount(BandSlideMain *plugin,
48 BandSlideWindow *window,
51 : BC_TumbleTextBox(window,
52 (int64_t)plugin->bands,
59 this->plugin = plugin;
60 this->window = window;
63 int BandSlideCount::handle_event()
65 plugin->bands = atol(get_text());
66 plugin->send_configure_change();
70 BandSlideIn::BandSlideIn(BandSlideMain *plugin,
71 BandSlideWindow *window,
76 plugin->direction == 0,
79 this->plugin = plugin;
80 this->window = window;
83 int BandSlideIn::handle_event()
86 plugin->direction = 0;
87 window->out->update(0);
88 plugin->send_configure_change();
92 BandSlideOut::BandSlideOut(BandSlideMain *plugin,
93 BandSlideWindow *window,
98 plugin->direction == 1,
101 this->plugin = plugin;
102 this->window = window;
105 int BandSlideOut::handle_event()
108 plugin->direction = 1;
109 window->in->update(0);
110 plugin->send_configure_change();
121 BandSlideWindow::BandSlideWindow(BandSlideMain *plugin)
122 : PluginClientWindow(plugin,
129 this->plugin = plugin;
133 void BandSlideWindow::create_objects()
136 add_subwindow(new BC_Title(x, y, _("Bands:")));
138 count = new BandSlideCount(plugin,
142 count->create_objects();
146 add_subwindow(new BC_Title(x, y, _("Direction:")));
148 add_subwindow(in = new BandSlideIn(plugin,
153 add_subwindow(out = new BandSlideOut(plugin,
171 BandSlideMain::BandSlideMain(PluginServer *server)
172 : PluginVClient(server)
179 BandSlideMain::~BandSlideMain()
184 const char* BandSlideMain::plugin_title() { return N_("BandSlide"); }
185 int BandSlideMain::is_transition() { return 1; }
186 int BandSlideMain::uses_gui() { return 1; }
188 NEW_WINDOW_MACRO(BandSlideMain, BandSlideWindow);
191 void BandSlideMain::save_data(KeyFrame *keyframe)
194 output.set_shared_output(keyframe->xbuf);
195 output.tag.set_title("BANDSLIDE");
196 output.tag.set_property("BANDS", bands);
197 output.tag.set_property("DIRECTION", direction);
199 output.tag.set_title("/BANDSLIDE");
201 output.append_newline();
202 output.terminate_string();
205 void BandSlideMain::read_data(KeyFrame *keyframe)
209 input.set_shared_input(keyframe->xbuf);
211 while(!input.read_tag())
213 if(input.tag.title_is("BANDSLIDE"))
215 bands = input.tag.get_property("BANDS", bands);
216 direction = input.tag.get_property("DIRECTION", direction);
221 int BandSlideMain::load_configuration()
223 read_data(get_prev_keyframe(get_source_position()));
229 #define BANDSLIDE(type, components) \
234 PluginClient::get_source_position() / \
235 PluginClient::get_total_len(); \
236 for(int i = 0; i < bands; i++) \
238 for(int j = 0; j < band_h; j++) \
240 int row = i * band_h + j; \
242 if(row >= 0 && row < h) \
244 type *in_row = (type*)incoming->get_rows()[row]; \
245 type *out_row = (type*)outgoing->get_rows()[row]; \
249 for(int k = 0, l = w - x; k < x; k++, l++) \
251 out_row[k * components + 0] = in_row[l * components + 0]; \
252 out_row[k * components + 1] = in_row[l * components + 1]; \
253 out_row[k * components + 2] = in_row[l * components + 2]; \
254 if(components == 4) out_row[k * components + 3] = in_row[l * components + 3]; \
259 for(int k = w - x, l = 0; k < w; k++, l++) \
261 out_row[k * components + 0] = in_row[l * components + 0]; \
262 out_row[k * components + 1] = in_row[l * components + 1]; \
263 out_row[k * components + 2] = in_row[l * components + 2]; \
264 if(components == 4) out_row[k * components + 3] = in_row[l * components + 3]; \
274 PluginClient::get_source_position() / \
275 PluginClient::get_total_len(); \
276 for(int i = 0; i < bands; i++) \
278 for(int j = 0; j < band_h; j++) \
280 int row = i * band_h + j; \
282 if(row >= 0 && row < h) \
284 type *in_row = (type*)incoming->get_rows()[row]; \
285 type *out_row = (type*)outgoing->get_rows()[row]; \
290 for(k = 0, l = w - x; k < x; k++, l++) \
292 out_row[k * components + 0] = out_row[l * components + 0]; \
293 out_row[k * components + 1] = out_row[l * components + 1]; \
294 out_row[k * components + 2] = out_row[l * components + 2]; \
295 if(components == 4) out_row[k * components + 3] = out_row[l * components + 3]; \
299 out_row[k * components + 0] = in_row[k * components + 0]; \
300 out_row[k * components + 1] = in_row[k * components + 1]; \
301 out_row[k * components + 2] = in_row[k * components + 2]; \
302 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
307 for(int k = w - 1, l = x - 1; k >= w - x; k--, l--) \
309 out_row[k * components + 0] = out_row[l * components + 0]; \
310 out_row[k * components + 1] = out_row[l * components + 1]; \
311 out_row[k * components + 2] = out_row[l * components + 2]; \
312 if(components == 4) out_row[k * components + 3] = out_row[l * components + 3]; \
314 for(int k = 0; k < w - x; k++) \
316 out_row[k * components + 0] = in_row[k * components + 0]; \
317 out_row[k * components + 1] = in_row[k * components + 1]; \
318 out_row[k * components + 2] = in_row[k * components + 2]; \
319 if(components == 4) out_row[k * components + 3] = in_row[k * components + 3]; \
330 int BandSlideMain::process_realtime(VFrame *incoming, VFrame *outgoing)
332 load_configuration();
334 int w = incoming->get_w();
335 int h = incoming->get_h();
336 int band_h = ((bands == 0) ? h : (h / bands + 1));
338 switch(incoming->get_color_model())
342 BANDSLIDE(unsigned char, 3)
349 BANDSLIDE(unsigned char, 4)
356 BANDSLIDE(uint16_t, 3)
358 case BC_RGBA16161616:
359 case BC_YUVA16161616:
360 BANDSLIDE(uint16_t, 4)