diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-01-07 10:55:47 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-01-07 10:55:47 +0000 |
| commit | 107482fc19404e20db544e989d880752377fde26 (patch) | |
| tree | e6d8dc6857d79bf355d08248df4287bb4a838ef1 /test | |
| parent | 1ec06907de2eb4382e5f0e6f9953e3026f1461e7 (diff) | |
Clamp out-of-range XYZ values in xyz_to_rgb() and pass notes about their existance.
Diffstat (limited to 'test')
| -rw-r--r-- | test/rgb_xyz_test.cc | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/rgb_xyz_test.cc b/test/rgb_xyz_test.cc index 2c76bb33..75e0d8b9 100644 --- a/test/rgb_xyz_test.cc +++ b/test/rgb_xyz_test.cc @@ -22,9 +22,13 @@ #include "xyz_frame.h" #include "colour_conversion.h" #include <boost/test/unit_test.hpp> +#include <boost/bind.hpp> using std::max; +using std::list; +using std::string; using boost::shared_ptr; +using boost::optional; class SimpleImage : public dcp::Image { @@ -127,3 +131,58 @@ BOOST_AUTO_TEST_CASE (rgb_xyz_test) } } } + +static list<string> notes; + +static void +note_handler (dcp::NoteType n, string s) +{ + BOOST_REQUIRE_EQUAL (n, dcp::DCP_NOTE); + notes.push_back (s); +} + +/** Check that xyz_to_rgb clamps XYZ values correctly */ +BOOST_AUTO_TEST_CASE (xyz_rgb_range_test) +{ + shared_ptr<dcp::XYZFrame> xyz (new dcp::XYZFrame (dcp::Size (2, 2))); + + xyz->data(0)[0] = -4; + xyz->data(0)[1] = 6901; + xyz->data(0)[2] = 0; + xyz->data(0)[3] = 4095; + xyz->data(1)[0] = -4; + xyz->data(1)[1] = 6901; + xyz->data(1)[2] = 0; + xyz->data(1)[3] = 4095; + xyz->data(2)[0] = -4; + xyz->data(2)[1] = 6901; + xyz->data(2)[2] = 0; + xyz->data(2)[3] = 4095; + + uint16_t buffer[12]; + + notes.clear (); + dcp::xyz_to_rgb (xyz, dcp::ColourConversion::xyz_to_srgb (), buffer, boost::optional<dcp::NoteHandler> (boost::bind (¬e_handler, _1, _2))); + + /* The 6 out-of-range samples should have been noted */ + BOOST_REQUIRE_EQUAL (notes.size(), 6); + list<string>::const_iterator i = notes.begin (); + BOOST_REQUIRE_EQUAL (*i++, "XYZ value -4 out of range"); + BOOST_REQUIRE_EQUAL (*i++, "XYZ value -4 out of range"); + BOOST_REQUIRE_EQUAL (*i++, "XYZ value -4 out of range"); + BOOST_REQUIRE_EQUAL (*i++, "XYZ value 6901 out of range"); + BOOST_REQUIRE_EQUAL (*i++, "XYZ value 6901 out of range"); + BOOST_REQUIRE_EQUAL (*i++, "XYZ value 6901 out of range"); + + /* And those samples should have been clamped, so check that they give the same result + as inputs at the extremes (0 and 4095). + */ + + BOOST_REQUIRE_EQUAL (buffer[0 * 3 + 0], buffer[2 * 3 + 1]); + BOOST_REQUIRE_EQUAL (buffer[0 * 3 + 1], buffer[2 * 3 + 1]); + BOOST_REQUIRE_EQUAL (buffer[0 * 3 + 2], buffer[2 * 3 + 2]); + + BOOST_REQUIRE_EQUAL (buffer[1 * 3 + 0], buffer[3 * 3 + 0]); + BOOST_REQUIRE_EQUAL (buffer[1 * 3 + 1], buffer[3 * 3 + 1]); + BOOST_REQUIRE_EQUAL (buffer[1 * 3 + 2], buffer[3 * 3 + 2]); +} |
