X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fvideo_content.cc;h=d173b4607abb7e698568ca7b6564d01c961309e2;hb=0303a96b66eaf85060ce02d85cc36067f34b1051;hp=51d6ba418f8848e9d32862fc91da113bec60788a;hpb=769d56b7f3b2fe78036b4ba12c0cfe71734b379d;p=dcpomatic.git diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 51d6ba418..d173b4607 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -86,17 +86,20 @@ VideoContent::VideoContent (Content* parent) } +/** @param video_range_hint Video range to use if none is given in the XML */ shared_ptr -VideoContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version) +VideoContent::from_xml (Content* parent, cxml::ConstNodePtr node, int version, VideoRange video_range_hint) { if (!node->optional_number_child ("VideoWidth")) { return {}; } - return make_shared(parent, node, version); + return make_shared(parent, node, version, video_range_hint); } -VideoContent::VideoContent (Content* parent, cxml::ConstNodePtr node, int version) + +/** @param video_range_hint Video range to use if none is given in the XML */ +VideoContent::VideoContent (Content* parent, cxml::ConstNodePtr node, int version, VideoRange video_range_hint) : ContentPart (parent) { _size.width = node->number_child ("VideoWidth"); @@ -185,8 +188,12 @@ VideoContent::VideoContent (Content* parent, cxml::ConstNodePtr node, int versio _fade_in = _fade_out = 0; } - _range = VideoRange::FULL; - if (node->optional_string_child("Range").get_value_or("full") == "video") { + auto video_range = node->optional_string_child("Range"); + if (!video_range) { + _range = video_range_hint; + } else if (*video_range == "full") { + _range = VideoRange::FULL; + } else { _range = VideoRange::VIDEO; } @@ -410,27 +417,29 @@ VideoContent::size_after_crop () const } -/** @param f Frame index within the whole (untrimmed) content. +/** @param time Time within the whole (untrimmed) content. * @return Fade factor (between 0 and 1) or unset if there is no fade. */ optional -VideoContent::fade (shared_ptr film, Frame f) const +VideoContent::fade(shared_ptr film, ContentTime time) const { - DCPOMATIC_ASSERT (f >= 0); + DCPOMATIC_ASSERT(time.get() >= 0); double const vfr = _parent->active_video_frame_rate(film); - auto const ts = _parent->trim_start().frames_round(vfr); - if ((f - ts) < fade_in()) { - return double (f - ts) / fade_in(); + auto const ts = _parent->trim_start(); + auto const fade_in_time = ContentTime::from_frames(fade_in(), vfr); + if ((time - ts) < fade_in_time) { + return double(ContentTime(time - ts).get()) / fade_in_time.get(); } - auto fade_out_start = length() - _parent->trim_end().frames_round(vfr) - fade_out(); - if (f >= fade_out_start) { - return 1 - double (f - fade_out_start) / fade_out(); + auto const fade_out_time = ContentTime::from_frames(fade_out(), vfr); + auto fade_out_start = ContentTime::from_frames(length(), vfr) - _parent->trim_end() - fade_out_time; + if (time >= fade_out_start) { + return 1 - double(ContentTime(time - fade_out_start).get()) / fade_out_time.get(); } - return optional (); + return {}; } string @@ -522,6 +531,12 @@ VideoContent::set_length (Frame len) maybe_set (_length, len, ContentProperty::LENGTH); } +void +VideoContent::set_crop (Crop c) +{ + maybe_set (_crop, c, VideoContentProperty::CROP); +} + void VideoContent::set_left_crop (int c) { @@ -647,7 +662,7 @@ VideoContent::scaled_size (dcp::Size film_container) } auto size = size_after_crop (); - size.width *= _sample_aspect_ratio.get_value_or(1); + size.width = std::lrint(size.width * _sample_aspect_ratio.get_value_or(1)); /* This is what we will return unless there is any legacy stuff to take into account */ auto auto_size = fit_ratio_within (size.ratio(), film_container);