#ifndef _CV_FLOAT_IMAGE_H
#define _CV_FLOAT_IMAGE_H


#include "ofCore.h"
#include "ofCvConstants.h"

class ofCvColorImage;
class ofCvGrayscaleImage;

//------------------------------------
class ofCvFloatImage {

	public:

		ofCvFloatImage();
		ofCvFloatImage(int _width, int _height);
		~ofCvFloatImage();
		
		void allocate(int _w, int _h);
		void clear();
		void setFromPixels(unsigned char * _pixels, int w, int h);
		void setFromColorImage(ofCvColorImage& mom);
		void setFromGrayscaleImage(ofCvGrayscaleImage& mom);

		// singular (inernal) operations:
		void set(int value);
		
		void contrastStretch();				// attempts to remap pixels to 0-255
		void threshold(int value);			// binary threshold on value
		void erode_3x3();
		void dilate_3x3();
		void mirror(bool bFlipVertically, bool bFlipHorizontally);
		void blur();
		void blurHeavily();
		void filter(CvMat* pFilter);
		//void sobel(int iXOrder, int iYOrder, int iAperatureSize);

		// 1->1 (one to one) operations
		void warpIntoMe(ofCvFloatImage& mom, ofCvPoint2f src[4], ofCvPoint2f dst[4]);

		// 2->1 (two into one) operations
		void absDiff(ofCvFloatImage& mom, ofCvFloatImage& dad);

		void addWeighted( ofCvGrayscaleImage& mom, float f);

		// operators ------------------------------
		void operator =		( ofCvFloatImage & mom );
		void operator -=	( ofCvFloatImage & mom );
		void operator +=	( ofCvFloatImage & mom );
		void operator *=	( ofCvFloatImage & mom );

		void operator -=	( float scalar );
		void operator +=	( float scalar );
		// ----------------------------------------

		// statistics:
		int countNonZeroInRegion(int x, int y, int w, int h);

		unsigned char 	* getPixels();
		IplImage 		* getCvImage(){ return cvImage;};

		void 			draw(float x, float y);
		void 			draw(float x, float y, float w, float h);

		int 			width, height;

	private:

		//----------------------------
		// internal functionality
		// we will use two iplImages internally, since many of the
		// operations expect a "src" and a "swap"
		//----------------------------

		IplImage		* 	cvImage;
		IplImage		* 	cvImageTemp;
		IplImage		*	cvImageTemp2;
		IplImage		*	cvImage8U;
		void 			swapTemp();		// make the "dst" image the current "src" image

		unsigned char 	* 	pixels;		// not width stepped
		ofTexture 			tex;		// internal tex

		bool				bAllocated;
};



#endif
