FIXME: Remove all use of add_child() from xmlpp.
[dcpomatic.git] / src / lib / colour_conversion.cc
index 57e73a5b5c02133b65d30b5d544cc48a7b03a130..f1e6258122fbf3cebb7638be85e38ecedb4f8705 100644 (file)
 
 */
 
-#include "config.h"
+
 #include "colour_conversion.h"
-#include "util.h"
+#include "config.h"
 #include "digester.h"
-#include "warnings.h"
-#include <dcp/raw_convert.h>
+#include "util.h"
 #include <dcp/chromaticity.h>
 #include <dcp/gamma_transfer_function.h>
-#include <dcp/modified_gamma_transfer_function.h>
 #include <dcp/identity_transfer_function.h>
+#include <dcp/modified_gamma_transfer_function.h>
+#include <dcp/raw_convert.h>
 #include <dcp/s_gamut3_transfer_function.h>
+#include <dcp/warnings.h>
 #include <libcxml/cxml.h>
-DCPOMATIC_DISABLE_WARNINGS
+LIBDCP_DISABLE_WARNINGS
 #include <libxml++/libxml++.h>
-DCPOMATIC_ENABLE_WARNINGS
+LIBDCP_ENABLE_WARNINGS
 #include <iostream>
 
 #include "i18n.h"
 
-using std::list;
-using std::string;
+
 using std::cout;
-using std::vector;
+using std::dynamic_pointer_cast;
+using std::list;
 using std::make_shared;
 using std::shared_ptr;
+using std::string;
+using std::vector;
 using boost::optional;
-using std::dynamic_pointer_cast;
 using dcp::raw_convert;
 
+
 vector<PresetColourConversion> PresetColourConversion::_presets;
 
+
 ColourConversion::ColourConversion ()
        : dcp::ColourConversion (dcp::ColourConversion::srgb_to_xyz ())
 {
@@ -95,7 +99,7 @@ ColourConversion::ColourConversion (cxml::NodePtr node, int version)
                }
        }
 
-       _yuv_to_rgb = static_cast<dcp::YUVToRGB> (node->optional_number_child<int>("YUVToRGB").get_value_or (dcp::YUV_TO_RGB_REC601));
+       _yuv_to_rgb = static_cast<dcp::YUVToRGB>(node->optional_number_child<int>("YUVToRGB").get_value_or(static_cast<int>(dcp::YUVToRGB::REC601)));
 
        auto m = node->node_children ("Matrix");
        if (!m.empty ()) {
@@ -147,41 +151,40 @@ ColourConversion::from_xml (cxml::NodePtr node, int version)
 }
 
 void
-ColourConversion::as_xml (xmlpp::Node* node) const
+ColourConversion::as_xml(xmlpp::Element* element) const
 {
-       auto in_node = node->add_child ("InputTransferFunction");
+       auto in_node = cxml::add_child(element, "InputTransferFunction");
        if (dynamic_pointer_cast<const dcp::GammaTransferFunction> (_in)) {
                auto tf = dynamic_pointer_cast<const dcp::GammaTransferFunction> (_in);
-               in_node->add_child("Type")->add_child_text ("Gamma");
-               in_node->add_child("Gamma")->add_child_text (raw_convert<string> (tf->gamma ()));
+               cxml::add_text_child(in_node, "Type", "Gamma");
+               cxml::add_text_child(in_node, "Gamma", raw_convert<string>(tf->gamma()));
        } else if (dynamic_pointer_cast<const dcp::ModifiedGammaTransferFunction> (_in)) {
                auto tf = dynamic_pointer_cast<const dcp::ModifiedGammaTransferFunction> (_in);
-               in_node->add_child("Type")->add_child_text ("ModifiedGamma");
-               in_node->add_child("Power")->add_child_text (raw_convert<string> (tf->power ()));
-               in_node->add_child("Threshold")->add_child_text (raw_convert<string> (tf->threshold ()));
-               in_node->add_child("A")->add_child_text (raw_convert<string> (tf->A ()));
-               in_node->add_child("B")->add_child_text (raw_convert<string> (tf->B ()));
-       } else if (dynamic_pointer_cast<const dcp::SGamut3TransferFunction> (_in)) {
-               in_node->add_child("Type")->add_child_text ("SGamut3");
+               cxml::add_text_child(in_node, "Type", "ModifiedGamma");
+               cxml::add_text_child(in_node, "Power", raw_convert<string>(tf->power ()));
+               cxml::add_text_child(in_node, "Threshold", raw_convert<string>(tf->threshold ()));
+               cxml::add_text_child(in_node, "A", raw_convert<string>(tf->A()));
+               cxml::add_text_child(in_node, "B", raw_convert<string>(tf->B()));
+       } else if (dynamic_pointer_cast<const dcp::SGamut3TransferFunction>(_in)) {
+               cxml::add_text_child(in_node, "Type", "SGamut3");
        }
 
-       node->add_child("YUVToRGB")->add_child_text (raw_convert<string> (static_cast<int> (_yuv_to_rgb)));
-       node->add_child("RedX")->add_child_text (raw_convert<string> (_red.x));
-       node->add_child("RedY")->add_child_text (raw_convert<string> (_red.y));
-       node->add_child("GreenX")->add_child_text (raw_convert<string> (_green.x));
-       node->add_child("GreenY")->add_child_text (raw_convert<string> (_green.y));
-       node->add_child("BlueX")->add_child_text (raw_convert<string> (_blue.x));
-       node->add_child("BlueY")->add_child_text (raw_convert<string> (_blue.y));
-       node->add_child("WhiteX")->add_child_text (raw_convert<string> (_white.x));
-       node->add_child("WhiteY")->add_child_text (raw_convert<string> (_white.y));
+       cxml::add_text_child(element, "YUVToRGB", raw_convert<string>(static_cast<int>(_yuv_to_rgb)));
+       cxml::add_text_child(element, "RedX", raw_convert<string>(_red.x));
+       cxml::add_text_child(element, "RedY", raw_convert<string>(_red.y));
+       cxml::add_text_child(element, "GreenX", raw_convert<string>(_green.x));
+       cxml::add_text_child(element, "GreenY", raw_convert<string>(_green.y));
+       cxml::add_text_child(element, "BlueX", raw_convert<string>(_blue.x));
+       cxml::add_text_child(element, "BlueY", raw_convert<string>(_blue.y));
+       cxml::add_text_child(element, "WhiteX", raw_convert<string>(_white.x));
+       cxml::add_text_child(element, "WhiteY", raw_convert<string>(_white.y));
        if (_adjusted_white) {
-               node->add_child("AdjustedWhiteX")->add_child_text (raw_convert<string> (_adjusted_white.get().x));
-               node->add_child("AdjustedWhiteY")->add_child_text (raw_convert<string> (_adjusted_white.get().y));
+               cxml::add_text_child(element, "AdjustedWhiteX", raw_convert<string>(_adjusted_white.get().x));
+               cxml::add_text_child(element, "AdjustedWhiteY", raw_convert<string>(_adjusted_white.get().y));
        }
 
-       if (dynamic_pointer_cast<const dcp::GammaTransferFunction> (_out)) {
-               shared_ptr<const dcp::GammaTransferFunction> gf = dynamic_pointer_cast<const dcp::GammaTransferFunction> (_out);
-               node->add_child("OutputGamma")->add_child_text (raw_convert<string> (gf->gamma ()));
+       if (auto gf = dynamic_pointer_cast<const dcp::GammaTransferFunction>(_out)) {
+               cxml::add_text_child(element, "OutputGamma", raw_convert<string>(gf->gamma()));
        }
 }
 
@@ -231,6 +234,8 @@ ColourConversion::identifier () const
                digester.add (_adjusted_white.get().y);
        }
 
+       digester.add(static_cast<int>(_yuv_to_rgb));
+
        auto gf = dynamic_pointer_cast<const dcp::GammaTransferFunction> (_out);
        if (gf) {
                digester.add (gf->gamma ());