+void EffectChain::finalize()
+{
+ // Add normalizers to get the output format right.
+ assert(output_gamma_curve.count(last_added_effect()) != 0);
+ assert(output_color_space.count(last_added_effect()) != 0);
+ ColorSpace current_color_space = output_color_space[last_added_effect()]; // FIXME
+ if (current_color_space != output_format.color_space) {
+ ColorSpaceConversionEffect *colorspace_conversion = new ColorSpaceConversionEffect();
+ colorspace_conversion->set_int("source_space", current_color_space);
+ colorspace_conversion->set_int("destination_space", output_format.color_space);
+ std::vector<Effect *> inputs;
+ inputs.push_back(last_added_effect());
+ colorspace_conversion->add_self_to_effect_chain(this, inputs);
+ output_color_space[colorspace_conversion] = output_format.color_space;
+ }
+ GammaCurve current_gamma_curve = output_gamma_curve[last_added_effect()]; // FIXME
+ if (current_gamma_curve != output_format.gamma_curve) {
+ if (current_gamma_curve != GAMMA_LINEAR) {
+ normalize_to_linear_gamma(last_added_effect()); // FIXME
+ }
+ assert(current_gamma_curve == GAMMA_LINEAR);
+ GammaCompressionEffect *gamma_conversion = new GammaCompressionEffect();
+ gamma_conversion->set_int("destination_curve", output_format.gamma_curve);
+ std::vector<Effect *> inputs;
+ inputs.push_back(last_added_effect());
+ gamma_conversion->add_self_to_effect_chain(this, inputs);
+ output_gamma_curve[gamma_conversion] = output_format.gamma_curve;
+ }