X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fvideo_content.cc;h=b5097b35546ecd95d5dc75031911f206b5ac844f;hb=6de35d058821acc092d2aae75543024a97026b8a;hp=a2a4e6c6b3b46c452290975d5eccb2952fbaab89;hpb=8d58a7c5f4320ad5c111e336c45e44d6b51ab509;p=dcpomatic.git diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index a2a4e6c6b..b5097b355 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -32,6 +32,7 @@ #include "exceptions.h" #include "frame_rate_change.h" #include "log.h" +#include "safe_stringstream.h" #include "i18n.h" @@ -45,7 +46,6 @@ int const VideoContentProperty::VIDEO_SCALE = 4; int const VideoContentProperty::COLOUR_CONVERSION = 5; using std::string; -using std::stringstream; using std::setprecision; using std::cout; using std::vector; @@ -56,14 +56,12 @@ using boost::optional; using boost::dynamic_pointer_cast; using dcp::raw_convert; -vector VideoContentScale::_scales; - VideoContent::VideoContent (shared_ptr f) : Content (f) , _video_length (0) , _video_frame_rate (0) , _video_frame_type (VIDEO_FRAME_TYPE_2D) - , _scale (Ratio::from_id ("185")) + , _scale (Config::instance()->default_scale ()) { setup_default_colour_conversion (); } @@ -73,7 +71,7 @@ VideoContent::VideoContent (shared_ptr f, DCPTime s, ContentTime len , _video_length (len) , _video_frame_rate (0) , _video_frame_type (VIDEO_FRAME_TYPE_2D) - , _scale (Ratio::from_id ("185")) + , _scale (Config::instance()->default_scale ()) { setup_default_colour_conversion (); } @@ -83,7 +81,7 @@ VideoContent::VideoContent (shared_ptr f, boost::filesystem::path p) , _video_length (0) , _video_frame_rate (0) , _video_frame_type (VIDEO_FRAME_TYPE_2D) - , _scale (Ratio::from_id ("185")) + , _scale (Config::instance()->default_scale ()) { setup_default_colour_conversion (); } @@ -192,7 +190,7 @@ VideoContent::take_from_video_examiner (shared_ptr d) dcp::Size const vs = d->video_size (); float const vfr = d->video_frame_rate (); ContentTime vl = d->video_length (); - + { boost::mutex::scoped_lock lm (_mutex); _video_size = vs; @@ -217,7 +215,7 @@ VideoContent::information () const return ""; } - stringstream s; + SafeStringStream s; s << String::compose ( _("%1x%2 pixels (%3:1)"), @@ -309,7 +307,7 @@ VideoContent::set_scale (VideoContentScale s) string VideoContent::identifier () const { - stringstream s; + SafeStringStream s; s << Content::identifier() << "_" << crop().left << "_" << crop().right @@ -433,123 +431,3 @@ VideoContent::set_video_frame_rate (float r) signal_changed (VideoContentProperty::VIDEO_FRAME_RATE); } -VideoContentScale::VideoContentScale (Ratio const * r) - : _ratio (r) - , _scale (true) -{ - -} - -VideoContentScale::VideoContentScale () - : _ratio (0) - , _scale (false) -{ - -} - -VideoContentScale::VideoContentScale (bool scale) - : _ratio (0) - , _scale (scale) -{ - -} - -VideoContentScale::VideoContentScale (cxml::NodePtr node) - : _ratio (0) - , _scale (true) -{ - optional r = node->optional_string_child ("Ratio"); - if (r) { - _ratio = Ratio::from_id (r.get ()); - } else { - _scale = node->bool_child ("Scale"); - } -} - -void -VideoContentScale::as_xml (xmlpp::Node* node) const -{ - if (_ratio) { - node->add_child("Ratio")->add_child_text (_ratio->id ()); - } else { - node->add_child("Scale")->add_child_text (_scale ? "1" : "0"); - } -} - -string -VideoContentScale::id () const -{ - stringstream s; - - if (_ratio) { - s << _ratio->id () << "_"; - } else { - s << (_scale ? "S1" : "S0"); - } - - return s.str (); -} - -string -VideoContentScale::name () const -{ - if (_ratio) { - return _ratio->nickname (); - } - - if (_scale) { - return _("No stretch"); - } - - return _("No scale"); -} - -/** @param display_container Size of the container that we are displaying this content in. - * @param film_container The size of the film's image. - */ -dcp::Size -VideoContentScale::size (shared_ptr c, dcp::Size display_container, dcp::Size film_container) const -{ - if (_ratio) { - return fit_ratio_within (_ratio->ratio (), display_container); - } - - dcp::Size const ac = c->video_size_after_crop (); - - /* Force scale if the film_container is smaller than the content's image */ - if (_scale || film_container.width < ac.width || film_container.height < ac.height) { - return fit_ratio_within (ac.ratio (), display_container); - } - - /* Scale the image so that it will be in the right place in film_container, even if display_container is a - different size. - */ - return dcp::Size ( - c->video_size().width * float(display_container.width) / film_container.width, - c->video_size().height * float(display_container.height) / film_container.height - ); -} - -void -VideoContentScale::setup_scales () -{ - vector ratios = Ratio::all (); - for (vector::const_iterator i = ratios.begin(); i != ratios.end(); ++i) { - _scales.push_back (VideoContentScale (*i)); - } - - _scales.push_back (VideoContentScale (true)); - _scales.push_back (VideoContentScale (false)); -} - -bool -operator== (VideoContentScale const & a, VideoContentScale const & b) -{ - return (a.ratio() == b.ratio() && a.scale() == b.scale()); -} - -bool -operator!= (VideoContentScale const & a, VideoContentScale const & b) -{ - return (a.ratio() != b.ratio() || a.scale() != b.scale()); -}