00001 #ifndef X3DTK_IMAGE_H
00002 #define X3DTK_IMAGE_H
00003
00004 #include "Platform.h"
00005
00006 #include <GL/gl.h>
00007 #include <limits>
00008
00009 #undef max
00010
00011 namespace X3DTK {
00012
00013 class Image;
00014
00015 template<class T>
00016 struct Memory
00017 {
00018 inline static T *access(Image *I, unsigned short x, unsigned short y);
00019 };
00020
00021 template<class IT, class OT>
00022 struct ImageConverter
00023 {
00024 static void make(unsigned char *out, unsigned char *in, unsigned int length);
00025 };
00026
00035 class Image
00036 {
00037 public:
00039 Image();
00041 Image(const char *fileName);
00043 ~Image();
00044
00046 inline bool isLoaded() const {return (_data != 0);};
00048 void saveAs(const char *fileName, float quality = 1.0f);
00050 void resize(unsigned short width, unsigned short height, GLenum GLType = GL_NONE);
00052 unsigned char *resizeData(unsigned short width, unsigned short height, GLenum GLType = GL_NONE);
00055 void resizeGL(float (& textureTransform)[16]);
00057 bool allocate(unsigned short width, unsigned short height, GLenum GLFormat, GLenum GLType);
00059 void release();
00060
00062 inline unsigned short getWidth() const {return _width;};
00064 inline unsigned short getHeight() const {return _height;};
00066 inline GLenum getGLFormat() const {return _glFormat;};
00068 inline GLenum getGLType() const {return _type;};
00070 inline int getPixelSize() const;
00072 inline unsigned char* getData() const {return _data;};
00074 static int computePixelSize(GLenum GLFormat, GLenum GLType);
00075 private:
00076 unsigned char *_data;
00077 GLenum _glFormat;
00078 GLenum _type;
00079 unsigned short _width;
00080 unsigned short _height;
00081
00082 void convert(GLenum oldType, GLenum newType, unsigned char *newData, unsigned char *data, unsigned int length);
00083 };
00084
00085 }
00086
00087 #include "Image.inl"
00088
00089 #endif