colors.hxx

00001 // colours.h 
00002 //
00003 // -- This header file contains color related functions
00004 //
00005 // Copyright (C) 2003  FlightGear Flight Simulator
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 as
00009 // published by the Free Software Foundation; either version 2 of the
00010 // License, or (at your option) any later version.
00011 //
00012 // This program is distributed in the hope that it will be useful, but
00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 // 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020 //
00021 // $Id: colors_8hxx-source.html,v 1.12 2007-12-17 15:37:00 curt Exp $
00022 
00023 
00024 #ifndef _SG_COLORS_HXX
00025 #define _SG_COLORS_HXX 1
00026 
00027 #include <math.h>
00028 
00029 #if defined( macintosh )
00030 const float system_gamma = 1.4;
00031 
00032 #elif defined (sgi)
00033 const float system_gamma = 2.0/1.7;
00034 
00035 #else   // others
00036 const float system_gamma = 2.5;
00037 #endif
00038 
00039 // simple architecture independant gamma correction function.
00040 inline void gamma_correct_rgb(float *color,
00041                               float reff = 2.5, float system = system_gamma)
00042 {
00043     if (reff == system)
00044        return;
00045 
00046     float tmp = reff/system;
00047     color[0] = pow(color[0], tmp);
00048     color[1] = pow(color[1], tmp);
00049     color[2] = pow(color[2], tmp);
00050 };
00051 
00052 inline void gamma_correct_c(float *color,
00053                             float reff = 2.5, float system = system_gamma)
00054 {
00055    if (reff == system)
00056       return;
00057 
00058    *color = pow(*color, reff/system);
00059 };
00060 
00061 inline void gamma_restore_rgb(float *color,
00062                               float reff = 2.5, float system = system_gamma)
00063 {
00064     if (reff == system)
00065        return;
00066 
00067     float tmp = system/reff;
00068     color[0] = pow(color[0], tmp);
00069     color[1] = pow(color[1], tmp);
00070     color[2] = pow(color[2], tmp);
00071 };
00072 
00073 inline void gamma_restore_c(float *color,
00074                             float reff = 2.5, float system = system_gamma)
00075 {
00076    if (reff == system)
00077       return;
00078 
00079    *color = pow(*color, system/reff);
00080 };
00081 
00082 
00083 #endif // _SG_COLORS_HXX
00084 

Generated on Mon Dec 17 09:30:54 2007 for SimGear by  doxygen 1.5.1