//------------------------------------------------------------------------------ #ifndef FLOATIMAGE_H #define FLOATIMAGE_H #include #include class bwImage; class rgbImage; class floatImage { public: floatImage( int w, int h ); // new image floatImage( float *data, int w, int h ); // shallow copy floatImage( float *data, int w, int h, bool deep ); // deep copy floatImage( floatImage *src ); // deep copy floatImage( floatImage *src1, floatImage *src2, bool add=false ); floatImage( floatImage *src1, floatImage *src2, floatImage *src3, bool add=false ); ~floatImage(); // deallocates data irrespective of shallow/deep public: int getWidth() { return width_; } int getHeight() { return height_; } int getSize() { return size_; } void clampInImage( int &x, int &y ); float *rawData() { return data_; } float &pixel( int x, int y ) { return data_[y*width_+x]; } public: float maxComponent(); float minComponent(); float findMaxComponent( int &x, int &y ); void setBorder( int borderWidth, float intens ); public: void drawSolidSquare( int x1, int y1, int x2, int y2, float intens, bool checkInBounds=false ); public: // fast gradient (standard technique) // (allocates the memory for the floatImages - user should use delete // when finished) void imgGrad( floatImage *&gradImgX, floatImage *&gradImgY ); // quality gradient (Toulouse's technique) void imgGradToulouse( floatImage *&gradImgX, floatImage *&gradImgY ); private: void gradToulouse( int x, int y, float &grdX, float &grdY ); private: int width_, height_, size_, memSize_; float *data_; }; inline floatImage::floatImage( int w, int h ) : width_(w), height_(h), size_(w*h), memSize_(size_*sizeof(float)) { data_=(float*)malloc(memSize_); } inline floatImage::floatImage( float *data, int w, int h ) : data_(data), width_(w), height_(h), size_(w*h), memSize_(size_*sizeof(float)) { } inline floatImage::floatImage( float *data, int w, int h, bool deep ) : width_(w), height_(h), size_(w*h), memSize_(size_*sizeof(float)) { if ( (data_=(float*)malloc(memSize_))!=0 ) { memcpy( data_, data, memSize_ ); } } inline floatImage::floatImage( floatImage *src ) : width_(src->getWidth()), height_(src->getHeight()), size_(src->getSize()), memSize_(size_*sizeof(float)) { if ( (data_=(float*)malloc(memSize_))!=0 ) { memcpy( data_, src->rawData(), memSize_ ); } } inline floatImage::~floatImage() { if ( data_!=0 ) free( data_ ); } inline void floatImage::clampInImage( int &x, int &y ) { if ( x<0 ) x=0; else if (x>=width_) x=width_-1; if ( y<0 ) y=0; else if (y>=height_) y=height_-1; } #endif // FLOATIMAGE_H