summaryrefslogtreecommitdiff
path: root/rotord/cvimage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/cvimage.cpp')
-rw-r--r--rotord/cvimage.cpp62
1 files changed, 60 insertions, 2 deletions
diff --git a/rotord/cvimage.cpp b/rotord/cvimage.cpp
index 3a070a9..2130fc6 100644
--- a/rotord/cvimage.cpp
+++ b/rotord/cvimage.cpp
@@ -3,7 +3,6 @@
using namespace std;
namespace Rotor {
- //believe these still work, don't know if these optimisations are better than opencvs..
Image & Image::operator+=(const Image &other) {
if (other.w!=w||other.h!=h) {
cerr<<"Rotor: cannot add images with different sizes! (wanted "<<w<<"x"<<h<<", got "<<other.w<<"x"<<other.h<<")"<<endl;
@@ -28,12 +27,71 @@ namespace Rotor {
}
else {
for (int i=0;i<w*h*3;i++){
- //creates rainbow overload
+ //creates rainbow overload, openCV doesn't do this
RGBdata[i]=(unsigned char)(((int)other.RGBdata[i]+(int)RGBdata[i]));
}
}
return *this;
}
+ Image & Image::alpha_blend(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 {
+ //overlay the other image based on its alpha values
+ //https://gist.github.com/Brick85/5009046 - this is a dumb way to do it?
+ //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);
+ //rgb+=other.rgb;
+ for (int i=0;i<w*h*3;i++) {
+ rgb.data[i]=(uint8_t)(((((int)rgb.data[i])*(0xFF-((int)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) {
+ //converts the incoming image to monochrome and inserts it into the alpha channel of this image
+ if (other.w!=w||other.h!=h) {
+ 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;
+ }
+ }
+ return *this;
+ }
+ //channel rearrangement
+ //RGBAZ - these are channels 0-4
+ //HSB - can also have these virtual channels 5-7
+ //convert channels- int outChannel[5] - {0,1,2,-5,4} - this mapping sends inverted brightness to alpha
+
//scalar operations allocate a new image.
//maybe this could not be the case if the data is owned by this image?
//need to look into auto_ptr