X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fvideo_content.cc;h=676a694da6412bc1ba4625d23e4d533e76e88d33;hb=7d93aa13507094e87bc9086986b36edd96a613b0;hp=783cddafad958fcb5ee81cc3806bea3dc2dff8e8;hpb=df085fc0ea4f1a3f009de5a7a5bf9f241173bcba;p=dcpomatic.git diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 783cddafa..676a694da 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -30,6 +30,7 @@ #include "util.h" #include "film.h" #include "exceptions.h" +#include "frame_rate_change.h" #include "i18n.h" @@ -45,6 +46,8 @@ using std::stringstream; using std::setprecision; using std::cout; using std::vector; +using std::min; +using std::max; using boost::shared_ptr; using boost::optional; using boost::dynamic_pointer_cast; @@ -161,10 +164,7 @@ VideoContent::as_xml (xmlpp::Node* node) const node->add_child("VideoHeight")->add_child_text (raw_convert (_video_size.height)); node->add_child("VideoFrameRate")->add_child_text (raw_convert (_video_frame_rate)); node->add_child("VideoFrameType")->add_child_text (raw_convert (static_cast (_video_frame_type))); - node->add_child("LeftCrop")->add_child_text (raw_convert (_crop.left)); - node->add_child("RightCrop")->add_child_text (raw_convert (_crop.right)); - node->add_child("TopCrop")->add_child_text (raw_convert (_crop.top)); - node->add_child("BottomCrop")->add_child_text (raw_convert (_crop.bottom)); + _crop.as_xml (node); _scale.as_xml (node->add_child("Scale")); _colour_conversion.as_xml (node->add_child("ColourConversion")); } @@ -370,7 +370,7 @@ VideoContent::time_to_content_video_frames (Time t) const shared_ptr film = _film.lock (); assert (film); - FrameRateConversion frc (video_frame_rate(), film->video_frame_rate()); + FrameRateChange frc (video_frame_rate(), film->video_frame_rate()); /* Here we are converting from time (in the DCP) to a frame number in the content. Hence we need to use the DCP's frame rate and the double/skip correction, not @@ -379,6 +379,47 @@ VideoContent::time_to_content_video_frames (Time t) const return t * film->video_frame_rate() / (frc.factor() * TIME_HZ); } +void +VideoContent::scale_and_crop_to_fit_width () +{ + shared_ptr film = _film.lock (); + assert (film); + + set_scale (VideoContentScale (film->container ())); + + int const crop = max (0, int (video_size().height - double (film->frame_size().height) * video_size().width / film->frame_size().width)); + set_top_crop (crop / 2); + set_bottom_crop (crop / 2); +} + +void +VideoContent::scale_and_crop_to_fit_height () +{ + shared_ptr film = _film.lock (); + assert (film); + + set_scale (VideoContentScale (film->container ())); + + int const crop = max (0, int (video_size().width - double (film->frame_size().width) * video_size().height / film->frame_size().height)); + set_left_crop (crop / 2); + set_right_crop (crop / 2); +} + +void +VideoContent::set_video_frame_rate (float r) +{ + { + boost::mutex::scoped_lock lm (_mutex); + if (_video_frame_rate == r) { + return; + } + + _video_frame_rate = r; + } + + signal_changed (VideoContentProperty::VIDEO_FRAME_RATE); +} + VideoContentScale::VideoContentScale (Ratio const * r) : _ratio (r) , _scale (true)