Home · All Namespaces · All Classes · Functions · Coding Style · 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 private:
00143     // The global luminance scaling
00144     float inputScale;
00145     float lnInputScale;     // std::log(inputScale)
00146     
00147     float Lda;      // Display luminance adaptation (in cd/m^2)
00148     float Lwa;      // World   luminance adaptation (in cd/m^2)
00149     float oneOverMaxdL; // 1 / Display maximum luminance (in cd/m^2)
00150     float lnOneOverMaxdL; // log(oneOverMaxdL)
00151     float oneOverGamma; // 1 / Screen gamma value
00152 
00153     // Precomputed variables
00154     float alphaDa;
00155     float betaDa;
00156     float alphaWa;
00157     float betaWa;
00158     float alphaWaOverAlphaDa;
00159     float term2;
00160     float lnTerm2;  // log(term2)
00161     
00162     float term2TimesOneOverMaxdLpOneOverGamma;
00163 };
00164 
00165 #endif // _STELTONEREPRODUCER_HPP_
00166 

Generated on Mon Mar 9 16:16:16 2009 for Stellarium by  doxygen 1.5.5