Extract common code out into kdm_for_screen()
[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 <dcp/raw_convert.h>
23 #include <libxml++/libxml++.h>
24 #include <boost/foreach.hpp>
25 #include <iostream>
26
27 using std::string;
28 using std::map;
29 using std::list;
30 using std::cout;
31 using std::make_pair;
32 using dcp::raw_convert;
33
34 /** Construct a SubtitleStream from a value returned from to_string().
35  *  @param node String returned from to_string().
36  *  @param version State file version.
37  */
38 FFmpegSubtitleStream::FFmpegSubtitleStream (cxml::ConstNodePtr node, int version)
39         : FFmpegStream (node)
40 {
41         if (version >= 33) {
42                 boost::mutex::scoped_lock lm (_mutex);
43                 BOOST_FOREACH (cxml::NodePtr i, node->node_children ("Colour")) {
44                         _colours[RGBA(i->node_child("From"))] = RGBA (i->node_child("To"));
45                 }
46         }
47 }
48
49 void
50 FFmpegSubtitleStream::as_xml (xmlpp::Node* root) const
51 {
52         FFmpegStream::as_xml (root);
53
54         boost::mutex::scoped_lock lm (_mutex);
55         for (map<RGBA, RGBA>::const_iterator i = _colours.begin(); i != _colours.end(); ++i) {
56                 xmlpp::Node* node = root->add_child("Colour");
57                 i->first.as_xml (node->add_child("From"));
58                 i->second.as_xml (node->add_child("To"));
59         }
60 }
61
62 map<RGBA, RGBA>
63 FFmpegSubtitleStream::colours () const
64 {
65         boost::mutex::scoped_lock lm (_mutex);
66         return _colours;
67 }
68
69 void
70 FFmpegSubtitleStream::set_colour (RGBA from, RGBA to)
71 {
72         boost::mutex::scoped_lock lm (_mutex);
73         _colours[from] = to;
74 }