Note whether subtitle colour is forced or not.
authorCarl Hetherington <cth@carlh.net>
Fri, 12 Jan 2018 12:48:50 +0000 (12:48 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 13 Jan 2018 00:06:28 +0000 (00:06 +0000)
src/lib/subtitle_content.cc
src/lib/subtitle_content.h
src/lib/subtitle_decoder.cc
src/wx/subtitle_appearance_dialog.cc
src/wx/subtitle_appearance_dialog.h

index 55493039ce728874d5e0405dd3fc63205f0520b4..b169cfb69beebd31a7e8a9ea0c4b46d2668db092 100644 (file)
@@ -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));
@@ -328,6 +332,12 @@ SubtitleContent::set_colour (dcp::Colour colour)
        maybe_set (_colour, colour, SubtitleContentProperty::COLOUR);
 }
 
+void
+SubtitleContent::unset_colour ()
+{
+       maybe_set (_colour, optional<dcp::Colour>(), SubtitleContentProperty::COLOUR);
+}
+
 void
 SubtitleContent::set_outline (bool o)
 {
@@ -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);
index 2fc6d0fd6f89d3b00ee03d4134df9055232c2de1..b071824069282fc997fe52cd1fce873e0c08c023 100644 (file)
@@ -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;
index 3de097215f6d0b2df51dbc33cbeadf5d15a0016f..eecfce19dde7f05a65fcee9200eab9f4536317cf 100644 (file)
@@ -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);
index 2f9b4760c67faf9006d751ea41d45097ac668f67..c72ef773625fa7eb96e7797678197365f1622dac 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2015-2017 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2015-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -33,6 +33,7 @@ using std::map;
 using boost::shared_ptr;
 using boost::bind;
 using boost::dynamic_pointer_cast;
+using boost::optional;
 
 int const SubtitleAppearanceDialog::NONE = 0;
 int const SubtitleAppearanceDialog::OUTLINE = 1;
@@ -57,8 +58,14 @@ SubtitleAppearanceDialog::SubtitleAppearanceDialog (wxWindow* parent, shared_ptr
        int r = 0;
 
        add_label_to_sizer (_table, this, _("Colour"), true, wxGBPosition (r, 0));
-       _colour = new wxColourPickerCtrl (this, wxID_ANY);
-       _table->Add (_colour, wxGBPosition (r, 1));
+       {
+               wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
+               _force_colour = new wxCheckBox (this, wxID_ANY, _("Set to"));
+               s->Add (_force_colour, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 8);
+               _colour = new wxColourPickerCtrl (this, wxID_ANY);
+               s->Add (_colour, 0, wxALIGN_CENTER_VERTICAL);
+               _table->Add (s, wxGBPosition (r, 1));
+       }
        ++r;
 
        add_label_to_sizer (_table, this, _("Effect"), true, wxGBPosition (r, 0));
@@ -135,7 +142,15 @@ SubtitleAppearanceDialog::SubtitleAppearanceDialog (wxWindow* parent, shared_ptr
        _effect->Append (_("Outline"));
        _effect->Append (_("Shadow"));;
 
-       _colour->SetColour (wxColour (_content->subtitle->colour().r, _content->subtitle->colour().g, _content->subtitle->colour().b));
+       optional<dcp::Colour> colour = _content->subtitle->colour();
+       if (colour) {
+               _force_colour->SetValue (true);
+               _colour->SetColour (wxColour (colour->r, colour->g, colour->b));
+       } else {
+               _force_colour->SetValue (false);
+               _colour->SetColour (wxColour (255, 255, 255));
+       }
+
        if (_content->subtitle->outline()) {
                _effect->SetSelection (OUTLINE);
        } else if (_content->subtitle->shadow()) {
@@ -150,6 +165,7 @@ SubtitleAppearanceDialog::SubtitleAppearanceDialog (wxWindow* parent, shared_ptr
        _fade_out->set (_content->subtitle->fade_out(), _content->active_video_frame_rate ());
        _outline_width->SetValue (_content->subtitle->outline_width ());
 
+       _force_colour->Bind (wxEVT_CHECKBOX, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
        _effect->Bind (wxEVT_CHOICE, bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
        _content_connection = _content->Changed.connect (bind (&SubtitleAppearanceDialog::setup_sensitivity, this));
 
@@ -159,8 +175,12 @@ SubtitleAppearanceDialog::SubtitleAppearanceDialog (wxWindow* parent, shared_ptr
 void
 SubtitleAppearanceDialog::apply ()
 {
-       wxColour const c = _colour->GetColour ();
-       _content->subtitle->set_colour (dcp::Colour (c.Red(), c.Green(), c.Blue()));
+       if (_force_colour->GetValue ()) {
+               wxColour const c = _colour->GetColour ();
+               _content->subtitle->set_colour (dcp::Colour (c.Red(), c.Green(), c.Blue()));
+       } else {
+               _content->subtitle->unset_colour ();
+       }
        _content->subtitle->set_outline (_effect->GetSelection() == OUTLINE);
        _content->subtitle->set_shadow (_effect->GetSelection() == SHADOW);
        wxColour const ec = _effect_colour->GetColour ();
@@ -192,6 +212,7 @@ SubtitleAppearanceDialog::restore ()
 void
 SubtitleAppearanceDialog::setup_sensitivity ()
 {
+       _colour->Enable (_force_colour->GetValue ());
        _effect_colour->Enable (_effect->GetSelection() != NONE);
 
        bool const can_outline_width = _effect->GetSelection() == OUTLINE && _content->subtitle->burn ();
index 2e007e57ba6a9b3a3ffdfcf91a4b36430fcc55a8..8d36d4da83e27bb99f266959bacc0d7fa2b97e85 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2015-2017 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2015-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -42,6 +42,7 @@ private:
        void setup_sensitivity ();
        void restore ();
 
+       wxCheckBox* _force_colour;
        wxColourPickerCtrl* _colour;
        wxChoice* _effect;
        wxColourPickerCtrl* _effect_colour;