summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-01-12 12:48:50 +0000
committerCarl Hetherington <cth@carlh.net>2018-01-13 00:06:28 +0000
commit10818d95000c291af776ed9ba1c847257ded4b1f (patch)
treeaa22b0c81dc0af1d30b8df952e876b7f2353522c /src/lib
parent199ac062ed945192f2909bd4fbaa629d57a256c9 (diff)
Note whether subtitle colour is forced or not.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/subtitle_content.cc36
-rw-r--r--src/lib/subtitle_content.h7
-rw-r--r--src/lib/subtitle_decoder.cc6
3 files changed, 33 insertions, 16 deletions
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 <cth@carlh.net>
+ Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
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<int>("Red").get_value_or(255),
- node->optional_number_child<int>("Green").get_value_or(255),
- node->optional_number_child<int>("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<double>("LineSpacing").get_value_or (1))
@@ -134,6 +129,13 @@ SubtitleContent::SubtitleContent (Content* parent, cxml::ConstNodePtr node, int
_x_scale = _y_scale = node->number_child<double> ("SubtitleScale");
}
+ optional<int> r = node->optional_number_child<int>("Red");
+ optional<int> g = node->optional_number_child<int>("Green");
+ optional<int> b = node->optional_number_child<int>("Blue");
+ if (r && g && b) {
+ _colour = dcp::Colour (*r, *g, *b);
+ }
+
if (version >= 36) {
_effect_colour = dcp::Colour (
node->optional_number_child<int>("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<string> (_x_scale));
root->add_child("SubtitleYScale")->add_child_text (raw_convert<string> (_y_scale));
root->add_child("SubtitleLanguage")->add_child_text (_language);
- root->add_child("Red")->add_child_text (raw_convert<string> (_colour.r));
- root->add_child("Green")->add_child_text (raw_convert<string> (_colour.g));
- root->add_child("Blue")->add_child_text (raw_convert<string> (_colour.b));
+ if (_colour) {
+ root->add_child("Red")->add_child_text (raw_convert<string> (_colour->r));
+ root->add_child("Green")->add_child_text (raw_convert<string> (_colour->g));
+ root->add_child("Blue")->add_child_text (raw_convert<string> (_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<string> (_effect_colour.r));
@@ -329,6 +333,12 @@ SubtitleContent::set_colour (dcp::Colour colour)
}
void
+SubtitleContent::unset_colour ()
+{
+ maybe_set (_colour, optional<dcp::Colour>(), SubtitleContentProperty::COLOUR);
+}
+
+void
SubtitleContent::set_outline (bool o)
{
maybe_set (_outline, o, SubtitleContentProperty::OUTLINE);
@@ -422,7 +432,11 @@ SubtitleContent::take_settings_from (shared_ptr<const SubtitleContent> 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 <cth@carlh.net>
+ Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
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<dcp::Colour> 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<boost::shared_ptr<Font> > _fonts;
- dcp::Colour _colour;
+ boost::optional<dcp::Colour> _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<dcp::SubtitleString> s)
boost::algorithm::replace_all (t, ">", "&gt;");
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);