From 0e032143cee2a5253d7e940b6f0c84df9d900897 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 25 Oct 2021 00:40:30 +0200 Subject: [PATCH] Fix fade factor calculation when there is no end time. In this case we can't do any fade out. --- src/lib/render_text.cc | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/lib/render_text.cc b/src/lib/render_text.cc index bcf04147a..6f7614d36 100644 --- a/src/lib/render_text.cc +++ b/src/lib/render_text.cc @@ -244,19 +244,30 @@ calculate_fade_factor (StringText const& first, DCPTime time, int frame_rate) */ auto const fade_in_start = DCPTime::from_seconds(first.in().as_seconds()).round(frame_rate); auto const fade_in_end = fade_in_start + DCPTime::from_seconds (first.fade_up_time().as_seconds ()); - auto const fade_out_end = DCPTime::from_seconds (first.out().as_seconds()).round(frame_rate); - auto const fade_out_start = fade_out_end - DCPTime::from_seconds (first.fade_down_time().as_seconds ()); if (fade_in_start <= time && time <= fade_in_end && fade_in_start != fade_in_end) { fade_factor *= DCPTime(time - fade_in_start).seconds() / DCPTime(fade_in_end - fade_in_start).seconds(); } - if (fade_out_start <= time && time <= fade_out_end && fade_out_start != fade_out_end) { - fade_factor *= 1 - DCPTime(time - fade_out_start).seconds() / DCPTime(fade_out_end - fade_out_start).seconds(); - } - if (time < fade_in_start || time > fade_out_end) { + + if (time < fade_in_start) { fade_factor = 0; } + /* first.out() may be zero if we don't know when this subtitle will finish. We can only think about + * fading out if we _do_ know when it will finish. + */ + if (first.out() != dcp::Time()) { + auto const fade_out_end = DCPTime::from_seconds (first.out().as_seconds()).round(frame_rate); + auto const fade_out_start = fade_out_end - DCPTime::from_seconds(first.fade_down_time().as_seconds()); + + if (fade_out_start <= time && time <= fade_out_end && fade_out_start != fade_out_end) { + fade_factor *= 1 - DCPTime(time - fade_out_start).seconds() / DCPTime(fade_out_end - fade_out_start).seconds(); + } + if (time > fade_out_end) { + fade_factor = 0; + } + } + return fade_factor; } -- 2.30.2