//------------------------------------------------------------------------------

#ifndef HLSIMAGE_H
#define HLSIMAGE_H

#include <stdlib.h>
#include <string.h>

class floatImage;
class rgbImage;

#define H 0
#define L 1
#define S 2

class hlsImage
{
public:
  hlsImage( const rgbImage &src  );  // deep copy
  ~hlsImage();  // deallocates data irrespective of shallow/deep

  
public:
  int getWidth()   { return width_; }
  int getHeight()  { return height_; }
  int getSize()    { return size_; }
  int getMemSize() { return memSize_; }

  void clampInImage( int &x, int &y );
  
  unsigned char *rawData() { return data_; }
  
  unsigned char *pixel( int x, int y ) { return &data_[(y*width_+x)*3]; }

  
public:
  void grad( int x, int y, float &grdX, float &grdY );
  void createImgGrad( floatImage *&gradImgX, floatImage *&gradImgY );

  
private:
  int width_, height_, size_, memSize_;
  unsigned char *data_;
};

inline
hlsImage::~hlsImage()
{
  if ( data_!=0 ) free( data_ );
}

inline void 
hlsImage::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 // HLSIMAGE_H
