Merge master.
[dcpomatic.git] / src / lib / video_content.cc
index 58053c822b9a61f5c08e643d50bd007f8ef94f45..05f5c538eee2a81c6344f603ab2bfa3e60dfd2cb 100644 (file)
@@ -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;
@@ -379,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<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)