StelToneReproducer.hpp   StelToneReproducer.hpp 
skipping to change at line 22 skipping to change at line 22
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/ */
#ifndef _STELTONEREPRODUCER_HPP_ #ifndef _STELTONEREPRODUCER_HPP_
#define _STELTONEREPRODUCER_HPP_ #define _STELTONEREPRODUCER_HPP_
#include <QDebug> #include "config.h"
#include <cmath>
//! Converts tones in function of the eye adaptation to luminance. //! Converts tones in function of the eye adaptation to luminance.
//! The aim is to get on the screen something which is perceptualy accurate , //! The aim is to get on the screen something which is perceptualy accurate ,
//! ie. to compress high dynamic range luminance to CRT display range. //! ie. to compress high dynamic range luminance to CRT display range.
//! The class perform mainly a fast implementation of the algorithm from th e //! The class perform mainly a fast implementation of the algorithm from th e
//! paper [1], with more accurate values from [2]. The blue shift formula i s taken //! paper [1], with more accurate values from [2]. The blue shift formula i s taken
//! from [3] and combined with the Scotopic vision formula from [4]. //! from [3] and combined with the Scotopic vision formula from [4].
//! //!
//! Important : you may call setDisplayAdaptationLuminance() //! Important : you may call setDisplayAdaptationLuminance()
//! and setWorldAdaptationLuminance() before any call to xyYToRGB() //! and setWorldAdaptationLuminance() before any call to xyYToRGB()
skipping to change at line 55 skipping to change at line 57
//! //!
//! [3] "Night Rendering", H. Wann Jensen, S. Premoze, P. Shirley, //! [3] "Night Rendering", H. Wann Jensen, S. Premoze, P. Shirley,
//! W.B. Thompson, J.A. Ferwerda, M.M. Stark //! W.B. Thompson, J.A. Ferwerda, M.M. Stark
//! //!
//! [4] "A Visibility Matching Tone Reproduction Operator for High Dynamic //! [4] "A Visibility Matching Tone Reproduction Operator for High Dynamic
//! Range Scenes", G.W. Larson, H. Rushmeier, C. Piatko //! Range Scenes", G.W. Larson, H. Rushmeier, C. Piatko
class StelToneReproducer class StelToneReproducer
{ {
public: public:
//! Constructor //! Constructor
StelToneReproducer(); StelToneReproducer();
//! Desctructor //! Desctructor
virtual ~StelToneReproducer(); virtual ~StelToneReproducer();
//! Set the eye adaptation luminance for the display (and precompute what can be) //! Set the eye adaptation luminance for the display (and precompute what can be)
//! Usual luminance range is 1-100 cd/m^2 for a CRT screen //! Usual luminance range is 1-100 cd/m^2 for a CRT screen
//! @param displayAdaptationLuminance the new display luminance in c d/m^2. The initial default value is 50 cd/m^2 //! @param displayAdaptationLuminance the new display luminance in c d/m^2. The initial default value is 50 cd/m^2
void setDisplayAdaptationLuminance(float displayAdaptationLuminance) ; void setDisplayAdaptationLuminance(float displayAdaptationLuminance) ;
//! Set the eye adaptation luminance for the world (and precompute w hat can be) //! Set the eye adaptation luminance for the world (and precompute w hat can be)
//! @param worldAdaptationLuminance the new world luminance in cd/m^ 2. The initial default value is 40000 cd/m^2 for Skylight //! @param worldAdaptationLuminance the new world luminance in cd/m^ 2. The initial default value is 40000 cd/m^2 for Skylight
//! Star Light : 0.001 cd/m^2 //! Star Light : 0.001 cd/m^2
//! Moon Light : 0.1 cd/m^2 //! Moon Light : 0.1 cd/m^2
//! Indoor Lighting : 100 cd/m^2 //! Indoor Lighting : 100 cd/m^2
//! Sun Light : 100000 cd/m^2 //! Sun Light : 100000 cd/m^2
void setWorldAdaptationLuminance(float worldAdaptationLuminance); void setWorldAdaptationLuminance(float worldAdaptationLuminance);
//! Get the eye adaptation luminance for the world //! Get the eye adaptation luminance for the world
float getWorldAdaptationLuminance() const {return Lwa;} float getWorldAdaptationLuminance() const
{
return Lwa;
}
//! Set the global scale applied to input lumiances, i.e before the adaptation //! Set the global scale applied to input lumiances, i.e before the adaptation
//! It is the parameter to modify to simulate aperture*exposition ti me //! It is the parameter to modify to simulate aperture*exposition ti me
//! @param scale the global input scale //! @param scale the global input scale
void setInputScale(float scale=1.f); void setInputScale(float scale=1.f);
//! Get the global scale applied to input lumiances, i.e before the adaptation //! Get the global scale applied to input lumiances, i.e before the adaptation
float getInputScale() const {return inputScale;} float getInputScale() const
{
return inputScale;
}
//! Set the maximum luminance of the display (CRT, screen etc..) //! Set the maximum luminance of the display (CRT, screen etc..)
//! This value is used to scale the RGB range //! This value is used to scale the RGB range
//! @param maxdL the maximum lumiance in cd/m^2. Initial default val ue is 120 cd/m^2 //! @param maxdL the maximum lumiance in cd/m^2. Initial default val ue is 120 cd/m^2
void setMaxDisplayLuminance(float maxdL) void setMaxDisplayLuminance(float maxdL)
{oneOverMaxdL = 1.f/maxdL; lnOneOverMaxdL=std::log(oneOverMaxdL); te {
rm2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, oneOverGam oneOverMaxdL = 1.f/maxdL; lnOneOverMaxdL=std::log(oneOverMax
ma);} dL); term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, one
OverGamma);
}
//! Get the display gamma //! Get the display gamma
//! @return the display gamma. Default value is 2.2222 for a CRT //! @return the display gamma. Default value is 2.2222 for a CRT
float getDisplayGamma() const {return 1.f/oneOverGamma;} float getDisplayGamma() const
{
return 1.f/oneOverGamma;
}
//! Set the display gamma //! Set the display gamma
//! @param gamma the gamma. Initial default value is 2.2222 //! @param gamma the gamma. Initial default value is 2.2222
void setDisplayGamma(float gamma) void setDisplayGamma(float gamma)
{oneOverGamma = 1.f/gamma; term2TimesOneOverMaxdLpOneOverGamma = std {
::pow(term2*oneOverMaxdL, oneOverGamma);} oneOverGamma = 1.f/gamma; term2TimesOneOverMaxdLpOneOverGamm
a = std::pow(term2*oneOverMaxdL, oneOverGamma);
}
//! Return adapted luminance from world to display //! Return adapted luminance from world to display
//! @param worldLuminance the world luminance to convert in cd/m^2 //! @param worldLuminance the world luminance to convert in cd/m^2
//! @return the converted display luminance in cd/m^2 //! @return the converted display luminance in cd/m^2
float adaptLuminance(float worldLuminance) const float adaptLuminance(float worldLuminance) const
{ {
return std::pow((float)(inputScale*worldLuminance*M_PI*0.000 1f),alphaWaOverAlphaDa) * term2; return std::pow((float)(inputScale*worldLuminance*M_PI*0.000 1f),alphaWaOverAlphaDa) * term2;
} }
//! Return adapted luminance from display to world //! Return adapted luminance from display to world
//! @param displayLuminance the display luminance to convert in cd/m ^2 //! @param displayLuminance the display luminance to convert in cd/m ^2
//! @return the converted world luminance in cd/m^2 //! @return the converted world luminance in cd/m^2
float reverseAdaptLuminance(float displayLuminance) const float reverseAdaptLuminance(float displayLuminance) const
{ {
return std::pow((float)(displayLuminance/term2),1.f/alphaWaO verAlphaDa)/(inputScale*M_PI*0.0001f); return (float) std::pow((float)(displayLuminance/term2),1.f/ alphaWaOverAlphaDa)/(inputScale*M_PI*0.0001f);
} }
//! Return adapted luminance from world to display with 1 correspond ing to full display white //! Return adapted luminance from world to display with 1 correspond ing to full display white
//! @param worldLuminance the world luminance to convert in cd/m^2 //! @param worldLuminance the world luminance to convert in cd/m^2
//! @return the converted display luminance with 1 corresponding to full display white. The value can be more than 1 when saturation.. //! @return the converted display luminance with 1 corresponding to full display white. The value can be more than 1 when saturation..
float adaptLuminanceScaled(float worldLuminance) const float adaptLuminanceScaled(float worldLuminance) const
{ {
return adaptLuminance(worldLuminance)*oneOverMaxdL; return adaptLuminance(worldLuminance)*oneOverMaxdL;
} }
skipping to change at line 136 skipping to change at line 151
return reverseAdaptLuminance(displayLuminance/oneOverMaxdL); return reverseAdaptLuminance(displayLuminance/oneOverMaxdL);
} }
//! Return adapted ln(luminance) from world to display with 1 corres ponding to full display white //! Return adapted ln(luminance) from world to display with 1 corres ponding to full display white
//! @param lnWorldLuminance the world luminance to convert in ln(cd/ m^2) //! @param lnWorldLuminance the world luminance to convert in ln(cd/ m^2)
//! @param pFact the power at whihc the result should be set. The de fault is 0.5 and therefore return the square root of the adapted luminance //! @param pFact the power at whihc the result should be set. The de fault is 0.5 and therefore return the square root of the adapted luminance
//! @return the converted display set at the pFact power. Luminance with 1 corresponding to full display white. The value can be more than 1 wh en saturation.. //! @return the converted display set at the pFact power. Luminance with 1 corresponding to full display white. The value can be more than 1 wh en saturation..
float adaptLuminanceScaledLn(float lnWorldLuminance, float pFact=0.5 f) const float adaptLuminanceScaledLn(float lnWorldLuminance, float pFact=0.5 f) const
{ {
const float lnPix0p0001 = -8.0656104861f; const float lnPix0p0001 = -8.0656104861f;
//Needs better name return std::exp(((lnInputScale+lnWorldLuminance+lnPix0p0001)
const float temp = ((lnInputScale + lnWorldLuminance *alphaWaOverAlphaDa+lnTerm2+lnOneOverMaxdL)*pFact);
+ lnPix0p0001) *
alphaWaOverAlphaDa+lnTerm2 + lnO
neOverMaxdL) * pFact;
// Optimization:
// Always using exp here takes 6-9% of runtime in release mo
de.
// This code is used to determine point source radius.
//
// If this value is < 5 (and < 4, for that matter), the star
won't
// even be displayed as it's radius is too low. We also get
rid
// of ~90% of exp calls.
if(temp < -5.0f)
{
return 0.0f;
}
return std::exp(temp);
} }
//! Convert from xyY color system to RGB. //! Convert from xyY color system to RGB.
//! The first two components x and y indicate the "color", the Y is luminance in cd/m^2. //! The first two components x and y indicate the "color", the Y is luminance in cd/m^2.
//! @param xyY an array of 3 floats which are replaced by the conver ted RGB values //! @param xyY an array of 3 floats which are replaced by the conver ted RGB values
void xyYToRGB(float* xyY) const; void xyYToRGB(float* xyY) const;
void getShadersParams(float& a, float& b, float & c) const void getShadersParams(float& a, float& b, float & c) const
{ {
a=alphaWaOverAlphaDa; a=alphaWaOverAlphaDa;
 End of changes. 10 change blocks. 
34 lines changed or deleted 29 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/