diff options
| author | Tim Redfern <tim@Adaptics.local> | 2013-11-05 15:05:23 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@Adaptics.local> | 2013-11-05 15:05:23 +0000 |
| commit | b60ef5570f005374e688d62c69017543befca74e (patch) | |
| tree | b1af031769b297295fa864a86df0b168a074ed6d /rotord/src | |
| parent | 8bba898010f1a8f728a0a7e91be93a0671a4efed (diff) | |
overlay in blend mode
Diffstat (limited to 'rotord/src')
| -rw-r--r-- | rotord/src/cvimage.cpp | 12 | ||||
| -rw-r--r-- | rotord/src/cvimage.h | 8 | ||||
| -rw-r--r-- | rotord/src/nodes_channels.h | 6 |
3 files changed, 25 insertions, 1 deletions
diff --git a/rotord/src/cvimage.cpp b/rotord/src/cvimage.cpp index 74a21dd..8f2c181 100644 --- a/rotord/src/cvimage.cpp +++ b/rotord/src/cvimage.cpp @@ -138,6 +138,18 @@ namespace Rotor { //} return *this; } + Image & Image::overlay(cv::Mat &other){ + if (other.w!=w||other.h!=h) { + cerr<<"Rotor: cannot overlay images with different sizes! (wanted "<<w<<"x"<<h<<", got "<<other.w<<"x"<<other.h<<")"<<endl; + //why not?? + } + else { + for (int i=0;i<h*w*3;i++) { + rgb.data[i]=pixels.overlsy[rgb.data[i]][other.rgb.data[i]]; + } + } + return *this; + } Image & Image::operator=(const Image &other) { //can be optimised? was trying to use other.data.clone() setup(other.w,other.h); diff --git a/rotord/src/cvimage.h b/rotord/src/cvimage.h index 8a6fdae..a0a2cf4 100644 --- a/rotord/src/cvimage.h +++ b/rotord/src/cvimage.h @@ -29,12 +29,15 @@ namespace Rotor { pixeltables(){ add=new uint8_t*[256]; multiply=new uint8_t*[256]; + overlay=new uint8_t*[256]; for (int i=0;i<256;i++){ add[i]=new uint8_t[256]; multiply[i]=new uint8_t[256]; + overlay[i]=new uint8_t[256]; for (int j=0;j<256;j++){ add[i][j]=(uint8_t)std::min(i+j,0xFF); multiply[i][j]=(uint8_t)(((float)i)*(((float)j)/255.0f)); + overlay[i][j]=j<128?(uint8_t)((i*j)>>7):255-(((0xFF-i)*(0xFF-j))>>7); } } mono_weights=new uint8_t*[3]; @@ -50,9 +53,11 @@ namespace Rotor { for (int i=0;i<256;i++){ delete[] add[i]; delete[] multiply[i]; + delete[] overlay[i]; } delete[] add; delete[] multiply; + delete[] overlay; for (int i=0;i<3;i++) { delete[] mono_weights[i]; } @@ -60,7 +65,9 @@ namespace Rotor { } uint8_t **add; uint8_t **multiply; + uint8_t **overlay; uint8_t **mono_weights; + }; static pixeltables pixels; class Image{ @@ -200,6 +207,7 @@ namespace Rotor { Image & alpha_from_cv(cv::Mat &other); Image & add_wrap(const Image &other); Image & divide_wrap(const Image &other); + Image & overlay(const Image &other); Image & operator*=(const float &amount); Image & operator+=(const float &amount); Image & operator-=(const float &amount); diff --git a/rotord/src/nodes_channels.h b/rotord/src/nodes_channels.h index fe129ea..e991660 100644 --- a/rotord/src/nodes_channels.h +++ b/rotord/src/nodes_channels.h @@ -69,13 +69,14 @@ namespace Rotor { #define BLEND_alpha 4 #define BLEND_wrap 5 #define BLEND_xor 6 +#define BLEND_overlay 7 class Blend: public Image_node { public: Blend(){ create_image_input("image input 1","Image input 1"); create_image_input("image input 2","Image input 2"); create_parameter("amount","number","amount to blend input 2","Blend amount",0.5f,0.0f,1.0f); - create_attribute("mode","Blend mode","Blend mode","blend",{"blend","screen","multiply","alpha","wrap","xor"}); + create_attribute("mode","Blend mode","Blend mode","blend",{"blend","screen","multiply","alpha","wrap","xor","overlay"}); title ="Blend"; description="Blend images in various modes"; UID="12ed7af0-2d0a-11e3-ae32-2b44203b93c9"; @@ -107,6 +108,9 @@ namespace Rotor { case BLEND_wrap: image=image.add_wrap(*in2); break; + case BLEND_overlay: + image=image.overlay(*in2); + break; case BLEND_blend: //has to be last because of initialser of *in? go figure image*=(1.0f-parameters["amount"]->value); |
