~ubuntu-branches/debian/squeeze/stellarium/squeeze

« back to all changes in this revision

Viewing changes to src/tone_reproductor.h

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2008-05-19 21:28:23 UTC
  • mfrom: (3.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080519212823-m5nfiuntxstxzxj7
Tags: 0.9.1-4
Add libxcursor-dev, libxfixes-dev, libxinerama-dev, libqt4-opengl-dev to
build-deps (Closes: #479906)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 
 */
18
 
 
19
 
// Class which converts tones in function of the eye adaptation to luminance.
20
 
// The aim is to get on the screen something which is perceptualy accurate,
21
 
// ie. to compress high dynamic range luminance to CRT display range.
22
 
// The class perform mainly a fast implementation of the algorithm from the
23
 
// paper [1], with more accurate values from [2]. The blue shift formula is taken
24
 
// from [3] and combined with the Scotopic vision formula from [4].
25
 
 
26
 
// Important : you may call set_display_adaptation_luminance()
27
 
// and set_world_adaptation_luminance() before any call to xyY_to_RGB()
28
 
// or adapt_luminance otherwise the default values will be used. (they are
29
 
// appropriate for a daylight sky luminance)
30
 
 
31
 
// REFERENCES :
32
 
// Thanks to all the authors of the following papers i used for providing
33
 
// their work freely online.
34
 
//
35
 
// [1] "Tone Reproduction for Realistic Images", Tumblin and Rushmeier,
36
 
// IEEE Computer Graphics & Application, November 1993
37
 
//
38
 
// [2] "Tone Reproduction and Physically Based Spectral Rendering",
39
 
// Devlin, Chalmers, Wilkie and Purgathofer in EUROGRAPHICS 2002
40
 
//
41
 
// [3] "Night Rendering", H. Wann Jensen, S. Premoze, P. Shirley,
42
 
// W.B. Thompson, J.A. Ferwerda, M.M. Stark
43
 
//
44
 
// [4] "A Visibility Matching Tone Reproduction Operator for High Dynamic
45
 
// Range Scenes", G.W. Larson, H. Rushmeier, C. Piatko
46
 
 
47
 
 
48
 
#ifndef _TONE_REPRODUCTOR_H_
49
 
#define _TONE_REPRODUCTOR_H_
50
 
 
51
 
#include "fmath.h"
52
 
 
53
 
class ToneReproductor
54
 
{
55
 
public:
56
 
    ToneReproductor();
57
 
    virtual ~ToneReproductor();
58
 
 
59
 
        // Set the eye adaptation luminance for the display (and precompute what can be)
60
 
        // Usual luminance range is 1-100 cd/m^2 for a CRT screen
61
 
        // default value = 50 cd/m^2
62
 
        void set_display_adaptation_luminance(float display_adaptation_luminance);
63
 
 
64
 
        // Set the eye adaptation luminance for the world (and precompute what can be)
65
 
        // default value = 40000 cd/m^2 for Skylight
66
 
        // Star Light      : 0.001  cd/m^2
67
 
        // Moon Light      : 0.1    cd/m^2
68
 
        // Indoor Lighting : 100    cd/m^2
69
 
        // Sun Light       : 100000 cd/m^2
70
 
        void set_world_adaptation_luminance(float world_adaptation_luminance);
71
 
 
72
 
        // Set the maximum display luminance : default value = 100 cd/m^2
73
 
        // This value is used to scale the RGB range
74
 
        void set_max_display_luminance(float maxdL) {one_over_maxdL = 1.f/maxdL;}
75
 
 
76
 
        // Set the display gamma : default value = 2.3
77
 
        void set_display_gamma(float gamma) {one_over_gamma = 1.f/gamma;}
78
 
 
79
 
        // Return adapted luminance from world to display
80
 
        float adapt_luminance(float world_luminance) const
81
 
        {
82
 
                return powf(world_luminance*M_PI*0.0001f,alpha_wa_over_alpha_da) * term2;
83
 
        }
84
 
 
85
 
        // Convert from xyY color system to RGB
86
 
        void xyY_to_RGB(float*);
87
 
 
88
 
private:
89
 
        float Lda;              // Display luminance adaptation (in cd/m^2)
90
 
        float Lwa;              // World   luminance adaptation (in cd/m^2)
91
 
        float one_over_maxdL;   // 1 / Display maximum luminance (in cd/m^2)
92
 
        float one_over_gamma;   // 1 / Screen gamma value
93
 
 
94
 
        // Precomputed variables
95
 
        float alpha_da;
96
 
        float beta_da;
97
 
        float alpha_wa;
98
 
        float beta_wa;
99
 
        float alpha_wa_over_alpha_da;
100
 
        float term2;
101
 
};
102
 
 
103
 
#endif // _TONE_REPRODUCTOR_H_