/* LICENSE:
  =========================================================================
    CMPack'04 Source Code Release for OPEN-R SDK 1.1.5-r2 for ERS7
    Copyright (C) 2004 Multirobot Lab [Project Head: Manuela Veloso]
    School of Computer Science, Carnegie Mellon University
    All rights reserved.
  ========================================================================= */


#ifndef PPMImage_h
#define PPMImage_h

/* A quick and dirty PPM reader/writer */

struct RGBTriplet;

/* Currently we only accept colornums <= to 255. This is
   less than general. Mostly I'm defining a constant to
   remind me that ::save hardcodes this value.
*/

const int NumColors = 255;

class PPMImage {

 private:

  int Width;
  int Height;
  RGBTriplet *Data;
  char *Filename;

  void freeBuffer(void);

 public:

  PPMImage(void);
  PPMImage(char *filename);

  // Bitmap will consist of noise - you need to set
  // the background color yourself.
  PPMImage(int width, int height);

  bool load(char *filename);
  bool save(char *filename);

  RGBTriplet get(int x, int y);
  void set(int x, int y, RGBTriplet color);
  void replace(RGBTriplet replace_me, 
	       RGBTriplet new_color);
  int getWidth(void) { return Width; }
  int getHeight(void) { return Height; }

  // Copy other into this image at (x, y) - that is,
  // (0, 0) in other maps to (x, y) in this.
  void copyInto(int x, int y, PPMImage &other);
  void copyInto(int x, int y, PPMImage &other,
		int start_x, int start_y, int width,
		int height);

  // do NOT overwrite or free the returned buffer.
  char *getFilename(void);
};

#endif
