diff options
| author | Tim Redfern <tim@herge.(none)> | 2013-06-25 12:46:38 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@herge.(none)> | 2013-06-25 12:46:38 +0100 |
| commit | f191b170379e5ae7f237aa2f7adae5f387caaa35 (patch) | |
| tree | 1b44c642082bccb62c7e1e4025679fc665f3f309 | |
| parent | 38bc7e11aa796eea0fed963922013e25719a2723 (diff) | |
blend node/ blend, subtract, multiply modes
| -rwxr-xr-x | rotord/rotor.h | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/rotord/rotor.h b/rotord/rotor.h index 0c16df7..cb1e815 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -119,19 +119,19 @@ namespace Rotor { //so - pixels.add[0x78][0x66]; will give the precalculated result of adding with saturation public: pixeltables(){ - add=new uint8_t*[0xFF]; - multiply=new uint8_t*[0xFF]; - for (int i=0;i<0xFF;i++){ - add[i]=new uint8_t[0xFF]; - multiply[i]=new uint8_t[0xFF]; - for (int j=0;j<0xFF;j++){ + add=new uint8_t*[256]; + multiply=new uint8_t*[256]; + for (int i=0;i<256;i++){ + add[i]=new uint8_t[256]; + multiply[i]=new uint8_t[256]; + for (int j=0;j<256;j++){ add[i][j]=(uint8_t)min(i+j,0xFF); multiply[i][j]=(uint8_t)((((float)i)/255.0f)*(((float)j)/255.0f)*255.0f); } } } virtual ~pixeltables(){ - for (int i=0;i<0xFF;i++){ + for (int i=0;i<256;i++){ delete[] add[i]; delete[] multiply[i]; } @@ -265,6 +265,8 @@ namespace Rotor { else { for (int i=0;i<w*h*3;i++){ //calculate with tables + uint8_t p1=RGBdata[i]; + uint8_t p2=other.RGBdata[i]; RGBdata[i]=pixels.multiply[RGBdata[i]][other.RGBdata[i]]; } } @@ -282,10 +284,25 @@ namespace Rotor { } return *this; } + //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 + Image & operator*=(const float &amount) { + uint8_t *LUT=new uint8_t[256]; + for (int i=0;i<256;i++) { + LUT[i]=(uint8_t)min(0xFF,max(0,(int)(i*amount))); + } + for (int i=0;i<w*h*3;i++){ + //calculate with table + RGBdata[i]=LUT[RGBdata[i]]; + } + delete[] LUT; + return *this; + } Image * operator*(const float &amount) { Image *other=new Image(w,h); - uint8_t *LUT=new uint8_t[0xFF]; - for (int i=0;i<0xFF;i++) { + uint8_t *LUT=new uint8_t[256]; + for (int i=0;i<256;i++) { LUT[i]=(uint8_t)min(0xFF,max(0,(int)(i*amount))); } for (int i=0;i<w*h*3;i++){ @@ -296,8 +313,8 @@ namespace Rotor { } Image * operator+(const float &amount) { Image *other=new Image(w,h); - uint8_t *LUT=new uint8_t[0xFF]; - for (int i=0;i<0xFF;i++) { + uint8_t *LUT=new uint8_t[256]; + for (int i=0;i<256;i++) { LUT[i]=(uint8_t)min(0xFF,max(0,(int)(i+(amount*255.0f)))); } for (int i=0;i<w*h*3;i++){ @@ -308,8 +325,8 @@ namespace Rotor { } Image * operator-(const float &amount) { Image *other=new Image(w,h); - uint8_t *LUT=new uint8_t[0xFF]; - for (int i=0;i<0xFF;i++) { + uint8_t *LUT=new uint8_t[256]; + for (int i=0;i<256;i++) { LUT[i]=(uint8_t)min(0xFF,max(0,(int)(i-(amount*255.0f)))); } for (int i=0;i<w*h*3;i++){ @@ -320,8 +337,8 @@ namespace Rotor { } Image * operator/(const float &amount) { Image *other=new Image(w,h); - uint8_t *LUT=new uint8_t[0xFF]; - for (int i=0;i<0xFF;i++) { + uint8_t *LUT=new uint8_t[256]; + for (int i=0;i<256;i++) { LUT[i]=(uint8_t)min(0xFF,max(0,(int)(i/amount))); } for (int i=0;i<w*h*3;i++){ @@ -790,7 +807,7 @@ namespace Rotor { Video_output(map<string,string> &settings) { base_settings(settings); }; - ~Video_output(){ }; + ~Video_output(){ }; Image *output(const Frame_spec &frame){ if (image_inputs[0]->connection) { return ((Image_node*)(image_inputs[0]->connection))->get_output(frame); @@ -854,7 +871,7 @@ namespace Rotor { palette.push_back(Colour(colours.substr(i*6,6))); } for (auto i: palette) { - cerr << "Signal_colour found palette colour: "<<(int)i.r<<" "<<(int)i.g<<" "<<(int)i.b<<endl; + cerr << "Signal_colour found palette colour: "<<(int)i.r<<" "<<(int)i.g<<" "<<(int)i.b<<endl; } prevcol=-1; }; @@ -937,7 +954,7 @@ namespace Rotor { p->receiver=&value; } } - + }; ~Image_arithmetic(){if (image) delete image;}; Image *output(const Frame_spec &frame){ @@ -1183,6 +1200,7 @@ namespace Rotor { if (_mode=="screen") mode=BLEND_screen; if (_mode=="multiply") mode=BLEND_multiply; if (_mode=="blend") mode=BLEND_blend; + cerr<<"blend node: mode: "<<mode<<" amount: "<<amount<<endl; }; void link_params() { for (auto p:parameter_inputs){ @@ -1194,7 +1212,7 @@ namespace Rotor { Image *output(const Frame_spec &frame){ if (image_inputs.size()) { if (image_inputs[0]->connection){ - if (inputs.size()>1) { + if (image_inputs.size()>1) { if (image_inputs[1]->connection) { //copy incoming image **writable image->free(); @@ -1206,7 +1224,12 @@ namespace Rotor { case BLEND_multiply: (*image)*=(*(((Image_node*)image_inputs[1]->connection)->get_output(frame))); break; - + case BLEND_blend: + (*image)*=(1.0f-amount); + Image *in=(*(((Image_node*)image_inputs[1]->connection)->get_output(frame)))*amount; + (*image)+=(*in); + delete in; + break; } return image; } |
