+ shared_ptr<dcp::TransferFunction> in;
+
+ if (version >= 32) {
+
+ /* Version 2.x */
+
+ cxml::ConstNodePtr in_node = node->node_child ("InputTransferFunction");
+ string in_type = in_node->string_child ("Type");
+ if (in_type == "Gamma") {
+ _in.reset (new dcp::GammaTransferFunction (in_node->number_child<double> ("Gamma")));
+ } else if (in_type == "ModifiedGamma") {
+ _in.reset (new dcp::ModifiedGammaTransferFunction (
+ in_node->number_child<double> ("Power"),
+ in_node->number_child<double> ("Threshold"),
+ in_node->number_child<double> ("A"),
+ in_node->number_child<double> ("B")
+ ));
+ } else if (in_type == "SGamut3") {
+ _in.reset (new dcp::SGamut3TransferFunction ());
+ }
+
+ } else {
+
+ /* Version 1.x */
+
+ if (node->bool_child ("InputGammaLinearised")) {
+ _in.reset (new dcp::ModifiedGammaTransferFunction (node->number_child<double> ("InputGamma"), 0.04045, 0.055, 12.92));
+ } else {
+ _in.reset (new dcp::GammaTransferFunction (node->number_child<double> ("InputGamma")));
+ }
+ }
+
+ _yuv_to_rgb = static_cast<dcp::YUVToRGB> (node->optional_number_child<int>("YUVToRGB").get_value_or (dcp::YUV_TO_RGB_REC601));
+
+ list<cxml::NodePtr> m = node->node_children ("Matrix");
+ if (!m.empty ()) {
+ /* Read in old <Matrix> nodes and convert them to chromaticities */
+ boost::numeric::ublas::matrix<double> C (3, 3);
+ for (list<cxml::NodePtr>::iterator i = m.begin(); i != m.end(); ++i) {
+ int const ti = (*i)->number_attribute<int> ("i");
+ int const tj = (*i)->number_attribute<int> ("j");
+ C(ti, tj) = raw_convert<double> ((*i)->content ());
+ }
+
+ double const rd = C(0, 0) + C(1, 0) + C(2, 0);
+ _red = dcp::Chromaticity (C(0, 0) / rd, C(1, 0) / rd);
+ double const gd = C(0, 1) + C(1, 1) + C(2, 1);
+ _green = dcp::Chromaticity (C(0, 1) / gd, C(1, 1) / gd);
+ double const bd = C(0, 2) + C(1, 2) + C(2, 2);
+ _blue = dcp::Chromaticity (C(0, 2) / bd, C(1, 2) / bd);
+ double const wd = C(0, 0) + C(0, 1) + C(0, 2) + C(1, 0) + C(1, 1) + C(1, 2) + C(2, 0) + C(2, 1) + C(2, 2);
+ _white = dcp::Chromaticity ((C(0, 0) + C(0, 1) + C(0, 2)) / wd, (C(1, 0) + C(1, 1) + C(1, 2)) / wd);
+ } else {
+ /* New-style chromaticities */
+ _red = dcp::Chromaticity (node->number_child<double> ("RedX"), node->number_child<double> ("RedY"));
+ _green = dcp::Chromaticity (node->number_child<double> ("GreenX"), node->number_child<double> ("GreenY"));
+ _blue = dcp::Chromaticity (node->number_child<double> ("BlueX"), node->number_child<double> ("BlueY"));
+ _white = dcp::Chromaticity (node->number_child<double> ("WhiteX"), node->number_child<double> ("WhiteY"));
+ if (node->optional_node_child ("AdjustedWhiteX")) {
+ _adjusted_white = dcp::Chromaticity (
+ node->number_child<double> ("AdjustedWhiteX"), node->number_child<double> ("AdjustedWhiteY")
+ );