From 819590f9f8217235ebf4467b1d24e1aec1f97c29 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 24 Oct 2014 22:34:45 +0100 Subject: Add basics of colourspace conversion bypass (#266). --- src/lib/colour_conversion.cc | 10 +++++++++ src/lib/colour_conversion.h | 2 ++ src/lib/dcp_video_frame.cc | 47 +++++++++++++++++++++++++------------------ src/lib/player_video_frame.cc | 8 +++++--- src/lib/player_video_frame.h | 6 +++--- src/lib/video_content.cc | 38 +++++++++++++++++++++++++--------- src/lib/video_content.h | 8 ++++---- 7 files changed, 79 insertions(+), 40 deletions(-) (limited to 'src/lib') diff --git a/src/lib/colour_conversion.cc b/src/lib/colour_conversion.cc index e5b1104ff..daf890aea 100644 --- a/src/lib/colour_conversion.cc +++ b/src/lib/colour_conversion.cc @@ -84,6 +84,16 @@ ColourConversion::ColourConversion (cxml::NodePtr node) output_gamma = node->number_child ("OutputGamma"); } +boost::optional +ColourConversion::from_xml (cxml::NodePtr node) +{ + if (!node->optional_node_child ("InputGamma")) { + return boost::optional (); + } + + return ColourConversion (node); +} + void ColourConversion::as_xml (xmlpp::Node* node) const { diff --git a/src/lib/colour_conversion.h b/src/lib/colour_conversion.h index fa1a955e1..706e51fe8 100644 --- a/src/lib/colour_conversion.h +++ b/src/lib/colour_conversion.h @@ -46,6 +46,8 @@ public: boost::optional preset () const; + static boost::optional from_xml (cxml::NodePtr); + double input_gamma; bool input_gamma_linearised; boost::numeric::ublas::matrix matrix; diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc index fac247aeb..e3a9fcc11 100644 --- a/src/lib/dcp_video_frame.cc +++ b/src/lib/dcp_video_frame.cc @@ -108,29 +108,36 @@ DCPVideoFrame::DCPVideoFrame (shared_ptr frame, shared_p shared_ptr DCPVideoFrame::encode_locally () { - shared_ptr in_lut; - if (_frame->colour_conversion().input_gamma_linearised) { - in_lut = libdcp::SRGBLinearisedGammaLUT::cache.get (12, _frame->colour_conversion().input_gamma); - } else { - in_lut = libdcp::GammaLUT::cache.get (12, _frame->colour_conversion().input_gamma); - } - - /* XXX: libdcp should probably use boost */ - - double matrix[3][3]; - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 3; ++j) { - matrix[i][j] = _frame->colour_conversion().matrix (i, j); + shared_ptr xyz; + + if (_frame->colour_conversion()) { + ColourConversion conversion = _frame->colour_conversion().get (); + shared_ptr in_lut; + if (conversion.input_gamma_linearised) { + in_lut = libdcp::SRGBLinearisedGammaLUT::cache.get (12, conversion.input_gamma); + } else { + in_lut = libdcp::GammaLUT::cache.get (12, conversion.input_gamma); + } + + /* XXX: libdcp should probably use boost */ + + double matrix[3][3]; + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + matrix[i][j] = conversion.matrix (i, j); + } } + + xyz = libdcp::rgb_to_xyz ( + _frame->image(AV_PIX_FMT_RGB48LE), + in_lut, + libdcp::GammaLUT::cache.get (16, 1 / conversion.output_gamma), + matrix + ); + } else { + xyz = libdcp::xyz_to_xyz (_frame->image (AV_PIX_FMT_RGB48LE)); } - shared_ptr xyz = libdcp::rgb_to_xyz ( - _frame->image(AV_PIX_FMT_RGB48LE), - in_lut, - libdcp::GammaLUT::cache.get (16, 1 / _frame->colour_conversion().output_gamma), - matrix - ); - /* Set the max image and component sizes based on frame_rate */ int max_cs_len = ((float) _j2k_bandwidth) / 8 / _frames_per_second; if (_frame->eyes() == EYES_LEFT || _frame->eyes() == EYES_RIGHT) { diff --git a/src/lib/player_video_frame.cc b/src/lib/player_video_frame.cc index 63ddc637b..771e0a912 100644 --- a/src/lib/player_video_frame.cc +++ b/src/lib/player_video_frame.cc @@ -36,7 +36,7 @@ PlayerVideoFrame::PlayerVideoFrame ( Scaler const * scaler, Eyes eyes, Part part, - ColourConversion colour_conversion + boost::optional colour_conversion ) : _in (in) , _crop (crop) @@ -59,7 +59,7 @@ PlayerVideoFrame::PlayerVideoFrame (shared_ptr node, shared_ptrstring_child ("Scaler")); _eyes = (Eyes) node->number_child ("Eyes"); _part = (Part) node->number_child ("Part"); - _colour_conversion = ColourConversion (node); + _colour_conversion = ColourConversion::from_xml (node); _in = image_proxy_factory (node->node_child ("In"), socket, log); @@ -129,7 +129,9 @@ PlayerVideoFrame::add_metadata (xmlpp::Node* node) const node->add_child("Scaler")->add_child_text (_scaler->id ()); node->add_child("Eyes")->add_child_text (raw_convert (_eyes)); node->add_child("Part")->add_child_text (raw_convert (_part)); - _colour_conversion.as_xml (node); + if (_colour_conversion) { + _colour_conversion.get().as_xml (node); + } if (_subtitle_image) { node->add_child ("SubtitleWidth")->add_child_text (raw_convert (_subtitle_image->size().width)); node->add_child ("SubtitleHeight")->add_child_text (raw_convert (_subtitle_image->size().height)); diff --git a/src/lib/player_video_frame.h b/src/lib/player_video_frame.h index 6a6868292..6b123c6e1 100644 --- a/src/lib/player_video_frame.h +++ b/src/lib/player_video_frame.h @@ -38,7 +38,7 @@ class Log; class PlayerVideoFrame { public: - PlayerVideoFrame (boost::shared_ptr, Crop, libdcp::Size, libdcp::Size, Scaler const *, Eyes, Part, ColourConversion); + PlayerVideoFrame (boost::shared_ptr, Crop, libdcp::Size, libdcp::Size, Scaler const *, Eyes, Part, boost::optional); PlayerVideoFrame (boost::shared_ptr, boost::shared_ptr, boost::shared_ptr); void set_subtitle (boost::shared_ptr, Position); @@ -52,7 +52,7 @@ public: return _eyes; } - ColourConversion colour_conversion () const { + boost::optional colour_conversion () const { return _colour_conversion; } @@ -64,7 +64,7 @@ private: Scaler const * _scaler; Eyes _eyes; Part _part; - ColourConversion _colour_conversion; + boost::optional _colour_conversion; boost::shared_ptr _subtitle_image; Position _subtitle_position; }; diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 13f2cf516..3094a70c8 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -61,7 +61,7 @@ VideoContent::VideoContent (shared_ptr f) , _video_frame_type (VIDEO_FRAME_TYPE_2D) , _scale (Config::instance()->default_scale ()) { - setup_default_colour_conversion (); + set_default_colour_conversion (); } VideoContent::VideoContent (shared_ptr f, Time s, VideoContent::Frame len) @@ -72,7 +72,7 @@ VideoContent::VideoContent (shared_ptr f, Time s, VideoContent::Fram , _video_frame_type (VIDEO_FRAME_TYPE_2D) , _scale (Config::instance()->default_scale ()) { - setup_default_colour_conversion (); + set_default_colour_conversion (); } VideoContent::VideoContent (shared_ptr f, boost::filesystem::path p) @@ -83,7 +83,7 @@ VideoContent::VideoContent (shared_ptr f, boost::filesystem::path p) , _video_frame_type (VIDEO_FRAME_TYPE_2D) , _scale (Config::instance()->default_scale ()) { - setup_default_colour_conversion (); + set_default_colour_conversion (); } VideoContent::VideoContent (shared_ptr f, shared_ptr node, int version) @@ -108,8 +108,10 @@ VideoContent::VideoContent (shared_ptr f, shared_ptrnode_child ("Scale")); } - - _colour_conversion = ColourConversion (node->node_child ("ColourConversion")); + + if (node->optional_node_child ("ColourConversion")) { + _colour_conversion = ColourConversion (node->node_child ("ColourConversion")); + } } VideoContent::VideoContent (shared_ptr f, vector > c) @@ -170,13 +172,15 @@ VideoContent::as_xml (xmlpp::Node* node) const node->add_child("VideoFrameType")->add_child_text (raw_convert (static_cast (_video_frame_type))); _crop.as_xml (node); _scale.as_xml (node->add_child("Scale")); - _colour_conversion.as_xml (node->add_child("ColourConversion")); + if (_colour_conversion) { + _colour_conversion.get().as_xml (node->add_child("ColourConversion")); + } } void -VideoContent::setup_default_colour_conversion () +VideoContent::set_default_colour_conversion () { - _colour_conversion = PresetColourConversion (_("sRGB"), 2.4, true, libdcp::colour_matrix::srgb_to_xyz, 2.6).conversion; + set_colour_conversion (PresetColourConversion (_("sRGB"), 2.4, true, libdcp::colour_matrix::srgb_to_xyz, 2.6).conversion); } void @@ -303,8 +307,11 @@ VideoContent::identifier () const << "_" << crop().right << "_" << crop().top << "_" << crop().bottom - << "_" << scale().id() - << "_" << colour_conversion().identifier (); + << "_" << scale().id(); + + if (colour_conversion()) { + s << "_" << colour_conversion().get().identifier (); + } return s.str (); } @@ -348,6 +355,17 @@ VideoContent::video_size_after_3d_split () const assert (false); } +void +VideoContent::unset_colour_conversion () +{ + { + boost::mutex::scoped_lock lm (_mutex); + _colour_conversion = boost::optional (); + } + + signal_changed (VideoContentProperty::COLOUR_CONVERSION); +} + void VideoContent::set_colour_conversion (ColourConversion c) { diff --git a/src/lib/video_content.h b/src/lib/video_content.h index 3a7b44306..9aa3be521 100644 --- a/src/lib/video_content.h +++ b/src/lib/video_content.h @@ -92,7 +92,9 @@ public: void set_bottom_crop (int); void set_scale (VideoContentScale); + void unset_colour_conversion (); void set_colour_conversion (ColourConversion); + void set_default_colour_conversion (); VideoFrameType video_frame_type () const { boost::mutex::scoped_lock lm (_mutex); @@ -130,7 +132,7 @@ public: return _scale; } - ColourConversion colour_conversion () const { + boost::optional colour_conversion () const { boost::mutex::scoped_lock lm (_mutex); return _colour_conversion; } @@ -156,13 +158,11 @@ private: friend class best_dcp_frame_rate_test_double; friend class audio_sampling_rate_test; - void setup_default_colour_conversion (); - libdcp::Size _video_size; VideoFrameType _video_frame_type; Crop _crop; VideoContentScale _scale; - ColourConversion _colour_conversion; + boost::optional _colour_conversion; }; #endif -- cgit v1.2.3