summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-06-12 16:47:08 +0100
committerCarl Hetherington <cth@carlh.net>2014-06-12 16:47:08 +0100
commitea5cd3b3a69d1b651c0e2baa41e0117da084bbc4 (patch)
treea9d1d39ca056e23bba4afeecadc25379d6f8c59f /src/lib
parent66162217d93baa3fd50594bb013a44bbd779d02a (diff)
Add "scale to fit height/width" options to a new Content menu.
Requested-by: Johan Malmsten
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/video_content.cc28
-rw-r--r--src/lib/video_content.h3
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>);