2 Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file test/colour_conversion_test.cc
21 * @brief Various tests of ColourConversion.
24 #include "lib/colour_conversion.h"
26 #include <dcp/colour_matrix.h>
27 #include <dcp/gamma_transfer_function.h>
28 #include <libxml++/libxml++.h>
29 #include <boost/test/unit_test.hpp>
30 #include <boost/foreach.hpp>
34 using boost::shared_ptr;
36 BOOST_AUTO_TEST_CASE (colour_conversion_test1)
38 ColourConversion A (dcp::ColourConversion::srgb_to_xyz ());
39 ColourConversion B (dcp::ColourConversion::rec709_to_xyz ());
41 BOOST_CHECK_EQUAL (A.identifier(), "9840c601d2775bf1b3847254bbaa36a9");
42 BOOST_CHECK_EQUAL (B.identifier(), "58151ac92fdf333663a62c9a8ba5c5f4");
45 BOOST_AUTO_TEST_CASE (colour_conversion_test2)
47 ColourConversion A (dcp::ColourConversion::srgb_to_xyz ());
49 xmlpp::Element* root = doc.create_root_node ("Test");
52 doc.write_to_string_formatted ("UTF-8"),
53 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
55 " <InputTransferFunction>\n"
56 " <Type>ModifiedGamma</Type>\n"
57 " <Power>2.4</Power>\n"
58 " <Threshold>0.04045</Threshold>\n"
61 " </InputTransferFunction>\n"
62 " <YUVToRGB>0</YUVToRGB>\n"
63 " <RedX>0.64</RedX>\n"
64 " <RedY>0.33</RedY>\n"
65 " <GreenX>0.3</GreenX>\n"
66 " <GreenY>0.6</GreenY>\n"
67 " <BlueX>0.15</BlueX>\n"
68 " <BlueY>0.06</BlueY>\n"
69 " <WhiteX>0.3127</WhiteX>\n"
70 " <WhiteY>0.329</WhiteY>\n"
71 " <OutputGamma>2.6</OutputGamma>\n"
76 BOOST_AUTO_TEST_CASE (colour_conversion_test3)
78 ColourConversion A (dcp::ColourConversion::rec709_to_xyz ());
80 xmlpp::Element* root = doc.create_root_node ("Test");
83 doc.write_to_string_formatted ("UTF-8"),
84 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
86 " <InputTransferFunction>\n"
87 " <Type>Gamma</Type>\n"
88 " <Gamma>2.2</Gamma>\n"
89 " </InputTransferFunction>\n"
90 " <YUVToRGB>1</YUVToRGB>\n"
91 " <RedX>0.64</RedX>\n"
92 " <RedY>0.33</RedY>\n"
93 " <GreenX>0.3</GreenX>\n"
94 " <GreenY>0.6</GreenY>\n"
95 " <BlueX>0.15</BlueX>\n"
96 " <BlueY>0.06</BlueY>\n"
97 " <WhiteX>0.3127</WhiteX>\n"
98 " <WhiteY>0.329</WhiteY>\n"
99 " <OutputGamma>2.6</OutputGamma>\n"
104 /** Test a round trip via the XML representation */
105 BOOST_AUTO_TEST_CASE (colour_conversion_test4)
107 BOOST_FOREACH (PresetColourConversion const & i, PresetColourConversion::all ()) {
109 xmlpp::Element* out_root = out.create_root_node ("Test");
110 i.conversion.as_xml (out_root);
111 shared_ptr<cxml::Document> in (new cxml::Document ("Test"));
112 in->read_string (out.write_to_string ("UTF-8"));
113 BOOST_CHECK (ColourConversion::from_xml (in, Film::current_state_version).get () == i.conversion);