Fix loading of 1.x metadata.
authorCarl Hetherington <cth@carlh.net>
Sun, 4 Jan 2015 23:10:39 +0000 (23:10 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 4 Jan 2015 23:10:39 +0000 (23:10 +0000)
src/lib/colour_conversion.cc
src/lib/colour_conversion.h
src/lib/config.cc
src/lib/player_video.cc
src/lib/player_video.h
src/lib/video_content.cc

index ef36087e7449ab40b01668f4c275d60c294b8c45..ad09458f98a2ec4338b4ce7f97c1d476966b70b8 100644 (file)
@@ -51,22 +51,37 @@ ColourConversion::ColourConversion (dcp::ColourConversion conversion_)
        
 }
 
-ColourConversion::ColourConversion (cxml::NodePtr node)
+ColourConversion::ColourConversion (cxml::NodePtr node, int version)
 {
        shared_ptr<dcp::TransferFunction> in;
-       
-       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 (false, in_node->number_child<double> ("Gamma")));
-       } else if (in_type == "ModifiedGamma") {
-               _in.reset (new dcp::ModifiedGammaTransferFunction (
-                                  false,
-                                  in_node->number_child<double> ("Power"),
-                                  in_node->number_child<double> ("Threshold"),
-                                  in_node->number_child<double> ("A"),
-                                  in_node->number_child<double> ("B")
-                                  ));
+
+       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 (false, in_node->number_child<double> ("Gamma")));
+               } else if (in_type == "ModifiedGamma") {
+                       _in.reset (new dcp::ModifiedGammaTransferFunction (
+                                          false,
+                                          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 {
+
+               /* Version 1.x */
+               
+               if (node->bool_child ("InputGammaLinearised")) {
+                       _in.reset (new dcp::ModifiedGammaTransferFunction (false, node->number_child<float> ("InputGamma"), 0.04045, 0.055, 12.92));
+               } else {
+                       _in.reset (new dcp::GammaTransferFunction (false, node->number_child<float> ("InputGamma")));
+               }
        }
 
        list<cxml::NodePtr> m = node->node_children ("Matrix");
@@ -75,18 +90,18 @@ ColourConversion::ColourConversion (cxml::NodePtr node)
                int const tj = (*i)->number_attribute<int> ("j");
                _matrix(ti, tj) = raw_convert<double> ((*i)->content ());
        }
-
+       
        _out.reset (new dcp::GammaTransferFunction (true, node->number_child<double> ("OutputGamma")));
 }
 
 boost::optional<ColourConversion>
-ColourConversion::from_xml (cxml::NodePtr node)
+ColourConversion::from_xml (cxml::NodePtr node, int version)
 {
        if (!node->optional_node_child ("InputTransferFunction")) {
                return boost::optional<ColourConversion> ();
        }
 
-       return ColourConversion (node);
+       return ColourConversion (node, version);
 }
 
 void
@@ -176,8 +191,8 @@ PresetColourConversion::PresetColourConversion (string n, dcp::ColourConversion
 
 }
 
-PresetColourConversion::PresetColourConversion (cxml::NodePtr node)
-       : conversion (node)
+PresetColourConversion::PresetColourConversion (cxml::NodePtr node, int version)
+       : conversion (node, version)
 {
        name = node->string_child ("Name");
 }
index bf883a07c32413f3bd28071ee287882ea6cc0a08..ae207b46aa3acc5ddd10a4df1c837d3cf052648f 100644 (file)
@@ -38,14 +38,14 @@ class ColourConversion : public dcp::ColourConversion
 public:
        ColourConversion ();
        ColourConversion (dcp::ColourConversion);
-       ColourConversion (cxml::NodePtr);
+       ColourConversion (cxml::NodePtr, int version);
 
        virtual void as_xml (xmlpp::Node *) const;
        std::string identifier () const;
 
        boost::optional<size_t> preset () const;
 
-       static boost::optional<ColourConversion> from_xml (cxml::NodePtr);
+       static boost::optional<ColourConversion> from_xml (cxml::NodePtr, int version);
 };
 
 class PresetColourConversion
@@ -53,7 +53,7 @@ class PresetColourConversion
 public:
        PresetColourConversion ();
        PresetColourConversion (std::string, dcp::ColourConversion);
-       PresetColourConversion (cxml::NodePtr);
+       PresetColourConversion (cxml::NodePtr node, int version);
 
        void as_xml (xmlpp::Node *) const;
 
index d43024128915d19046c1e6150cc87bcb31f20250..306b48a9fd50b067d124248362a6928861077cb2 100644 (file)
@@ -179,7 +179,10 @@ Config::read ()
 
        try {
                for (list<cxml::NodePtr>::iterator i = cc.begin(); i != cc.end(); ++i) {
-                       _colour_conversions.push_back (PresetColourConversion (*i));
+                       /* This is a bit of a hack; use 32 (the first Film state file version for the 2.x branch)
+                          for version 2 and 10 (the current Film state version for the 1.x branch) for version 1.
+                       */
+                       _colour_conversions.push_back (PresetColourConversion (*i, version == 2 ? 32 : 10));
                }
        } catch (cxml::Error) {
                /* Probably failed to load an old-style ColourConversion tag; just give up */
index fae66bf624aa29b0f363f3153113def9c96e705d..94e6f3f2acd87afc357a06a99fcad7de357a4f11 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2015 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
@@ -23,6 +23,7 @@
 #include "image_proxy.h"
 #include "j2k_image_proxy.h"
 #include "scaler.h"
+#include "film.h"
 
 using std::string;
 using std::cout;
@@ -68,7 +69,9 @@ PlayerVideo::PlayerVideo (shared_ptr<cxml::Node> node, shared_ptr<Socket> socket
        _scaler = Scaler::from_id (node->string_child ("Scaler"));
        _eyes = (Eyes) node->number_child<int> ("Eyes");
        _part = (Part) node->number_child<int> ("Part");
-       _colour_conversion = ColourConversion::from_xml (node);
+
+       /* Assume that the ColourConversion uses the current state version */
+       _colour_conversion = ColourConversion::from_xml (node, Film::current_state_version);
 
        _in = image_proxy_factory (node->node_child ("In"), socket);
 
index 935690a08dea475057dd30d647743e6604e6060c..1468b78637e23f1fd753a51c4eccec7baf16dc45 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2015 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
index 8973fba7e2786e5c818dd46ce87d9582b2e7fe99..a76ddcd39b88632fc30129c7216d80e6f75459cb 100644 (file)
@@ -123,7 +123,7 @@ VideoContent::VideoContent (shared_ptr<const Film> f, cxml::ConstNodePtr node, i
 
        
        if (node->optional_node_child ("ColourConversion")) {
-               _colour_conversion = ColourConversion (node->node_child ("ColourConversion"));
+               _colour_conversion = ColourConversion (node->node_child ("ColourConversion"), version);
        }
        if (version >= 32) {
                _fade_in = ContentTime (node->number_child<int64_t> ("FadeIn"));