From 07089e6e66bd7002e1b2f9c394e97708bb9d9ebc Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 12 Feb 2020 18:00:33 +0100 Subject: [PATCH] Use the new automatic white balance functionality from Nageru 1.9.2. --- nageru/ultimate.lua | 57 +++++++++------------------------------------ 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/nageru/ultimate.lua b/nageru/ultimate.lua index efbeb3e..5722a96 100644 --- a/nageru/ultimate.lua +++ b/nageru/ultimate.lua @@ -9,16 +9,6 @@ local state = { transition_src_signal = 0, transition_dst_signal = 0, - neutral_colors = { - {0.5, 0.5, 0.5}, -- Input 0. - {0.5, 0.5, 0.5}, -- Input 1. - {0.5, 0.5, 0.5}, -- Input 2. - {0.5, 0.5, 0.5}, -- Input 3. - {0.5, 0.5, 0.5}, -- Input 4. - {0.5, 0.5, 0.5} -- Input 5. - -- Will also be filled with VIDEO_SIGNAL_NUM below. - }, - overlay_transition_start = -2.0, overlay_transition_end = -1.0, overlay_alpha_src = 0.0, @@ -34,7 +24,7 @@ local state = { live_signal_num = 0, preview_signal_num = 1 } -local NUM_CAMERAS = 6 -- Remember to update neutral_colors, too. +local NUM_CAMERAS = 6 -- Valid values for live_signal_num and preview_signal_num. local INPUT0_SIGNAL_NUM = 0 @@ -47,8 +37,6 @@ local SBS_SIGNAL_NUM = NUM_CAMERAS local STATIC_SIGNAL_NUM = NUM_CAMERAS + 1 local VIDEO_SIGNAL_NUM = NUM_CAMERAS + 2 -state.neutral_colors[VIDEO_SIGNAL_NUM - INPUT0_SIGNAL_NUM + 1] = {0.5, 0.5, 0.5} - -- Preview-only signal showing the current signal with the overlay. -- Not valid for live_signal_num! local OVERLAY_SIGNAL_NUM = NUM_CAMERAS + 3 @@ -99,7 +87,7 @@ function make_fade_input(scene) local ret = { input = scene:add_input(), resample_effect = scene:add_optional_effect(ResampleEffect.new()), -- Activated if scaling. - wb_effect = scene:add_optional_effect(WhiteBalanceEffect.new()) -- Activated for video inputs. + wb_effect = scene:add_auto_white_balance() } ret.overlay = make_overlay(scene, ret.wb_effect) return ret @@ -140,12 +128,16 @@ fade_scene = make_fade_scene() function make_sbs_input(scene, has_overlay) local input = scene:add_input() + local overlay = has_overlay and make_overlay(scene, input) or nil + local resample_effect = scene:add_effect({ResampleEffect.new(), ResizeEffect.new()}) + local wb_effect = scene:add_auto_white_balance(resample_effect, input) + local padding_effect = scene:add_effect(IntegralPaddingEffect.new()) return { input = input, - overlay = has_overlay and make_overlay(scene, input) or nil, - resample_effect = scene:add_effect({ResampleEffect.new(), ResizeEffect.new()}), - wb_effect = scene:add_effect(WhiteBalanceEffect.new()), - padding_effect = scene:add_effect(IntegralPaddingEffect.new()) + overlay = overlay, + resample_effect = resample_effect, + wb_effect = wb_effect, + padding_effect = padding_effect } end @@ -181,7 +173,7 @@ function make_simple_scene_no_finalize() local input = scene:add_input() local resample_effect = scene:add_effect({ResampleEffect.new(), ResizeEffect.new(), IdentityEffect.new()}) - local wb_effect = scene:add_effect(WhiteBalanceEffect.new()) + local wb_effect = scene:add_auto_white_balance() local overlay = make_overlay(scene, wb_effect) return { @@ -424,15 +416,6 @@ function supports_set_wb(channel) return is_plain_signal(channel - 2) end --- API ENTRY POINT --- Gets called with a new gray point when the white balance is changing. --- The color is in linear light (not sRGB gamma). -function set_wb(channel, red, green, blue) - if is_plain_signal(channel - 2) then - state.neutral_colors[channel - 2 + 1] = { red, green, blue } - end -end - function finish_transitions(t) if state.transition_type ~= NO_TRANSITION and t >= state.transition_end then state.live_signal_num = state.transition_dst_signal @@ -622,14 +605,11 @@ end function setup_fade_input(state, input, signals, signal_num, width, height) if signal_num == STATIC_SIGNAL_NUM then input.input:display(static_image) - input.wb_effect:disable() -- We assume this is already correctly scaled at load time. input.resample_effect:disable() else input.input:display(signal_num) - input.wb_effect:enable() - set_neutral_color(input.wb_effect, state.neutral_colors[signal_num - INPUT0_SIGNAL_NUM + 1]) if (signals:get_width(signal_num) ~= width or signals:get_height(signal_num) ~= height) then input.resample_effect:enable() @@ -777,7 +757,6 @@ function get_scene(num, t, width, height, signals) stinger_scene.input:display(state.live_signal_num) end set_scale_parameters_if_needed(stinger_scene, signals, state.live_signal_num, width, height, true) - set_neutral_color_from_signal(state, stinger_scene.wb_effect, state.live_signal_num) stinger_scene.stinger_input:display(stinger_images[state.stinger_frame]) state.stinger_frame = state.stinger_frame + 1 @@ -808,7 +787,6 @@ function get_scene(num, t, width, height, signals) simple_scene.input:display(state.live_signal_num) end set_scale_parameters_if_needed(simple_scene, signals, state.live_signal_num, width, height, true) - set_neutral_color_from_signal(state, simple_scene.wb_effect, state.live_signal_num) prepare_overlay_live(state, simple_scene, t, 1.0) return simple_scene.scene end @@ -846,7 +824,6 @@ function get_scene(num, t, width, height, signals) simple_scene.input:display(signal_num) end set_scale_parameters_if_needed(simple_scene, signals, signal_num, width, height, false) - set_neutral_color_from_signal(state, simple_scene.wb_effect, signal_num) prepare_overlay_static(simple_scene, t) return simple_scene.scene end @@ -895,8 +872,6 @@ end function prepare_sbs_scene(state, scene, t, transition_type, src_signal, dst_signal, screen_width, screen_height, input_resolution, hq) scene.input0.input:display(0) scene.input1.input:display(4) - set_neutral_color(scene.input0.wb_effect, state.neutral_colors[1]) - set_neutral_color(scene.input1.wb_effect, state.neutral_colors[5]) -- Both inputs are the same size (true side-by-side). local pos0 = pos_from_top_left(1280 - 616 - 16, 186, 616, 347, screen_width, screen_height) @@ -1067,16 +1042,6 @@ function prepare_overlay_static(scene) end end -function set_neutral_color(effect, color) - effect:set_vec3("neutral_color", color[1], color[2], color[3]) -end - -function set_neutral_color_from_signal(state, effect, signal) - if is_plain_signal(signal) then - set_neutral_color(effect, state.neutral_colors[signal - INPUT0_SIGNAL_NUM + 1]) - end -end - function calc_zoom_progress(t) if t < state.transition_start then return 0.0 -- 2.39.2