00001 #ifndef IMAGE_H 00002 #define IMAGE_H 00003 00004 #include "Types.h" 00005 #include "AbstractPropertyContainer.h" 00006 00007 #include <string> 00008 00009 using namespace std; 00010 00011 namespace RenderTools { 00012 00013 class Image : public AbstractPropertyContainer { 00014 public: 00015 00016 Image( void ); 00017 virtual ~Image( void ); 00018 00019 static PropertyPtr create( const XMLNodePtr & xml = XMLNodePtr() ); 00020 virtual void createProperties( void ); 00021 virtual const string getTypeName( bool ofComponent = false ) const; 00022 virtual void onPropertyEvent( const PropertyEvent & e ); 00023 virtual void onInitialize( void ); 00024 const string & getFilename( void ) const ; 00025 GLuint getWidth( void ) const ; 00026 GLuint getHeight( void ) const ; 00027 GLuint getChannels( void ) const ; 00028 GLuint getBytesPerPixel( void ) const ; 00029 GLenum getFormat( void ) const ; 00030 GLenum getType( void ) const ; 00031 const void * getData( void ) const ; 00032 void setData( const void * data, bool send = true ); 00033 void deleteImage( bool send = true ); 00034 void save( string filename ); 00035 static void screenDump( int w, int h, string filename ); 00036 00037 protected: 00038 string m_filename; // the filename used on construction 00039 bool m_fileNotFound; // set if the file was specified but could not be read on Initialize: 00040 GLuint m_w; // 0 by default 00041 GLuint m_h; // 0 by default 00042 GLuint m_channels; // 4 by default 00043 GLint m_bytespp; // 4 by default, BYTES per pixel 00044 GLenum m_format; // GL_RGBA by default GL format 00045 GLenum m_type; // GL_UNSIGNED_BYTE by default GL type 00046 void * m_data; // set to the actual GL data 00047 00048 #ifdef RT_DEVIL 00049 private: 00050 ILuint m_idIL; // the generated image name 00051 static bool s_init; // static flag to make sure DevIL gets initialised 00052 void initIL(); // makes sure DevIL is initialised 00053 void makeAndBindILName(); // call ilGenImageNames 00054 static GLuint getChannels( ILenum format ); // derives the number of channels if not constructed with filename 00055 static GLuint getBytesPerPixel( ILenum type, ILenum format ); // derives the bytes per pixel if not constructed with filename 00056 static string getError(); 00057 #endif 00058 }; 00059 00060 }; // namespace RenderTools 00061 00062 #endif