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
27 REGISTER_PLUGIN(RotateEffect)
32 RotateConfig::RotateConfig()
37 void RotateConfig::reset()
45 int RotateConfig::equivalent(RotateConfig &that)
47 return EQUIV(angle, that.angle) &&
48 EQUIV(pivot_x, that.pivot_y) &&
49 EQUIV(pivot_y, that.pivot_y) &&
50 draw_pivot == that.draw_pivot;
53 void RotateConfig::copy_from(RotateConfig &that)
56 pivot_x = that.pivot_x;
57 pivot_y = that.pivot_y;
58 draw_pivot = that.draw_pivot;
59 // bilinear = that.bilinear;
62 void RotateConfig::interpolate(RotateConfig &prev,
68 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
69 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
71 this->angle = prev.angle * prev_scale + next.angle * next_scale;
72 this->pivot_x = prev.pivot_x * prev_scale + next.pivot_x * next_scale;
73 this->pivot_y = prev.pivot_y * prev_scale + next.pivot_y * next_scale;
74 draw_pivot = prev.draw_pivot;
75 // bilinear = prev.bilinear;
88 RotateToggle::RotateToggle(RotateWindow *window,
95 : BC_Radial(x, y, init_value, string)
98 this->plugin = plugin;
99 this->window = window;
102 int RotateToggle::handle_event()
104 plugin->config.angle = (float)value;
106 plugin->send_configure_change();
116 RotateDrawPivot::RotateDrawPivot(RotateWindow *window,
117 RotateEffect *plugin,
120 : BC_CheckBox(x, y, plugin->config.draw_pivot, _("Draw pivot"))
122 this->plugin = plugin;
123 this->window = window;
126 int RotateDrawPivot::handle_event()
128 plugin->config.draw_pivot = get_value();
129 plugin->send_configure_change();
137 // RotateInterpolate::RotateInterpolate(RotateEffect *plugin, int x, int y)
138 // : BC_CheckBox(x, y, plugin->config.bilinear, _("Interpolate"))
140 // this->plugin = plugin;
142 // int RotateInterpolate::handle_event()
144 // plugin->config.bilinear = get_value();
145 // plugin->send_configure_change();
152 RotateFine::RotateFine(RotateWindow *window, RotateEffect *plugin, int x, int y)
155 (float)plugin->config.angle,
159 this->window = window;
160 this->plugin = plugin;
165 int RotateFine::handle_event()
167 plugin->config.angle = get_value();
168 window->update_toggles();
169 window->update_text();
170 plugin->send_configure_change();
176 RotateText::RotateText(RotateWindow *window,
177 RotateEffect *plugin,
184 (float)plugin->config.angle)
186 this->window = window;
187 this->plugin = plugin;
191 int RotateText::handle_event()
193 plugin->config.angle = atof(get_text());
194 window->update_toggles();
195 window->update_fine();
196 plugin->send_configure_change();
202 RotateX::RotateX(RotateWindow *window, RotateEffect *plugin, int x, int y)
205 (float)plugin->config.pivot_x,
209 this->window = window;
210 this->plugin = plugin;
215 int RotateX::handle_event()
217 plugin->config.pivot_x = get_value();
218 plugin->send_configure_change();
222 RotateY::RotateY(RotateWindow *window, RotateEffect *plugin, int x, int y)
225 (float)plugin->config.pivot_y,
229 this->window = window;
230 this->plugin = plugin;
235 int RotateY::handle_event()
237 plugin->config.pivot_y = get_value();
238 plugin->send_configure_change();
243 RotateReset::RotateReset(RotateEffect *plugin, RotateWindow *window, int x, int y)
244 : BC_GenericButton(x, y, _("Reset"))
246 this->plugin = plugin;
247 this->window = window;
249 RotateReset::~RotateReset()
252 int RotateReset::handle_event()
254 plugin->config.reset();
256 plugin->send_configure_change();
265 RotateWindow::RotateWindow(RotateEffect *plugin)
266 : PluginClientWindow(plugin, 300, 230, 300, 230, 0)
268 this->plugin = plugin;
273 void RotateWindow::create_objects()
277 add_tool(new BC_Title(x, y, _("Rotate")));
279 add_tool(toggle0 = new RotateToggle(this, plugin,
280 plugin->config.angle == 0, x, y, 0, "0"));
281 x += RADIUS; y += RADIUS;
282 add_tool(toggle90 = new RotateToggle(this, plugin,
283 plugin->config.angle == 90, x, y, 90, "90"));
284 x -= RADIUS; y += RADIUS;
285 add_tool(toggle180 = new RotateToggle(this, plugin,
286 plugin->config.angle == 180, x, y, 180, "180"));
287 x -= RADIUS; y -= RADIUS;
288 add_tool(toggle270 = new RotateToggle(this, plugin,
289 plugin->config.angle == 270, x, y, 270, "270"));
290 // add_subwindow(bilinear = new RotateInterpolate(plugin, 10, y + 60));
292 add_tool(fine = new RotateFine(this, plugin, x, y));
293 y += fine->get_h() + 10;
294 add_tool(text = new RotateText(this, plugin, x, y));
296 add_tool(new BC_Title(x, y, _("Degrees")));
298 y += text->get_h() + 10;
299 add_subwindow(title = new BC_Title(x, y, _("Pivot (x,y):")));
300 y += title->get_h() + 10;
301 add_subwindow(this->x = new RotateX(this, plugin, x, y));
302 x += this->x->get_w() + 10;
303 add_subwindow(this->y = new RotateY(this, plugin, x, y));
305 // y += this->y->get_h() + 10;
307 add_subwindow(draw_pivot = new RotateDrawPivot(this, plugin, x, y));
309 add_subwindow(reset = new RotateReset(plugin, this, x, y));
316 int RotateWindow::update()
321 // bilinear->update(plugin->config.bilinear);
325 int RotateWindow::update_fine()
327 fine->update(plugin->config.angle);
328 x->update(plugin->config.pivot_x);
329 y->update(plugin->config.pivot_y);
333 int RotateWindow::update_text()
335 text->update(plugin->config.angle);
339 int RotateWindow::update_toggles()
341 toggle0->update(EQUIV(plugin->config.angle, 0));
342 toggle90->update(EQUIV(plugin->config.angle, 90));
343 toggle180->update(EQUIV(plugin->config.angle, 180));
344 toggle270->update(EQUIV(plugin->config.angle, 270));
345 draw_pivot->update(plugin->config.draw_pivot);
382 RotateEffect::RotateEffect(PluginServer *server)
383 : PluginVClient(server)
386 need_reconfigure = 1;
390 RotateEffect::~RotateEffect()
393 if(engine) delete engine;
398 const char* RotateEffect::plugin_title() { return N_("Rotate"); }
399 int RotateEffect::is_realtime() { return 1; }
402 NEW_WINDOW_MACRO(RotateEffect, RotateWindow)
405 void RotateEffect::update_gui()
409 load_configuration();
410 thread->window->lock_window();
411 ((RotateWindow*)thread->window)->update();
412 thread->window->unlock_window();
416 LOAD_CONFIGURATION_MACRO(RotateEffect, RotateConfig)
421 void RotateEffect::save_data(KeyFrame *keyframe)
425 // cause data to be stored directly in text
426 output.set_shared_output(keyframe->xbuf);
427 output.tag.set_title("ROTATE");
428 output.tag.set_property("ANGLE", (float)config.angle);
429 output.tag.set_property("PIVOT_X", (float)config.pivot_x);
430 output.tag.set_property("PIVOT_Y", (float)config.pivot_y);
431 output.tag.set_property("DRAW_PIVOT", (int)config.draw_pivot);
432 // output.tag.set_property("INTERPOLATE", (int)config.bilinear);
434 output.tag.set_title("/ROTATE");
436 output.append_newline();
437 output.terminate_string();
438 // data is now in *text
441 void RotateEffect::read_data(KeyFrame *keyframe)
445 input.set_shared_input(keyframe->xbuf);
451 result = input.read_tag();
455 if(input.tag.title_is("ROTATE"))
457 config.angle = input.tag.get_property("ANGLE", (float)config.angle);
458 config.pivot_x = input.tag.get_property("PIVOT_X", (float)config.pivot_x);
459 config.pivot_y = input.tag.get_property("PIVOT_Y", (float)config.pivot_y);
460 config.draw_pivot = input.tag.get_property("DRAW_PIVOT", (int)config.draw_pivot);
461 // config.bilinear = input.tag.get_property("INTERPOLATE", (int)config.bilinear);
467 int RotateEffect::process_buffer(VFrame *frame,
468 int64_t start_position,
471 load_configuration();
472 int w = frame->get_w();
473 int h = frame->get_h();
474 //printf("RotateEffect::process_buffer %d\n", __LINE__);
477 if(config.angle == 0 && !config.draw_pivot)
486 //printf("RotateEffect::process_buffer %d\n", __LINE__);
488 if(!engine) engine = new AffineEngine(PluginClient::smp + 1,
489 PluginClient::smp + 1);
490 int pivot_x = (int)(config.pivot_x * get_input()->get_w() / 100);
491 int pivot_y = (int)(config.pivot_y * get_input()->get_h() / 100);
492 engine->set_in_pivot(pivot_x, pivot_y);
493 engine->set_out_pivot(pivot_x, pivot_y);
497 // engine->set_out_viewport(0, 0, 320, 240);
498 // engine->set_out_pivot(160, 120);
509 //printf("RotateEffect::process_buffer %d\n", __LINE__);
512 // engine->set_viewport(50,
516 // engine->set_pivot(100, 100);
519 VFrame *temp_frame = PluginVClient::new_temp(get_input()->get_w(),
520 get_input()->get_h(),
521 get_input()->get_color_model());
522 read_frame(temp_frame,
527 frame->clear_frame();
528 engine->rotate(frame,
532 //printf("RotateEffect::process_buffer %d draw_pivot=%d\n", __LINE__, config.draw_pivot);
537 #define DRAW_CENTER(components, type, max) \
539 type **rows = (type**)get_output()->get_rows(); \
540 if( (center_x >= 0 && center_x < w) && (center_y >= 0 && center_y < h) ) \
542 for(int i = center_x - CENTER_W / 2; i <= center_x + CENTER_W / 2; i++) \
544 if(i >= 0 && i < w) \
546 type *hrow = rows[center_y] + components * i; \
547 hrow[0] = max - hrow[0]; \
548 hrow[1] = max - hrow[1]; \
549 hrow[2] = max - hrow[2]; \
550 hrow += components; \
554 for(int i = center_y - CENTER_W / 2; i <= center_y + CENTER_W / 2; i++) \
556 if(i >= 0 && i < h) \
558 type *vrow = rows[i] + center_x * components; \
559 vrow[0] = max - vrow[0]; \
560 vrow[1] = max - vrow[1]; \
561 vrow[2] = max - vrow[2]; \
567 if(config.draw_pivot)
569 int center_x = (int)(config.pivot_x * w / 100); \
570 int center_y = (int)(config.pivot_y * h / 100); \
572 //printf("RotateEffect::process_buffer %d %d %d\n", __LINE__, center_x, center_y);
573 switch(get_output()->get_color_model())
576 DRAW_CENTER(3, float, 1.0)
579 DRAW_CENTER(4, float, 1.0)
582 DRAW_CENTER(3, unsigned char, 0xff)
585 DRAW_CENTER(4, unsigned char, 0xff)
588 DRAW_CENTER(3, unsigned char, 0xff)
591 DRAW_CENTER(4, unsigned char, 0xff)
596 // Conserve memory by deleting large frames
597 if(get_input()->get_w() > PLUGIN_MAX_W &&
598 get_input()->get_h() > PLUGIN_MAX_H)
608 int RotateEffect::handle_opengl()
611 engine->set_opengl(1);
612 engine->rotate(get_output(),
615 engine->set_opengl(0);
617 if(config.draw_pivot)
619 int w = get_output()->get_w();
620 int h = get_output()->get_h();
621 int center_x = (int)(config.pivot_x * w / 100);
622 int center_y = (int)(config.pivot_y * h / 100);
624 glDisable(GL_TEXTURE_2D);
625 glColor4f(0.0, 0.0, 0.0, 1.0);
627 glVertex3f(center_x, -h + center_y - CENTER_H / 2, 0.0);
628 glVertex3f(center_x, -h + center_y + CENTER_H / 2, 0.0);
631 glVertex3f(center_x - CENTER_W / 2, -h + center_y, 0.0);
632 glVertex3f(center_x + CENTER_W / 2, -h + center_y, 0.0);
634 glColor4f(1.0, 1.0, 1.0, 1.0);
636 glVertex3f(center_x - 1, -h + center_y - CENTER_H / 2 - 1, 0.0);
637 glVertex3f(center_x - 1, -h + center_y + CENTER_H / 2 - 1, 0.0);
640 glVertex3f(center_x - CENTER_W / 2 - 1, -h + center_y - 1, 0.0);
641 glVertex3f(center_x + CENTER_W / 2 - 1, -h + center_y - 1, 0.0);