libdcp
colour_conversion.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
3 
4  This file is part of libdcp.
5 
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.
10 
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.
15 
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/>.
18 
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
23  including the two.
24 
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.
32 */
33 
34 
40 #ifndef LIBDCP_COLOUR_CONVERSION_H
41 #define LIBDCP_COLOUR_CONVERSION_H
42 
43 
44 #include "chromaticity.h"
45 #include <memory>
46 #if BOOST_VERSION >= 106400
47 #include <boost/serialization/array_wrapper.hpp>
48 #endif
49 #include <boost/numeric/ublas/matrix.hpp>
50 #include <boost/optional.hpp>
51 
52 
53 namespace dcp {
54 
55 
56 class TransferFunction;
57 
58 
59 enum class YUVToRGB {
60  REC601,
61  REC709,
62  REC2020,
63  COUNT
64 };
65 
66 
72 {
73 public:
75  : _yuv_to_rgb (YUVToRGB::REC601)
76  {}
77 
79  std::shared_ptr<const TransferFunction> in,
80  YUVToRGB yuv_to_rgb,
81  Chromaticity red,
82  Chromaticity green,
83  Chromaticity blue,
84  Chromaticity white,
85  boost::optional<Chromaticity> adjusted_white,
86  std::shared_ptr<const TransferFunction> out
87  );
88 
89  std::shared_ptr<const TransferFunction> in () const {
90  return _in;
91  }
92 
93  YUVToRGB yuv_to_rgb () const {
94  return _yuv_to_rgb;
95  }
96 
97  Chromaticity red () const {
98  return _red;
99  }
100 
101  Chromaticity green () const {
102  return _green;
103  }
104 
105  Chromaticity blue () const {
106  return _blue;
107  }
108 
109  Chromaticity white () const {
110  return _white;
111  }
112 
113  boost::optional<Chromaticity> adjusted_white () const {
114  return _adjusted_white;
115  }
116 
117  std::shared_ptr<const TransferFunction> out () const {
118  return _out;
119  }
120 
121  void set_in (std::shared_ptr<const TransferFunction> f) {
122  _in = f;
123  }
124 
125  void set_yuv_to_rgb (YUVToRGB y) {
126  _yuv_to_rgb = y;
127  }
128 
129  void set_red (Chromaticity red) {
130  _red = red;
131  }
132 
133  void set_green (Chromaticity green) {
134  _green = green;
135  }
136 
137  void set_blue (Chromaticity blue) {
138  _blue = blue;
139  }
140 
141  void set_white (Chromaticity white) {
142  _white = white;
143  }
144 
145  void set_adjusted_white (Chromaticity adjusted_white) {
146  _adjusted_white = adjusted_white;
147  }
148 
149  void unset_adjusted_white () {
150  _adjusted_white = boost::optional<Chromaticity> ();
151  }
152 
153  void set_out (std::shared_ptr<const TransferFunction> f) {
154  _out = f;
155  }
156 
157  bool about_equal (ColourConversion const & other, float epsilon) const;
158 
159  boost::numeric::ublas::matrix<double> rgb_to_xyz () const;
160  boost::numeric::ublas::matrix<double> xyz_to_rgb () const;
161  boost::numeric::ublas::matrix<double> bradford () const;
162 
163  static ColourConversion const & srgb_to_xyz ();
164  static ColourConversion const & rec601_to_xyz ();
165  static ColourConversion const & rec709_to_xyz ();
166  static ColourConversion const & p3_to_xyz ();
167  static ColourConversion const & rec1886_to_xyz ();
168  static ColourConversion const & rec2020_to_xyz ();
169  static ColourConversion const & s_gamut3_to_xyz ();
170 
171 protected:
173  std::shared_ptr<const TransferFunction> _in;
175  YUVToRGB _yuv_to_rgb;
176  Chromaticity _red;
177  Chromaticity _green;
178  Chromaticity _blue;
179  Chromaticity _white;
181  boost::optional<Chromaticity> _adjusted_white;
183  std::shared_ptr<const TransferFunction> _out;
184 };
185 
186 
187 }
188 
189 
190 #endif
Chromaticity class.
A representation of a x,y,z chromaticity, where z = 1 - x - y.
Definition: chromaticity.h:54
A representation of all the parameters involved the colourspace conversion of a YUV image to XYZ (via...
std::shared_ptr< const TransferFunction > _out
static ColourConversion const & s_gamut3_to_xyz()
boost::optional< Chromaticity > _adjusted_white
std::shared_ptr< const TransferFunction > _in
Namespace for everything in libdcp.
Definition: array_data.h:50