diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-10-24 22:34:45 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-10-24 22:34:45 +0100 |
| commit | 819590f9f8217235ebf4467b1d24e1aec1f97c29 (patch) | |
| tree | f493c7f715e646a332431a510eff58e09b0a9d59 /src/lib | |
| parent | 360f49fad409d1e37318ffcf3069c4111c19c7b8 (diff) | |
Add basics of colourspace conversion bypass (#266).
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/colour_conversion.cc | 10 | ||||
| -rw-r--r-- | src/lib/colour_conversion.h | 2 | ||||
| -rw-r--r-- | src/lib/dcp_video_frame.cc | 47 | ||||
| -rw-r--r-- | src/lib/player_video_frame.cc | 8 | ||||
| -rw-r--r-- | src/lib/player_video_frame.h | 6 | ||||
| -rw-r--r-- | src/lib/video_content.cc | 38 | ||||
| -rw-r--r-- | src/lib/video_content.h | 8 |
7 files changed, 79 insertions, 40 deletions
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<double> ("OutputGamma"); } +boost::optional<ColourConversion> +ColourConversion::from_xml (cxml::NodePtr node) +{ + if (!node->optional_node_child ("InputGamma")) { + return boost::optional<ColourConversion> (); + } + + 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<size_t> preset () const; + static boost::optional<ColourConversion> from_xml (cxml::NodePtr); + double input_gamma; bool input_gamma_linearised; boost::numeric::ublas::matrix<double> 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<const PlayerVideoFrame> frame, shared_p shared_ptr<EncodedData> DCPVideoFrame::encode_locally () { - shared_ptr<libdcp::LUT> 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<libdcp::XYZFrame> xyz; + + if (_frame->colour_conversion()) { + ColourConversion conversion = _frame->colour_conversion().get (); + shared_ptr<libdcp::LUT> 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<libdcp::XYZFrame> 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<ColourConversion> colour_conversion ) : _in (in) , _crop (crop) @@ -59,7 +59,7 @@ PlayerVideoFrame::PlayerVideoFrame (shared_ptr<cxml::Node> node, shared_ptr<Sock _scaler = Scaler::from_id (node->string_child ("Scaler")); _eyes = (Eyes) node->number_child<int> ("Eyes"); _part = (Part) node->number_child<int> ("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<string> (_eyes)); node->add_child("Part")->add_child_text (raw_convert<string> (_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<string> (_subtitle_image->size().width)); node->add_child ("SubtitleHeight")->add_child_text (raw_convert<string> (_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<const ImageProxy>, Crop, libdcp::Size, libdcp::Size, Scaler const *, Eyes, Part, ColourConversion); + PlayerVideoFrame (boost::shared_ptr<const ImageProxy>, Crop, libdcp::Size, libdcp::Size, Scaler const *, Eyes, Part, boost::optional<ColourConversion>); PlayerVideoFrame (boost::shared_ptr<cxml::Node>, boost::shared_ptr<Socket>, boost::shared_ptr<Log>); void set_subtitle (boost::shared_ptr<const Image>, Position<int>); @@ -52,7 +52,7 @@ public: return _eyes; } - ColourConversion colour_conversion () const { + boost::optional<ColourConversion> colour_conversion () const { return _colour_conversion; } @@ -64,7 +64,7 @@ private: Scaler const * _scaler; Eyes _eyes; Part _part; - ColourConversion _colour_conversion; + boost::optional<ColourConversion> _colour_conversion; boost::shared_ptr<const Image> _subtitle_image; Position<int> _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<const Film> 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<const Film> f, Time s, VideoContent::Frame len) @@ -72,7 +72,7 @@ VideoContent::VideoContent (shared_ptr<const Film> 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<const Film> f, boost::filesystem::path p) @@ -83,7 +83,7 @@ VideoContent::VideoContent (shared_ptr<const Film> 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<const Film> f, shared_ptr<const cxml::Node> node, int version) @@ -108,8 +108,10 @@ VideoContent::VideoContent (shared_ptr<const Film> f, shared_ptr<const cxml::Nod } else { _scale = VideoContentScale (node->node_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<const Film> f, vector<shared_ptr<Content> > c) @@ -170,13 +172,15 @@ VideoContent::as_xml (xmlpp::Node* node) const node->add_child("VideoFrameType")->add_child_text (raw_convert<string> (static_cast<int> (_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 (); } @@ -349,6 +356,17 @@ VideoContent::video_size_after_3d_split () const } void +VideoContent::unset_colour_conversion () +{ + { + boost::mutex::scoped_lock lm (_mutex); + _colour_conversion = boost::optional<ColourConversion> (); + } + + 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<ColourConversion> 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<ColourConversion> _colour_conversion; }; #endif |
