Stellarium 0.12.4
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 <QDebug>
23 
24 
53 {
54 public:
57 
59  virtual ~StelToneReproducer();
60 
64  void setDisplayAdaptationLuminance(float displayAdaptationLuminance);
65 
72  void setWorldAdaptationLuminance(float worldAdaptationLuminance);
74  float getWorldAdaptationLuminance() const {return Lwa;}
75 
79  void setInputScale(float scale=1.f);
81  float getInputScale() const {return inputScale;}
82 
86  void setMaxDisplayLuminance(float maxdL)
87  {oneOverMaxdL = 1.f/maxdL; lnOneOverMaxdL=std::log(oneOverMaxdL); term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, oneOverGamma);}
88 
91  float getDisplayGamma() const {return 1.f/oneOverGamma;}
92 
95  void setDisplayGamma(float gamma)
96  {oneOverGamma = 1.f/gamma; term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, oneOverGamma);}
97 
101  float adaptLuminance(float worldLuminance) const
102  {
103  return std::pow((float)(inputScale*worldLuminance*M_PI*0.0001f),alphaWaOverAlphaDa) * term2;
104  }
105 
109  float reverseAdaptLuminance(float displayLuminance) const
110  {
111  return std::pow((float)(displayLuminance/term2),1.f/alphaWaOverAlphaDa)/(inputScale*M_PI*0.0001f);
112  }
113 
117  float adaptLuminanceScaled(float worldLuminance) const
118  {
119  return adaptLuminance(worldLuminance)*oneOverMaxdL;
120  }
121 
125  float reverseAdaptLuminanceScaled(float displayLuminance) const
126  {
127  return reverseAdaptLuminance(displayLuminance/oneOverMaxdL);
128  }
129 
134  float adaptLuminanceScaledLn(float lnWorldLuminance, float pFact=0.5f) const
135  {
136  const float lnPix0p0001 = -8.0656104861f;
137  //Needs better name
138  const float temp = ((lnInputScale + lnWorldLuminance + lnPix0p0001) *
139  alphaWaOverAlphaDa+lnTerm2 + lnOneOverMaxdL) * pFact;
140 
141  // Optimization:
142  // Always using exp here takes 6-9% of runtime in release mode.
143  // This code is used to determine point source radius.
144  //
145  // If this value is < 5 (and < 4, for that matter), the star won't
146  // even be displayed as it's radius is too low. We also get rid
147  // of ~90% of exp calls.
148  if(temp < -5.0f)
149  {
150  return 0.0f;
151  }
152 
153  return std::exp(temp);
154  }
155 
159  void xyYToRGB(float* xyY) const;
160 
161  void getShadersParams(float& a, float& b, float & c) const
162  {
163  a=alphaWaOverAlphaDa;
164  b=oneOverGamma;
165  c=term2TimesOneOverMaxdLpOneOverGamma;
166  }
167 private:
168  // The global luminance scaling
169  float inputScale;
170  float lnInputScale; // std::log(inputScale)
171 
172  float Lda; // Display luminance adaptation (in cd/m^2)
173  float Lwa; // World luminance adaptation (in cd/m^2)
174  float oneOverMaxdL; // 1 / Display maximum luminance (in cd/m^2)
175  float lnOneOverMaxdL; // log(oneOverMaxdL)
176  float oneOverGamma; // 1 / Screen gamma value
177 
178  // Precomputed variables
179  float alphaDa;
180  float betaDa;
181  float alphaWa;
182  float betaWa;
183  float alphaWaOverAlphaDa;
184  float term2;
185  float lnTerm2; // log(term2)
186 
187  float term2TimesOneOverMaxdLpOneOverGamma;
188 };
189 
190 #endif // _STELTONEREPRODUCER_HPP_
191