2 Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 /** @file test/colour_conversion_test.cc
23 * @brief Test ColourConversion class.
24 * @ingroup selfcontained
28 #include "lib/colour_conversion.h"
30 #include <dcp/gamma_transfer_function.h>
31 #include <libxml++/libxml++.h>
32 #include <boost/test/unit_test.hpp>
37 using std::make_shared;
38 using std::shared_ptr;
41 BOOST_AUTO_TEST_CASE (colour_conversion_test1)
43 ColourConversion A (dcp::ColourConversion::srgb_to_xyz());
44 ColourConversion B (dcp::ColourConversion::rec709_to_xyz());
46 BOOST_CHECK_EQUAL (A.identifier(), "9840c601d2775bf1b3847254bbaa36a9");
47 BOOST_CHECK_EQUAL (B.identifier(), "58151ac92fdf333663a62c9a8ba5c5f4");
51 BOOST_AUTO_TEST_CASE (colour_conversion_test2)
53 ColourConversion A (dcp::ColourConversion::srgb_to_xyz ());
55 auto root = doc.create_root_node ("Test");
58 doc.write_to_string_formatted ("UTF-8"),
59 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
61 " <InputTransferFunction>\n"
62 " <Type>ModifiedGamma</Type>\n"
63 " <Power>2.4</Power>\n"
64 " <Threshold>0.04045</Threshold>\n"
67 " </InputTransferFunction>\n"
68 " <YUVToRGB>0</YUVToRGB>\n"
69 " <RedX>0.64</RedX>\n"
70 " <RedY>0.33</RedY>\n"
71 " <GreenX>0.3</GreenX>\n"
72 " <GreenY>0.6</GreenY>\n"
73 " <BlueX>0.15</BlueX>\n"
74 " <BlueY>0.06</BlueY>\n"
75 " <WhiteX>0.3127</WhiteX>\n"
76 " <WhiteY>0.329</WhiteY>\n"
77 " <OutputGamma>2.6</OutputGamma>\n"
83 BOOST_AUTO_TEST_CASE (colour_conversion_test3)
85 ColourConversion A (dcp::ColourConversion::rec709_to_xyz());
87 auto root = doc.create_root_node ("Test");
90 doc.write_to_string_formatted ("UTF-8"),
91 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
93 " <InputTransferFunction>\n"
94 " <Type>Gamma</Type>\n"
95 " <Gamma>2.2</Gamma>\n"
96 " </InputTransferFunction>\n"
97 " <YUVToRGB>1</YUVToRGB>\n"
98 " <RedX>0.64</RedX>\n"
99 " <RedY>0.33</RedY>\n"
100 " <GreenX>0.3</GreenX>\n"
101 " <GreenY>0.6</GreenY>\n"
102 " <BlueX>0.15</BlueX>\n"
103 " <BlueY>0.06</BlueY>\n"
104 " <WhiteX>0.3127</WhiteX>\n"
105 " <WhiteY>0.329</WhiteY>\n"
106 " <OutputGamma>2.6</OutputGamma>\n"
112 /** Test a round trip via the XML representation */
113 BOOST_AUTO_TEST_CASE (colour_conversion_test4)
115 for (auto const& i: PresetColourConversion::all()) {
117 auto out_root = out.create_root_node("Test");
118 i.conversion.as_xml (out_root);
119 auto in = make_shared<cxml::Document> ("Test");
120 in->read_string (out.write_to_string("UTF-8"));
121 BOOST_CHECK (ColourConversion::from_xml(in, Film::current_state_version).get() == i.conversion);