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 const &
29 ColourConversion::srgb_to_xyz ()
31 static ColourConversion* c = new ColourConversion (
32 shared_ptr<const TransferFunction> (new ModifiedGammaTransferFunction (false, 2.4, 0.04045, 0.055, 12.92)),
33 dcp::colour_matrix::rgb_to_xyz,
34 shared_ptr<const TransferFunction> (new GammaTransferFunction (true, 2.6))
39 ColourConversion const &
40 ColourConversion::xyz_to_srgb ()
42 static ColourConversion* c = new ColourConversion (
43 shared_ptr<const TransferFunction> (new GammaTransferFunction (false, 2.6)),
44 dcp::colour_matrix::xyz_to_rgb,
45 shared_ptr<const TransferFunction> (new ModifiedGammaTransferFunction (true, 2.4, 0.04045, 0.055, 12.92))
50 ColourConversion const &
51 ColourConversion::rec709_to_xyz ()
53 static ColourConversion* c = new ColourConversion (
54 shared_ptr<const TransferFunction> (new ModifiedGammaTransferFunction (false, 1 / 0.45, 0.081, 0.099, 4.5)),
55 dcp::colour_matrix::rgb_to_xyz,
56 shared_ptr<const TransferFunction> (new GammaTransferFunction (true, 2.6))
61 ColourConversion::ColourConversion (
62 shared_ptr<const TransferFunction> in,
63 double const matrix[3][3],
64 shared_ptr<const TransferFunction> out
70 for (int i = 0; i < 3; ++i) {
71 for (int j = 0; j < 3; ++j) {
72 _matrix (i, j) = matrix[i][j];
78 ColourConversion::about_equal (ColourConversion const & other, float epsilon) const
80 for (int i = 0; i < 3; ++i) {
81 for (int j = 0; j < 3; ++j) {
82 if (fabs (_matrix(i, j) - other._matrix(i, j)) > epsilon) {
88 return _in->about_equal (other._in, epsilon) && _out->about_equal (other._out, epsilon);