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;
40 BOOST_AUTO_TEST_CASE (colour_conversion_test1)
42 ColourConversion A (dcp::ColourConversion::srgb_to_xyz());
43 ColourConversion B (dcp::ColourConversion::rec709_to_xyz());
45 BOOST_CHECK_EQUAL (A.identifier(), "ef8af1b1fda1dfe9656dc99b7a9532c7");
46 BOOST_CHECK_EQUAL (B.identifier(), "e6bd82fd7ebeabe75742fbece0cbf652");
50 BOOST_AUTO_TEST_CASE (colour_conversion_test2)
52 ColourConversion A (dcp::ColourConversion::srgb_to_xyz ());
54 auto root = doc.create_root_node ("Test");
57 doc.write_to_string_formatted ("UTF-8"),
58 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
60 " <InputTransferFunction>\n"
61 " <Type>ModifiedGamma</Type>\n"
62 " <Power>2.4</Power>\n"
63 " <Threshold>0.04045</Threshold>\n"
66 " </InputTransferFunction>\n"
67 " <YUVToRGB>0</YUVToRGB>\n"
68 " <RedX>0.64</RedX>\n"
69 " <RedY>0.33</RedY>\n"
70 " <GreenX>0.3</GreenX>\n"
71 " <GreenY>0.6</GreenY>\n"
72 " <BlueX>0.15</BlueX>\n"
73 " <BlueY>0.06</BlueY>\n"
74 " <WhiteX>0.3127</WhiteX>\n"
75 " <WhiteY>0.329</WhiteY>\n"
76 " <OutputGamma>2.6</OutputGamma>\n"
82 BOOST_AUTO_TEST_CASE (colour_conversion_test3)
84 ColourConversion A (dcp::ColourConversion::rec709_to_xyz());
86 auto root = doc.create_root_node ("Test");
89 doc.write_to_string_formatted ("UTF-8"),
90 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
92 " <InputTransferFunction>\n"
93 " <Type>Gamma</Type>\n"
94 " <Gamma>2.2</Gamma>\n"
95 " </InputTransferFunction>\n"
96 " <YUVToRGB>1</YUVToRGB>\n"
97 " <RedX>0.64</RedX>\n"
98 " <RedY>0.33</RedY>\n"
99 " <GreenX>0.3</GreenX>\n"
100 " <GreenY>0.6</GreenY>\n"
101 " <BlueX>0.15</BlueX>\n"
102 " <BlueY>0.06</BlueY>\n"
103 " <WhiteX>0.3127</WhiteX>\n"
104 " <WhiteY>0.329</WhiteY>\n"
105 " <OutputGamma>2.6</OutputGamma>\n"
111 /** Test a round trip via the XML representation */
112 BOOST_AUTO_TEST_CASE (colour_conversion_test4)
114 for (auto const& i: PresetColourConversion::all()) {
116 auto out_root = out.create_root_node("Test");
117 i.conversion.as_xml (out_root);
118 auto in = make_shared<cxml::Document> ("Test");
119 in->read_string (out.write_to_string("UTF-8"));
120 BOOST_CHECK (ColourConversion::from_xml(in, Film::current_state_version).get() == i.conversion);