00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef WP_IMAGE_H
00018 #define WP_IMAGE_H
00019
00020 #include <string>
00021 #include "WP_Def.h"
00022 #include "WP_RGBA.h"
00023
00024 namespace WPCG
00025 {
00044 class WP_Image
00045 {
00046 public:
00047 WP_Image();
00048
00049 WP_Image(int width, int height);
00050
00051 WP_Image(const string &filename);
00052
00053
00054 WP_Image(const WP_Image &image);
00055
00056 ~WP_Image();
00057
00063 WP_Image& operator=(const WP_Image& image);
00064
00071 inline void setPixel(int x, int y, const WP_RGBA& p)
00072 {
00073 if (x >= 0 && x < columns && y >= 0 && y < rows)
00074 pixels[y * columns + x] = p;
00075 }
00076
00083 inline void setFastPixel(int x, int y, const WP_RGBA& p)
00084 {
00085 pixels[y * columns + x] = p;
00086 }
00087
00094 inline WP_RGBA* getPixel(int x, int y)
00095 {
00096 if (x >= 0 && x < columns && y >= 0 && y < rows)
00097 return pixels + (y * columns + x);
00098
00099 return (WP_RGBA*)0;
00100 }
00101
00108 inline WP_RGBA* getFastPixel(int x, int y)
00109 {
00110 return pixels + (y * columns + x);
00111 }
00112
00116 void drawToFrameBuffer() const;
00117
00126 bool readFromFrameBuffer(int x, int y, int width, int height);
00127
00136 inline void copy(int x, int y, int width, int height)
00137 {
00138 glCopyPixels(x, y, width, height, GL_COLOR);
00139 }
00140
00150 void setTextureGL(GLuint* texture_id, GLint wrap_s=GL_REPEAT, GLint wrap_t=GL_REPEAT,
00151 GLint mag_filter=GL_NEAREST, GLint min_filter=GL_NEAREST, bool mipmapping=false);
00152
00158 bool loadImage(const string &file);
00159
00165 void chromaKey(const WP_RGBA& key, byte alpha);
00166
00170 int rasterpos_x;
00171
00175 int rasterpos_y;
00176
00180 int rows;
00181
00185 int columns;
00186
00187 protected:
00191 WP_RGBA* pixels;
00192
00199 inline bool hasValidExtension(const string &file, const string &extension)
00200 {
00201 int pos = file.find('.' + extension);
00202 return pos != string::npos;
00203 }
00204
00210 bool loadBMP(const string &file);
00211
00217 bool loadPCX(const string &file);
00218 };
00219 }
00220 #endif
00221