-Node *EffectChain::normalize_to_linear_gamma(Node *input)
-{
- // Find out if all the inputs can be set to deliver sRGB inputs.
- // If so, we can just ask them to do that instead of inserting a
- // (possibly expensive) conversion operation.
- //
- // NOTE: We assume that effects generally don't mess with the gamma
- // curve (except GammaCompressionEffect, which should never be
- // inserted into a chain when this is called), so that we can just
- // update the output gamma as we go.
- //
- // TODO: Setting this flag for one source might confuse a different
- // part of the pipeline using the same source.
- std::vector<Node *> nonlinear_inputs;
- std::vector<Node *> intermediates;
- find_all_nonlinear_inputs(input, &nonlinear_inputs, &intermediates);
-
- bool all_ok = true;
- for (unsigned i = 0; i < nonlinear_inputs.size(); ++i) {
- Input *input = static_cast<Input *>(nonlinear_inputs[i]->effect);
- all_ok &= input->can_output_linear_gamma();
- }
-
- if (all_ok) {
- for (unsigned i = 0; i < nonlinear_inputs.size(); ++i) {
- bool ok = nonlinear_inputs[i]->effect->set_int("output_linear_gamma", 1);
- assert(ok);
- nonlinear_inputs[i]->output_gamma_curve = GAMMA_LINEAR;
- }
- for (unsigned i = 0; i < intermediates.size(); ++i) {
- intermediates[i]->output_gamma_curve = GAMMA_LINEAR;
- }
- return input;
- }
-
- // OK, that didn't work. Insert a conversion effect.
- GammaExpansionEffect *gamma_conversion = new GammaExpansionEffect();
- gamma_conversion->set_int("source_curve", input->output_gamma_curve);
- std::vector<Effect *> inputs;
- inputs.push_back(input->effect);
- gamma_conversion->add_self_to_effect_chain(this, inputs);
-
- assert(node_map.count(gamma_conversion) != 0);
- Node *node = node_map[gamma_conversion];
- node->output_gamma_curve = GAMMA_LINEAR;
- return node;
-}
-
-Node *EffectChain::normalize_to_srgb(Node *input)
-{
- assert(input->output_gamma_curve == GAMMA_LINEAR);
- ColorSpaceConversionEffect *colorspace_conversion = new ColorSpaceConversionEffect();
- colorspace_conversion->set_int("source_space", input->output_color_space);
- colorspace_conversion->set_int("destination_space", COLORSPACE_sRGB);
- std::vector<Effect *> inputs;
- inputs.push_back(input->effect);
- colorspace_conversion->add_self_to_effect_chain(this, inputs);
-
- assert(node_map.count(colorspace_conversion) != 0);
- Node *node = node_map[colorspace_conversion];
- node->output_color_space = COLORSPACE_sRGB;
- return node;
-}
-