Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

WP_Image.h

Go to the documentation of this file.
00001 /* Copyright (C) 2001 W.P. van Paassen - peter@paassen.tmfweb.nl
00002 
00003    This program is free software; you can redistribute it and/or modify it under
00004    the terms of the GNU General Public License as published by the Free
00005    Software Foundation; either version 2 of the License, or (at your
00006    option) any later version.
00007 
00008    This program is distributed in the hope that it will be useful, but WITHOUT
00009    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00010    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00011    for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; see the file COPYING.  If not, write to the Free
00015    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
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   //copy constructor
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; //failure
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 

Generated on Tue Jan 28 20:26:33 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002