/*
 * Image.h
 *
 *  Created on: Mar 15, 2011
 *      Author: cpresser
 */

#ifndef _PGM_IMAGE_H_
#define _PGM_IMAGE_H_

#include <exception>
#include <string>

typedef unsigned char pixel;

class PGMImageException: public std::exception {
public:
        virtual const char *what(){
                return "Image Exception.";
        }
};

class PGMImage {
public:
        //create an image that is w by h pixels
        PGMImage(int w, int h);

        //copy constructor
        PGMImage(const PGMImage &image);

        //destroy the image
        virtual ~PGMImage();

        //assignment operator
        const PGMImage &operator=(const PGMImage &right);


        //get the value at pixel x, y
        virtual pixel getPixel(int x, int y) throw (PGMImageException);
        virtual void setPixel(int x, int y, pixel p) throw (PGMImageException);

        virtual void writeToFile(std::string name);

protected:
        virtual int posToIndex(int x, int y) throw (PGMImageException) ;


        pixel *m_data;
        int m_width;
        int m_height;

};

#endif /* IMAGE_H_ */