diff options
Diffstat (limited to 'rotord')
| -rw-r--r-- | rotord/cvimage.cpp | 52 | ||||
| -rw-r--r-- | rotord/cvimage.h | 1 | ||||
| -rwxr-xr-x | rotord/rotor.cpp | 12 | ||||
| -rwxr-xr-x | rotord/rotor.h | 1 |
4 files changed, 42 insertions, 24 deletions
diff --git a/rotord/cvimage.cpp b/rotord/cvimage.cpp index a623bfd..ca094d3 100644 --- a/rotord/cvimage.cpp +++ b/rotord/cvimage.cpp @@ -49,25 +49,39 @@ namespace Rotor { //how to invert a matrix? //'invert' is matrix invert - different //subtract from a scalar (1) ? - //vector<cv::Mat> ichans,ochans; - //vector<cv::Mat> compchans; - //cv::split(rgb,ichans); - //cv::split(other.rgb,ochans); - //uint8_t b=0xFF; - //cv::Mat iA=b-other.alpha; - //cv::Mat iA=cv::Mat(h,w,CV_8UC1); - //for (int i=0;i<w*h;i++) iA.data[i]=(uint8_t)0xFF-other.alpha.data[i]; - //for (int i=0;i<3;i++) { - // compchans.push_back((ichans[i]/iA)+(ochans[i]/other.alpha)); //.mul(iA,1.0/255.0)); //+ochans[i].mul(other.alpha)); - //} - //merge(compchans,rgb); + vector<cv::Mat> ichans,ochans; + vector<cv::Mat> compchans; + cv::split(rgb,ichans); + cv::split(other.rgb,ochans); + uint8_t b=0xFF; + cv::Mat iA=b-other.alpha; + for (int i=0;i<3;i++) { + compchans.push_back(ichans[i].mul(iA,1.0/255.0)+ochans[i].mul(other.alpha,1.0/255.0)); + } + merge(compchans,rgb); //rgb+=other.rgb; + //for (int i=0;i<w*h*3;i++) { + // rgb.data[i]=(uint8_t)(((((int)rgb.data[i])*(0xFF-other.alpha.data[i/3]))>>8)+((((int)other.rgb.data[i])*((int)other.alpha.data[i/3]))>>8)); + //} + } + + return *this; + } + Image & Image::alpha_blend_old(const Image &other) { + if (other.w!=w||other.h!=h) { + cerr<<"Rotor: cannot blend images with different sizes! (wanted "<<w<<"x"<<h<<", got "<<other.w<<"x"<<other.h<<")"<<endl; + //why not?? + } + else if (!other.alpha.data){ + //default to full on alpha + rgb=other.rgb.clone(); + } + else { + rgb+=other.rgb; for (int i=0;i<w*h*3;i++) { rgb.data[i]=(uint8_t)(((((int)rgb.data[i])*(0xFF-other.alpha.data[i/3]))>>8)+((((int)other.rgb.data[i])*((int)other.alpha.data[i/3]))>>8)); - } } - return *this; } Image & Image::alpha_merge(const Image &other) { @@ -76,15 +90,7 @@ namespace Rotor { cerr<<"Rotor: cannot merge alpha with different size! (wanted "<<w<<"x"<<h<<", got "<<other.w<<"x"<<other.h<<")"<<endl; } else { - alpha=cv::Mat(h,w,CV_8UC1); - //cv::cvtColor(other.rgb,alpha,CV_RGB2GRAY); - for (int i=0;i<w*h;i++) { - uint8_t v=0; - for (int j=0;j<3;j++){ - v+=pixels.mono_weights[j][other.rgb.data[i*3+j]]; - } - alpha.data[i]=v; - } + cv::cvtColor(other.rgb,alpha,CV_RGB2GRAY); } return *this; } diff --git a/rotord/cvimage.h b/rotord/cvimage.h index 7935ded..c73ba70 100644 --- a/rotord/cvimage.h +++ b/rotord/cvimage.h @@ -162,6 +162,7 @@ namespace Rotor { Image & operator*=(const Image &other); Image & add_wrap(const Image &other); Image & alpha_blend(const Image &other); + Image & alpha_blend_old(const Image &other); Image & alpha_merge(const Image &other); Image & operator*=(const float &amount); Image * operator*(const float &amount); diff --git a/rotord/rotor.cpp b/rotord/rotor.cpp index a1163fe..f1c9575 100755 --- a/rotord/rotor.cpp +++ b/rotord/rotor.cpp @@ -211,6 +211,11 @@ bool Video_output::render(const float duration, const float framerate,const stri //25fps video and 43.06640625fps audio? hmm //how to get the timecodes correct for the interleaved files + struct timeval start, end; + + gettimeofday(&start, NULL); + + float vstep=1.0f/framerate; float v=0.0f; float vf=0.0f; @@ -246,7 +251,12 @@ bool Video_output::render(const float duration, const float framerate,const stri } exporter.finishRecord(); - cerr << "Rotor: Video_output finished "<< endl; + + gettimeofday(&end, NULL); + + float mtime = ((end.tv_sec-start.tv_sec) + (end.tv_usec-start.tv_usec)/1000000.0) + 0.5; + + printf("Rotor Video_output: rendered in %02f seconds\n", mtime); if (usingaudio) audioloader.close(); diff --git a/rotord/rotor.h b/rotord/rotor.h index 055d0b7..1d0172f 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -16,6 +16,7 @@ http://stackoverflow.com/questions/5261658/how-to-seek-in-ffmpeg-c-c #include <deque> #include <math.h> #include <memory> +#include <sys/time.h> #include "Poco/Net/HTTPServer.h" #include "Poco/Net/HTTPResponse.h" |
