X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fcolour_conversion.cc;h=22404c2796d165fe0716ea461ac36ad3a0e187fd;hb=2bec3708fc744c18128c5bdb4c2a332f5c8eb283;hp=0f05474d8780fa148543219d4d13de0c45ba62d8;hpb=975a9752b6fb007509605cce7b62bc4c139ddada;p=dcpomatic.git diff --git a/src/lib/colour_conversion.cc b/src/lib/colour_conversion.cc index 0f05474d8..22404c279 100644 --- a/src/lib/colour_conversion.cc +++ b/src/lib/colour_conversion.cc @@ -1,34 +1,40 @@ /* - Copyright (C) 2013-2015 Carl Hetherington + Copyright (C) 2013-2020 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ #include "config.h" #include "colour_conversion.h" #include "util.h" -#include "md5_digester.h" -#include "raw_convert.h" +#include "digester.h" +#include "warnings.h" +#include #include -#include #include #include +#include +#include #include +DCPOMATIC_DISABLE_WARNINGS #include +DCPOMATIC_ENABLE_WARNINGS #include +#include #include "i18n.h" @@ -39,19 +45,20 @@ using std::vector; using boost::shared_ptr; using boost::optional; using boost::dynamic_pointer_cast; +using dcp::raw_convert; vector PresetColourConversion::_presets; ColourConversion::ColourConversion () : dcp::ColourConversion (dcp::ColourConversion::srgb_to_xyz ()) { - + } ColourConversion::ColourConversion (dcp::ColourConversion conversion_) : dcp::ColourConversion (conversion_) { - + } ColourConversion::ColourConversion (cxml::NodePtr node, int version) @@ -73,21 +80,23 @@ ColourConversion::ColourConversion (cxml::NodePtr node, int version) in_node->number_child ("A"), in_node->number_child ("B") )); + } else if (in_type == "SGamut3") { + _in.reset (new dcp::SGamut3TransferFunction ()); } } else { /* Version 1.x */ - + if (node->bool_child ("InputGammaLinearised")) { - _in.reset (new dcp::ModifiedGammaTransferFunction (node->number_child ("InputGamma"), 0.04045, 0.055, 12.92)); + _in.reset (new dcp::ModifiedGammaTransferFunction (node->number_child ("InputGamma"), 0.04045, 0.055, 12.92)); } else { - _in.reset (new dcp::GammaTransferFunction (node->number_child ("InputGamma"))); + _in.reset (new dcp::GammaTransferFunction (node->number_child ("InputGamma"))); } } _yuv_to_rgb = static_cast (node->optional_number_child("YUVToRGB").get_value_or (dcp::YUV_TO_RGB_REC601)); - + list m = node->node_children ("Matrix"); if (!m.empty ()) { /* Read in old nodes and convert them to chromaticities */ @@ -117,9 +126,14 @@ ColourConversion::ColourConversion (cxml::NodePtr node, int version) node->number_child ("AdjustedWhiteX"), node->number_child ("AdjustedWhiteY") ); } - } - - _out.reset (new dcp::GammaTransferFunction (node->number_child ("OutputGamma"))); + } + + optional gamma = node->optional_number_child ("OutputGamma"); + if (gamma) { + _out.reset (new dcp::GammaTransferFunction (node->number_child ("OutputGamma"))); + } else { + _out.reset (new dcp::IdentityTransferFunction ()); + } } boost::optional @@ -147,8 +161,11 @@ ColourConversion::as_xml (xmlpp::Node* node) const in_node->add_child("Threshold")->add_child_text (raw_convert (tf->threshold ())); in_node->add_child("A")->add_child_text (raw_convert (tf->A ())); in_node->add_child("B")->add_child_text (raw_convert (tf->B ())); + } else if (dynamic_pointer_cast (_in)) { + in_node->add_child("Type")->add_child_text ("SGamut3"); } + node->add_child("YUVToRGB")->add_child_text (raw_convert (static_cast (_yuv_to_rgb))); node->add_child("RedX")->add_child_text (raw_convert (_red.x)); node->add_child("RedY")->add_child_text (raw_convert (_red.y)); node->add_child("GreenX")->add_child_text (raw_convert (_green.x)); @@ -162,7 +179,10 @@ ColourConversion::as_xml (xmlpp::Node* node) const node->add_child("AdjustedWhiteY")->add_child_text (raw_convert (_adjusted_white.get().y)); } - node->add_child("OutputGamma")->add_child_text (raw_convert (dynamic_pointer_cast (_out)->gamma ())); + if (dynamic_pointer_cast (_out)) { + shared_ptr gf = dynamic_pointer_cast (_out); + node->add_child("OutputGamma")->add_child_text (raw_convert (gf->gamma ())); + } } optional @@ -170,7 +190,7 @@ ColourConversion::preset () const { vector presets = PresetColourConversion::all (); size_t i = 0; - while (i < presets.size() && (presets[i].conversion != *this)) { + while (i < presets.size() && presets[i].conversion != *this) { ++i; } @@ -184,7 +204,7 @@ ColourConversion::preset () const string ColourConversion::identifier () const { - MD5Digester digester; + Digester digester; if (dynamic_pointer_cast (_in)) { shared_ptr tf = dynamic_pointer_cast (_in); @@ -211,8 +231,11 @@ ColourConversion::identifier () const digester.add (_adjusted_white.get().y); } - digester.add (dynamic_pointer_cast (_out)->gamma ()); - + shared_ptr gf = dynamic_pointer_cast (_out); + if (gf) { + digester.add (gf->gamma ()); + } + return digester.get (); } @@ -262,6 +285,9 @@ PresetColourConversion::setup_colour_conversion_presets () _presets.push_back (PresetColourConversion (_("Rec. 601"), "rec601", dcp::ColourConversion::rec601_to_xyz ())); _presets.push_back (PresetColourConversion (_("Rec. 709"), "rec709", dcp::ColourConversion::rec709_to_xyz ())); _presets.push_back (PresetColourConversion (_("P3"), "p3", dcp::ColourConversion::p3_to_xyz ())); + _presets.push_back (PresetColourConversion (_("Rec. 1886"), "rec1886", dcp::ColourConversion::rec1886_to_xyz ())); + _presets.push_back (PresetColourConversion (_("Rec. 2020"), "rec2020", dcp::ColourConversion::rec2020_to_xyz ())); + _presets.push_back (PresetColourConversion (_("S-Gamut3/S-Log3"), "sgamut3", dcp::ColourConversion::s_gamut3_to_xyz ())); } PresetColourConversion @@ -275,4 +301,3 @@ PresetColourConversion::from_id (string s) DCPOMATIC_ASSERT (false); } -