2 Copyright (C) 2013-2015 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/>.
21 /** @file test/colour_conversion_test.cc
22 * @brief Test ColourConversion class.
23 * @ingroup selfcontained
26 #include "lib/colour_conversion.h"
28 #include <dcp/gamma_transfer_function.h>
29 #include <libxml++/libxml++.h>
30 #include <boost/test/unit_test.hpp>
31 #include <boost/foreach.hpp>
35 using boost::shared_ptr;
37 BOOST_AUTO_TEST_CASE (colour_conversion_test1)
39 ColourConversion A (dcp::ColourConversion::srgb_to_xyz ());
40 ColourConversion B (dcp::ColourConversion::rec709_to_xyz ());
42 BOOST_CHECK_EQUAL (A.identifier(), "9840c601d2775bf1b3847254bbaa36a9");
43 BOOST_CHECK_EQUAL (B.identifier(), "58151ac92fdf333663a62c9a8ba5c5f4");
46 BOOST_AUTO_TEST_CASE (colour_conversion_test2)
48 ColourConversion A (dcp::ColourConversion::srgb_to_xyz ());
50 xmlpp::Element* root = doc.create_root_node ("Test");
53 doc.write_to_string_formatted ("UTF-8"),
54 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
56 " <InputTransferFunction>\n"
57 " <Type>ModifiedGamma</Type>\n"
58 " <Power>2.4</Power>\n"
59 " <Threshold>0.04045</Threshold>\n"
62 " </InputTransferFunction>\n"
63 " <YUVToRGB>0</YUVToRGB>\n"
64 " <RedX>0.64</RedX>\n"
65 " <RedY>0.33</RedY>\n"
66 " <GreenX>0.3</GreenX>\n"
67 " <GreenY>0.6</GreenY>\n"
68 " <BlueX>0.15</BlueX>\n"
69 " <BlueY>0.06</BlueY>\n"
70 " <WhiteX>0.3127</WhiteX>\n"
71 " <WhiteY>0.329</WhiteY>\n"
72 " <OutputGamma>2.6</OutputGamma>\n"
77 BOOST_AUTO_TEST_CASE (colour_conversion_test3)
79 ColourConversion A (dcp::ColourConversion::rec709_to_xyz ());
81 xmlpp::Element* root = doc.create_root_node ("Test");
84 doc.write_to_string_formatted ("UTF-8"),
85 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
87 " <InputTransferFunction>\n"
88 " <Type>Gamma</Type>\n"
89 " <Gamma>2.2</Gamma>\n"
90 " </InputTransferFunction>\n"
91 " <YUVToRGB>1</YUVToRGB>\n"
92 " <RedX>0.64</RedX>\n"
93 " <RedY>0.33</RedY>\n"
94 " <GreenX>0.3</GreenX>\n"
95 " <GreenY>0.6</GreenY>\n"
96 " <BlueX>0.15</BlueX>\n"
97 " <BlueY>0.06</BlueY>\n"
98 " <WhiteX>0.3127</WhiteX>\n"
99 " <WhiteY>0.329</WhiteY>\n"
100 " <OutputGamma>2.6</OutputGamma>\n"
105 /** Test a round trip via the XML representation */
106 BOOST_AUTO_TEST_CASE (colour_conversion_test4)
108 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all ()) {
110 xmlpp::Element* out_root = out.create_root_node ("Test");
111 i.conversion.as_xml (out_root);
112 shared_ptr<cxml::Document> in (new cxml::Document ("Test"));
113 in->read_string (out.write_to_string ("UTF-8"));
114 BOOST_CHECK (ColourConversion::from_xml (in, Film::current_state_version).get () == i.conversion);