/****************************************************************
 *
 * ppm.h
 *
 * Read and write PPM files.  Only works for "raw" format.
 *
 * AF970205
 *
 ****************************************************************/

#ifndef PPM_H
#define PPM_H

#include <sys/types.h>
#include "math.h"
typedef unsigned char u_char;

#define GRAY 1
#define GREY 1
#define RGB 3

typedef struct Image
{
  int width;
  int height;
  u_char *data;
  double *fdata;
} Image;

Image *ImageCreate(int width, int height);
void ImageDestroy(Image *image);
Image *ImageCreatef(int width, int height);
Image *ImageRead(char *filename);
Image *ImageReadP3(char *filename);
void   ImageWrite(Image *image, char *filename);
void ImageWriteP3(Image *image, char *filename);
Image *ImageReadP2(char *filename);
void   ImageWriteP2(Image *image, char *filename);
void   ImageWriteP5(Image *image, char *filename);
void ImageWriteP7(Image *image, char *filename);
void ImageWriteP7greyfloat2color(double **image, int width, int height, char *filename);
void ImageWriteP6grey2color(Image *image, char *filename);



int    ImageWidth(Image *image);
int    ImageHeight(Image *image);

void   ImageClear(Image *image, u_char red, u_char green, u_char blue);

void   ImageSetPixel(Image *image, int x, int y, int chan, u_char val, int format);
u_char ImageGetPixel(Image *image, int x, int y, int chan, int format);

void   ImageSetPixelf(Image *image, int x, int y, int chan, double val, int format);
double ImageGetPixelf(Image *image, int x, int y, int chan, int format);

void imageGradient(Image *image, Image *gradHx, Image *gradHy, Image * edgeimage, Image * maskimage);
void GradientFromImage(Image * horimage, Image * verimage, Image *gradHx, Image *gradHy);
void GradientFromImageNew(Image * hor_red, Image * hor_redblur, Image * hor_blue, Image * hor_blueblur,
				 Image * ver_red, Image * ver_redblur, Image * ver_blue, Image * ver_blueblur, 
				 Image * gradHx, Image * gradHy);
void imageGradientNew(Image *image, Image *gradHx, Image *gradHy, Image * edgeimage, Image * maskimage);
//sort of selective gradient compression
void maskGradient(Image *mask, Image *gradHx, Image *gradHy);
void imageGradientTodivG(Image *gradHx, Image *gradHy, Image *divG);


#endif /* PPM_H */

