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 "colour_conversion.h"
21 #include "gamma_transfer_function.h"
22 #include "modified_gamma_transfer_function.h"
23 #include "colour_matrix.h"
25 using boost::shared_ptr;
28 ColourConversion ColourConversion::srgb_to_xyz (
29 shared_ptr<const TransferFunction> (new ModifiedGammaTransferFunction (2.4, 0.04045, 0.055, 12.92)),
30 dcp::colour_matrix::srgb_to_xyz,
31 shared_ptr<const TransferFunction> (new GammaTransferFunction (2.6))
34 /* XXX: what sort of RGB is this...? */
35 ColourConversion ColourConversion::xyz_to_rgb (
36 shared_ptr<const TransferFunction> (new GammaTransferFunction (2.6)),
37 dcp::colour_matrix::xyz_to_rgb,
38 shared_ptr<const TransferFunction> (new GammaTransferFunction (2.2))
41 ColourConversion ColourConversion::rec709_to_xyz (
42 shared_ptr<const TransferFunction> (new ModifiedGammaTransferFunction (2.4, 0.081, 0.099, 4.5)),
43 dcp::colour_matrix::srgb_to_xyz,
44 shared_ptr<const TransferFunction> (new GammaTransferFunction (2.6))
47 ColourConversion::ColourConversion (
48 shared_ptr<const TransferFunction> in,
49 double const matrix[3][3],
50 shared_ptr<const TransferFunction> out
56 for (int i = 0; i < 3; ++i) {
57 for (int j = 0; j < 3; ++j) {
58 _matrix (i, j) = matrix[i][j];
64 ColourConversion::about_equal (ColourConversion const & other, float epsilon) const
66 for (int i = 0; i < 3; ++i) {
67 for (int j = 0; j < 3; ++j) {
68 if (fabs (_matrix(i, j) - other._matrix(i, j)) > epsilon) {
74 return _in->about_equal (other._in, epsilon) && _out->about_equal (other._out, epsilon);