]> git.mxchange.org Git - simgear.git/blob - simgear/screen/colors.hxx
Remove SVN sync code.
[simgear.git] / simgear / screen / colors.hxx
1 // colours.h 
2 //
3 // -- This header file contains color related functions
4 //
5 // Copyright (C) 2003  FlightGear Flight Simulator
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _SG_COLORS_HXX
25 #define _SG_COLORS_HXX 1
26
27 #include <math.h>
28
29 #if defined (sgi)
30 const float system_gamma = 2.0/1.7;
31
32 #else   // others
33 const float system_gamma = 2.5;
34 #endif
35
36 // simple architecture independant gamma correction function.
37 inline void gamma_correct_rgb(float *color,
38                               float reff = 2.5, float system = system_gamma)
39 {
40     if (reff == system)
41        return;
42
43     float tmp = reff/system;
44     color[0] = pow(color[0], tmp);
45     color[1] = pow(color[1], tmp);
46     color[2] = pow(color[2], tmp);
47 }
48
49 inline void gamma_correct_c(float *color,
50                             float reff = 2.5, float system = system_gamma)
51 {
52    if (reff == system)
53       return;
54
55    *color = pow(*color, reff/system);
56 }
57
58 inline void gamma_restore_rgb(float *color,
59                               float reff = 2.5, float system = system_gamma)
60 {
61     if (reff == system)
62        return;
63
64     float tmp = system/reff;
65     color[0] = pow(color[0], tmp);
66     color[1] = pow(color[1], tmp);
67     color[2] = pow(color[2], tmp);
68 }
69
70 inline void gamma_restore_c(float *color,
71                             float reff = 2.5, float system = system_gamma)
72 {
73    if (reff == system)
74       return;
75
76    *color = pow(*color, system/reff);
77 }
78
79
80 #endif // _SG_COLORS_HXX
81