41d985f7606196407b7ead288c5e7f3d2c30aa64
[libdcp.git] / test / lut_test.cc
1 /*
2     Copyright (C) 2013 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 #include "opendcp_lut.h"
21 #include "opendcp_lut.cc"
22 #include "srgb_linearised_gamma_lut.h"
23 #include "rec709_linearised_gamma_lut.h"
24 #include "gamma_lut.h"
25
26 /* Check that some of our LUTs match the ones from OpenDCP that
27    DVD-o-matic uses / once used.
28 */
29 BOOST_AUTO_TEST_CASE (lut_test)
30 {
31         libdcp::SRGBLinearisedGammaLUT lut_in_srgb (12, 2.4);
32         for (int i = 0; i < 4096; ++i) {
33                 /* Hmm; 1% isn't exactly great... */
34                 BOOST_CHECK_CLOSE (opendcp::lut_in[0][i], lut_in_srgb.lut()[i], 1);
35         }
36
37         libdcp::Rec709LinearisedGammaLUT lut_in_rec709 (12, 1 / 0.45);
38         for (int i = 0; i < 4096; ++i) {
39                 /* Hmm; 1% isn't exactly great... */
40                 BOOST_CHECK_CLOSE (opendcp::lut_in[1][i], lut_in_rec709.lut()[i], 1);
41         }
42
43         libdcp::GammaLUT lut_out (16, 1 / 2.6);
44         for (int i = 0; i < 65536; ++i) {
45                 BOOST_CHECK_CLOSE (opendcp::lut_out[0][i], lut_out.lut()[i] * 4096, 1);
46         }
47 }