diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/raw_convert.h | 5 | ||||
| -rw-r--r-- | src/reel_picture_asset.cc | 28 | ||||
| -rw-r--r-- | src/subtitle_string.h | 3 |
3 files changed, 30 insertions, 6 deletions
diff --git a/src/raw_convert.h b/src/raw_convert.h index 90737c0c..142763f2 100644 --- a/src/raw_convert.h +++ b/src/raw_convert.h @@ -30,11 +30,14 @@ namespace dcp { */ template <typename P, typename Q> P -raw_convert (Q v, int precision = 16) +raw_convert (Q v, int precision = 16, bool fixed = false) { std::stringstream s; s.imbue (std::locale::classic ()); s << std::setprecision (precision); + if (fixed) { + s << std::fixed; + } s << v; P r; s >> r; diff --git a/src/reel_picture_asset.cc b/src/reel_picture_asset.cc index 096d3476..36ccb810 100644 --- a/src/reel_picture_asset.cc +++ b/src/reel_picture_asset.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,16 +24,19 @@ #include "reel_picture_asset.h" #include "picture_asset.h" #include "dcp_assert.h" +#include "raw_convert.h" #include "compose.hpp" #include <libcxml/cxml.h> #include <libxml++/libxml++.h> #include <iomanip> +#include <cmath> using std::bad_cast; using std::string; using std::stringstream; using boost::shared_ptr; using boost::dynamic_pointer_cast; +using boost::optional; using namespace dcp; ReelPictureAsset::ReelPictureAsset () @@ -80,9 +83,26 @@ ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const mp->add_child ("FrameRate")->add_child_text (String::compose ("%1 %2", _frame_rate.numerator, _frame_rate.denominator)); if (standard == INTEROP) { - stringstream s; - s << std::fixed << std::setprecision (2) << (float (_screen_aspect_ratio.numerator) / _screen_aspect_ratio.denominator); - mp->add_child ("ScreenAspectRatio")->add_child_text (s.str ()); + + /* Allowed values for this tag from the standard */ + float allowed[] = { 1.33, 1.66, 1.77, 1.85, 2.00, 2.39 }; + int const num_allowed = sizeof(allowed) / sizeof(float); + + /* Actual ratio */ + float ratio = float (_screen_aspect_ratio.numerator) / _screen_aspect_ratio.denominator; + + /* Pick the closest and use that */ + optional<float> closest; + optional<float> error; + for (int i = 0; i < num_allowed; ++i) { + float const e = fabsf (allowed[i] - ratio); + if (!closest || e < error.get()) { + closest = allowed[i]; + error = e; + } + } + + mp->add_child ("ScreenAspectRatio")->add_child_text (raw_convert<string> (closest.get(), 2, true)); } else { mp->add_child ("ScreenAspectRatio")->add_child_text ( String::compose ("%1 %2", _screen_aspect_ratio.numerator, _screen_aspect_ratio.denominator) diff --git a/src/subtitle_string.h b/src/subtitle_string.h index 2317af5f..eaea94c0 100644 --- a/src/subtitle_string.h +++ b/src/subtitle_string.h @@ -89,7 +89,8 @@ public: return _h_align; } - /** @return vertical position as a proportion of the screen height from the top + /** @return vertical position as a proportion of the screen height from the + * vertical alignment point. * (between 0 and 1) */ float v_position () const { |
