diff options
Diffstat (limited to 'rotord/cvimage.cpp')
| -rw-r--r-- | rotord/cvimage.cpp | 52 |
1 files changed, 29 insertions, 23 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; } |
