gamma.h

Go to the documentation of this file.
00001 /*
00002 
00003 Gamma Table Class
00004 
00005 Copyright (C) 2000  Ryan Nunn
00006 
00007 This program is free software; you can redistribute it and/or
00008 modify it under the terms of the GNU General Public License
00009 as published by the Free Software Foundation; either version 2
00010 of the License, or (at your option) any later version.
00011 
00012 This program is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program; if not, write to the Free Software
00019 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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   // No
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

Generated on Mon Jul 9 14:42:47 2007 for ExultEngine by  doxygen 1.5.1