X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fvideo_content.cc;fp=src%2Flib%2Fvideo_content.cc;h=05f5c538eee2a81c6344f603ab2bfa3e60dfd2cb;hp=f871f2df666438a1846d465642f8cb991e729723;hb=04533b9cf34ce8089113015715083ee9c5b2b001;hpb=4e411ea97b4dab8a5fa282d1d4cf7971ef1e24ad diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index f871f2df6..05f5c538e 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -46,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; @@ -380,6 +382,32 @@ VideoContent::dcp_time_to_content_time (DCPTime t) const return ContentTime (t, FrameRateChange (video_frame_rate(), film->video_frame_rate())); } +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); +} + VideoContentScale::VideoContentScale (Ratio const * r) : _ratio (r) , _scale (true)