From 86bfdeb77f55b379302a65b22f57fc0583ec6b3c Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 22 Apr 2015 13:58:16 +0100 Subject: Express colour conversions as chromaticities and adjust so that everything is specified as something_to_xyz and then you can get an inverse LUT if you want one. --- src/colour_conversion.h | 84 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 9 deletions(-) (limited to 'src/colour_conversion.h') diff --git a/src/colour_conversion.h b/src/colour_conversion.h index cf19d447..e1ee1b11 100644 --- a/src/colour_conversion.h +++ b/src/colour_conversion.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Carl Hetherington + Copyright (C) 2014-2015 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,23 +17,35 @@ */ +#include "chromaticity.h" #include #include +#include namespace dcp { class TransferFunction; +enum YUVToRGB { + YUV_TO_RGB_REC601, + YUV_TO_RGB_REC709, + YUV_TO_RGB_COUNT +}; + class ColourConversion { public: ColourConversion () - : _matrix (3, 3) {} ColourConversion ( boost::shared_ptr in, - double const matrix[3][3], + YUVToRGB yuv_to_rgb, + Chromaticity red, + Chromaticity green, + Chromaticity blue, + Chromaticity white, + boost::optional adjusted_white, boost::shared_ptr out ); @@ -41,10 +53,30 @@ public: return _in; } - boost::numeric::ublas::matrix matrix () const { - return _matrix; + YUVToRGB yuv_to_rgb () const { + return _yuv_to_rgb; + } + + Chromaticity red () const { + return _red; } + Chromaticity green () const { + return _green; + } + + Chromaticity blue () const { + return _blue; + } + + Chromaticity white () const { + return _white; + } + + boost::optional adjusted_white () const { + return _adjusted_white; + } + boost::shared_ptr out () const { return _out; } @@ -53,23 +85,57 @@ public: _in = f; } - void set_matrix (boost::numeric::ublas::matrix m) { - _matrix = m; + void set_yuv_to_rgb (YUVToRGB y) { + _yuv_to_rgb = y; } + void set_red (Chromaticity red) { + _red = red; + } + + void set_green (Chromaticity green) { + _green = green; + } + + void set_blue (Chromaticity blue) { + _blue = blue; + } + + void set_white (Chromaticity white) { + _white = white; + } + + void set_adjusted_white (Chromaticity adjusted_white) { + _adjusted_white = adjusted_white; + } + + void unset_adjusted_white () { + _adjusted_white = boost::optional (); + } + void set_out (boost::shared_ptr f) { _out = f; } bool about_equal (ColourConversion const & other, float epsilon) const; + boost::numeric::ublas::matrix rgb_to_xyz () const; + boost::numeric::ublas::matrix xyz_to_rgb () const; + boost::numeric::ublas::matrix bradford () const; + static ColourConversion const & srgb_to_xyz (); - static ColourConversion const & xyz_to_srgb (); + static ColourConversion const & rec601_to_xyz (); static ColourConversion const & rec709_to_xyz (); protected: boost::shared_ptr _in; - boost::numeric::ublas::matrix _matrix; + YUVToRGB _yuv_to_rgb; + Chromaticity _red; + Chromaticity _green; + Chromaticity _blue; + Chromaticity _white; + /** White point that we are adjusting to using a Bradford matrix */ + boost::optional _adjusted_white; boost::shared_ptr _out; }; -- cgit v1.2.3