summaryrefslogtreecommitdiff
path: root/rotord/cvimage.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@herge.(none)>2013-07-11 13:21:36 +0100
committerTim Redfern <tim@herge.(none)>2013-07-11 13:21:36 +0100
commitf758127362e3c1e4e926204a83ce3104af1278bb (patch)
tree8a859e2e174054edf93a816c7e25f6abcd869caf /rotord/cvimage.cpp
parentedd05e4ad726c5aec6807a30dc9ff7de8f97b28b (diff)
cvimage fully incorporated
Diffstat (limited to 'rotord/cvimage.cpp')
-rw-r--r--rotord/cvimage.cpp66
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;
+ }
+}