2 Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
35 /** @file src/colour_conversion.h
36 * @brief ColourConversion class.
40 #ifndef DCP_COLOUR_CONVERSION_H
41 #define DCP_COLOUR_CONVERSION_H
44 #include "chromaticity.h"
46 #if BOOST_VERSION >= 106400
47 #include <boost/serialization/array_wrapper.hpp>
49 #include <boost/numeric/ublas/matrix.hpp>
50 #include <boost/optional.hpp>
56 class TransferFunction;
66 /** @class ColourConversion
67 * @brief A representation of all the parameters involved the colourspace conversion
68 * of a YUV image to XYZ (via RGB)
70 class ColourConversion
74 : _yuv_to_rgb (YUVToRGB::REC601)
78 std::shared_ptr<const TransferFunction> in,
84 boost::optional<Chromaticity> adjusted_white,
85 std::shared_ptr<const TransferFunction> out
88 std::shared_ptr<const TransferFunction> in () const {
92 YUVToRGB yuv_to_rgb () const {
96 Chromaticity red () const {
100 Chromaticity green () const {
104 Chromaticity blue () const {
108 Chromaticity white () const {
112 boost::optional<Chromaticity> adjusted_white () const {
113 return _adjusted_white;
116 std::shared_ptr<const TransferFunction> out () const {
120 void set_in (std::shared_ptr<const TransferFunction> f) {
124 void set_yuv_to_rgb (YUVToRGB y) {
128 void set_red (Chromaticity red) {
132 void set_green (Chromaticity green) {
136 void set_blue (Chromaticity blue) {
140 void set_white (Chromaticity white) {
144 void set_adjusted_white (Chromaticity adjusted_white) {
145 _adjusted_white = adjusted_white;
148 void unset_adjusted_white () {
149 _adjusted_white = boost::optional<Chromaticity> ();
152 void set_out (std::shared_ptr<const TransferFunction> f) {
156 bool about_equal (ColourConversion const & other, float epsilon) const;
158 boost::numeric::ublas::matrix<double> rgb_to_xyz () const;
159 boost::numeric::ublas::matrix<double> xyz_to_rgb () const;
160 boost::numeric::ublas::matrix<double> bradford () const;
162 static ColourConversion const & srgb_to_xyz ();
163 static ColourConversion const & rec601_to_xyz ();
164 static ColourConversion const & rec709_to_xyz ();
165 static ColourConversion const & p3_to_xyz ();
166 static ColourConversion const & rec1886_to_xyz ();
167 static ColourConversion const & rec2020_to_xyz ();
168 static ColourConversion const & s_gamut3_to_xyz ();
171 /** Input transfer function (probably a gamma function, or something similar) */
172 std::shared_ptr<const TransferFunction> _in;
173 /** Conversion to use from YUV to RGB */
174 YUVToRGB _yuv_to_rgb;
179 /** White point that we are adjusting to using a Bradford matrix */
180 boost::optional<Chromaticity> _adjusted_white;
181 /** Output transfer function (probably an inverse gamma function, or something similar) */
182 std::shared_ptr<const TransferFunction> _out;