72698fa51cc49b2a947abde2fedf87ed2d461cd8
[dcpomatic.git] / src / lib / ffmpeg_subtitle_stream.cc
1 /*
2     Copyright (C) 2013-2017 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "ffmpeg_subtitle_stream.h"
22 #include "warnings.h"
23 #include <dcp/raw_convert.h>
24 DCPOMATIC_DISABLE_WARNINGS
25 #include <libxml++/libxml++.h>
26 DCPOMATIC_ENABLE_WARNINGS
27 #include <boost/foreach.hpp>
28 #include <iostream>
29
30 using std::string;
31 using std::map;
32 using std::list;
33 using std::cout;
34 using std::make_pair;
35 using dcp::raw_convert;
36
37 /** Construct a SubtitleStream from a value returned from to_string().
38  *  @param node String returned from to_string().
39  *  @param version State file version.
40  */
41 FFmpegSubtitleStream::FFmpegSubtitleStream (cxml::ConstNodePtr node, int version)
42         : FFmpegStream (node)
43 {
44         if (version >= 33) {
45                 boost::mutex::scoped_lock lm (_mutex);
46                 BOOST_FOREACH (cxml::NodePtr i, node->node_children ("Colour")) {
47                         _colours[RGBA(i->node_child("From"))] = RGBA (i->node_child("To"));
48                 }
49         }
50 }
51
52 void
53 FFmpegSubtitleStream::as_xml (xmlpp::Node* root) const
54 {
55         FFmpegStream::as_xml (root);
56
57         boost::mutex::scoped_lock lm (_mutex);
58         for (map<RGBA, RGBA>::const_iterator i = _colours.begin(); i != _colours.end(); ++i) {
59                 xmlpp::Node* node = root->add_child("Colour");
60                 i->first.as_xml (node->add_child("From"));
61                 i->second.as_xml (node->add_child("To"));
62         }
63 }
64
65 map<RGBA, RGBA>
66 FFmpegSubtitleStream::colours () const
67 {
68         boost::mutex::scoped_lock lm (_mutex);
69         return _colours;
70 }
71
72 void
73 FFmpegSubtitleStream::set_colour (RGBA from, RGBA to)
74 {
75         boost::mutex::scoped_lock lm (_mutex);
76         _colours[from] = to;
77 }