| 1 |
//////////////////////////////////////////////////////////////////////////// |
| 2 |
// File: GLTexImage.h |
| 3 |
// Author: Changchang Wu |
| 4 |
// Description : interface for the GLTexImage class. |
| 5 |
// GLTexImage: naive texture class. |
| 6 |
// sevral different quad drawing functions are provied |
| 7 |
// GLTexPacked: packed version (four value packed as four channels of a pixel) |
| 8 |
// GLTexInput: GLTexImage + some input information |
| 9 |
// |
| 10 |
// Copyright (c) 2007 University of North Carolina at Chapel Hill |
| 11 |
// All Rights Reserved |
| 12 |
// |
| 13 |
// Permission to use, copy, modify and distribute this software and its |
| 14 |
// documentation for educational, research and non-profit purposes, without |
| 15 |
// fee, and without a written agreement is hereby granted, provided that the |
| 16 |
// above copyright notice and the following paragraph appear in all copies. |
| 17 |
// |
| 18 |
// The University of North Carolina at Chapel Hill make no representations |
| 19 |
// about the suitability of this software for any purpose. It is provided |
| 20 |
// 'as is' without express or implied warranty. |
| 21 |
// |
| 22 |
// Please send BUG REPORTS to [email protected] |
| 23 |
// |
| 24 |
//////////////////////////////////////////////////////////////////////////// |
| 25 |
|
| 26 |
|
| 27 |
#ifndef GL_TEX_IMAGE_H |
| 28 |
#define GL_TEX_IMAGE_H |
| 29 |
|
| 30 |
class GlobalUtil; |
| 31 |
class GLTexImage :public GlobalUtil |
| 32 |
{ |
| 33 |
protected: |
| 34 |
GLuint _texID; |
| 35 |
int _imgWidth; |
| 36 |
int _imgHeight; |
| 37 |
int _texWidth; |
| 38 |
int _texHeight; |
| 39 |
int _drawWidth; |
| 40 |
int _drawHeight; |
| 41 |
public: |
| 42 |
static void DetachFBO(int i); |
| 43 |
static void UnbindTex(); |
| 44 |
static void UnbindMultiTex(int n); |
| 45 |
static void DrawQuad(float x1, float x2, float y1, float y2); |
| 46 |
|
| 47 |
public: |
| 48 |
virtual void DrawQuadUS(int scale); |
| 49 |
virtual void DrawQuadDS(int scale); |
| 50 |
virtual void DrawImage(); |
| 51 |
virtual void TexConvertRGB(); |
| 52 |
virtual void ZeroHistoMargin(); |
| 53 |
virtual void SetImageSize(int width, int height); |
| 54 |
virtual void InitTexture(int width, int height, int clamp_to_edge =1 ); |
| 55 |
void InitTexture(int width, int height, int clamp_to_edge, GLuint format); |
| 56 |
virtual void FillMargin(int marginx, int marginy); |
| 57 |
public: |
| 58 |
void DrawScaledQuad(float scale); |
| 59 |
int CopyToPBO(GLuint pbo, int width, int height, GLenum format = GL_RGBA); |
| 60 |
void CopyFromPBO(GLuint pbo, int width, int height, GLenum format = GL_RGBA); |
| 61 |
void FitRealTexViewPort(); |
| 62 |
void DrawQuadMT8(); |
| 63 |
void DrawQuadMT4(); |
| 64 |
void DrawQuadReduction(); |
| 65 |
void DrawQuadReduction(int w, int h); |
| 66 |
void DrawMargin(int right, int bottom); |
| 67 |
void DrawQuad(); |
| 68 |
void FitTexViewPort(); |
| 69 |
void ZeroHistoMargin(int hw, int hh); |
| 70 |
int CheckTexture(); |
| 71 |
void SaveToASCII(const char* path); |
| 72 |
public: |
| 73 |
void AttachToFBO(int i ); |
| 74 |
void BindTex(); |
| 75 |
operator GLuint (){return _texID;} |
| 76 |
GLuint GetTexID(){return _texID;} |
| 77 |
int GetImgPixelCount(){return _imgWidth*_imgHeight;} |
| 78 |
int GetTexPixelCount(){return _texWidth*_texHeight;} |
| 79 |
int GetImgWidth(){return _imgWidth;} |
| 80 |
int GetImgHeight(){return _imgHeight;} |
| 81 |
int GetTexWidth(){return _texWidth;} |
| 82 |
int GetTexHeight(){return _texHeight;} |
| 83 |
int GetDrawWidth(){return _drawWidth;} |
| 84 |
int GetDrawHeight(){return _drawHeight;} |
| 85 |
//int IsTexTight(){return _texWidth == _drawWidth && _texHeight == _drawHeight;} |
| 86 |
int IsTexPacked(){return _drawWidth != _imgWidth;} |
| 87 |
GLTexImage(); |
| 88 |
virtual ~GLTexImage(); |
| 89 |
friend class SiftGPU; |
| 90 |
}; |
| 91 |
|
| 92 |
//class for handle data input, to support all openGL-supported data format, |
| 93 |
//data are first uploaded to an openGL texture then converted, and optionally |
| 94 |
//when the datatype is simple, we downsample/convert on cpu |
| 95 |
class GLTexInput:public GLTexImage |
| 96 |
{ |
| 97 |
public: |
| 98 |
int _down_sampled; |
| 99 |
int _rgb_converted; |
| 100 |
int _data_modified; |
| 101 |
|
| 102 |
////////////////////////// |
| 103 |
float * _converted_data; |
| 104 |
const void* _pixel_data; |
| 105 |
public: |
| 106 |
static int IsSimpleGlFormat(unsigned int gl_format, unsigned int gl_type) |
| 107 |
{ |
| 108 |
//the formats there is a cpu code to conver rgb and downsample |
| 109 |
return (gl_format ==GL_LUMINANCE ||gl_format == GL_LUMINANCE_ALPHA|| |
| 110 |
gl_format == GL_RGB|| gl_format == GL_RGBA|| |
| 111 |
gl_format == GL_BGR || gl_format == GL_BGRA) && |
| 112 |
(gl_type == GL_UNSIGNED_BYTE || gl_type == GL_FLOAT || gl_type == GL_UNSIGNED_SHORT); |
| 113 |
} |
| 114 |
//in vc6, template member function doesn't work |
| 115 |
#if !defined(_MSC_VER) || _MSC_VER > 1200 |
| 116 |
template <class Uint> |
| 117 |
static int DownSamplePixelDataI(unsigned int gl_format, int width, int height, |
| 118 |
int ds, const Uint * pin, Uint * pout); |
| 119 |
template <class Uint> |
| 120 |
static int DownSamplePixelDataI2F(unsigned int gl_format, int width, int height, |
| 121 |
int ds, const Uint * pin, float * pout, int skip = 0); |
| 122 |
#endif |
| 123 |
static int DownSamplePixelDataF(unsigned int gl_format, int width, int height, |
| 124 |
int ds, const float * pin, float * pout, int skip = 0); |
| 125 |
static int TruncateWidthCU(int w) {return w & 0xfffffffc; } |
| 126 |
public: |
| 127 |
GLTexInput() : _down_sampled(0), _rgb_converted(0), _data_modified(0), |
| 128 |
_converted_data(0), _pixel_data(0){} |
| 129 |
int SetImageData(int width, int height, const void * data, |
| 130 |
unsigned int gl_format, unsigned int gl_type); |
| 131 |
int LoadImageFile(char * imagepath, int & w, int &h); |
| 132 |
void VerifyTexture(); |
| 133 |
virtual ~GLTexInput(); |
| 134 |
}; |
| 135 |
|
| 136 |
//GLTexPacked doesn't have any data |
| 137 |
//so that we can use the GLTexImage* pointer to index a GLTexPacked Vector |
| 138 |
|
| 139 |
class GLTexPacked:public GLTexImage |
| 140 |
{ |
| 141 |
public: |
| 142 |
virtual void DrawImage(); |
| 143 |
virtual void DrawQuadUS(int scale); |
| 144 |
virtual void DrawQuadDS(int scale); |
| 145 |
virtual void FillMargin(int marginx, int marginy); |
| 146 |
virtual void InitTexture(int width, int height, int clamp_to_edge =1); |
| 147 |
virtual void TexConvertRGB(); |
| 148 |
virtual void SetImageSize(int width, int height); |
| 149 |
virtual void ZeroHistoMargin(); |
| 150 |
//virtual void GetHistWH(int& w, int& h){return w = (3 + sz)>>1;} |
| 151 |
public: |
| 152 |
void DrawMargin(int right, int bottom, int mx, int my); |
| 153 |
GLTexPacked():GLTexImage(){} |
| 154 |
}; |
| 155 |
|
| 156 |
|
| 157 |
#endif // !defined(GL_TEX_IMAGE_H) |
| 158 |
|