summaryrefslogtreecommitdiff
path: root/rotord/cvimage.h
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/cvimage.h')
-rw-r--r--rotord/cvimage.h121
1 files changed, 14 insertions, 107 deletions
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
+}