Go to the documentation of this file.00001 #ifndef _OF_IMAGE_H_
00002 #define _OF_IMAGE_H_
00003 
00004 #include "ofConstants.h"
00005 #include "ofTexture.h"
00006 #include "ofGraphics.h"
00007 #include "ofAppRunner.h"                
00008 #include "FreeImage.h"
00009 #include "ofUtils.h"
00010 
00011 typedef struct {
00012 
00013         unsigned char * pixels;
00014         int width;
00015         int height;
00016 
00017         int             bitsPerPixel;           
00018         int             bytesPerPixel;          
00019         GLint   glDataType;                     
00020         int             ofImageType;            
00021         bool    bAllocated;
00022 
00023 } ofPixels;
00024 
00025 
00026 
00027 
00028 void    ofCloseFreeImage();             
00029 
00030 
00031 
00032 class ofImage : public ofBaseDraws, public ofBaseHasTexture, public ofBaseHasPixels{
00033 
00034         public :
00035 
00036                 ofImage();
00037                 virtual ~ofImage();
00038 
00039                 
00040                 void                            allocate(int w, int h, int type);
00041                 void                            clear();
00042 
00043                 
00044                 ofImage(const ofImage& mom);
00045                 ofImage& operator= (const ofImage& mom);
00046 
00047                 
00048                 void                            clone(const ofImage &mom);
00049 
00050                 
00051                 void                            setUseTexture(bool bUse);
00052 
00053                 
00054                 ofTexture & getTextureReference();
00055 
00056                 
00057                 bool                            loadImage(string fileName);
00058                 void                            saveImage(string fileName);
00059 
00060                 
00061                 unsigned char *         getPixels();                    
00062 
00063                 
00064                 void                            setFromPixels(unsigned char * pixels, int w, int h, int newType, bool bOrderIsRGB = true);
00065                 void                            setImageType(int type);
00066                 void                            resize(int newWidth, int newHeight);
00067                 void                            grabScreen(int x, int y, int w, int h);         
00068 
00069                 
00070                 void                            update();
00071 
00072                 
00073                 
00074                 
00075         void                            setAnchorPercent(float xPct, float yPct);       
00076         void                            setAnchorPoint(int x, int y);                           
00077         void                            resetAnchor();                                                          
00078 
00079                 
00080                 void                            draw(float x, float y, float w, float h);
00081                 void                            draw(float x, float y);
00082 
00083                 float                           getHeight();
00084                 float                           getWidth();
00085 
00086                 int                             width, height, bpp;             
00087                 int                                     type;                                   
00088 
00089         protected:
00090 
00091                 
00092 
00093                 bool                            loadImageIntoPixels(string fileName, ofPixels &pix);
00094                 void                            saveImageFromPixels(string fileName, ofPixels &pix);
00095                 void                            changeTypeOfPixels(ofPixels &pix, int newType);
00096                 void                            resizePixels(ofPixels &pix, int newWidth, int newHeight);
00097                 FIBITMAP *                      getBmpFromPixels(ofPixels &pix);
00098                 void                            putBmpIntoPixels(FIBITMAP * bmp, ofPixels &pix);
00099 
00100                 
00101                 inline void                     allocatePixels(ofPixels &pix, int width, int height, int bpp);
00102                 inline void                     swapRgb(ofPixels &pix);
00103 
00104                 ofPixels                        myPixels;
00105                 bool                            bUseTexture;
00106                 ofTexture                       tex;
00107 
00108 
00109 
00110 };
00111 
00112 
00113 
00114 #endif