eb3e3c294f2432f19a1dce31384c920e422b1510
[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(), "8b5a265a7c63c22a6a8fc871c64d6116");
39         BOOST_CHECK_EQUAL (B.identifier(), "bc82e69f700d0426f2ae1848d05ed006");
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.400000095367432</Power>\n"
55                 "    <Threshold>0.04044999927282333</Threshold>\n"
56                 "    <A>0.05499999970197678</A>\n"
57                 "    <B>12.92000007629395</B>\n"
58                 "  </InputTransferFunction>\n"
59                 "  <Matrix i=\"0\" j=\"0\">0.4124564</Matrix>\n"
60                 "  <Matrix i=\"0\" j=\"1\">0.3575761</Matrix>\n"
61                 "  <Matrix i=\"0\" j=\"2\">0.1804375</Matrix>\n"
62                 "  <Matrix i=\"1\" j=\"0\">0.2126729</Matrix>\n"
63                 "  <Matrix i=\"1\" j=\"1\">0.7151522</Matrix>\n"
64                 "  <Matrix i=\"1\" j=\"2\">0.072175</Matrix>\n"
65                 "  <Matrix i=\"2\" j=\"0\">0.0193339</Matrix>\n"
66                 "  <Matrix i=\"2\" j=\"1\">0.119192</Matrix>\n"
67                 "  <Matrix i=\"2\" j=\"2\">0.9503041</Matrix>\n"
68                 "  <OutputGamma>2.599999904632568</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>ModifiedGamma</Type>\n"
85                 "    <Power>2.400000095367432</Power>\n"
86                 "    <Threshold>0.08100000023841858</Threshold>\n"
87                 "    <A>0.0989999994635582</A>\n"
88                 "    <B>4.5</B>\n"
89                 "  </InputTransferFunction>\n"
90                 "  <Matrix i=\"0\" j=\"0\">0.4124564</Matrix>\n"
91                 "  <Matrix i=\"0\" j=\"1\">0.3575761</Matrix>\n"
92                 "  <Matrix i=\"0\" j=\"2\">0.1804375</Matrix>\n"
93                 "  <Matrix i=\"1\" j=\"0\">0.2126729</Matrix>\n"
94                 "  <Matrix i=\"1\" j=\"1\">0.7151522</Matrix>\n"
95                 "  <Matrix i=\"1\" j=\"2\">0.072175</Matrix>\n"
96                 "  <Matrix i=\"2\" j=\"0\">0.0193339</Matrix>\n"
97                 "  <Matrix i=\"2\" j=\"1\">0.119192</Matrix>\n"
98                 "  <Matrix i=\"2\" j=\"2\">0.9503041</Matrix>\n"
99                 "  <OutputGamma>2.599999904632568</OutputGamma>\n"
100                 "</Test>\n"
101                 );
102 }