From 10818d95000c291af776ed9ba1c847257ded4b1f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 12 Jan 2018 12:48:50 +0000 Subject: Note whether subtitle colour is forced or not. --- src/lib/subtitle_content.cc | 36 +++++++++++++++++++++++++----------- src/lib/subtitle_content.h | 7 ++++--- src/lib/subtitle_decoder.cc | 6 ++++-- 3 files changed, 33 insertions(+), 16 deletions(-) (limited to 'src/lib') diff --git a/src/lib/subtitle_content.cc b/src/lib/subtitle_content.cc index 55493039c..b169cfb69 100644 --- a/src/lib/subtitle_content.cc +++ b/src/lib/subtitle_content.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2016 Carl Hetherington + Copyright (C) 2013-2018 Carl Hetherington This file is part of DCP-o-matic. @@ -37,6 +37,7 @@ using std::cout; using std::list; using boost::shared_ptr; using boost::dynamic_pointer_cast; +using boost::optional; using dcp::raw_convert; int const SubtitleContentProperty::X_OFFSET = 500; @@ -64,7 +65,6 @@ SubtitleContent::SubtitleContent (Content* parent) , _y_offset (0) , _x_scale (1) , _y_scale (1) - , _colour (255, 255, 255) , _outline (false) , _shadow (false) , _effect_colour (0, 0, 0) @@ -103,11 +103,6 @@ SubtitleContent::SubtitleContent (Content* parent, cxml::ConstNodePtr node, int , _y_offset (0) , _x_scale (1) , _y_scale (1) - , _colour ( - node->optional_number_child("Red").get_value_or(255), - node->optional_number_child("Green").get_value_or(255), - node->optional_number_child("Blue").get_value_or(255) - ) , _outline (node->optional_bool_child("Outline").get_value_or(false)) , _shadow (node->optional_bool_child("Shadow").get_value_or(false)) , _line_spacing (node->optional_number_child("LineSpacing").get_value_or (1)) @@ -134,6 +129,13 @@ SubtitleContent::SubtitleContent (Content* parent, cxml::ConstNodePtr node, int _x_scale = _y_scale = node->number_child ("SubtitleScale"); } + optional r = node->optional_number_child("Red"); + optional g = node->optional_number_child("Green"); + optional b = node->optional_number_child("Blue"); + if (r && g && b) { + _colour = dcp::Colour (*r, *g, *b); + } + if (version >= 36) { _effect_colour = dcp::Colour ( node->optional_number_child("EffectRed").get_value_or(255), @@ -249,9 +251,11 @@ SubtitleContent::as_xml (xmlpp::Node* root) const root->add_child("SubtitleXScale")->add_child_text (raw_convert (_x_scale)); root->add_child("SubtitleYScale")->add_child_text (raw_convert (_y_scale)); root->add_child("SubtitleLanguage")->add_child_text (_language); - root->add_child("Red")->add_child_text (raw_convert (_colour.r)); - root->add_child("Green")->add_child_text (raw_convert (_colour.g)); - root->add_child("Blue")->add_child_text (raw_convert (_colour.b)); + if (_colour) { + root->add_child("Red")->add_child_text (raw_convert (_colour->r)); + root->add_child("Green")->add_child_text (raw_convert (_colour->g)); + root->add_child("Blue")->add_child_text (raw_convert (_colour->b)); + } root->add_child("Outline")->add_child_text (_outline ? "1" : "0"); root->add_child("Shadow")->add_child_text (_shadow ? "1" : "0"); root->add_child("EffectRed")->add_child_text (raw_convert (_effect_colour.r)); @@ -328,6 +332,12 @@ SubtitleContent::set_colour (dcp::Colour colour) maybe_set (_colour, colour, SubtitleContentProperty::COLOUR); } +void +SubtitleContent::unset_colour () +{ + maybe_set (_colour, optional(), SubtitleContentProperty::COLOUR); +} + void SubtitleContent::set_outline (bool o) { @@ -422,7 +432,11 @@ SubtitleContent::take_settings_from (shared_ptr c) set_x_scale (c->_x_scale); set_y_scale (c->_y_scale); maybe_set (_fonts, c->_fonts, SubtitleContentProperty::FONTS); - set_colour (c->_colour); + if (c->_colour) { + set_colour (*c->_colour); + } else { + unset_colour (); + } set_outline (c->_outline); set_shadow (c->_shadow); set_effect_colour (c->_effect_colour); diff --git a/src/lib/subtitle_content.h b/src/lib/subtitle_content.h index 2fc6d0fd6..b07182406 100644 --- a/src/lib/subtitle_content.h +++ b/src/lib/subtitle_content.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2016 Carl Hetherington + Copyright (C) 2013-2018 Carl Hetherington This file is part of DCP-o-matic. @@ -75,6 +75,7 @@ public: void set_y_scale (double); void set_language (std::string language); void set_colour (dcp::Colour); + void unset_colour (); void set_outline (bool); void set_shadow (bool); void set_effect_colour (dcp::Colour); @@ -123,7 +124,7 @@ public: return _language; } - dcp::Colour colour () const { + boost::optional colour () const { boost::mutex::scoped_lock lm (_mutex); return _colour; } @@ -193,7 +194,7 @@ private: /** y scale factor to apply to subtitles */ double _y_scale; std::list > _fonts; - dcp::Colour _colour; + boost::optional _colour; bool _outline; bool _shadow; dcp::Colour _effect_colour; diff --git a/src/lib/subtitle_decoder.cc b/src/lib/subtitle_decoder.cc index 3de097215..eecfce19d 100644 --- a/src/lib/subtitle_decoder.cc +++ b/src/lib/subtitle_decoder.cc @@ -75,8 +75,10 @@ SubtitleDecoder::emit_text_start (ContentTime from, list s) boost::algorithm::replace_all (t, ">", ">"); i.set_text (t); - /* Force our configured appearance */ - i.set_colour (content()->colour()); + /* Set any forced appearance */ + if (content()->colour()) { + i.set_colour (*content()->colour()); + } i.set_effect_colour (content()->effect_colour()); if (content()->outline()) { i.set_effect (dcp::BORDER); -- cgit v1.2.3