Stellarium 0.15.2
StelToneReproducer.hpp
1 /*
2  * Copyright (C) 2003 Fabien Chereau
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
17  */
18 
19 #ifndef _STELTONEREPRODUCER_HPP_
20 #define _STELTONEREPRODUCER_HPP_
21 
22 #include <cmath>
23 
52 {
53 public:
56 
58  virtual ~StelToneReproducer();
59 
63  void setDisplayAdaptationLuminance(float displayAdaptationLuminance);
64 
71  void setWorldAdaptationLuminance(float worldAdaptationLuminance);
74  {
75  return Lwa;
76  }
77 
81  void setInputScale(float scale=1.f);
83  float getInputScale() const
84  {
85  return inputScale;
86  }
87 
91  void setMaxDisplayLuminance(float maxdL)
92  {
93  oneOverMaxdL = 1.f/maxdL; lnOneOverMaxdL=std::log(oneOverMaxdL); term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, oneOverGamma);
94  }
95 
98  float getDisplayGamma() const
99  {
100  return 1.f/oneOverGamma;
101  }
102 
105  void setDisplayGamma(float gamma)
106  {
107  oneOverGamma = 1.f/gamma; term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, oneOverGamma);
108  }
109 
113  float adaptLuminance(float worldLuminance) const
114  {
115  return std::pow((float)(inputScale*worldLuminance*M_PI*0.0001f),alphaWaOverAlphaDa) * term2;
116  }
117 
121  float reverseAdaptLuminance(float displayLuminance) const
122  {
123  return (float) std::pow((float)(displayLuminance/term2),1.f/alphaWaOverAlphaDa)/(inputScale*M_PI*0.0001f);
124  }
125 
129  float adaptLuminanceScaled(float worldLuminance) const
130  {
131  return adaptLuminance(worldLuminance)*oneOverMaxdL;
132  }
133 
137  float reverseAdaptLuminanceScaled(float displayLuminance) const
138  {
139  return reverseAdaptLuminance(displayLuminance/oneOverMaxdL);
140  }
141 
146  float adaptLuminanceScaledLn(float lnWorldLuminance, float pFact=0.5f) const
147  {
148  const float lnPix0p0001 = -8.0656104861f;
149  return std::exp(((lnInputScale+lnWorldLuminance+lnPix0p0001)*alphaWaOverAlphaDa+lnTerm2+lnOneOverMaxdL)*pFact);
150  }
151 
155  void xyYToRGB(float* xyY) const;
156 
157  void getShadersParams(float& a, float& b, float & c) const
158  {
159  a=alphaWaOverAlphaDa;
160  b=oneOverGamma;
161  c=term2TimesOneOverMaxdLpOneOverGamma;
162  }
163 private:
164  // The global luminance scaling
165  float inputScale;
166  float lnInputScale; // std::log(inputScale)
167 
168  float Lda; // Display luminance adaptation (in cd/m^2)
169  float Lwa; // World luminance adaptation (in cd/m^2)
170  float oneOverMaxdL; // 1 / Display maximum luminance (in cd/m^2)
171  float lnOneOverMaxdL; // log(oneOverMaxdL)
172  float oneOverGamma; // 1 / Screen gamma value
173 
174  // Precomputed variables
175  float alphaDa;
176  float betaDa;
177  float alphaWa;
178  float betaWa;
179  float alphaWaOverAlphaDa;
180  float term2;
181  float lnTerm2; // log(term2)
182 
183  float term2TimesOneOverMaxdLpOneOverGamma;
184 };
185 
186 #endif // _STELTONEREPRODUCER_HPP_
187 
void setInputScale(float scale=1.f)
Set the global scale applied to input lumiances, i.e before the adaptation It is the parameter to mod...
void setDisplayAdaptationLuminance(float displayAdaptationLuminance)
Set the eye adaptation luminance for the display (and precompute what can be) Usual luminance range i...
float getWorldAdaptationLuminance() const
Get the eye adaptation luminance for the world.
float adaptLuminanceScaled(float worldLuminance) const
Return adapted luminance from world to display with 1 corresponding to full display white...
void xyYToRGB(float *xyY) const
Convert from xyY color system to RGB.
StelToneReproducer()
Constructor.
float reverseAdaptLuminance(float displayLuminance) const
Return adapted luminance from display to world.
Converts tones in function of the eye adaptation to luminance.
float getInputScale() const
Get the global scale applied to input luminances, i.e before the adaptation.
void setMaxDisplayLuminance(float maxdL)
Set the maximum luminance of the display (CRT, screen etc..) This value is used to scale the RGB rang...
void setDisplayGamma(float gamma)
Set the display gamma.
float getDisplayGamma() const
Get the display gamma.
float adaptLuminance(float worldLuminance) const
Return adapted luminance from world to display.
virtual ~StelToneReproducer()
Desctructor.
void setWorldAdaptationLuminance(float worldAdaptationLuminance)
Set the eye adaptation luminance for the world (and precompute what can be)
float reverseAdaptLuminanceScaled(float displayLuminance) const
Return adapted luminance from display to world with 1 corresponding to full display white...
float adaptLuminanceScaledLn(float lnWorldLuminance, float pFact=0.5f) const
Return adapted ln(luminance) from world to display with 1 corresponding to full display white...