From 574c15ebe9989d079eee42b9cee4be19333fe24e Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 10 May 2013 17:51:45 +0100 Subject: echo trails almost working (?) --- rotord/rotor.h | 88 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 25 deletions(-) (limited to 'rotord') diff --git a/rotord/rotor.h b/rotord/rotor.h index 407d57c..60138fe 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -124,6 +124,8 @@ namespace Rotor { class Frame_spec: public Time_spec{ public: Frame_spec(float _time,float _framerate,int _w,int _h){ time=_time; framerate=_framerate; w=_w; h=_h;}; + Frame_spec(int _frame,float _framerate,int _w,int _h){ time=((float)_frame)/framerate; framerate=_framerate; w=_w; h=_h;}; + //float time; //this hould probably be implemented with a num/denom scheme eventually for accuracy //float framerate; int h,w; @@ -187,13 +189,20 @@ namespace Rotor { } return false; } + Image* clone(){ + Image *t=new Image(w,h); + for (int i=0;iRGBdata[i]=RGBdata[i]; + } + return t; + } Image & operator+=(const Image &other) { if (other.w!=w||other.h!=h) { - cerr<<"Rotor: cannot add images with different sizes!"<setup(frame.w,frame.h); if (image_inputs.size()) { if (image_inputs[0]->connection){ if (LUT) { - Image *in= (((Image_node*)image_inputs[0]->connection)->get_output(frame)); - for (int i=0;iRGBdata[i]=LUT[in->RGBdata[i]]; - } + apply_LUT(*(((Image_node*)image_inputs[0]->connection)->get_output(frame))); return image; } } @@ -564,7 +578,7 @@ namespace Rotor { }; class Echo_trails: public Luma_levels { //draw trail frames additively that fade off over time - //the hard thing here is how to cache frames, if its done cleverly it could have no impact when + //the hard thing here is how to cache frames, if its done cleverly it could have no impact when //used linearly //Image needs to overload operator+ //need a clever data structure to cache frames - maybe a map of Image pointers @@ -598,17 +612,16 @@ namespace Rotor { number=find_setting(settings,"number",1); levels_settings(settings); image=new Image(); - w=h=0; + lastframe=-1; }; ~Echo_trails(){if (image) {delete image;} }; Image *get_output(const Frame_spec &frame){ - //cache frames - if (frame.w!=w||frame.h!=h){ //or framerate changed? + //check if cache is valid + if (frame.w!=image->w||frame.h!=image->h){ //or framerate changed? //clear cache and start over images.clear(); + lastframe=-1; //calculate frame interval - w=frame.w; - h=frame.h; interval=(int)((duration/number)*frame.framerate); total=interval*number; } @@ -623,15 +636,40 @@ namespace Rotor { ++i; } //if frame has already been calculated just return it - if (image) delete image; - if (image_inputs.size()) { - if (image_inputs[0]->connection){ - if (LUT) { - (*image)= *(((Image_node*)image_inputs[0]->connection)->get_output(frame)); - for (int i=0;iRGBdata[i]=LUT[in->RGBdata[i]]; + if (thisframe==lastframe) { + return image; + } + else { + if (image_inputs.size()) { + if (image_inputs[0]->connection){ + if (LUT) { + //copy incoming image **writable + image->free(); + image=(((Image_node*)image_inputs[0]->connection)->get_output(frame))->clone(); + for (int i=0;i-1){ + //check if image is in the cache + if (images.find(absframe)==images.end()){ + //cerr<<"Rotor: preparing image ("<w<<"x"<h<<")"<w,image->h); + //cerr<<"Rotor: prepared image ("<connection)->get_output(wanted)),*images[absframe]); + } + //cerr<<"Rotor: about to apply image ("<RGBdata[i]=LUT[in->RGBdata[i]]; + //} + lastframe=thisframe; + return image; } - return image; } } } @@ -640,9 +678,9 @@ namespace Rotor { Echo_trails* clone(map &_settings) { return new Echo_trails(_settings);}; private: float duration; - int number,w,h; - int interval,total; //number of frames between displayed echoes - unordered_map images; + int number; + int interval,total,lastframe; //number of frames between displayed echoes + unordered_map images; }; //------------------------------------------------------------------- class Node_factory{ -- cgit v1.2.3