Prevent theoretical possibility of an uninitialised variable.
[libdcp.git] / src / colour_conversion.h
1 /*
2     Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file  src/colour_conversion.h
21  *  @brief ColourConversion class.
22  */
23
24 #ifndef DCP_COLOUR_CONVERSION_H
25 #define DCP_COLOUR_CONVERSION_H
26
27 #include "chromaticity.h"
28 #include <boost/shared_ptr.hpp>
29 #include <boost/numeric/ublas/matrix.hpp>
30 #include <boost/optional.hpp>
31
32 namespace dcp {
33
34 class TransferFunction;
35
36 enum YUVToRGB {
37         YUV_TO_RGB_REC601,
38         YUV_TO_RGB_REC709,
39         YUV_TO_RGB_COUNT
40 };
41
42 /** @class ColourConversion
43  *  @brief A representation of all the parameters involved the colourspace conversion
44  *  of a YUV image to XYZ (via RGB).
45  */
46 class ColourConversion
47 {
48 public:
49         ColourConversion ()
50                 : _yuv_to_rgb (YUV_TO_RGB_REC601)
51         {}
52
53         ColourConversion (
54                 boost::shared_ptr<const TransferFunction> in,
55                 YUVToRGB yuv_to_rgb,
56                 Chromaticity red,
57                 Chromaticity green,
58                 Chromaticity blue,
59                 Chromaticity white,
60                 boost::optional<Chromaticity> adjusted_white,
61                 boost::shared_ptr<const TransferFunction> out
62                 );
63
64         boost::shared_ptr<const TransferFunction> in () const {
65                 return _in;
66         }
67
68         YUVToRGB yuv_to_rgb () const {
69                 return _yuv_to_rgb;
70         }
71
72         Chromaticity red () const {
73                 return _red;
74         }
75
76         Chromaticity green () const {
77                 return _green;
78         }
79
80         Chromaticity blue () const {
81                 return _blue;
82         }
83
84         Chromaticity white () const {
85                 return _white;
86         }
87
88         boost::optional<Chromaticity> adjusted_white () const {
89                 return _adjusted_white;
90         }
91
92         boost::shared_ptr<const TransferFunction> out () const {
93                 return _out;
94         }
95
96         void set_in (boost::shared_ptr<const TransferFunction> f) {
97                 _in = f;
98         }
99
100         void set_yuv_to_rgb (YUVToRGB y) {
101                 _yuv_to_rgb = y;
102         }
103
104         void set_red (Chromaticity red) {
105                 _red = red;
106         }
107
108         void set_green (Chromaticity green) {
109                 _green = green;
110         }
111
112         void set_blue (Chromaticity blue) {
113                 _blue = blue;
114         }
115
116         void set_white (Chromaticity white) {
117                 _white = white;
118         }
119
120         void set_adjusted_white (Chromaticity adjusted_white) {
121                 _adjusted_white = adjusted_white;
122         }
123
124         void unset_adjusted_white () {
125                 _adjusted_white = boost::optional<Chromaticity> ();
126         }
127
128         void set_out (boost::shared_ptr<const TransferFunction> f) {
129                 _out = f;
130         }
131
132         bool about_equal (ColourConversion const & other, float epsilon) const;
133
134         boost::numeric::ublas::matrix<double> rgb_to_xyz () const;
135         boost::numeric::ublas::matrix<double> xyz_to_rgb () const;
136         boost::numeric::ublas::matrix<double> bradford () const;
137
138         static ColourConversion const & srgb_to_xyz ();
139         static ColourConversion const & rec601_to_xyz ();
140         static ColourConversion const & rec709_to_xyz ();
141         static ColourConversion const & p3_to_xyz ();
142
143 protected:
144         /** Input transfer function (probably a gamma function, or something similar) */
145         boost::shared_ptr<const TransferFunction> _in;
146         /** Conversion to use from YUV to RGB */
147         YUVToRGB _yuv_to_rgb;
148         Chromaticity _red;
149         Chromaticity _green;
150         Chromaticity _blue;
151         Chromaticity _white;
152         /** White point that we are adjusting to using a Bradford matrix */
153         boost::optional<Chromaticity> _adjusted_white;
154         /** Output transfer function (probably an inverse gamma function, or something similar) */
155         boost::shared_ptr<const TransferFunction> _out;
156 };
157
158 }
159
160 #endif