diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/video_content.cc | 28 | ||||
| -rw-r--r-- | src/lib/video_content.h | 3 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index ec5890b45..6f6b2c441 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; @@ -377,6 +379,32 @@ 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<const Film> 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<const Film> 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) diff --git a/src/lib/video_content.h b/src/lib/video_content.h index fbba9c09d..f23bf0abe 100644 --- a/src/lib/video_content.h +++ b/src/lib/video_content.h @@ -171,6 +171,9 @@ public: VideoContent::Frame time_to_content_video_frames (Time) const; + void scale_and_crop_to_fit_width (); + void scale_and_crop_to_fit_height (); + protected: void take_from_video_examiner (boost::shared_ptr<VideoExaminer>); |
