/*
- Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
*/
-#include "config.h"
+
#include "colour_conversion.h"
-#include "util.h"
+#include "config.h"
#include "digester.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>
+LIBDCP_DISABLE_WARNINGS
#include <libxml++/libxml++.h>
-#include <boost/foreach.hpp>
+LIBDCP_ENABLE_WARNINGS
#include <iostream>
#include "i18n.h"
+
+using std::cout;
+using std::dynamic_pointer_cast;
using std::list;
+using std::make_shared;
+using std::shared_ptr;
using std::string;
-using std::cout;
using std::vector;
-using boost::shared_ptr;
using boost::optional;
-using boost::dynamic_pointer_cast;
using dcp::raw_convert;
+
vector<PresetColourConversion> PresetColourConversion::_presets;
+
ColourConversion::ColourConversion ()
: dcp::ColourConversion (dcp::ColourConversion::srgb_to_xyz ())
{
/* Version 2.x */
- cxml::ConstNodePtr in_node = node->node_child ("InputTransferFunction");
- string in_type = in_node->string_child ("Type");
+ auto in_node = node->node_child ("InputTransferFunction");
+ auto in_type = in_node->string_child ("Type");
if (in_type == "Gamma") {
- _in.reset (new dcp::GammaTransferFunction (in_node->number_child<double> ("Gamma")));
+ _in = make_shared<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")
- ));
+ _in = make_shared<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 ());
+ _in = make_shared<dcp::SGamut3TransferFunction>();
}
} else {
}
}
- _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)));
- list<cxml::NodePtr> m = node->node_children ("Matrix");
+ auto 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 ());
+ for (auto i: m) {
+ 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);
}
}
- optional<double> gamma = node->optional_number_child<double> ("OutputGamma");
+ auto gamma = node->optional_number_child<double>("OutputGamma");
if (gamma) {
- _out.reset (new dcp::GammaTransferFunction (node->number_child<double> ("OutputGamma")));
+ _out = make_shared<dcp::GammaTransferFunction>(node->number_child<double>("OutputGamma"));
} else {
- _out.reset (new dcp::IdentityTransferFunction ());
+ _out = make_shared<dcp::IdentityTransferFunction>();
}
}
}
void
-ColourConversion::as_xml (xmlpp::Node* node) const
+ColourConversion::as_xml(xmlpp::Element* element) const
{
- xmlpp::Node* in_node = node->add_child ("InputTransferFunction");
+ auto in_node = cxml::add_child(element, "InputTransferFunction");
if (dynamic_pointer_cast<const dcp::GammaTransferFunction> (_in)) {
- shared_ptr<const dcp::GammaTransferFunction> 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 ()));
+ auto tf = dynamic_pointer_cast<const dcp::GammaTransferFunction> (_in);
+ 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)) {
- shared_ptr<const dcp::ModifiedGammaTransferFunction> 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");
+ auto tf = dynamic_pointer_cast<const dcp::ModifiedGammaTransferFunction> (_in);
+ 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()));
}
}
optional<size_t>
ColourConversion::preset () const
{
- vector<PresetColourConversion> presets = PresetColourConversion::all ();
+ auto presets = PresetColourConversion::all ();
size_t i = 0;
while (i < presets.size() && presets[i].conversion != *this) {
++i;
}
if (i >= presets.size ()) {
- return optional<size_t> ();
+ return {};
}
return i;
digester.add (_adjusted_white.get().y);
}
- shared_ptr<const dcp::GammaTransferFunction> gf = dynamic_pointer_cast<const dcp::GammaTransferFunction> (_out);
+ digester.add(static_cast<int>(_yuv_to_rgb));
+
+ auto gf = dynamic_pointer_cast<const dcp::GammaTransferFunction> (_out);
if (gf) {
digester.add (gf->gamma ());
}
PresetColourConversion
PresetColourConversion::from_id (string s)
{
- BOOST_FOREACH (PresetColourConversion const& i, _presets) {
+ for (auto const& i: _presets) {
if (i.id == s) {
return i;
}