Update for change to default Rec. 601/709 gamma.
[dcpomatic.git] / test / colour_conversion_test.cc
1 /*
2     Copyright (C) 2013-2015 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(), "58151ac92fdf333663a62c9a8ba5c5f4");
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                 "  <YUVToRGB>0</YUVToRGB>\n"
60                 "  <RedX>0.64</RedX>\n"
61                 "  <RedY>0.33</RedY>\n"
62                 "  <GreenX>0.3</GreenX>\n"
63                 "  <GreenY>0.6</GreenY>\n"
64                 "  <BlueX>0.15</BlueX>\n"
65                 "  <BlueY>0.06</BlueY>\n"
66                 "  <WhiteX>0.3127</WhiteX>\n"
67                 "  <WhiteY>0.329</WhiteY>\n"
68                 "  <OutputGamma>2.6</OutputGamma>\n"
69                 "</Test>\n"
70                 );
71 }
72
73 BOOST_AUTO_TEST_CASE (colour_conversion_test3)
74 {
75         ColourConversion A (dcp::ColourConversion::rec709_to_xyz ());
76         xmlpp::Document doc;
77         xmlpp::Element* root = doc.create_root_node ("Test");
78         A.as_xml (root);
79         BOOST_CHECK_EQUAL (
80                 doc.write_to_string_formatted ("UTF-8"),
81                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
82                 "<Test>\n"
83                 "  <InputTransferFunction>\n"
84                 "    <Type>Gamma</Type>\n"
85                 "    <Gamma>2.2</Gamma>\n"
86                 "  </InputTransferFunction>\n"
87                 "  <YUVToRGB>1</YUVToRGB>\n"
88                 "  <RedX>0.64</RedX>\n"
89                 "  <RedY>0.33</RedY>\n"
90                 "  <GreenX>0.3</GreenX>\n"
91                 "  <GreenY>0.6</GreenY>\n"
92                 "  <BlueX>0.15</BlueX>\n"
93                 "  <BlueY>0.06</BlueY>\n"
94                 "  <WhiteX>0.3127</WhiteX>\n"
95                 "  <WhiteY>0.329</WhiteY>\n"
96                 "  <OutputGamma>2.6</OutputGamma>\n"
97                 "</Test>\n"
98                 );
99 }