00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INCL_GAMMA
00023 #define INCL_GAMMA 1
00024
00025 #ifndef ALPHA_LINUX_CXX
00026 # include <cmath>
00027 #endif
00028
00029 #ifndef UNDER_CE
00030 using std::pow;
00031 #endif
00032
00033 template <class T> class GammaTable
00034 {
00035 private:
00036 unsigned size;
00037 float sizef;
00038 T *table;
00039 float gamma;
00040
00041
00042 GammaTable() { }
00043
00044 public:
00045
00046 inline const float & get_gamma ()
00047 { return gamma; }
00048
00049 inline void set_gamma (float g)
00050 {
00051 if (g < 0.001f) g = 0.001f;
00052 if (g == gamma) return;
00053 gamma = g;
00054
00055 for (unsigned i = 0; i < size; i++)
00056 table[i] = (T) (pow (i / sizef, 1 / gamma) * sizef);
00057 }
00058
00059 GammaTable (unsigned int s, float g = 1) : sizef(-1), gamma(-1)
00060 {
00061 sizef += size = s>2?s:2;
00062 table = new T [size];
00063 set_gamma(g);
00064 }
00065
00066 ~GammaTable () { delete [] table; }
00067
00068 inline const T & operator [] (const T &i) const
00069 { return table[i]; }
00070
00071 };
00072
00073 #endif //INCL_GAMMA