2 Copyright (C) 2014-2015 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 /** @file src/colour_conversion.h
21 * @brief ColourConversion class.
24 #ifndef DCP_COLOUR_CONVERSION_H
25 #define DCP_COLOUR_CONVERSION_H
27 #include "chromaticity.h"
28 #include <boost/shared_ptr.hpp>
29 #include <boost/numeric/ublas/matrix.hpp>
30 #include <boost/optional.hpp>
34 class TransferFunction;
42 /** @class ColourConversion
43 * @brief A representation of all the parameters involved the colourspace conversion
44 * of a YUV image to XYZ (via RGB).
46 class ColourConversion
53 boost::shared_ptr<const TransferFunction> in,
59 boost::optional<Chromaticity> adjusted_white,
60 boost::shared_ptr<const TransferFunction> out
63 boost::shared_ptr<const TransferFunction> in () const {
67 YUVToRGB yuv_to_rgb () const {
71 Chromaticity red () const {
75 Chromaticity green () const {
79 Chromaticity blue () const {
83 Chromaticity white () const {
87 boost::optional<Chromaticity> adjusted_white () const {
88 return _adjusted_white;
91 boost::shared_ptr<const TransferFunction> out () const {
95 void set_in (boost::shared_ptr<const TransferFunction> f) {
99 void set_yuv_to_rgb (YUVToRGB y) {
103 void set_red (Chromaticity red) {
107 void set_green (Chromaticity green) {
111 void set_blue (Chromaticity blue) {
115 void set_white (Chromaticity white) {
119 void set_adjusted_white (Chromaticity adjusted_white) {
120 _adjusted_white = adjusted_white;
123 void unset_adjusted_white () {
124 _adjusted_white = boost::optional<Chromaticity> ();
127 void set_out (boost::shared_ptr<const TransferFunction> f) {
131 bool about_equal (ColourConversion const & other, float epsilon) const;
133 boost::numeric::ublas::matrix<double> rgb_to_xyz () const;
134 boost::numeric::ublas::matrix<double> xyz_to_rgb () const;
135 boost::numeric::ublas::matrix<double> bradford () const;
137 static ColourConversion const & srgb_to_xyz ();
138 static ColourConversion const & rec601_to_xyz ();
139 static ColourConversion const & rec709_to_xyz ();
140 static ColourConversion const & p3_to_xyz ();
143 /** Input transfer function (probably a gamma function, or something similar) */
144 boost::shared_ptr<const TransferFunction> _in;
145 /** Conversion to use from YUV to RGB */
146 YUVToRGB _yuv_to_rgb;
151 /** White point that we are adjusting to using a Bradford matrix */
152 boost::optional<Chromaticity> _adjusted_white;
153 /** Output transfer function (probably an inverse gamma function, or something similar) */
154 boost::shared_ptr<const TransferFunction> _out;