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