/*
- Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
*/
-#include <boost/test/unit_test.hpp>
-#include <dcp/colour_matrix.h>
+/** @file test/colour_conversion_test.cc
+ * @brief Various tests of ColourConversion.
+ */
+
#include "lib/colour_conversion.h"
+#include <dcp/colour_matrix.h>
+#include <dcp/gamma_transfer_function.h>
+#include <libxml++/libxml++.h>
+#include <boost/test/unit_test.hpp>
using std::cout;
+using boost::shared_ptr;
-/* Basic test of identifier() for ColourConversion (i.e. a hash of the numbers) */
-BOOST_AUTO_TEST_CASE (colour_conversion_test)
+BOOST_AUTO_TEST_CASE (colour_conversion_test1)
{
- ColourConversion A (2.4, true, dcp::colour_matrix::srgb_to_xyz, 2.6);
- ColourConversion B (2.4, false, dcp::colour_matrix::srgb_to_xyz, 2.6);
+ ColourConversion A (dcp::ColourConversion::srgb_to_xyz ());
+ ColourConversion B (dcp::ColourConversion::rec709_to_xyz ());
- BOOST_CHECK_EQUAL (A.identifier(), "246ff9b7dc32c0488948a32a713924b3");
- BOOST_CHECK_EQUAL (B.identifier(), "a8d1da30f96a121d8db06a03409758b3");
+ BOOST_CHECK_EQUAL (A.identifier(), "751dd37378fb52502d356ec334a104c8");
+ BOOST_CHECK_EQUAL (B.identifier(), "149bc864d969ad7446fa18d62d1690b2");
+}
+
+BOOST_AUTO_TEST_CASE (colour_conversion_test2)
+{
+ ColourConversion A (dcp::ColourConversion::srgb_to_xyz ());
+ xmlpp::Document doc;
+ xmlpp::Element* root = doc.create_root_node ("Test");
+ A.as_xml (root);
+ BOOST_CHECK_EQUAL (
+ doc.write_to_string_formatted ("UTF-8"),
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<Test>\n"
+ " <InputTransferFunction>\n"
+ " <Type>ModifiedGamma</Type>\n"
+ " <Power>2.4</Power>\n"
+ " <Threshold>0.04045</Threshold>\n"
+ " <A>0.055</A>\n"
+ " <B>12.92</B>\n"
+ " </InputTransferFunction>\n"
+ " <Matrix i=\"0\" j=\"0\">0.4124564</Matrix>\n"
+ " <Matrix i=\"0\" j=\"1\">0.3575761</Matrix>\n"
+ " <Matrix i=\"0\" j=\"2\">0.1804375</Matrix>\n"
+ " <Matrix i=\"1\" j=\"0\">0.2126729</Matrix>\n"
+ " <Matrix i=\"1\" j=\"1\">0.7151522</Matrix>\n"
+ " <Matrix i=\"1\" j=\"2\">0.072175</Matrix>\n"
+ " <Matrix i=\"2\" j=\"0\">0.0193339</Matrix>\n"
+ " <Matrix i=\"2\" j=\"1\">0.119192</Matrix>\n"
+ " <Matrix i=\"2\" j=\"2\">0.9503041</Matrix>\n"
+ " <OutputGamma>2.6</OutputGamma>\n"
+ "</Test>\n"
+ );
+}
+
+BOOST_AUTO_TEST_CASE (colour_conversion_test3)
+{
+ ColourConversion A (dcp::ColourConversion::rec709_to_xyz ());
+ xmlpp::Document doc;
+ xmlpp::Element* root = doc.create_root_node ("Test");
+ A.as_xml (root);
+ BOOST_CHECK_EQUAL (
+ doc.write_to_string_formatted ("UTF-8"),
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<Test>\n"
+ " <InputTransferFunction>\n"
+ " <Type>ModifiedGamma</Type>\n"
+ " <Power>2.4</Power>\n"
+ " <Threshold>0.081</Threshold>\n"
+ " <A>0.099</A>\n"
+ " <B>4.5</B>\n"
+ " </InputTransferFunction>\n"
+ " <Matrix i=\"0\" j=\"0\">0.4124564</Matrix>\n"
+ " <Matrix i=\"0\" j=\"1\">0.3575761</Matrix>\n"
+ " <Matrix i=\"0\" j=\"2\">0.1804375</Matrix>\n"
+ " <Matrix i=\"1\" j=\"0\">0.2126729</Matrix>\n"
+ " <Matrix i=\"1\" j=\"1\">0.7151522</Matrix>\n"
+ " <Matrix i=\"1\" j=\"2\">0.072175</Matrix>\n"
+ " <Matrix i=\"2\" j=\"0\">0.0193339</Matrix>\n"
+ " <Matrix i=\"2\" j=\"1\">0.119192</Matrix>\n"
+ " <Matrix i=\"2\" j=\"2\">0.9503041</Matrix>\n"
+ " <OutputGamma>2.6</OutputGamma>\n"
+ "</Test>\n"
+ );
}