Gamma.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <stdio.h>
00022 #include <common/Defines.h>
00023 #include <graph/Gamma.h>
00024 #include <graph/OptionsDisplay.h>
00025 #include <math.h>
00026 #include <SDL/SDL.h>
00027 
00028 Gamma *Gamma::instance_ = 0;
00029 
00030 Gamma *Gamma::instance()
00031 {
00032         if (!instance_)
00033         {
00034                 instance_ = new Gamma;
00035         }
00036 
00037         return instance_;
00038 }
00039 
00040 Gamma::Gamma()
00041 {
00042 
00043 }
00044 
00045 Gamma::~Gamma()
00046 {
00047         reset();
00048 }
00049 
00050 bool Gamma::set()
00051 {
00052         float gamma = 
00053                 float(OptionsDisplay::instance()->getBrightness()) / 10.0f;
00054 
00055         GammaSettings tmpSettings_;
00056         for (int n=0; n<256; n++) 
00057         {
00058                 float i = (float)n / 256.0f;
00059                 float c = powf(i,1.0f/gamma);
00060 
00061                 int value =  (int)(c*65535.0 + 0.5); 
00062                 if ( value > 65535 ) { value = 65535; } 
00063 
00064                 tmpSettings_.Red  [n] = (Uint16)value;
00065                 tmpSettings_.Green[n] = (Uint16)value;
00066                 tmpSettings_.Blue [n] = (Uint16)value;
00067         }
00068 
00069         if (SDL_SetGammaRamp(tmpSettings_.Red,tmpSettings_.Green,tmpSettings_.Blue) <0)
00070         {
00071                 return false;
00072         }
00073 
00074         return true;
00075 }
00076 
00077 bool Gamma::save()
00078 {
00079         if (SDL_GetGammaRamp(savedSettings_.Red,  savedSettings_.Green, savedSettings_.Blue) <0) 
00080                 return false;
00081         return true;
00082 }
00083 
00084 void Gamma::reset()
00085 {
00086         SDL_SetGammaRamp(savedSettings_.Red,  savedSettings_.Green, savedSettings_.Blue);
00087 }

Generated on Mon Feb 16 15:14:46 2009 for Scorched3D by  doxygen 1.5.3