-local main_chain = EffectChain.new(16, 9);
-local input0 = main_chain:add_live_input();
-input0:connect_signal(0);
-local input1 = main_chain:add_live_input();
-input1:connect_signal(1);
-local resample_effect = main_chain:add_effect(ResampleEffect.new(), input0);
-local padding_effect = main_chain:add_effect(IntegralPaddingEffect.new());
-padding_effect:set_vec4("border_color", 0.0, 0.0, 0.0, 1.0);
-
-local resample2_effect = main_chain:add_effect(ResampleEffect.new(), input1);
--- Effect *saturation_effect = main_chain->add_effect(new SaturationEffect());
--- CHECK(saturation_effect->set_float("saturation", 0.3f));
-local wb_effect = main_chain:add_effect(WhiteBalanceEffect.new());
-wb_effect:set_float("output_color_temperature", 3500.0);
-local padding2_effect = main_chain:add_effect(IntegralPaddingEffect.new());
-
-main_chain:add_effect(OverlayEffect.new(), padding_effect, padding2_effect);
-main_chain:finalize(true);
+function make_sbs_chain(input0_deint, input1_deint, hq)
+ local chain = EffectChain.new(16, 9)
+
+ local input0 = make_sbs_input(chain, INPUT0_SIGNAL_NUM, input0_deint, hq)
+ local input1 = make_sbs_input(chain, INPUT1_SIGNAL_NUM, input1_deint, hq)
+
+ input0.padding_effect:set_vec4("border_color", 0.0, 0.0, 0.0, 1.0)
+ input1.padding_effect:set_vec4("border_color", 0.0, 0.0, 0.0, 0.0)
+
+ chain:add_effect(OverlayEffect.new(), input0.padding_effect, input1.padding_effect)
+ chain:finalize(hq)
+
+ return {
+ chain = chain,
+ input0 = input0,
+ input1 = input1
+ }
+end
+
+-- Make all possible combinations of side-by-side chains.
+local sbs_chains = make_cartesian_product({
+ {"live", "livedeint"}, -- input0_type
+ {"live", "livedeint"}, -- input1_type
+ {true, false} -- hq
+}, function(input0_type, input1_type, hq)
+ local input0_deint = (input0_type == "livedeint")
+ local input1_deint = (input1_type == "livedeint")
+ return make_sbs_chain(input0_deint, input1_deint, hq)
+end)
+
+function make_fade_input(chain, signal, live, deint, scale)
+ local input, wb_effect, resample_effect, last
+ if live then
+ input = chain:add_live_input(false, deint)
+ wb_effect = chain:add_effect(WhiteBalanceEffect.new())
+ input:connect_signal(signal)
+ last = wb_effect
+ else
+ input = chain:add_effect(ImageInput.new("bg.jpeg"))
+ last = input
+ end
+
+ -- If we cared about this for the non-main inputs, we would have
+ -- checked hq here and invoked ResizeEffect instead.
+ if scale then
+ resample_effect = chain:add_effect(ResampleEffect.new())
+ last = resample_effect
+ end
+
+ return {
+ input = input,
+ wb_effect = wb_effect,
+ resample_effect = resample_effect,
+ last = last
+ }
+end
+
+-- A chain to fade between two inputs, of which either can be a picture
+-- or a live input. In practice only used live, but we still support the
+-- hq parameter.
+function make_fade_chain(input0_live, input0_deint, input0_scale, input1_live, input1_deint, input1_scale, hq)
+ local chain = EffectChain.new(16, 9)
+
+ local input0 = make_fade_input(chain, INPUT0_SIGNAL_NUM, input0_live, input0_deint, input0_scale)
+ local input1 = make_fade_input(chain, INPUT1_SIGNAL_NUM, input1_live, input1_deint, input1_scale)
+
+ local mix_effect = chain:add_effect(MixEffect.new(), input0.last, input1.last)
+ chain:finalize(hq)
+
+ return {
+ chain = chain,
+ input0 = input0,
+ input1 = input1,
+ mix_effect = mix_effect
+ }
+end
+
+-- Chains to fade between two inputs, in various configurations.
+local fade_chains = make_cartesian_product({
+ {"static", "live", "livedeint"}, -- input0_type
+ {true, false}, -- input0_scale
+ {"static", "live", "livedeint"}, -- input1_type
+ {true, false}, -- input1_scale
+ {true, false} -- hq
+}, function(input0_type, input0_scale, input1_type, input1_scale, hq)
+ local input0_live = (input0_type ~= "static")
+ local input1_live = (input1_type ~= "static")
+ local input0_deint = (input0_type == "livedeint")
+ local input1_deint = (input1_type == "livedeint")
+ return make_fade_chain(input0_live, input0_deint, input0_scale, input1_live, input1_deint, input1_scale, hq)
+end)