00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00025
00026
00027 #ifndef GL_TEX_IMAGE_H
00028 #define GL_TEX_IMAGE_H
00029
00030 class GlobalUtil;
00031 class GLTexImage :public GlobalUtil
00032 {
00033 protected:
00034 GLuint _texID;
00035 int _imgWidth;
00036 int _imgHeight;
00037 int _texWidth;
00038 int _texHeight;
00039 int _drawWidth;
00040 int _drawHeight;
00041 public:
00042 static void DetachFBO(int i);
00043 static void UnbindTex();
00044 static void UnbindMultiTex(int n);
00045 static void DrawQuad(float x1, float x2, float y1, float y2);
00046
00047 public:
00048 virtual void DrawQuadUS(int scale);
00049 virtual void DrawQuadDS(int scale);
00050 virtual void DrawImage();
00051 virtual void TexConvertRGB();
00052 virtual void ZeroHistoMargin();
00053 virtual void SetImageSize(int width, int height);
00054 virtual void InitTexture(int width, int height, int clamp_to_edge =1 );
00055 void InitTexture(int width, int height, int clamp_to_edge, GLuint format);
00056 virtual void FillMargin(int marginx, int marginy);
00057 public:
00058 void DrawScaledQuad(float scale);
00059 int CopyToPBO(GLuint pbo, int width, int height, GLenum format = GL_RGBA);
00060 void CopyFromPBO(GLuint pbo, int width, int height, GLenum format = GL_RGBA);
00061 void FitRealTexViewPort();
00062 void DrawQuadMT8();
00063 void DrawQuadMT4();
00064 void DrawQuadReduction();
00065 void DrawQuadReduction(int w, int h);
00066 void DrawMargin(int right, int bottom);
00067 void DrawQuad();
00068 void FitTexViewPort();
00069 void ZeroHistoMargin(int hw, int hh);
00070 int CheckTexture();
00071 public:
00072 void AttachToFBO(int i );
00073 void BindTex();
00074 operator GLuint (){return _texID;}
00075 GLuint GetTexID(){return _texID;}
00076 int GetImgPixelCount(){return _imgWidth*_imgHeight;}
00077 int GetTexPixelCount(){return _texWidth*_texHeight;}
00078 int GetImgWidth(){return _imgWidth;}
00079 int GetImgHeight(){return _imgHeight;}
00080 int GetTexWidth(){return _texWidth;}
00081 int GetTexHeight(){return _texHeight;}
00082 int GetDrawWidth(){return _drawWidth;}
00083 int GetDrawHeight(){return _drawHeight;}
00084
00085 int IsTexPacked(){return _drawWidth != _imgWidth;}
00086 GLTexImage();
00087 virtual ~GLTexImage();
00088 friend class SiftGPU;
00089 };
00090
00091
00092
00093
00094 class GLTexInput:public GLTexImage
00095 {
00096 public:
00097 int _down_sampled;
00098 int _rgb_converted;
00099 int _data_modified;
00100
00102 float * _converted_data;
00103 const void* _pixel_data;
00104 public:
00105 static int IsSimpleGlFormat(unsigned int gl_format, unsigned int gl_type)
00106 {
00107
00108 return (gl_format ==GL_LUMINANCE ||gl_format == GL_LUMINANCE_ALPHA||
00109 gl_format == GL_RGB|| gl_format == GL_RGBA||
00110 gl_format == GL_BGR || gl_format == GL_BGRA) &&
00111 (gl_type == GL_UNSIGNED_BYTE || gl_type == GL_FLOAT || gl_type == GL_UNSIGNED_SHORT);
00112 }
00113
00114 #if !defined(_MSC_VER) || _MSC_VER > 1200
00115 template <class Uint>
00116 static int DownSamplePixelDataI(unsigned int gl_format, int width, int height,
00117 int ds, const Uint * pin, Uint * pout);
00118 template <class Uint>
00119 static int DownSamplePixelDataI2F(unsigned int gl_format, int width, int height,
00120 int ds, const Uint * pin, float * pout, int skip = 0);
00121 #endif
00122 static int DownSamplePixelDataF(unsigned int gl_format, int width, int height,
00123 int ds, const float * pin, float * pout, int skip = 0);
00124 static int TruncateWidthCU(int w) {return w & 0xfffffffc; }
00125 public:
00126 GLTexInput() : _down_sampled(0), _rgb_converted(0), _data_modified(0),
00127 _converted_data(0), _pixel_data(0){}
00128 int SetImageData(int width, int height, const void * data,
00129 unsigned int gl_format, unsigned int gl_type);
00130 int LoadImageFile(char * imagepath, int & w, int &h);
00131 void VerifyTexture();
00132 virtual ~GLTexInput();
00133 };
00134
00135
00136
00137
00138 class GLTexPacked:public GLTexImage
00139 {
00140 public:
00141 virtual void DrawImage();
00142 virtual void DrawQuadUS(int scale);
00143 virtual void DrawQuadDS(int scale);
00144 virtual void FillMargin(int marginx, int marginy);
00145 virtual void InitTexture(int width, int height, int clamp_to_edge =1);
00146 virtual void TexConvertRGB();
00147 virtual void SetImageSize(int width, int height);
00148 virtual void ZeroHistoMargin();
00149
00150 public:
00151 void DrawMargin(int right, int bottom, int mx, int my);
00152 GLTexPacked():GLTexImage(){}
00153 };
00154
00155
00156 #endif // !defined(GL_TEX_IMAGE_H)
00157