#include <math.h>
/*#include <sys/time.h>*/
#include <time.h>


#define CLAMP(A,L,H)       ((A)<=(L) ? (L) : (A)<=(H) ? (A) : (H))
/*
#define MAX(A,B)   ((A) > (B) ? (A) : (B))
#define MIN(A,B)   ((A) < (B) ? (A) : (B))
*/
/* macro to swap 2 variables bit by bit */
#ifdef SWAP
#undef SWAP
#endif
#define SWAP(a,b) {a^=b; b^=a; a^=b;}

#define PI 3.14159
#define NUMCOLS 1500
#define NUMROWS 1500
#define SPNROWS 450
#define SPNCOLS 450
#define MAXGRAY_INT 255
#define NUMINTEN_INT 256
#define MAXGRAY_DB 255.0
#define NUMINTEN_DB 256.0
#define CONV_KERNEL_HEIGHT 70
#define CONV_KERNEL_WIDTH  70

struct image {
  int rows;
  int columns;
  int colors;
  unsigned char * data;
};
struct imageColor {
  int rows;
  int columns;
  int colors;
  unsigned char * dataR;
  unsigned char * dataG;
  unsigned char * dataB;
};

typedef struct {
  int width;    /*width of kernel */
  int height;   /*height of kernel*/
  float *kernel;/*pointer to floating point kernel*/
} kernel, *kernelP;

typedef unsigned char   uchar;

typedef struct{
  float xCoor;
  float yCoor;
} pixelAr;

enum /* scan direction */
{
  DIR_X,
  DIR_Y
};



int setSize(struct image *im, int rows, int columns);
/* sets the size of the image to the given 
    height (# of rows) and width (# of columns);	
    returns 0 if OK or -1 if fails;*/

int setSizeColor(struct imageColor *im, int rows, int columns);
/* sets the size of the image to the given 
    height (# of rows) and width (# of columns);	
    returns 0 if OK or -1 if fails;*/

int getNCols(struct image *im);
/*  returns the number of columns in the image;*/
int getNColsColor(struct imageColor *im);
/*  returns the number of columns in the image;*/


int getNRows(struct image *im);
/*  returns the number of rows in the image;*/

int getNRowsColor(struct imageColor *im);
/*  returns the number of rows in the image;*/

int setColors(struct image *, int colors);
/*  sets the number of gray-level colors in the image
       (not counting 0);
       returns 0 if OK or -1 if fails;*/

int setColorsColor(struct imageColor *, int colors);
/*  sets the number of gray-level colors in the image
       (not counting 0);
       returns 0 if OK or -1 if fails;*/


int getColors(struct image *);
/*  returns the number of gray-level colors in the image;*/
 
int getColorsColor(struct imageColor *);
/*  returns the number of gray-level colors in the image;*/
   
int setPixel(struct image *im, int i, int j, int color);
/*  sets the pixel in the image at row i and column j 
    to a particular color;*/

   
int setPixelColor(struct imageColor *im, int i, int j, int colorR, int colorG, int colorB);
/*  sets the pixel in the image at row i and column j 
    to a particular color;*/


int getPixel(struct image *im, int i, int j);
/*  returns the color of the pixel in the image at row i and column j;*/	

int getPixelColor(struct imageColor *im, int i, int j, int colorNum);
/*  returns the color of the pixel in the image at row i and column j;*/	

int readImage(struct image *im, const char *fname);
/*
  reads image from fname;

  returns 0 if OK or -1 if something goes wrong.
*/

int readImageColor(struct imageColor *im, const char *fname);
/*
  reads image from fname;

  returns 0 if OK or -1 if something goes wrong.
*/

int writeImage(struct image *im, const char *fname);
/*
  writes the image into fname;

  returns 0 if OK or -1 if something goes wrong.
*/

int writeImageColor(struct imageColor *im, const char *fname);
/*
  writes the image into fname;

  returns 0 if OK or -1 if something goes wrong.
*/
