Merge branch '2.0' of git.carlh.net:git/dcpomatic into 2.0
[dcpomatic.git] / test / colour_conversion_test.cc
1 /*
2     Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file  test/colour_conversion_test.cc
21  *  @brief Various tests of ColourConversion.
22  */
23
24 #include "lib/colour_conversion.h"
25 #include <dcp/colour_matrix.h>
26 #include <dcp/gamma_transfer_function.h>
27 #include <libxml++/libxml++.h>
28 #include <boost/test/unit_test.hpp>
29
30 using std::cout;
31 using boost::shared_ptr;
32
33 BOOST_AUTO_TEST_CASE (colour_conversion_test1)
34 {
35         ColourConversion A (dcp::ColourConversion::srgb_to_xyz ());
36         ColourConversion B (dcp::ColourConversion::rec709_to_xyz ());
37
38         BOOST_CHECK_EQUAL (A.identifier(), "9840c601d2775bf1b3847254bbaa36a9");
39         BOOST_CHECK_EQUAL (B.identifier(), "0778fbc5c87470f58820604a66992579");
40 }
41
42 BOOST_AUTO_TEST_CASE (colour_conversion_test2)
43 {
44         ColourConversion A (dcp::ColourConversion::srgb_to_xyz ());
45         xmlpp::Document doc;
46         xmlpp::Element* root = doc.create_root_node ("Test");
47         A.as_xml (root);
48         BOOST_CHECK_EQUAL (
49                 doc.write_to_string_formatted ("UTF-8"),
50                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
51                 "<Test>\n"
52                 "  <InputTransferFunction>\n"
53                 "    <Type>ModifiedGamma</Type>\n"
54                 "    <Power>2.4</Power>\n"
55                 "    <Threshold>0.04045</Threshold>\n"
56                 "    <A>0.055</A>\n"
57                 "    <B>12.92</B>\n"
58                 "  </InputTransferFunction>\n"
59                 "  <RedX>0.64</RedX>\n"
60                 "  <RedY>0.33</RedY>\n"
61                 "  <GreenX>0.3</GreenX>\n"
62                 "  <GreenY>0.6</GreenY>\n"
63                 "  <BlueX>0.15</BlueX>\n"
64                 "  <BlueY>0.06</BlueY>\n"
65                 "  <WhiteX>0.3127</WhiteX>\n"
66                 "  <WhiteY>0.329</WhiteY>\n"
67                 "  <OutputGamma>2.6</OutputGamma>\n"
68                 "</Test>\n"
69                 );
70 }
71
72 BOOST_AUTO_TEST_CASE (colour_conversion_test3)
73 {
74         ColourConversion A (dcp::ColourConversion::rec709_to_xyz ());
75         xmlpp::Document doc;
76         xmlpp::Element* root = doc.create_root_node ("Test");
77         A.as_xml (root);
78         BOOST_CHECK_EQUAL (
79                 doc.write_to_string_formatted ("UTF-8"),
80                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
81                 "<Test>\n"
82                 "  <InputTransferFunction>\n"
83                 "    <Type>ModifiedGamma</Type>\n"
84                 "    <Power>2.222222222222222</Power>\n"
85                 "    <Threshold>0.081</Threshold>\n"
86                 "    <A>0.099</A>\n"
87                 "    <B>4.5</B>\n"
88                 "  </InputTransferFunction>\n"
89                 "  <RedX>0.64</RedX>\n"
90                 "  <RedY>0.33</RedY>\n"
91                 "  <GreenX>0.3</GreenX>\n"
92                 "  <GreenY>0.6</GreenY>\n"
93                 "  <BlueX>0.15</BlueX>\n"
94                 "  <BlueY>0.06</BlueY>\n"
95                 "  <WhiteX>0.3127</WhiteX>\n"
96                 "  <WhiteY>0.329</WhiteY>\n"
97                 "  <OutputGamma>2.6</OutputGamma>\n"
98                 "</Test>\n"
99                 );
100 }