]> git.tdb.fi Git - libs/gl.git/blob - source/effects/colorcurve.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / effects / colorcurve.h
1 #ifndef MSP_GL_COLORCURVE_H_
2 #define MSP_GL_COLORCURVE_H_
3
4 #include "postprocessor.h"
5 #include "programdata.h"
6 #include "texture1d.h"
7
8 namespace Msp {
9 namespace GL {
10
11 class Program;
12
13 /**
14 Maps high dynamic range colors to 8-bit and applies gamma correction.
15
16 An exponential curve (with exponent less than or equal to 1) is applied to
17 simulate the response of the human eye.  If the maximum color component of the
18 result exceeds 1, the overflow is distributed to the other components to
19 increase the apparent brightness without changing the hue.
20
21 Gamma or sRGB correction can also be applied to the output.  It can be used to
22 improve color reproduction by performing lighting calculations in linear color
23 space and converting to sRGB for display.
24 */
25 class ColorCurve: public PostProcessor
26 {
27 public:
28         struct Template: public PostProcessor::Template
29         {
30                 class Loader: public DataFile::DerivedObjectLoader<Template, PostProcessor::Template::Loader>
31                 {
32                 public:
33                         Loader(Template &);
34
35                 private:
36                         void gamma(float);
37                         void srgb();
38                 };
39
40                 float exposure_adjust = 0.0f;
41                 float brightness_response = 0.4f;
42                 float gamma = 1.0f;
43                 bool srgb = false;
44
45                 virtual ColorCurve *create(unsigned, unsigned) const;
46         };
47
48 private:
49         const Program &shprog;
50         ProgramData shdata;
51         Texture1D curve;
52         const Mesh &quad;
53         const Sampler &linear_sampler;
54         const Sampler &nearest_sampler;
55
56 public:
57         ColorCurve();
58
59         /** Set exposure adjustment in EV units.  Positive values brighten the
60         image, negative values darken it.  Zero is neutral. */
61         void set_exposure_adjust(float);
62
63         /** Sets the exponent of the brightness response curve.  It must be greater
64         than zero and at most one.  A value of one gives a linear response; closer
65         to zero results in a more gentle curve. */
66         void set_brightness_response(float);
67
68         /** Sets the gamma value used for mapping output colors.  Allowed range is
69         from 0.1 to 10. */
70         void set_gamma(float);
71
72         /** Sets output mapping to sRGB.  This is almost, but not exactly equivalent
73         to set_gamma(2.2). */
74         void set_srgb();
75
76         /// Sets output mapping to linear.  This is equivalent to set_gamma(1).
77         void set_linear();
78
79         virtual void render(Renderer &, const Texture2D &, const Texture2D &);
80
81         virtual void set_debug_name(const std::string &);
82 };
83
84 } // namespace GL
85 } // namespace Msp
86
87 #endif