blob: 3a070a9ae6673d1ca71c316fe90fbeb79a7c9868 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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;
}
}
|