diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-10-15 15:26:04 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-10-15 15:26:04 +0100 |
| commit | 45f9912aa850546e319e32a4052517d67f4e3d8f (patch) | |
| tree | f92b43f73e82cd09bf6a3bea29147aafa9c59d79 /src/lib | |
| parent | 708dacb8247c73c02b6192464325738203ca001a (diff) | |
Allow no-stretch scaling of video content.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/image.cc | 5 | ||||
| -rw-r--r-- | src/lib/player.cc | 5 | ||||
| -rw-r--r-- | src/lib/ratio.cc | 14 | ||||
| -rw-r--r-- | src/lib/ratio.h | 2 | ||||
| -rw-r--r-- | src/lib/types.h | 15 | ||||
| -rw-r--r-- | src/lib/util.cc | 9 | ||||
| -rw-r--r-- | src/lib/util.h | 3 | ||||
| -rw-r--r-- | src/lib/video_content.cc | 10 | ||||
| -rw-r--r-- | src/lib/video_content.h | 2 | ||||
| -rw-r--r-- | src/lib/writer.cc | 2 |
10 files changed, 43 insertions, 24 deletions
diff --git a/src/lib/image.cc b/src/lib/image.cc index 9a3aa8d45..d56b8763a 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -155,10 +155,7 @@ Image::post_process (string pp, bool aligned) const shared_ptr<Image> Image::crop (Crop crop, bool aligned) const { - libdcp::Size cropped_size = size (); - cropped_size.width -= crop.left + crop.right; - cropped_size.height -= crop.top + crop.bottom; - + libdcp::Size cropped_size = crop.apply (size ()); shared_ptr<Image> out (new Image (pixel_format(), cropped_size, aligned)); for (int c = 0; c < components(); ++c) { diff --git a/src/lib/player.cc b/src/lib/player.cc index 70d6fa877..03c5dc322 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -103,7 +103,7 @@ Player::Player (shared_ptr<const Film> f, shared_ptr<const Playlist> p) _playlist_changed_connection = _playlist->Changed.connect (bind (&Player::playlist_changed, this)); _playlist_content_changed_connection = _playlist->ContentChanged.connect (bind (&Player::content_changed, this, _1, _2, _3)); _film_changed_connection = _film->Changed.connect (bind (&Player::film_changed, this, _1)); - set_video_container_size (_film->container()->size (_film->full_frame ())); + set_video_container_size (fit_ratio_within (_film->container()->ratio (), _film->full_frame ())); } void @@ -256,7 +256,8 @@ Player::process_video (weak_ptr<Piece> weak_piece, shared_ptr<const Image> image work_image = work_image->crop (content->crop(), true); - libdcp::Size const image_size = content->ratio()->size (_video_container_size); + float const ratio = content->ratio() ? content->ratio()->ratio() : content->video_size_after_crop().ratio(); + libdcp::Size image_size = fit_ratio_within (ratio, _video_container_size); work_image = work_image->scale (image_size, _film->scaler(), PIX_FMT_RGB24, true); diff --git a/src/lib/ratio.cc b/src/lib/ratio.cc index 5988b3418..41abbb760 100644 --- a/src/lib/ratio.cc +++ b/src/lib/ratio.cc @@ -19,6 +19,7 @@ #include <libdcp/types.h> #include "ratio.h" +#include "util.h" #include "i18n.h" @@ -28,19 +29,6 @@ using std::vector; vector<Ratio const *> Ratio::_ratios; -libdcp::Size -Ratio::size (libdcp::Size full_frame) const -{ - if (_ratio < static_cast<float>(full_frame.width) / full_frame.height) { - return libdcp::Size (full_frame.height * _ratio, full_frame.height); - } else { - return libdcp::Size (full_frame.width, full_frame.width / _ratio); - } - - return libdcp::Size (); -} - - void Ratio::setup_ratios () { diff --git a/src/lib/ratio.h b/src/lib/ratio.h index c331edabe..f3354f1b6 100644 --- a/src/lib/ratio.h +++ b/src/lib/ratio.h @@ -34,8 +34,6 @@ public: , _dci_name (d) {} - libdcp::Size size (libdcp::Size) const; - std::string id () const { return _id; } diff --git a/src/lib/types.h b/src/lib/types.h index 01560ba81..d4d66387d 100644 --- a/src/lib/types.h +++ b/src/lib/types.h @@ -87,6 +87,21 @@ struct Crop int top; /** Number of pixels to remove from the bottom */ int bottom; + + libdcp::Size apply (libdcp::Size s, int minimum = 4) const { + s.width -= left + right; + s.height -= top + bottom; + + if (s.width < minimum) { + s.width = minimum; + } + + if (s.height < minimum) { + s.height = minimum; + } + + return s; + } }; extern bool operator== (Crop const & a, Crop const & b); diff --git a/src/lib/util.cc b/src/lib/util.cc index b13d905bf..1c4347233 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -882,3 +882,12 @@ make_signer () return shared_ptr<const libdcp::Signer> (new libdcp::Signer (chain, signer_key)); } +libdcp::Size +fit_ratio_within (float ratio, libdcp::Size full_frame) +{ + if (ratio < full_frame.ratio ()) { + return libdcp::Size (full_frame.height * ratio, full_frame.height); + } + + return libdcp::Size (full_frame.width, full_frame.width / ratio); +} diff --git a/src/lib/util.h b/src/lib/util.h index 377b3b785..b8ea6ebec 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -75,7 +75,8 @@ extern bool valid_image_file (boost::filesystem::path); extern boost::filesystem::path mo_path (); #endif extern std::string tidy_for_filename (std::string); -boost::shared_ptr<const libdcp::Signer> make_signer (); +extern boost::shared_ptr<const libdcp::Signer> make_signer (); +extern libdcp::Size fit_ratio_within (float ratio, libdcp::Size); struct FrameRateConversion { diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index af0c3e12c..23ef2cf89 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -66,6 +66,7 @@ VideoContent::VideoContent (shared_ptr<const Film> f, boost::filesystem::path p) VideoContent::VideoContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node) : Content (f, node) + , _ratio (0) { _video_length = node->number_child<VideoContent::Frame> ("VideoLength"); _video_size.width = node->number_child<int> ("VideoWidth"); @@ -139,7 +140,7 @@ VideoContent::information () const _("%1x%2 pixels (%3:1)"), video_size().width, video_size().height, - setprecision (3), float (video_size().width) / video_size().height + setprecision (3), video_size().ratio () ); return s.str (); @@ -281,3 +282,10 @@ VideoContent::set_colour_conversion (ColourConversion c) signal_changed (VideoContentProperty::COLOUR_CONVERSION); } + +/** @return Video size after 3D split and crop */ +libdcp::Size +VideoContent::video_size_after_crop () const +{ + return crop().apply (video_size_after_3d_split ()); +} diff --git a/src/lib/video_content.h b/src/lib/video_content.h index 81325516d..369209776 100644 --- a/src/lib/video_content.h +++ b/src/lib/video_content.h @@ -87,6 +87,7 @@ public: void set_ratio (Ratio const *); + /** @return ratio to scale to, or 0 if the content's own ratio should be preserved. */ Ratio const * ratio () const { boost::mutex::scoped_lock lm (_mutex); return _ratio; @@ -98,6 +99,7 @@ public: } libdcp::Size video_size_after_3d_split () const; + libdcp::Size video_size_after_crop () const; protected: void take_from_video_examiner (boost::shared_ptr<VideoExaminer>); diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 5e8fb5b7a..968cd1505 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -80,7 +80,7 @@ Writer::Writer (shared_ptr<const Film> f, shared_ptr<Job> j) } _picture_asset->set_edit_rate (_film->video_frame_rate ()); - _picture_asset->set_size (_film->container()->size (_film->full_frame ())); + _picture_asset->set_size (fit_ratio_within (_film->container()->ratio(), _film->full_frame ())); if (_film->encrypted ()) { _picture_asset->set_key (_film->key ()); |
