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