2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 #include "gamma_transfer_function.h"
21 #include "colour_conversion.h"
22 #include "modified_gamma_transfer_function.h"
23 #include <boost/test/unit_test.hpp>
27 using boost::shared_ptr;
31 check_gamma (shared_ptr<const TransferFunction> tf, int bit_depth, float gamma)
33 double const * lut = tf->lut (bit_depth);
34 int const count = pow (2, bit_depth);
36 for (int i = 0; i < count; ++i) {
37 BOOST_CHECK_CLOSE (lut[i], pow (double(i) / (count - 1), gamma), 0.001);
42 check_modified_gamma (shared_ptr<const TransferFunction> tf, int bit_depth, double power, double threshold, double A, double B)
44 double const * lut = tf->lut (bit_depth);
45 int const count = pow (2, bit_depth);
47 for (int i = 0; i < count; ++i) {
48 double const x = double(i) / (count - 1);
50 BOOST_CHECK_CLOSE (lut[i], pow ((x + A) / (1 + A), power), 0.001);
52 BOOST_CHECK_CLOSE (lut[i], (x / B), 0.001);
57 BOOST_AUTO_TEST_CASE (colour_conversion_test1)
59 ColourConversion cc = ColourConversion::srgb_to_xyz ();
61 check_modified_gamma (cc.in(), 8, 2.4, 0.04045, 0.055, 12.92);
62 check_modified_gamma (cc.in(), 12, 2.4, 0.04045, 0.055, 12.92);
63 check_modified_gamma (cc.in(), 16, 2.4, 0.04045, 0.055, 12.92);
65 check_gamma (cc.out(), 8, 1 / 2.6);
66 check_gamma (cc.out(), 12, 1 / 2.6);
67 check_gamma (cc.out(), 16, 1 / 2.6);
70 BOOST_AUTO_TEST_CASE (colour_conversion_test2)
72 ColourConversion cc = ColourConversion::rec709_to_xyz ();
74 check_modified_gamma (cc.in(), 8, 2.4, 0.081, 0.099, 4.5);
75 check_modified_gamma (cc.in(), 12, 2.4, 0.081, 0.099, 4.5);
76 check_modified_gamma (cc.in(), 16, 2.4, 0.081, 0.099, 4.5);
78 check_gamma (cc.out(), 8, 1 / 2.6);
79 check_gamma (cc.out(), 12, 1 / 2.6);
80 check_gamma (cc.out(), 16, 1 / 2.6);