diff options
| author | Tim Redfern <tim@herge.(none)> | 2013-07-11 13:21:36 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@herge.(none)> | 2013-07-11 13:21:36 +0100 |
| commit | f758127362e3c1e4e926204a83ce3104af1278bb (patch) | |
| tree | 8a859e2e174054edf93a816c7e25f6abcd869caf | |
| parent | edd05e4ad726c5aec6807a30dc9ff7de8f97b28b (diff) | |
cvimage fully incorporated
| -rw-r--r-- | rotord/cvimage.cpp | 66 | ||||
| -rw-r--r-- | rotord/cvimage.h | 121 | ||||
| -rwxr-xr-x | rotord/rotor.h | 8 |
3 files changed, 85 insertions, 110 deletions
diff --git a/rotord/cvimage.cpp b/rotord/cvimage.cpp new file mode 100644 index 0000000..3a070a9 --- /dev/null +++ b/rotord/cvimage.cpp @@ -0,0 +1,66 @@ +#include "cvimage.h" + +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; + } + else { + rgb+=other.rgb; + } + return *this; + } + Image & Image::operator*=(const Image &other) { + if (other.w!=w||other.h!=h) { + cerr<<"Rotor: cannot multiply images with different sizes! (wanted "<<w<<"x"<<h<<", got "<<other.w<<"x"<<other.h<<")"<<endl; + } + else { + rgb/=other.rgb; //counter intuitive! + } + return *this; + } + Image & Image::add_wrap(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; + } + else { + for (int i=0;i<w*h*3;i++){ + //creates rainbow overload + RGBdata[i]=(unsigned char)(((int)other.RGBdata[i]+(int)RGBdata[i])); + } + } + 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 & Image::operator*=(const float &amount) { + rgb*=amount; + return *this; + } + Image * Image::operator*(const float &amount) { + Image *other=new Image(w,h); + other->rgb=rgb*amount; + return other; + } + Image * Image::operator+(const float &amount) { + uint8_t amt=(uint8_t)(amount*255.0f); + Image *other=new Image(w,h); + other->rgb=rgb+amt; + return other; + } + Image * Image::operator-(const float &amount) { + uint8_t amt=(uint8_t)(amount*255.0f); + Image *other=new Image(w,h); + other->rgb=rgb-amt; + return other; + } + Image * Image::operator/(const float &amount) { + Image *other=new Image(w,h); + other->rgb=rgb/amount; + return other; + } +} diff --git a/rotord/cvimage.h b/rotord/cvimage.h index 7588673..a538d4e 100644 --- a/rotord/cvimage.h +++ b/rotord/cvimage.h @@ -1,11 +1,9 @@ #include <math.h> #include <cv.h> -using namespace std; - //converting to use a cv image... //cv::Mat supports most of what we want here -//need to think +//need to think //http://answers.opencv.org/question/8202/using-external-image-data-in-a-cvmat/ //all access to the image is presently through a pointer to the data @@ -15,7 +13,7 @@ using namespace std; //Rotor::Image will contain a cv::Mat object which may own its data or inherit it //cv::Mat should take care of reference counting -//can cv::Mat +//can cv::Mat namespace Rotor { class pixeltables{ @@ -30,7 +28,7 @@ namespace Rotor { 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); + add[i][j]=(uint8_t)std::min(i+j,0xFF); multiply[i][j]=(uint8_t)((((float)i)/255.0f)*(((float)j)/255.0f)*255.0f); } } @@ -107,7 +105,7 @@ namespace Rotor { else return false; */ } - bool setup_fromRGB(int _w,int _h,uint8_t *pRGBdata){ + bool setup_fromRGB(int _w,int _h,uint8_t *pRGBdata){ //here the data belongs to libavcodec or other //could move to using cv::Mat there also and just passing cv:Mat over rgb=cv::Mat(_w,_h,CV_8UC3,pRGBdata); @@ -131,7 +129,7 @@ namespace Rotor { return false; */ } - bool setup_fromMat(cv::Mat& othermat){ + bool setup_fromMat(cv::Mat& othermat){ //here the mat belongs to another Image object rgb=cv::Mat(othermat); RGBdata=rgb.data; //can move to use the bare pointer eventually @@ -155,105 +153,14 @@ namespace Rotor { return t; } //believe these still work, don't know if these optimisations are better than opencvs.. - 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; - } - else { - for (int i=0;i<w*h*3;i++){ - //calculate with tables - RGBdata[i]=pixels.add[RGBdata[i]][other.RGBdata[i]]; - } - } - return *this; - } - Image & operator*=(const Image &other) { - if (other.w!=w||other.h!=h) { - cerr<<"Rotor: cannot multiply images with different sizes! (wanted "<<w<<"x"<<h<<", got "<<other.w<<"x"<<other.h<<")"<<endl; - } - else { - for (int i=0;i<w*h*3;i++){ - //calculate with tables - RGBdata[i]=pixels.multiply[RGBdata[i]][other.RGBdata[i]]; - } - } - return *this; - } - Image & add_wrap(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; - } - else { - for (int i=0;i<w*h*3;i++){ - //creates rainbow overload - RGBdata[i]=(unsigned char)(((int)other.RGBdata[i]+(int)RGBdata[i])); - } - } - 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[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++){ - other->RGBdata[i]=LUT[RGBdata[i]]; - } - delete[] LUT; - return other; - } - Image * operator+(const float &amount) { - Image *other=new Image(w,h); - 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++){ - other->RGBdata[i]=LUT[RGBdata[i]]; - } - delete[] LUT; - return other; - } - Image * operator-(const float &amount) { - Image *other=new Image(w,h); - 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++){ - other->RGBdata[i]=LUT[RGBdata[i]]; - } - delete[] LUT; - return other; - } - Image * operator/(const float &amount) { - Image *other=new Image(w,h); - 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++){ - other->RGBdata[i]=LUT[RGBdata[i]]; - } - delete[] LUT; - return other; - } + Image & operator+=(const Image &other); + Image & operator*=(const Image &other); + Image & add_wrap(const Image &other); + Image & operator*=(const float &amount); + Image * operator*(const float &amount); + Image * operator+(const float &amount); + Image * operator-(const float &amount); + Image * operator/(const float &amount); uint8_t *RGBdata; uint8_t *Adata; uint16_t *Zdata; @@ -262,4 +169,4 @@ namespace Rotor { cv::Mat rgb; }; -}
\ No newline at end of file +} diff --git a/rotord/rotor.h b/rotord/rotor.h index 3d260e4..953a69b 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -758,6 +758,7 @@ namespace Rotor { if (_op=="/") op=ARITHMETIC_divide; //if (_op=="%") op=ARITHMETIC_modulo; ??what would this even mean? image=nullptr; + cerr<<"image_arithmetic: mode "<<op<<", value "<<value<<endl; } void link_params() { for (auto p:parameter_inputs){ @@ -771,7 +772,8 @@ namespace Rotor { Image *output(const Frame_spec &frame){ if (image_inputs.size()) { if (image_inputs[0]->connection){ - if (image) image->free(); + if (image) delete image; //from the previous frame- this may not be ideal + //because operator* made a new image it should be deleted Image *in=(((Image_node*)image_inputs[0]->connection)->get_output(frame)); switch (op) { case ARITHMETIC_plus: @@ -1028,7 +1030,7 @@ namespace Rotor { if (image_inputs.size()>1) { if (image_inputs[1]->connection) { //copy incoming image **writable - if (image) image->free(); + if (image) delete image; image=(((Image_node*)image_inputs[0]->connection)->get_output(frame))->clone(); switch(mode){ case BLEND_screen: @@ -1080,7 +1082,7 @@ namespace Rotor { if (image_inputs.size()) { if (image_inputs[0]->connection){ //copy incoming image **writable - if (image) image->free(); + if (image) delete image; image=(((Image_node*)image_inputs[0]->connection)->get_output(frame))->clone(); switch (mode) { case MIRROR_horiz: |
