GLTexImage.h
Go to the documentation of this file.
00001 
00002 //      File:           GLTexImage.h
00003 //      Author:         Changchang Wu
00004 //      Description : interface for the GLTexImage class.
00005 //              GLTexImage:             naive texture class. 
00006 //                                              sevral different quad drawing functions are provied
00007 //              GLTexPacked:    packed version (four value packed as four channels of a pixel)
00008 //              GLTexInput:             GLTexImage + some input information
00009 //
00010 //      Copyright (c) 2007 University of North Carolina at Chapel Hill
00011 //      All Rights Reserved
00012 //
00013 //      Permission to use, copy, modify and distribute this software and its
00014 //      documentation for educational, research and non-profit purposes, without
00015 //      fee, and without a written agreement is hereby granted, provided that the
00016 //      above copyright notice and the following paragraph appear in all copies.
00017 //      
00018 //      The University of North Carolina at Chapel Hill make no representations
00019 //      about the suitability of this software for any purpose. It is provided
00020 //      'as is' without express or implied warranty. 
00021 //
00022 //      Please send BUG REPORTS to ccwu@cs.unc.edu
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         //int   IsTexTight(){return _texWidth == _drawWidth && _texHeight == _drawHeight;}
00086         int     IsTexPacked(){return _drawWidth != _imgWidth;}
00087         GLTexImage();
00088         virtual ~GLTexImage();
00089         friend class SiftGPU;
00090 };
00091 
00092 //class for handle data input, to support all openGL-supported data format, 
00093 //data are first uploaded to an openGL texture then converted, and optionally
00094 //when the datatype is simple, we downsample/convert on cpu
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                 //the formats there is a cpu code to conver rgb and downsample
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 //in vc6, template member function doesn't work
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 //GLTexPacked doesn't have any data
00137 //so that we can use the GLTexImage* pointer to index a GLTexPacked Vector
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         //virtual void  GetHistWH(int& w, int& h){return w = (3 + sz)>>1;}
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 


siftgpu
Author(s): Changchang Wu
autogenerated on Wed Aug 26 2015 15:24:06