Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Image.h

Go to the documentation of this file.
00001 #ifndef P_EXAMPLES_H
00002 #define P_EXAMPLES_H
00003 
00004 #include <stdint.h>
00005 #include "defines.h" //Vector
00006 #include "Exception.h"
00007 #include <iostream>
00008 #include <string>
00009 
00010 struct SDL_Surface;
00011 namespace annie {
00032 class Image {
00033 public:
00037     struct Color    {
00038         real r, g, b;
00039         real gray() const { return (r + g + b)/3.; }
00040         Color(real r, real g, real b) : r(r), g(g), b(b) {}
00041     };
00042 
00043 
00045     Image(unsigned xs, unsigned ys);
00046     void resize(unsigned xs, unsigned ys);
00047     ~Image();
00048 
00052     static Image *fromFile(const std::string &fileName);
00053 
00057     void toFile(const std::string &fileName);
00058 
00066     static Image *fromVector(const Vector &v, unsigned width, bool gray);
00067 
00072     Image *subImage(unsigned width, unsigned height, unsigned xOffset=0, unsigned yOffset=0) const;
00073 
00078     void setSubImage(const Image &src, unsigned xo=0, unsigned yo=0);
00079 
00083     Color getAverageColor() const throw(Exception);
00084 
00085 
00086 #ifdef HAVE_OPENGL
00087 
00090 #if 0
00091     Image *scale(uint width, uint height) const throw(Exception);
00092 #endif
00093 #endif
00094 
00099     Image *toRGBA() const;
00100 
00102     Image *clone() const;
00103 
00107     Image *upsideDown() const;
00108 
00114     Image *toGray() const;
00115 
00116     unsigned getWidth() const;
00117     unsigned getHeight() const;
00118     unsigned getBPP() const;
00119 
00126     enum { GRAY_MASK = 1 };
00127     Vector toVector(uint8_t bytes_mask) const;
00128 
00134     void display(unsigned xo=0, unsigned yo=0) const;
00135     //  void saveAs
00136 
00137     void clear();
00138     void rect(const Color &c, uint x1, uint y1, uint x2, uint y2);
00139 
00143 
00144 
00145     void putPixel(const Color &c, uint x, uint y);
00146 
00148     Color getPixel(uint x, uint y) const;
00149 
00151     real getPixelGray(uint x, uint y) const;
00152 
00153 protected:
00157     Image(SDL_Surface *i)   { surface = i; }
00158     int glFormat() const;
00159     void setGlPixelStore(bool unpack) const;
00160     
00162     SDL_Surface *createSameSurface(uint width, uint height) const;
00163     SDL_Surface *createSameSurface() const;
00164 
00166     void glDraw() const;
00167 
00172     void colorless();
00173     uint32_t color2SDL(const Color &c) const;
00174     uint32_t getPixelRaw(uint x, uint y)    const;
00175     Color sdl2color(uint32_t p) const;
00176     SDL_Surface *surface;
00177 };
00178 
00179 inline std::ostream & operator<<(std::ostream &o, const Image &i)   { o << "Image: " << i.getWidth() << " x " << i.getHeight() << ", " << i.getBPP() << " bytes per pixel"; return o;}
00180 inline std::ostream & operator<<(std::ostream &o, const Image::Color &c)    { o << "Color: " << c.r << "," << c.g << "," << c.b; return o;}
00181 
00182 }   //annie
00183 #endif //H

Generated on Fri Jun 18 13:18:10 2004 for Annie by doxygen 1.3.5