]> git.sesse.net Git - movit/blob - lift_gamma_gain_effect.h
Fix a bug where the wrong effect would be asked for compute shaders dimensions.
[movit] / lift_gamma_gain_effect.h
1 #ifndef _MOVIT_LIFT_GAMMA_GAIN_EFFECT_H
2 #define _MOVIT_LIFT_GAMMA_GAIN_EFFECT_H 1
3
4 // A simple lift/gamma/gain effect, used for color grading.
5 //
6 // Very roughly speaking, lift=shadows, gamma=midtones and gain=highlights,
7 // although all parameters affect the entire curve. Mathematically speaking,
8 // it is a bit unusual to look at gamma as a color, but it works pretty well
9 // in practice.
10 //
11 // The classic formula is: output = (gain * (x + lift * (1-x)))^(1/gamma).
12 //
13 // The lift is actually a case where we actually would _not_ want linear light;
14 // since black by definition becomes equal to the lift color, we want lift to
15 // be pretty close to black, but in linear light that means lift affects the
16 // rest of the curve relatively little. Thus, we actually convert to gamma 2.2
17 // before lift, and then back again afterwards. (Gain and gamma are,
18 // up to constants, commutative with the de-gamma operation.)
19 //
20 // Also, gamma is a case where we would not want premultiplied alpha.
21 // Thus, we have to divide away alpha first, and then re-multiply it back later.
22
23 #include <epoxy/gl.h>
24 #include <string>
25
26 #include "effect.h"
27
28 namespace movit {
29
30 class LiftGammaGainEffect : public Effect {
31 public:
32         LiftGammaGainEffect();
33         std::string effect_type_id() const override { return "LiftGammaGainEffect"; }
34         AlphaHandling alpha_handling() const override { return INPUT_PREMULTIPLIED_ALPHA_KEEP_BLANK; }
35         bool strong_one_to_one_sampling() const override { return true; }
36         std::string output_fragment_shader() override;
37
38         void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) override;
39
40 private:
41         RGBTriplet lift, gamma, gain;
42         RGBTriplet uniform_gain_pow_inv_gamma, uniform_inv_gamma22;
43 };
44
45 }  // namespace movit
46
47 #endif // !defined(_MOVIT_LIFT_GAMMA_GAIN_EFFECT_H)