]> git.tdb.fi Git - libs/gl.git/blob - source/effects/colorcurve.h
Access builtin resources through a global instance
[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 "program.h"
6 #include "programdata.h"
7 #include "texture1d.h"
8
9 namespace Msp {
10 namespace GL {
11
12 /**
13 Processes oversaturated colors to preserve hues.  When one color component
14 exceeds 1.0, the overflow is distributed to the other components, scaling the
15 color towards white.
16
17 Gamma or sRGB correction can also be applied to the output.  It can be used to
18 improve color reproduction by performing lighting calculations in linear color
19 space and converting to sRGB for display.
20 */
21 class ColorCurve: public PostProcessor
22 {
23 public:
24         struct Template: public PostProcessor::Template
25         {
26                 class Loader: public DataFile::DerivedObjectLoader<Template, PostProcessor::Template::Loader>
27                 {
28                 public:
29                         Loader(Template &);
30
31                 private:
32                         void gamma(float);
33                         void srgb();
34                 };
35
36                 float exposure_adjust;
37                 float brightness_response;
38                 float gamma;
39                 bool srgb;
40
41                 Template();
42
43                 virtual ColorCurve *create(unsigned, unsigned) const;
44         };
45
46 private:
47         const Program &shprog;
48         ProgramData shdata;
49         Texture1D curve;
50         const Mesh &quad;
51         const Sampler &linear_sampler;
52         const Sampler &nearest_sampler;
53
54 public:
55         ColorCurve();
56
57         /** Set exposure adjustment in EV units.  Positive values brighten the
58         image, negative values darken it.  Zero is neutral. */
59         void set_exposure_adjust(float);
60
61         /** Sets the exponent of the brightness response curve.  It must be greater
62         than zero and at most one.  A value of one gives a linear response; closer
63         to zero results in a more gentle curve. */
64         void set_brightness_response(float);
65
66         /** Sets the gamma value used for mapping output colors.  Allowed range is
67         from 0.1 to 10. */
68         void set_gamma(float);
69
70         /** Sets output mapping to sRGB.  This is almost, but not exactly equivalent
71         to set_gamma(2.2). */
72         void set_srgb();
73
74         /// Sets output mapping to linear.  This is equivalent to set_gamma(1).
75         void set_linear();
76
77         virtual void render(Renderer &, const Texture2D &, const Texture2D &);
78 };
79
80 } // namespace GL
81 } // namespace Msp
82
83 #endif