40 #include "compose.hpp"
46 #include <libcxml/cxml.h>
47 LIBDCP_DISABLE_WARNINGS
48 #include <libxml++/libxml++.h>
49 LIBDCP_ENABLE_WARNINGS
56 using std::shared_ptr;
57 using std::dynamic_pointer_cast;
58 using boost::optional;
62 ReelPictureAsset::ReelPictureAsset (shared_ptr<PictureAsset> asset, int64_t entry_point)
63 :
ReelFileAsset (asset, asset->key_id(), asset->id(), asset->edit_rate(), asset->intrinsic_duration(), entry_point)
64 , _frame_rate (asset->frame_rate ())
65 , _screen_aspect_ratio (asset->screen_aspect_ratio ())
71 ReelPictureAsset::ReelPictureAsset (shared_ptr<const cxml::Node> node)
74 _frame_rate =
Fraction (node->string_child (
"FrameRate"));
76 _screen_aspect_ratio =
Fraction (node->string_child (
"ScreenAspectRatio"));
80 float f = node->number_child<
float> (
"ScreenAspectRatio");
81 _screen_aspect_ratio =
Fraction (f * 1000, 1000);
82 }
catch (bad_cast& e) {
90 ReelPictureAsset::write_to_cpl (xmlpp::Node* node, Standard standard)
const
92 auto asset = ReelFileAsset::write_to_cpl (node, standard);
94 asset->add_child(
"FrameRate")->add_child_text(String::compose(
"%1 %2", _frame_rate.numerator, _frame_rate.denominator));
96 if (standard == Standard::INTEROP) {
99 float allowed[] = { 1.33, 1.66, 1.77, 1.85, 2.00, 2.39 };
100 int const num_allowed =
sizeof(allowed) /
sizeof(
float);
103 float ratio = float (_screen_aspect_ratio.numerator) / _screen_aspect_ratio.denominator;
106 optional<float> closest;
107 optional<float> error;
108 for (
int i = 0; i < num_allowed; ++i) {
109 float const e = fabsf (allowed[i] - ratio);
110 if (!closest || e < error.get()) {
111 closest = allowed[i];
116 asset->add_child(
"ScreenAspectRatio")->add_child_text(raw_convert<string>(closest.get(), 2,
true));
118 asset->add_child(
"ScreenAspectRatio")->add_child_text(
119 String::compose (
"%1 %2", _screen_aspect_ratio.numerator, _screen_aspect_ratio.denominator)
128 ReelPictureAsset::equals (shared_ptr<const ReelPictureAsset> other,
EqualityOptions opt, NoteHandler note)
const
130 if (!asset_equals (other, opt, note)) {
133 if (!file_asset_equals (other, opt, note)) {
137 auto rpa = dynamic_pointer_cast<const ReelPictureAsset>(other);
142 if (_frame_rate != rpa->_frame_rate) {
143 note (NoteType::ERROR,
"frame rates differ in reel");
147 if (_screen_aspect_ratio != rpa->_screen_aspect_ratio) {
148 note (NoteType::ERROR,
"screen aspect ratios differ in reel");
A fraction (i.e. a thing with an integer numerator and an integer denominator).
std::shared_ptr< const PictureAsset > asset() const
Namespace for everything in libdcp.
Methods for conversion to/from string.
A class to describe what "equality" means for a particular test.