Yet more moving of stuff around.
[movit] / effect_chain.cpp
1 #include <assert.h>
2
3 #include "effect_chain.h"
4 #include "gamma_expansion_effect.h"
5 #include "lift_gamma_gain_effect.h"
6 #include "colorspace_conversion_effect.h"
7
8 EffectChain::EffectChain(unsigned width, unsigned height)
9         : width(width), height(height) {}
10
11 void EffectChain::add_input(const ImageFormat &format)
12 {
13         input_format = format;
14         current_color_space = format.color_space;
15         current_gamma_curve = format.gamma_curve;
16 }
17
18 void EffectChain::add_output(const ImageFormat &format)
19 {
20         output_format = format;
21 }
22         
23 Effect *instantiate_effect(EffectId effect)
24 {
25         switch (effect) {
26         case GAMMA_CONVERSION:
27                 return new GammaExpansionEffect();
28         case RGB_PRIMARIES_CONVERSION:
29                 return new GammaExpansionEffect();
30         case LIFT_GAMMA_GAIN:
31                 return new LiftGammaGainEffect();
32         }
33         assert(false);
34 }
35
36 Effect *EffectChain::add_effect(EffectId effect_id)
37 {
38         Effect *effect = instantiate_effect(effect_id);
39
40         if (effect->needs_linear_light() && current_gamma_curve != GAMMA_LINEAR) {
41                 GammaExpansionEffect *gamma_conversion = new GammaExpansionEffect();
42                 gamma_conversion->set_int("source_curve", current_gamma_curve);
43                 effects.push_back(gamma_conversion);
44                 current_gamma_curve = GAMMA_LINEAR;
45         }
46
47         if (effect->needs_srgb_primaries() && current_color_space != COLORSPACE_sRGB) {
48                 assert(current_gamma_curve == GAMMA_LINEAR);
49                 ColorSpaceConversionEffect *colorspace_conversion = new ColorSpaceConversionEffect();
50                 colorspace_conversion->set_int("source_space", current_color_space);
51                 colorspace_conversion->set_int("destination_space", COLORSPACE_sRGB);
52                 effects.push_back(colorspace_conversion);
53                 current_color_space = COLORSPACE_sRGB;
54         }
55
56         effects.push_back(effect);
57         return effect;
58 }
59