ToneReproducer.cpp   StelToneReproducer.cpp 
skipping to change at line 27 skipping to change at line 27
*/ */
#include <cmath> #include <cmath>
# include <config.h> # include <config.h>
#ifndef HAVE_POW10 #ifndef HAVE_POW10
# define HAVE_POW10 1 # define HAVE_POW10 1
//# define pow10(x) pow(10,(x)) //# define pow10(x) pow(10,(x))
# define pow10(x) std::exp((x) * 2.3025850930) # define pow10(x) std::exp((x) * 2.3025850930)
#endif #endif
#include "ToneReproducer.hpp" #include "StelToneReproducer.hpp"
/********************************************************************* /*********************************************************************
Constructor: Set some default values to prevent bugs in case of bad use Constructor: Set some default values to prevent bugs in case of bad use
*********************************************************************/ *********************************************************************/
ToneReproducer::ToneReproducer() : Lda(50.f), Lwa(40000.f), oneOverMaxdL(1. f/100.f), lnOneOverMaxdL(std::log(1.f/100.f)), oneOverGamma(1.f/2.2222f) StelToneReproducer::StelToneReproducer() : Lda(50.f), Lwa(40000.f), oneOver MaxdL(1.f/100.f), lnOneOverMaxdL(std::log(1.f/100.f)), oneOverGamma(1.f/2.2 222f)
{ {
// Initialize sensor // Initialize sensor
setInputScale(); setInputScale();
// Update alphaDa and betaDa values // Update alphaDa and betaDa values
float log10Lwa = std::log10(Lwa); float log10Lwa = std::log10(Lwa);
alphaWa = 0.4f * log10Lwa + 1.519f; alphaWa = 0.4f * log10Lwa + 1.519f;
betaWa = -0.4f * log10Lwa*log10Lwa + 0.218f * log10Lwa + 6.1642f; betaWa = -0.4f * log10Lwa*log10Lwa + 0.218f * log10Lwa + 6.1642f;
setDisplayAdaptationLuminance(Lda); setDisplayAdaptationLuminance(Lda);
setWorldAdaptationLuminance(Lwa); setWorldAdaptationLuminance(Lwa);
} }
/********************************************************************* /*********************************************************************
Destructor Destructor
*********************************************************************/ *********************************************************************/
ToneReproducer::~ToneReproducer() StelToneReproducer::~StelToneReproducer()
{ {
} }
/********************************************************************* /*********************************************************************
Set the global input scale Set the global input scale
*********************************************************************/ *********************************************************************/
void ToneReproducer::setInputScale(float scale) void StelToneReproducer::setInputScale(float scale)
{ {
inputScale=scale; inputScale=scale;
lnInputScale = std::log(inputScale); lnInputScale = std::log(inputScale);
} }
/********************************************************************* /*********************************************************************
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)
*********************************************************************/ *********************************************************************/
void ToneReproducer::setDisplayAdaptationLuminance(float _Lda) void StelToneReproducer::setDisplayAdaptationLuminance(float _Lda)
{ {
Lda = _Lda; Lda = _Lda;
// Update alphaDa and betaDa values // Update alphaDa and betaDa values
float log10Lda = std::log10(Lda); float log10Lda = std::log10(Lda);
alphaDa = 0.4f * log10Lda + 1.519f; alphaDa = 0.4f * log10Lda + 1.519f;
betaDa = -0.4f * log10Lda*log10Lda + 0.218f * log10Lda + 6.1642f; betaDa = -0.4f * log10Lda*log10Lda + 0.218f * log10Lda + 6.1642f;
// Update terms // Update terms
alphaWaOverAlphaDa = alphaWa/alphaDa; alphaWaOverAlphaDa = alphaWa/alphaDa;
term2 = pow10((betaWa-betaDa)/alphaDa) / (M_PI*0.0001f); term2 = pow10((betaWa-betaDa)/alphaDa) / (M_PI*0.0001f);
lnTerm2 = std::log(term2); lnTerm2 = std::log(term2);
term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, o neOverGamma); term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, o neOverGamma);
} }
/********************************************************************* /*********************************************************************
Set the eye adaptation luminance for the world (and precompute what can be ) Set the eye adaptation luminance for the world (and precompute what can be )
*********************************************************************/ *********************************************************************/
void ToneReproducer::setWorldAdaptationLuminance(float _Lwa) void StelToneReproducer::setWorldAdaptationLuminance(float _Lwa)
{ {
Lwa = _Lwa; Lwa = _Lwa;
// Update alphaDa and betaDa values // Update alphaDa and betaDa values
float log10Lwa = std::log10(Lwa); float log10Lwa = std::log10(Lwa);
alphaWa = 0.4f * log10Lwa + 1.519f; alphaWa = 0.4f * log10Lwa + 1.519f;
betaWa = -0.4f * log10Lwa*log10Lwa + 0.218f * log10Lwa + 6.1642f; betaWa = -0.4f * log10Lwa*log10Lwa + 0.218f * log10Lwa + 6.1642f;
// Update terms // Update terms
alphaWaOverAlphaDa = alphaWa/alphaDa; alphaWaOverAlphaDa = alphaWa/alphaDa;
term2 = pow10((betaWa-betaDa)/alphaDa) / (M_PI*0.0001f); term2 = pow10((betaWa-betaDa)/alphaDa) / (M_PI*0.0001f);
lnTerm2 = std::log(term2); lnTerm2 = std::log(term2);
term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, o neOverGamma); term2TimesOneOverMaxdLpOneOverGamma = std::pow(term2*oneOverMaxdL, o neOverGamma);
} }
/********************************************************************* /*********************************************************************
Convert from xyY color system to RGB according to the adaptation Convert from xyY color system to RGB according to the adaptation
The Y component is in cd/m^2 The Y component is in cd/m^2
*********************************************************************/ *********************************************************************/
void ToneReproducer::xyYToRGB(float* color) const void StelToneReproducer::xyYToRGB(float* color) const
{ {
float log10Y;
// 1. Hue conversion // 1. Hue conversion
if (color[2] <= 0.f)
{
// qDebug() << "ToneReproducer::xyYToRGB: BIG WARNING: color
[2]<=0: " << color[2];
log10Y = -9e50;
}
else
{
log10Y = std::log10(color[2]);
}
// if log10Y>0.6, photopic vision only (with the cones, colors are s een) // if log10Y>0.6, photopic vision only (with the cones, colors are s een)
// else scotopic vision if log10Y<-2 (with the rods, no colors, ever ything blue), // else scotopic vision if log10Y<-2 (with the rods, no colors, ever ything blue),
// else mesopic vision (with rods and cones, transition state) // else mesopic vision (with rods and cones, transition state)
if (log10Y<0.6) if (color[2] <= 0.01f)
{ {
// Compute s, ratio between scotopic and photopic vision // special case for s = 0 (x=0.25, y=0.25)
float s = 0.f; color[2] *= 0.5121445;
if (log10Y > -2.f) color[2] = std::pow((float)(color[2]*M_PI*0.0001f), alphaWaO
{ verAlphaDa*oneOverGamma)* term2TimesOneOverMaxdLpOneOverGamma;
const float op = (log10Y + 2.f)/2.6f; color[0] = 0.787077*color[2];
s = 3.f * op * op - 2 * op * op * op; color[1] = 0.9898434*color[2];
} color[2] *= 1.9256125;
return;
}
if (color[2]<3.9810717055349722)
{
// Compute s, ratio between scotopic and photopic vision
const float op = (std::log10(color[2]) + 2.f)/2.6f;
const float s = op * op *(3.f - 2.f * op);
// Do the blue shift for scotopic vision simulation (night v ision) [3] // Do the blue shift for scotopic vision simulation (night v ision) [3]
// The "night blue" is x,y(0.25, 0.25) // The "night blue" is x,y(0.25, 0.25)
color[0] = (1.f - s) * 0.25f + s * color[0]; // Add scoto pic + photopic components color[0] = (1.f - s) * 0.25f + s * color[0]; // Add scoto pic + photopic components
color[1] = (1.f - s) * 0.25f + s * color[1]; // Add scoto pic + photopic components color[1] = (1.f - s) * 0.25f + s * color[1]; // Add scoto pic + photopic components
// Take into account the scotopic luminance approximated by V [3] [4] // Take into account the scotopic luminance approximated by V [3] [4]
const float V = color[2] * (1.33f * (1.f + color[1] / color[ 0] + color[0] * (1.f - color[0] - color[1])) - 1.68f); const float V = color[2] * (1.33f * (1.f + color[1] / color[ 0] + color[0] * (1.f - color[0] - color[1])) - 1.68f);
color[2] = 0.4468f * (1.f - s) * V + s * color[2]; color[2] = 0.4468f * (1.f - s) * V + s * color[2];
} }
// 2. Adapt the luminance value and scale it to fit in the RGB range [2] // 2. Adapt the luminance value and scale it to fit in the RGB range [2]
 End of changes. 12 change blocks. 
27 lines changed or deleted 22 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/