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 void SaveToASCII(const char* path);
00072 public:
00073 void AttachToFBO(int i );
00074 void BindTex();
00075 operator GLuint (){return _texID;}
00076 GLuint GetTexID(){return _texID;}
00077 int GetImgPixelCount(){return _imgWidth*_imgHeight;}
00078 int GetTexPixelCount(){return _texWidth*_texHeight;}
00079 int GetImgWidth(){return _imgWidth;}
00080 int GetImgHeight(){return _imgHeight;}
00081 int GetTexWidth(){return _texWidth;}
00082 int GetTexHeight(){return _texHeight;}
00083 int GetDrawWidth(){return _drawWidth;}
00084 int GetDrawHeight(){return _drawHeight;}
00085
00086 int IsTexPacked(){return _drawWidth != _imgWidth;}
00087 GLTexImage();
00088 virtual ~GLTexImage();
00089 friend class SiftGPU;
00090 };
00091
00092
00093
00094
00095 class GLTexInput:public GLTexImage
00096 {
00097 public:
00098 int _down_sampled;
00099 int _rgb_converted;
00100 int _data_modified;
00101
00103 float * _converted_data;
00104 const void* _pixel_data;
00105 public:
00106 static int IsSimpleGlFormat(unsigned int gl_format, unsigned int gl_type)
00107 {
00108
00109 return (gl_format ==GL_LUMINANCE ||gl_format == GL_LUMINANCE_ALPHA||
00110 gl_format == GL_RGB|| gl_format == GL_RGBA||
00111 gl_format == GL_BGR || gl_format == GL_BGRA) &&
00112 (gl_type == GL_UNSIGNED_BYTE || gl_type == GL_FLOAT || gl_type == GL_UNSIGNED_SHORT);
00113 }
00114
00115 #if !defined(_MSC_VER) || _MSC_VER > 1200
00116 template <class Uint>
00117 static int DownSamplePixelDataI(unsigned int gl_format, int width, int height,
00118 int ds, const Uint * pin, Uint * pout);
00119 template <class Uint>
00120 static int DownSamplePixelDataI2F(unsigned int gl_format, int width, int height,
00121 int ds, const Uint * pin, float * pout, int skip = 0);
00122 #endif
00123 static int DownSamplePixelDataF(unsigned int gl_format, int width, int height,
00124 int ds, const float * pin, float * pout, int skip = 0);
00125 static int TruncateWidthCU(int w) {return w & 0xfffffffc; }
00126 public:
00127 GLTexInput() : _down_sampled(0), _rgb_converted(0), _data_modified(0),
00128 _converted_data(0), _pixel_data(0){}
00129 int SetImageData(int width, int height, const void * data,
00130 unsigned int gl_format, unsigned int gl_type);
00131 int LoadImageFile(char * imagepath, int & w, int &h);
00132 void VerifyTexture();
00133 virtual ~GLTexInput();
00134 };
00135
00136
00137
00138
00139 class GLTexPacked:public GLTexImage
00140 {
00141 public:
00142 virtual void DrawImage();
00143 virtual void DrawQuadUS(int scale);
00144 virtual void DrawQuadDS(int scale);
00145 virtual void FillMargin(int marginx, int marginy);
00146 virtual void InitTexture(int width, int height, int clamp_to_edge =1);
00147 virtual void TexConvertRGB();
00148 virtual void SetImageSize(int width, int height);
00149 virtual void ZeroHistoMargin();
00150
00151 public:
00152 void DrawMargin(int right, int bottom, int mx, int my);
00153 GLTexPacked():GLTexImage(){}
00154 };
00155
00156
00157 #endif // !defined(GL_TEX_IMAGE_H)
00158