// pixmap.h, basic codes from Prof. F.S. Hill,Jr., Umass, Amherst

#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>
#include <string>
#include <strstream.h>
#include <stdio.h>
#include <GL/glut.h>

typedef unsigned char  uchar;
typedef unsigned short ushort;
typedef unsigned long  ulong;

//-------------- class mRGB ---------------
class mRGB{
 public: 
  uchar r,g,b;
  mRGB(){r = g = b = 0;}
  mRGB(mRGB& p){r = p.r; g = p.g; b = p.b;}
  mRGB(uchar rr, uchar gg, uchar bb){r = rr; g = gg; b = bb;}
  void set(uchar rr, uchar gg, uchar bb){r = rr; g = gg; b = bb;}
};

//------------- RGBPixmap --------------
class RGBpixmap{
 public: 
  mRGB* pixel; // array of pixels
	
 public:
  int nRows, nCols; // dimensions of the pixmap
  RGBpixmap() {nRows = nCols = 0; pixel = 0;}
  RGBpixmap(int rows, int cols) { //constructor 
    nRows = rows;
    nCols = cols;
    pixel = new mRGB[rows*cols]; 
  }
  
  int readBMPFile(string fname); // read BMP file into this pixmap
  
  void freeIt()  { // give back memory for this pixmap 
    delete []pixel;
    nRows = nCols = 0;
  }

  void draw() { // draw this pixmap at current raster position
    if(nRows == 0 || nCols == 0) return;
    //tell OpenGL NOT to try to align pixels to 4 byte boundaries in memory
    glPixelStorei(GL_UNPACK_ALIGNMENT,1);
    glDrawPixels(nCols, nRows,GL_RGB, GL_UNSIGNED_BYTE,pixel);
  }

};

