C++11 tidying.
[dcpomatic.git] / test / colour_conversion_test.cc
1 /*
2     Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 /** @file  test/colour_conversion_test.cc
23  *  @brief Test ColourConversion class.
24  *  @ingroup selfcontained
25  */
26
27
28 #include "lib/colour_conversion.h"
29 #include "lib/film.h"
30 #include <dcp/gamma_transfer_function.h>
31 #include <libxml++/libxml++.h>
32 #include <boost/test/unit_test.hpp>
33 #include <iostream>
34
35
36 using std::cout;
37 using std::make_shared;
38 using std::shared_ptr;
39
40
41 BOOST_AUTO_TEST_CASE (colour_conversion_test1)
42 {
43         ColourConversion A (dcp::ColourConversion::srgb_to_xyz());
44         ColourConversion B (dcp::ColourConversion::rec709_to_xyz());
45
46         BOOST_CHECK_EQUAL (A.identifier(), "9840c601d2775bf1b3847254bbaa36a9");
47         BOOST_CHECK_EQUAL (B.identifier(), "58151ac92fdf333663a62c9a8ba5c5f4");
48 }
49
50
51 BOOST_AUTO_TEST_CASE (colour_conversion_test2)
52 {
53         ColourConversion A (dcp::ColourConversion::srgb_to_xyz ());
54         xmlpp::Document doc;
55         auto root = doc.create_root_node ("Test");
56         A.as_xml (root);
57         BOOST_CHECK_EQUAL (
58                 doc.write_to_string_formatted ("UTF-8"),
59                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
60                 "<Test>\n"
61                 "  <InputTransferFunction>\n"
62                 "    <Type>ModifiedGamma</Type>\n"
63                 "    <Power>2.4</Power>\n"
64                 "    <Threshold>0.04045</Threshold>\n"
65                 "    <A>0.055</A>\n"
66                 "    <B>12.92</B>\n"
67                 "  </InputTransferFunction>\n"
68                 "  <YUVToRGB>0</YUVToRGB>\n"
69                 "  <RedX>0.64</RedX>\n"
70                 "  <RedY>0.33</RedY>\n"
71                 "  <GreenX>0.3</GreenX>\n"
72                 "  <GreenY>0.6</GreenY>\n"
73                 "  <BlueX>0.15</BlueX>\n"
74                 "  <BlueY>0.06</BlueY>\n"
75                 "  <WhiteX>0.3127</WhiteX>\n"
76                 "  <WhiteY>0.329</WhiteY>\n"
77                 "  <OutputGamma>2.6</OutputGamma>\n"
78                 "</Test>\n"
79                 );
80 }
81
82
83 BOOST_AUTO_TEST_CASE (colour_conversion_test3)
84 {
85         ColourConversion A (dcp::ColourConversion::rec709_to_xyz());
86         xmlpp::Document doc;
87         auto root = doc.create_root_node ("Test");
88         A.as_xml (root);
89         BOOST_CHECK_EQUAL (
90                 doc.write_to_string_formatted ("UTF-8"),
91                 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
92                 "<Test>\n"
93                 "  <InputTransferFunction>\n"
94                 "    <Type>Gamma</Type>\n"
95                 "    <Gamma>2.2</Gamma>\n"
96                 "  </InputTransferFunction>\n"
97                 "  <YUVToRGB>1</YUVToRGB>\n"
98                 "  <RedX>0.64</RedX>\n"
99                 "  <RedY>0.33</RedY>\n"
100                 "  <GreenX>0.3</GreenX>\n"
101                 "  <GreenY>0.6</GreenY>\n"
102                 "  <BlueX>0.15</BlueX>\n"
103                 "  <BlueY>0.06</BlueY>\n"
104                 "  <WhiteX>0.3127</WhiteX>\n"
105                 "  <WhiteY>0.329</WhiteY>\n"
106                 "  <OutputGamma>2.6</OutputGamma>\n"
107                 "</Test>\n"
108                 );
109 }
110
111
112 /** Test a round trip via the XML representation */
113 BOOST_AUTO_TEST_CASE (colour_conversion_test4)
114 {
115         for (auto const& i: PresetColourConversion::all()) {
116                 xmlpp::Document out;
117                 auto out_root = out.create_root_node("Test");
118                 i.conversion.as_xml (out_root);
119                 auto in = make_shared<cxml::Document> ("Test");
120                 in->read_string (out.write_to_string("UTF-8"));
121                 BOOST_CHECK (ColourConversion::from_xml(in, Film::current_state_version).get() == i.conversion);
122         }
123 }