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
26 #include "bcdisplayinfo.h"
30 #include "timefront.h"
33 #include "overlayframe.h"
39 REGISTER_PLUGIN(TimeFrontMain)
46 TimeFrontConfig::TimeFrontConfig()
52 track_usage = TimeFrontConfig::OTHERTRACK_INTENSITY;
53 shape = TimeFrontConfig::LINEAR;
54 rate = TimeFrontConfig::LINEAR;
61 int TimeFrontConfig::equivalent(TimeFrontConfig &that)
63 return (EQUIV(angle, that.angle) &&
64 EQUIV(in_radius, that.in_radius) &&
65 EQUIV(out_radius, that.out_radius) &&
66 frame_range == that.frame_range &&
67 track_usage == that.track_usage &&
68 shape == that.shape &&
70 EQUIV(center_x, that.center_x) &&
71 EQUIV(center_y, that.center_y) &&
72 invert == that.invert &&
73 show_grayscale == that.show_grayscale);
76 void TimeFrontConfig::copy_from(TimeFrontConfig &that)
79 in_radius = that.in_radius;
80 out_radius = that.out_radius;
81 frame_range = that.frame_range;
82 track_usage = that.track_usage;
85 center_x = that.center_x;
86 center_y = that.center_y;
88 show_grayscale = that.show_grayscale;
91 void TimeFrontConfig::interpolate(TimeFrontConfig &prev,
92 TimeFrontConfig &next,
97 double next_scale = (double)(current_frame - prev_frame) / (next_frame - prev_frame);
98 double prev_scale = (double)(next_frame - current_frame) / (next_frame - prev_frame);
101 this->angle = (int)(prev.angle * prev_scale + next.angle * next_scale);
102 this->in_radius = (int)(prev.in_radius * prev_scale + next.in_radius * next_scale);
103 this->out_radius = (int)(prev.out_radius * prev_scale + next.out_radius * next_scale);
104 frame_range = (int)(prev.frame_range * prev_scale + next.frame_range * next_scale);
105 track_usage = prev.track_usage;
108 center_x = prev.center_x * prev_scale + next.center_x * next_scale;
109 center_y = prev.center_y * prev_scale + next.center_y * next_scale;
110 invert = prev.invert;
111 show_grayscale = prev.show_grayscale;
121 TimeFrontWindow::TimeFrontWindow(TimeFrontMain *plugin)
122 : PluginClientWindow(plugin,
129 this->plugin = plugin;
140 out_radius_title = 0;
142 track_usage_title = 0;
147 TimeFrontWindow::~TimeFrontWindow()
151 void TimeFrontWindow::create_objects()
154 int ys10 = yS(10), ys35 = yS(35), ys40 = yS(40), ys140 = yS(140);
155 int x = xs10, y = ys10;
158 add_subwindow(title = new BC_Title(x, y, _("Type:")));
159 add_subwindow(shape = new TimeFrontShape(plugin,
161 x + title->get_w() + xs10,
163 shape->create_objects();
168 add_subwindow(title = new BC_Title(x, y, _("Time range:")));
169 add_subwindow(frame_range = new TimeFrontFrameRange(plugin, x + title->get_w() + xs10, y));
170 frame_range_x = x + frame_range->get_w() + xs10;
175 add_subwindow(invert = new TimeFrontInvert(plugin, x, y));
176 add_subwindow(show_grayscale = new TimeFrontShowGrayscale(plugin, x+ xS(100), y));
183 void TimeFrontWindow::update_shape()
185 int x = shape_x, y = shape_y;
187 if(plugin->config.shape == TimeFrontConfig::LINEAR)
189 delete center_x_title;
190 delete center_y_title;
193 delete track_usage_title;
199 track_usage_title = 0;
203 add_subwindow(angle_title = new BC_Title(x, y, _("Angle:")));
204 add_subwindow(angle = new TimeFrontAngle(plugin, x + angle_title->get_w() + xS(10), y));
207 y = shape_y + yS(40);
209 add_subwindow(rate_title = new BC_Title(x, y, _("Rate:")));
210 add_subwindow(rate = new TimeFrontRate(plugin,
211 x + rate_title->get_w() + xS(10),
213 rate->create_objects();
215 add_subwindow(in_radius_title = new BC_Title(x, y, _("Inner radius:")));
216 add_subwindow(in_radius = new TimeFrontInRadius(plugin, x + in_radius_title->get_w() + xS(10), y));
218 add_subwindow(out_radius_title = new BC_Title(x, y, _("Outer radius:")));
219 add_subwindow(out_radius = new TimeFrontOutRadius(plugin, x + out_radius_title->get_w() + xS(10), y));
224 if(plugin->config.shape == TimeFrontConfig::RADIAL)
228 delete track_usage_title;
232 track_usage_title = 0;
236 add_subwindow(center_x_title = new BC_Title(x, y, _("Center X:")));
237 add_subwindow(center_x = new TimeFrontCenterX(plugin,
238 x + center_x_title->get_w() + xS(10),
240 x += center_x_title->get_w() + xS(10) + center_x->get_w() + xS(10);
241 add_subwindow(center_y_title = new BC_Title(x, y, _("Center Y:")));
242 add_subwindow(center_y = new TimeFrontCenterY(plugin,
243 x + center_y_title->get_w() + xS(10),
250 y = shape_y + yS(40);
252 add_subwindow(rate_title = new BC_Title(x, y, _("Rate:")));
253 add_subwindow(rate = new TimeFrontRate(plugin,
254 x + rate_title->get_w() + xS(10),
256 rate->create_objects();
258 add_subwindow(in_radius_title = new BC_Title(x, y, _("Inner radius:")));
259 add_subwindow(in_radius = new TimeFrontInRadius(plugin, x + in_radius_title->get_w() + xS(10), y));
261 add_subwindow(out_radius_title = new BC_Title(x, y, _("Outer radius:")));
262 add_subwindow(out_radius = new TimeFrontOutRadius(plugin, x + out_radius_title->get_w() + xS(10), y));
266 if(plugin->config.shape == TimeFrontConfig::OTHERTRACK)
268 delete center_x_title;
269 delete center_y_title;
276 delete in_radius_title;
278 delete out_radius_title;
290 out_radius_title = 0;
294 add_subwindow(track_usage_title = new BC_Title(x, y, _("As timefront use:")));
295 add_subwindow(track_usage = new TimeFrontTrackUsage(plugin,
297 x + track_usage_title->get_w() + xS(10),
299 track_usage->create_objects();
303 if(plugin->config.shape == TimeFrontConfig::ALPHA)
305 delete center_x_title;
306 delete center_y_title;
313 delete in_radius_title;
315 delete out_radius_title;
317 delete track_usage_title;
329 out_radius_title = 0;
331 track_usage_title = 0;
350 TimeFrontShape::TimeFrontShape(TimeFrontMain *plugin,
351 TimeFrontWindow *gui,
354 : BC_PopupMenu(x, y, xS(230), to_text(plugin->config.shape), 1)
356 this->plugin = plugin;
359 void TimeFrontShape::create_objects()
361 add_item(new BC_MenuItem(to_text(TimeFrontConfig::LINEAR)));
362 add_item(new BC_MenuItem(to_text(TimeFrontConfig::RADIAL)));
363 add_item(new BC_MenuItem(to_text(TimeFrontConfig::ALPHA)));
364 add_item(new BC_MenuItem(to_text(TimeFrontConfig::OTHERTRACK)));
366 char* TimeFrontShape::to_text(int shape)
370 case TimeFrontConfig::LINEAR:
372 case TimeFrontConfig::OTHERTRACK:
373 return _("Other track as timefront");
374 case TimeFrontConfig::ALPHA:
375 return _("Alpha as timefront");
380 int TimeFrontShape::from_text(char *text)
382 if(!strcmp(text, to_text(TimeFrontConfig::LINEAR)))
383 return TimeFrontConfig::LINEAR;
384 if(!strcmp(text, to_text(TimeFrontConfig::OTHERTRACK)))
385 return TimeFrontConfig::OTHERTRACK;
386 if(!strcmp(text, to_text(TimeFrontConfig::ALPHA)))
387 return TimeFrontConfig::ALPHA;
388 return TimeFrontConfig::RADIAL;
390 int TimeFrontShape::handle_event()
392 plugin->config.shape = from_text(get_text());
395 plugin->send_configure_change();
400 TimeFrontTrackUsage::TimeFrontTrackUsage(TimeFrontMain *plugin,
401 TimeFrontWindow *gui, int x, int y)
402 : BC_PopupMenu(x, y, xS(140), to_text(plugin->config.track_usage), 1)
404 this->plugin = plugin;
407 void TimeFrontTrackUsage::create_objects()
409 add_item(new BC_MenuItem(to_text(TimeFrontConfig::OTHERTRACK_INTENSITY)));
410 add_item(new BC_MenuItem(to_text(TimeFrontConfig::OTHERTRACK_ALPHA)));
412 char* TimeFrontTrackUsage::to_text(int track_usage)
416 case TimeFrontConfig::OTHERTRACK_INTENSITY:
417 return _("Intensity");
418 case TimeFrontConfig::OTHERTRACK_ALPHA:
419 return _("Alpha mask");
424 int TimeFrontTrackUsage::from_text(char *text)
426 if(!strcmp(text, to_text(TimeFrontConfig::OTHERTRACK_INTENSITY)))
427 return TimeFrontConfig::OTHERTRACK_INTENSITY;
428 if(!strcmp(text, to_text(TimeFrontConfig::OTHERTRACK_ALPHA)))
429 return TimeFrontConfig::OTHERTRACK_ALPHA;
431 return TimeFrontConfig::OTHERTRACK_INTENSITY;
433 int TimeFrontTrackUsage::handle_event()
435 plugin->config.track_usage = from_text(get_text());
438 plugin->send_configure_change();
445 TimeFrontCenterX::TimeFrontCenterX(TimeFrontMain *plugin, int x, int y)
446 : BC_FPot(x, y, plugin->config.center_x, 0, 100)
448 this->plugin = plugin;
450 int TimeFrontCenterX::handle_event()
452 plugin->config.center_x = get_value();
453 plugin->send_configure_change();
459 TimeFrontCenterY::TimeFrontCenterY(TimeFrontMain *plugin, int x, int y)
460 : BC_FPot(x, y, plugin->config.center_y, 0, 100)
462 this->plugin = plugin;
465 int TimeFrontCenterY::handle_event()
467 plugin->config.center_y = get_value();
468 plugin->send_configure_change();
475 TimeFrontAngle::TimeFrontAngle(TimeFrontMain *plugin, int x, int y)
478 plugin->config.angle,
482 this->plugin = plugin;
485 int TimeFrontAngle::handle_event()
487 plugin->config.angle = get_value();
488 plugin->send_configure_change();
493 TimeFrontRate::TimeFrontRate(TimeFrontMain *plugin, int x, int y)
494 : BC_PopupMenu(x, y, xS(155), to_text(plugin->config.rate), 1)
496 this->plugin = plugin;
498 void TimeFrontRate::create_objects()
500 add_item(new BC_MenuItem(to_text(TimeFrontConfig::LINEAR)));
501 add_item(new BC_MenuItem(to_text(TimeFrontConfig::LOG)));
502 add_item(new BC_MenuItem(to_text(TimeFrontConfig::SQUARE)));
504 char* TimeFrontRate::to_text(int shape)
508 case TimeFrontConfig::LINEAR:
510 case TimeFrontConfig::LOG:
516 int TimeFrontRate::from_text(char *text)
518 if(!strcmp(text, to_text(TimeFrontConfig::LINEAR)))
519 return TimeFrontConfig::LINEAR;
520 if(!strcmp(text, to_text(TimeFrontConfig::LOG)))
521 return TimeFrontConfig::LOG;
522 return TimeFrontConfig::SQUARE;
524 int TimeFrontRate::handle_event()
526 plugin->config.rate = from_text(get_text());
527 plugin->send_configure_change();
533 TimeFrontInRadius::TimeFrontInRadius(TimeFrontMain *plugin, int x, int y)
541 (float)plugin->config.in_radius)
543 this->plugin = plugin;
546 int TimeFrontInRadius::handle_event()
548 plugin->config.in_radius = get_value();
549 plugin->send_configure_change();
554 TimeFrontOutRadius::TimeFrontOutRadius(TimeFrontMain *plugin, int x, int y)
562 (float)plugin->config.out_radius)
564 this->plugin = plugin;
567 int TimeFrontOutRadius::handle_event()
569 plugin->config.out_radius = get_value();
570 plugin->send_configure_change();
574 TimeFrontFrameRange::TimeFrontFrameRange(TimeFrontMain *plugin, int x, int y)
582 (int)plugin->config.frame_range)
584 this->plugin = plugin;
587 int TimeFrontFrameRange::handle_event()
589 plugin->config.frame_range = get_value();
590 plugin->send_configure_change();
595 TimeFrontInvert::TimeFrontInvert(TimeFrontMain *client, int x, int y)
598 client->config.invert,
601 this->plugin = client;
604 int TimeFrontInvert::handle_event()
606 plugin->config.invert = get_value();
607 plugin->send_configure_change();
611 TimeFrontShowGrayscale::TimeFrontShowGrayscale(TimeFrontMain *client, int x, int y)
614 client->config.show_grayscale,
615 _("Show grayscale (for tuning"))
617 this->plugin = client;
620 int TimeFrontShowGrayscale::handle_event()
622 plugin->config.show_grayscale = get_value();
623 plugin->send_configure_change();
629 TimeFrontMain::TimeFrontMain(PluginServer *server)
630 : PluginVClient(server)
633 need_reconfigure = 1;
639 TimeFrontMain::~TimeFrontMain()
643 if(gradient) delete gradient;
644 if(engine) delete engine;
645 if(overlayer) delete overlayer;
648 const char* TimeFrontMain::plugin_title() { return N_("TimeFront"); }
649 int TimeFrontMain::is_realtime() { return 1; }
650 int TimeFrontMain::is_multichannel() { return 1; }
654 NEW_WINDOW_MACRO(TimeFrontMain, TimeFrontWindow)
656 LOAD_CONFIGURATION_MACRO(TimeFrontMain, TimeFrontConfig)
658 int TimeFrontMain::is_synthesis()
663 #define GRADIENTFROMAVG(type, inttype, components, maxval) \
664 for(int i = 0; i < tfframe->get_h(); i++) \
666 type *in_row = (type *)tfframe->get_rows()[i]; \
667 unsigned char *grad_row = gradient->get_rows()[i]; \
668 for(int j = 0; j < tfframe->get_w(); j++) \
670 inttype tmp = (inttype) in_row[j * components] + \
671 in_row[j * components + 1] + \
672 in_row[j * components + 2]; \
673 if (components == 3) \
674 grad_row[j] = (unsigned char) (CLIP((float)config.frame_range * tmp / maxval / 3, 0.0F, config.frame_range)); \
675 else if(components == 4) \
676 grad_row[j] = (unsigned char) (CLIP((float)config.frame_range * tmp * in_row[j * components + 3] / maxval / maxval / 3, 0.0F, config.frame_range)); \
680 #define GRADIENTFROMCHANNEL(type, components, max, channel) \
681 for(int i = 0; i < tfframe->get_h(); i++) \
683 type *in_row = (type *)tfframe->get_rows()[i]; \
684 unsigned char *grad_row = gradient->get_rows()[i]; \
685 for(int j = 0; j < tfframe->get_w(); j++) \
687 if (components == 3) \
688 grad_row[j] = (unsigned char) (CLIP((float)config.frame_range * in_row[j * components + channel] / max, 0.0F, config.frame_range)); \
689 else if(components == 4) \
690 grad_row[j] = (unsigned char) (CLIP((float)config.frame_range * in_row[j * components + channel] * in_row[j * components + 3]/ max /max, 0.0F, config.frame_range)); \
694 #define SETALPHA(type, max) \
695 for(int i = 0; i < outframes[0]->get_h(); i++) \
697 type *out_row = (type *)outframes[0]->get_rows()[i]; \
698 for(int j = 0; j < outframes[0]->get_w(); j++) \
700 out_row[j * 4 + 3] = max; \
704 #define GRADIENTTOPICTURE(type, inttype, components, max, invertion) \
705 for(int i = 0; i < height; i++) \
707 type *out_row = (type *)outframes[0]->get_rows()[i]; \
708 unsigned char *grad_row = gradient->get_rows()[i]; \
709 for (int j = 0; j < width; j++) \
711 out_row[0] = (inttype)max * (invertion grad_row[0]) / config.frame_range; \
712 out_row[1] = (inttype)max * (invertion grad_row[0]) / config.frame_range; \
713 out_row[2] = (inttype)max * (invertion grad_row[0]) / config.frame_range; \
714 if (components == 4) \
716 out_row += components; \
721 #define GRADIENTTOYUVPICTURE(type, inttype, components, max, invertion) \
722 for(int i = 0; i < height; i++) \
724 type *out_row = (type *)outframes[0]->get_rows()[i]; \
725 unsigned char *grad_row = gradient->get_rows()[i]; \
726 for (int j = 0; j < width; j++) \
728 out_row[0] = (inttype)max * (invertion grad_row[0]) / config.frame_range; \
729 out_row[1] = max/2; \
730 out_row[2] = max/2; \
731 if (components == 4) \
733 out_row += components; \
738 #define COMPOSITEIMAGE(type, components, invertion) \
739 for (int i = 0; i < height; i++) \
741 type *out_row = (type *)outframes[0]->get_rows()[i]; \
742 unsigned char *gradient_row = gradient->get_rows()[i]; \
743 for (int j = 0; j < width; j++) \
745 unsigned int choice = invertion gradient_row[j]; \
747 type *in_row = (type *)framelist[choice]->get_rows()[i]; \
748 out_row[0] = in_row[j * components + 0]; \
749 out_row[1] = in_row[j * components + 1]; \
750 out_row[2] = in_row[j * components + 2]; \
751 if (components == 4) \
752 out_row[3] = in_row[j * components + 3]; \
754 out_row += components; \
760 int TimeFrontMain::process_buffer(VFrame **frame,
761 int64_t start_position,
763 //int TimeFrontMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
765 VFrame **outframes = frame;
766 VFrame *(framelist[1024]);
767 framelist[0] = new VFrame (outframes[0]->get_w(), outframes[0]->get_h(),
768 outframes[0]->get_color_model(), 0);
769 read_frame(framelist[0],
774 this->input = framelist[0];
775 this->output = outframes[0];
776 need_reconfigure |= load_configuration();
777 if (config.shape == TimeFrontConfig::OTHERTRACK)
779 // this->output = frame[1];
780 if (get_total_buffers() != 2)
782 // FIXME, maybe this should go to some other notification area?
783 printf(_("ERROR: TimeFront plugin - If you are using another track for timefront, you have to have it under shared effects\n"));
786 if (outframes[0]->get_w() != outframes[1]->get_w() || outframes[0]->get_h() != outframes[1]->get_h())
788 printf(_("Sizes of master track and timefront track do not match\n"));
793 // Generate new gradient
796 need_reconfigure = 0;
799 gradient = new VFrame( outframes[0]->get_w(), outframes[0]->get_h(), BC_A8, 0);
801 if (config.shape != TimeFrontConfig::OTHERTRACK &&
802 config.shape != TimeFrontConfig::ALPHA)
804 if(!engine) engine = new TimeFrontServer(this,
805 get_project_smp() + 1,
806 get_project_smp() + 1);
807 engine->process_packages();
811 if (config.shape == TimeFrontConfig::ALPHA)
814 gradient = new VFrame(outframes[0]->get_w(), outframes[0]->get_h(), BC_A8, 0);
815 VFrame *tfframe = framelist[0];
816 switch (tfframe->get_color_model())
820 GRADIENTFROMCHANNEL(unsigned char, 4, 255, 3);
825 GRADIENTFROMCHANNEL(float, 4, 1.0f, 3);
830 printf(_("TimeFront plugin error: ALPHA used, but project color model does not have alpha\n"));
837 if (config.shape == TimeFrontConfig::OTHERTRACK)
840 gradient = new VFrame(outframes[0]->get_w(), outframes[0]->get_h(), BC_A8, 0);
841 VFrame *tfframe = outframes[1];
847 if (config.track_usage == TimeFrontConfig::OTHERTRACK_INTENSITY)
849 switch (tfframe->get_color_model())
852 GRADIENTFROMAVG(unsigned char, unsigned short, 4, 255); // Has to be 2 ranges bigger, sice we need precision for alpha
855 GRADIENTFROMAVG(unsigned char, unsigned short, 3, 255);
858 GRADIENTFROMAVG(float, float, 3, 1.0f);
861 GRADIENTFROMAVG(float, float, 4, 1.0f);
863 case BC_YUV888: // We cheat and take Y component as intensity
864 GRADIENTFROMCHANNEL(unsigned char, 3, 255, 0);
867 GRADIENTFROMCHANNEL(unsigned char, 4, 255, 0);
873 if (config.track_usage == TimeFrontConfig::OTHERTRACK_ALPHA)
875 switch (tfframe->get_color_model())
879 GRADIENTFROMCHANNEL(unsigned char, 4, 255, 3);
884 GRADIENTFROMCHANNEL(float, 4, 1.0f, 3);
889 printf(_("TimeFront plugin error: ALPHA track used, but project color model does not have alpha\n"));
896 printf(_("TimeFront plugin error: unsupported track_usage parameter\n"));
901 if (!config.show_grayscale)
903 for (int i = 1; i <= config.frame_range; i++)
905 framelist[i] = new VFrame (outframes[0]->get_w(), outframes[0]->get_h(),
906 outframes[0]->get_color_model(), 0);
908 read_frame(framelist[i],
917 int width = outframes[0]->get_w();
918 int height = outframes[0]->get_h();
919 if (config.show_grayscale)
923 switch (outframes[0]->get_color_model())
926 GRADIENTTOPICTURE(unsigned char, unsigned short, 3, 255, );
929 GRADIENTTOPICTURE(unsigned char, unsigned short, 4, 255, );
932 GRADIENTTOYUVPICTURE(unsigned char, unsigned short, 3, 255, );
935 GRADIENTTOYUVPICTURE(unsigned char, unsigned short, 4, 255, );
938 GRADIENTTOPICTURE(float, float, 3, 1.0f, );
941 GRADIENTTOPICTURE(float, float, 4, 1.0f, );
948 switch (outframes[0]->get_color_model())
951 GRADIENTTOPICTURE(unsigned char, unsigned short, 3, 255, config.frame_range -);
954 GRADIENTTOPICTURE(unsigned char, unsigned short, 4, 255, config.frame_range -);
957 GRADIENTTOYUVPICTURE(unsigned char, unsigned short, 3, 255, config.frame_range -);
960 GRADIENTTOYUVPICTURE(unsigned char, unsigned short, 4, 255, config.frame_range -);
963 GRADIENTTOPICTURE(float, float, 3, 1.0f, config.frame_range -);
966 GRADIENTTOPICTURE(float, float, 4, 1.0f, config.frame_range -);
975 switch (outframes[0]->get_color_model())
978 COMPOSITEIMAGE(unsigned char, 3, );
981 COMPOSITEIMAGE(unsigned char, 4, );
984 COMPOSITEIMAGE(unsigned char, 3, );
987 COMPOSITEIMAGE(unsigned char, 4, );
990 COMPOSITEIMAGE(float, 3, );
993 COMPOSITEIMAGE(float, 4, );
1001 switch (outframes[0]->get_color_model())
1004 COMPOSITEIMAGE(unsigned char, 3, config.frame_range -);
1007 COMPOSITEIMAGE(unsigned char, 4, config.frame_range -);
1010 COMPOSITEIMAGE(unsigned char, 3, config.frame_range -);
1013 COMPOSITEIMAGE(unsigned char, 4, config.frame_range -);
1016 COMPOSITEIMAGE(float, 3, config.frame_range -);
1019 COMPOSITEIMAGE(float, 4, config.frame_range -);
1026 if (config.shape == TimeFrontConfig::ALPHA)
1029 switch (outframes[0]->get_color_model())
1033 SETALPHA(unsigned char, 255);
1036 SETALPHA(float, 1.0f);
1044 delete framelist[0];
1045 if (!config.show_grayscale)
1047 for (int i = 1; i <= config.frame_range; i++)
1048 delete framelist[i];
1054 void TimeFrontMain::update_gui()
1058 if(load_configuration())
1060 thread->window->lock_window("TimeFrontMain::update_gui");
1061 ((TimeFrontWindow*)thread->window)->frame_range->update(config.frame_range);
1062 ((TimeFrontWindow*)thread->window)->shape->set_text(TimeFrontShape::to_text(config.shape));
1063 ((TimeFrontWindow*)thread->window)->show_grayscale->update(config.show_grayscale);
1064 ((TimeFrontWindow*)thread->window)->invert->update(config.invert);
1065 ((TimeFrontWindow*)thread->window)->shape->set_text(TimeFrontShape::to_text(config.shape));
1066 if (((TimeFrontWindow*)thread->window)->rate)
1067 ((TimeFrontWindow*)thread->window)->rate->set_text(TimeFrontRate::to_text(config.rate));
1068 if (((TimeFrontWindow*)thread->window)->in_radius)
1069 ((TimeFrontWindow*)thread->window)->in_radius->update(config.in_radius);
1070 if (((TimeFrontWindow*)thread->window)->out_radius)
1071 ((TimeFrontWindow*)thread->window)->out_radius->update(config.out_radius);
1072 if (((TimeFrontWindow*)thread->window)->track_usage)
1073 ((TimeFrontWindow*)thread->window)->track_usage->set_text(TimeFrontTrackUsage::to_text(config.track_usage));
1074 if(((TimeFrontWindow*)thread->window)->angle)
1075 ((TimeFrontWindow*)thread->window)->angle->update(config.angle);
1076 if(((TimeFrontWindow*)thread->window)->center_x)
1077 ((TimeFrontWindow*)thread->window)->center_x->update(config.center_x);
1078 if(((TimeFrontWindow*)thread->window)->center_y)
1079 ((TimeFrontWindow*)thread->window)->center_y->update(config.center_y);
1081 ((TimeFrontWindow*)thread->window)->update_shape();
1082 thread->window->unlock_window();
1090 void TimeFrontMain::save_data(KeyFrame *keyframe)
1094 // cause data to be stored directly in text
1095 output.set_shared_output(keyframe->xbuf);
1096 output.tag.set_title("TIMEFRONT");
1098 output.tag.set_property("ANGLE", config.angle);
1099 output.tag.set_property("IN_RADIUS", config.in_radius);
1100 output.tag.set_property("OUT_RADIUS", config.out_radius);
1101 output.tag.set_property("FRAME_RANGE", config.frame_range);
1102 output.tag.set_property("SHAPE", config.shape);
1103 output.tag.set_property("TRACK_USAGE", config.track_usage);
1104 output.tag.set_property("RATE", config.rate);
1105 output.tag.set_property("CENTER_X", config.center_x);
1106 output.tag.set_property("CENTER_Y", config.center_y);
1107 output.tag.set_property("INVERT", config.invert);
1108 output.tag.set_property("SHOW_GRAYSCALE", config.show_grayscale);
1109 output.append_tag();
1110 output.tag.set_title("/TIMEFRONT");
1111 output.append_tag();
1112 output.append_newline();
1113 output.terminate_string();
1116 void TimeFrontMain::read_data(KeyFrame *keyframe)
1120 input.set_shared_input(keyframe->xbuf);
1126 result = input.read_tag();
1130 if(input.tag.title_is("TIMEFRONT"))
1132 config.angle = input.tag.get_property("ANGLE", config.angle);
1133 config.rate = input.tag.get_property("RATE", config.rate);
1134 config.in_radius = input.tag.get_property("IN_RADIUS", config.in_radius);
1135 config.out_radius = input.tag.get_property("OUT_RADIUS", config.out_radius);
1136 config.frame_range = input.tag.get_property("FRAME_RANGE", config.frame_range);
1137 config.shape = input.tag.get_property("SHAPE", config.shape);
1138 config.track_usage = input.tag.get_property("TRACK_USAGE", config.track_usage);
1139 config.center_x = input.tag.get_property("CENTER_X", config.center_x);
1140 config.center_y = input.tag.get_property("CENTER_Y", config.center_y);
1141 config.invert = input.tag.get_property("INVERT", config.invert);
1142 config.show_grayscale = input.tag.get_property("SHOW_GRAYSCALE", config.show_grayscale);
1153 TimeFrontPackage::TimeFrontPackage()
1161 TimeFrontUnit::TimeFrontUnit(TimeFrontServer *server, TimeFrontMain *plugin)
1162 : LoadClient(server)
1164 this->plugin = plugin;
1165 this->server = server;
1171 #define CREATE_GRADIENT \
1173 /* Synthesize linear gradient for lookups */ \
1175 a_table = (unsigned char *)malloc(sizeof(unsigned char) * gradient_size); \
1177 for(int i = 0; i < gradient_size; i++) \
1179 float opacity = 0.0; \
1180 switch(plugin->config.rate) \
1182 case TimeFrontConfig::LINEAR: \
1186 if(i >= out_radius) \
1189 opacity = (float)(i - in_radius) / (out_radius - in_radius); \
1191 case TimeFrontConfig::LOG: \
1192 opacity = 1 - exp(LOG_RANGE * -(float)(i - in_radius) / (out_radius - in_radius)); \
1194 case TimeFrontConfig::SQUARE: \
1195 opacity = SQR((float)(i - in_radius) / (out_radius - in_radius)); \
1199 CLAMP(opacity, 0, 1); \
1200 float transparency = 1.0 - opacity; \
1201 a_table[i] = (unsigned char)(out4 * opacity + in4 * transparency); \
1204 for(int i = pkg->y1; i < pkg->y2; i++) \
1206 unsigned char *out_row = plugin->gradient->get_rows()[i]; \
1208 switch(plugin->config.shape) \
1210 case TimeFrontConfig::LINEAR: \
1211 for(int j = 0; j < w; j++) \
1213 int x = j - half_w; \
1214 int y = -(i - half_h); \
1216 /* Rotate by effect angle */ \
1217 int input_y = (int)(gradient_size / 2 - \
1218 (x * sin_angle + y * cos_angle) + \
1221 /* Get gradient value from these coords */ \
1225 out_row[0] = out4; \
1228 if(input_y >= gradient_size) \
1234 out_row[0] = a_table[input_y]; \
1241 case TimeFrontConfig::RADIAL: \
1242 for(int j = 0; j < w; j++) \
1244 double x = j - center_x; \
1245 double y = i - center_y; \
1246 double magnitude = hypot(x, y); \
1247 int input_y = (int)magnitude; \
1248 out_row[0] = a_table[input_y]; \
1256 void TimeFrontUnit::process_package(LoadPackage *package)
1258 TimeFrontPackage *pkg = (TimeFrontPackage*)package;
1259 int h = plugin->input->get_h();
1260 int w = plugin->input->get_w();
1263 int gradient_size = (int)(ceil(hypot(w, h)));
1264 int in_radius = (int)(plugin->config.in_radius / 100 * gradient_size);
1265 int out_radius = (int)(plugin->config.out_radius / 100 * gradient_size);
1266 double sin_angle = sin(plugin->config.angle * (M_PI / 180));
1267 double cos_angle = cos(plugin->config.angle * (M_PI / 180));
1268 double center_x = plugin->config.center_x * w / 100;
1269 double center_y = plugin->config.center_y * h / 100;
1270 unsigned char *a_table = 0;
1272 if(in_radius > out_radius)
1274 in_radius ^= out_radius;
1275 out_radius ^= in_radius;
1276 in_radius ^= out_radius;
1280 int in4 = plugin->config.frame_range;
1284 if(a_table) free(a_table);
1292 TimeFrontServer::TimeFrontServer(TimeFrontMain *plugin,
1295 : LoadServer(total_clients, total_packages)
1297 this->plugin = plugin;
1300 void TimeFrontServer::init_packages()
1302 for(int i = 0; i < get_total_packages(); i++)
1304 TimeFrontPackage *package = (TimeFrontPackage*)get_package(i);
1305 package->y1 = plugin->input->get_h() *
1307 get_total_packages();
1308 package->y2 = plugin->input->get_h() *
1310 get_total_packages();
1314 LoadClient* TimeFrontServer::new_client()
1316 return new TimeFrontUnit(this, plugin);
1319 LoadPackage* TimeFrontServer::new_package()
1321 return new TimeFrontPackage;