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 /rotord/cvimage.cpp | |
| parent | edd05e4ad726c5aec6807a30dc9ff7de8f97b28b (diff) | |
cvimage fully incorporated
Diffstat (limited to 'rotord/cvimage.cpp')
| -rw-r--r-- | rotord/cvimage.cpp | 66 |
1 files changed, 66 insertions, 0 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; + } +} |
