Stellarium 0.13.0
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 "config.h"
23 
24 #include <cmath>
25 
54 {
55 public:
58 
60  virtual ~StelToneReproducer();
61 
65  void setDisplayAdaptationLuminance(float displayAdaptationLuminance);
66 
73  void setWorldAdaptationLuminance(float worldAdaptationLuminance);
76  {
77  return Lwa;
78  }
79 
83  void setInputScale(float scale=1.f);
85  float getInputScale() const
86  {
87  return inputScale;
88  }
89 
93  void setMaxDisplayLuminance(float maxdL)
94  {
95  oneOverMaxdL = 1.f/maxdL; lnOneOverMaxdL=std::log(oneOverMaxdL); term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, oneOverGamma);
96  }
97 
100  float getDisplayGamma() const
101  {
102  return 1.f/oneOverGamma;
103  }
104 
107  void setDisplayGamma(float gamma)
108  {
109  oneOverGamma = 1.f/gamma; term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, oneOverGamma);
110  }
111 
115  float adaptLuminance(float worldLuminance) const
116  {
117  return std::pow((float)(inputScale*worldLuminance*M_PI*0.0001f),alphaWaOverAlphaDa) * term2;
118  }
119 
123  float reverseAdaptLuminance(float displayLuminance) const
124  {
125  return (float) std::pow((float)(displayLuminance/term2),1.f/alphaWaOverAlphaDa)/(inputScale*M_PI*0.0001f);
126  }
127 
131  float adaptLuminanceScaled(float worldLuminance) const
132  {
133  return adaptLuminance(worldLuminance)*oneOverMaxdL;
134  }
135 
139  float reverseAdaptLuminanceScaled(float displayLuminance) const
140  {
141  return reverseAdaptLuminance(displayLuminance/oneOverMaxdL);
142  }
143 
148  float adaptLuminanceScaledLn(float lnWorldLuminance, float pFact=0.5f) const
149  {
150  const float lnPix0p0001 = -8.0656104861f;
151  return std::exp(((lnInputScale+lnWorldLuminance+lnPix0p0001)*alphaWaOverAlphaDa+lnTerm2+lnOneOverMaxdL)*pFact);
152  }
153 
157  void xyYToRGB(float* xyY) const;
158 
159  void getShadersParams(float& a, float& b, float & c) const
160  {
161  a=alphaWaOverAlphaDa;
162  b=oneOverGamma;
163  c=term2TimesOneOverMaxdLpOneOverGamma;
164  }
165 private:
166  // The global luminance scaling
167  float inputScale;
168  float lnInputScale; // std::log(inputScale)
169 
170  float Lda; // Display luminance adaptation (in cd/m^2)
171  float Lwa; // World luminance adaptation (in cd/m^2)
172  float oneOverMaxdL; // 1 / Display maximum luminance (in cd/m^2)
173  float lnOneOverMaxdL; // log(oneOverMaxdL)
174  float oneOverGamma; // 1 / Screen gamma value
175 
176  // Precomputed variables
177  float alphaDa;
178  float betaDa;
179  float alphaWa;
180  float betaWa;
181  float alphaWaOverAlphaDa;
182  float term2;
183  float lnTerm2; // log(term2)
184 
185  float term2TimesOneOverMaxdLpOneOverGamma;
186 };
187 
188 #endif // _STELTONEREPRODUCER_HPP_
189 
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 lumiances, 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...