From 94b3924ed3cbf4fbfa2445ca1007f25c53dc8b60 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 16 Aug 2016 08:41:25 +0100 Subject: Basic support for fading subtitles in and out (#923). --- src/lib/render_subtitles.cc | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/lib/render_subtitles.cc') diff --git a/src/lib/render_subtitles.cc b/src/lib/render_subtitles.cc index 5c8cf13ee..6e4dcf46a 100644 --- a/src/lib/render_subtitles.cc +++ b/src/lib/render_subtitles.cc @@ -92,9 +92,11 @@ marked_up (list subtitles) return out; } -/** @param subtitles A list of subtitles that are all on the same line */ +/** @param subtitles A list of subtitles that are all on the same line, + * at the same time and with the same fade in/out. + */ static PositionImage -render_line (list subtitles, list > fonts, dcp::Size target) +render_line (list subtitles, list > fonts, dcp::Size target, DCPTime time) { /* XXX: this method can only handle italic / bold changes mid-line, nothing else yet. @@ -205,7 +207,9 @@ render_line (list subtitles, list > fonts, } } - FcPattern* pattern = FcPatternBuild (0, FC_FILE, FcTypeString, font_files.get(FontFiles::NORMAL).get().string().c_str(), static_cast (0)); + FcPattern* pattern = FcPatternBuild ( + 0, FC_FILE, FcTypeString, font_files.get(FontFiles::NORMAL).get().string().c_str(), static_cast (0) + ); FcObjectSet* object_set = FcObjectSetBuild (FC_FAMILY, FC_STYLE, FC_LANG, FC_FILE, static_cast (0)); FcFontSet* font_set = FcFontList (fc_config, pattern, object_set); if (font_set) { @@ -248,9 +252,18 @@ render_line (list subtitles, list > fonts, layout->set_markup (marked_up (subtitles)); /* Compute fade factor */ - /* XXX */ float fade_factor = 1; + DCPTime const fade_in_start = DCPTime::from_seconds (subtitles.front().in().as_seconds ()); + DCPTime const fade_in_end = fade_in_start + DCPTime::from_seconds (subtitles.front().fade_up_time().as_seconds ()); + DCPTime const fade_out_end = DCPTime::from_seconds (subtitles.front().out().as_seconds ()); + DCPTime const fade_out_start = fade_out_end - DCPTime::from_seconds (subtitles.front().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(); + } else 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(); + } + context->scale (xscale, yscale); layout->update_from_cairo_context (context); @@ -335,22 +348,23 @@ render_line (list subtitles, list > fonts, return PositionImage (image, Position (max (0, x), max (0, y))); } +/** @param time Time of the frame that these subtitles are going on */ list -render_subtitles (list subtitles, list > fonts, dcp::Size target) +render_subtitles (list subtitles, list > fonts, dcp::Size target, DCPTime time) { list pending; list images; BOOST_FOREACH (dcp::SubtitleString const & i, subtitles) { if (!pending.empty() && fabs (i.v_position() - pending.back().v_position()) > 1e-4) { - images.push_back (render_line (pending, fonts, target)); + images.push_back (render_line (pending, fonts, target, time)); pending.clear (); } pending.push_back (i); } if (!pending.empty ()) { - images.push_back (render_line (pending, fonts, target)); + images.push_back (render_line (pending, fonts, target, time)); } return images; -- cgit v1.2.3