00001 00007 #ifndef IMAGE_H 00008 #define IMAGE_H IMAGE_H 00009 00010 #include "ColorRGBA.h" 00011 #include <cassert> 00012 00017 class Image 00018 { 00023 int resX; 00028 int resY; 00029 00034 ColorRGBA *pixel; 00035 00036 public: 00037 00042 Image(int resX,int resY) : resX(resX),resY(resY) 00043 { 00044 assert (resX > 0 && resY > 0); 00045 pixel = new ColorRGBA[resX*resY]; 00046 } 00047 00052 Image() : resX(0),resY(0) 00053 { 00054 pixel = NULL; 00055 } 00056 00061 ~Image() 00062 { 00063 if (pixel) delete[] pixel; 00064 }; 00065 00070 ColorRGBA* operator[](int y) 00071 { 00072 assert(pixel != NULL); 00073 return pixel + y * resX; 00074 }; 00075 00080 int getWidth() const { return resX; } 00081 00086 int getHeight() const { return resY; } 00087 00092 ColorRGBA& getPixel (int x, int y) 00093 { 00094 if (x < 0 || y < 0) printf("x=%d, y=%d\n", x, y); 00095 // just for sure 00096 assert(pixel != NULL && x >=0 && y >= 0); 00097 assert(x < resX && y < resY); 00098 00099 // return pixel 00100 return pixel[y * resX + x]; 00101 }; 00102 00107 void setPixel (const ColorRGBA& p, int x, int y) 00108 { 00109 // just for sure 00110 assert(pixel != NULL && x >=0 && y >= 0); 00111 assert(x < resX && y < resY); 00112 00113 // return pixel 00114 pixel[y * resX + x] = p; 00115 }; 00116 00121 bool ReadPNG(const char* fileName); 00122 00127 inline bool LoadImage(const char* fileName) { return ReadPNG(fileName); }; 00128 00133 void WritePNG(const char* fileName); 00134 00135 }; 00136 00137 #endif