Stellarium 0.11.4
Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure

core/StelToneReproducer.hpp

00001 /*
00002  * Copyright (C) 2003 Fabien Chereau
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
00017  */
00018 
00019 #ifndef _STELTONEREPRODUCER_HPP_
00020 #define _STELTONEREPRODUCER_HPP_
00021 
00049 class StelToneReproducer
00050 {
00051 public:
00053     StelToneReproducer();
00054     
00056     virtual ~StelToneReproducer();
00057 
00061     void setDisplayAdaptationLuminance(float displayAdaptationLuminance);
00062 
00069     void setWorldAdaptationLuminance(float worldAdaptationLuminance);
00071     float getWorldAdaptationLuminance() const {return Lwa;}
00072     
00076     void setInputScale(float scale=1.f);
00078     float getInputScale() const {return inputScale;}
00079     
00083     void setMaxDisplayLuminance(float maxdL)
00084     {oneOverMaxdL = 1.f/maxdL; lnOneOverMaxdL=std::log(oneOverMaxdL); term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, oneOverGamma);}
00085 
00088     float getDisplayGamma() const {return 1.f/oneOverGamma;}
00089     
00092     void setDisplayGamma(float gamma)
00093     {oneOverGamma = 1.f/gamma; term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, oneOverGamma);}
00094 
00098     float adaptLuminance(float worldLuminance) const
00099     {
00100         return std::pow((float)(inputScale*worldLuminance*M_PI*0.0001f),alphaWaOverAlphaDa) * term2;
00101     }
00102 
00106     float reverseAdaptLuminance(float displayLuminance) const
00107     {
00108         return std::pow((float)(displayLuminance/term2),1.f/alphaWaOverAlphaDa)/(inputScale*M_PI*0.0001f);
00109     }
00110     
00114     float adaptLuminanceScaled(float worldLuminance) const
00115     {
00116         return adaptLuminance(worldLuminance)*oneOverMaxdL;
00117     }
00118     
00122     float reverseAdaptLuminanceScaled(float displayLuminance) const
00123     {
00124         return reverseAdaptLuminance(displayLuminance/oneOverMaxdL);
00125     }
00126     
00131     float adaptLuminanceScaledLn(float lnWorldLuminance, float pFact=0.5f) const
00132     {
00133         const float lnPix0p0001 = -8.0656104861f;
00134         return std::exp(((lnInputScale+lnWorldLuminance+lnPix0p0001)*alphaWaOverAlphaDa+lnTerm2+lnOneOverMaxdL)*pFact);
00135     }
00136     
00140     void xyYToRGB(float* xyY) const;
00141     
00142     void getShadersParams(float& a, float& b, float & c) const
00143     {
00144         a=alphaWaOverAlphaDa;
00145         b=oneOverGamma;
00146         c=term2TimesOneOverMaxdLpOneOverGamma;
00147     }
00148 private:
00149     // The global luminance scaling
00150     float inputScale;
00151     float lnInputScale;     // std::log(inputScale)
00152     
00153     float Lda;      // Display luminance adaptation (in cd/m^2)
00154     float Lwa;      // World   luminance adaptation (in cd/m^2)
00155     float oneOverMaxdL; // 1 / Display maximum luminance (in cd/m^2)
00156     float lnOneOverMaxdL; // log(oneOverMaxdL)
00157     float oneOverGamma; // 1 / Screen gamma value
00158 
00159     // Precomputed variables
00160     float alphaDa;
00161     float betaDa;
00162     float alphaWa;
00163     float betaWa;
00164     float alphaWaOverAlphaDa;
00165     float term2;
00166     float lnTerm2;  // log(term2)
00167     
00168     float term2TimesOneOverMaxdLpOneOverGamma;
00169 };
00170 
00171 #endif // _STELTONEREPRODUCER_HPP_
00172 
Generated on Sat Aug 25 22:13:30 2012 for Stellarium by  doxygen 1.6.3