2
* Copyright (C) 2003 Fabien Chereau
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.
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.
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.
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].
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)
32
// Thanks to all the authors of the following papers i used for providing
33
// their work freely online.
35
// [1] "Tone Reproduction for Realistic Images", Tumblin and Rushmeier,
36
// IEEE Computer Graphics & Application, November 1993
38
// [2] "Tone Reproduction and Physically Based Spectral Rendering",
39
// Devlin, Chalmers, Wilkie and Purgathofer in EUROGRAPHICS 2002
41
// [3] "Night Rendering", H. Wann Jensen, S. Premoze, P. Shirley,
42
// W.B. Thompson, J.A. Ferwerda, M.M. Stark
44
// [4] "A Visibility Matching Tone Reproduction Operator for High Dynamic
45
// Range Scenes", G.W. Larson, H. Rushmeier, C. Piatko
48
#ifndef _TONE_REPRODUCTOR_H_
49
#define _TONE_REPRODUCTOR_H_
57
virtual ~ToneReproductor();
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);
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);
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;}
76
// Set the display gamma : default value = 2.3
77
void set_display_gamma(float gamma) {one_over_gamma = 1.f/gamma;}
79
// Return adapted luminance from world to display
80
float adapt_luminance(float world_luminance) const
82
return powf(world_luminance*M_PI*0.0001f,alpha_wa_over_alpha_da) * term2;
85
// Convert from xyY color system to RGB
86
void xyY_to_RGB(float*);
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
94
// Precomputed variables
99
float alpha_wa_over_alpha_da;
103
#endif // _TONE_REPRODUCTOR_H_