Allow changes to colours of FFmpeg subtitles (#795).
[dcpomatic.git] / src / lib / ffmpeg_subtitle_stream.cc
index 33759d86e544f348fc374238fc1cc741e2508033..eca3fda6fcac490b4bfe8ff6bb67fe6bffb2b4c6 100644 (file)
@@ -27,6 +27,7 @@ using std::string;
 using std::map;
 using std::list;
 using std::cout;
+using std::make_pair;
 
 /** Construct a SubtitleStream from a value returned from to_string().
  *  @param t String returned from to_string().
@@ -82,6 +83,10 @@ FFmpegSubtitleStream::FFmpegSubtitleStream (cxml::ConstNodePtr node, int version
                                        )
                                );
                }
+
+               BOOST_FOREACH (cxml::NodePtr i, node->node_children ("Colour")) {
+                       _colours[RGBA(i->node_child("From"))] = RGBA (i->node_child("To"));
+               }
        }
 }
 
@@ -92,6 +97,12 @@ FFmpegSubtitleStream::as_xml (xmlpp::Node* root) const
 
        as_xml (root, _image_subtitles, "ImageSubtitle");
        as_xml (root, _text_subtitles, "TextSubtitle");
+
+       for (map<RGBA, RGBA>::const_iterator i = _colours.begin(); i != _colours.end(); ++i) {
+               xmlpp::Node* node = root->add_child("Colour");
+               i->first.as_xml (node->add_child("From"));
+               i->second.as_xml (node->add_child("To"));
+       }
 }
 
 void
@@ -173,3 +184,15 @@ FFmpegSubtitleStream::add_offset (ContentTime offset)
                i->second.to += offset;
        }
 }
+
+map<RGBA, RGBA>
+FFmpegSubtitleStream::colours () const
+{
+       return _colours;
+}
+
+void
+FFmpegSubtitleStream::set_colour (RGBA from, RGBA to)
+{
+       _colours[from] = to;
+}