2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "dcp_reader.h"
21 #include "vertical_reference.h"
23 #include <libcxml/cxml.h>
24 #include <dcp/interop_subtitle_content.h>
25 #include <dcp/smpte_subtitle_content.h>
26 #include <dcp/subtitle.h>
30 using boost::shared_ptr;
34 dcp_to_metric (dcp::Time t)
36 return MetricTime (t.h, t.m, t.s, t.e * 1000 / t.tcr);
40 dcp_to_colour (dcp::Colour c)
42 return Colour (float (c.r) / 255, float (c.g) / 255, float (c.b) / 255);
46 * @brief A class to read DCP subtitles.
48 DCPReader::DCPReader (boost::filesystem::path file, bool interop)
50 shared_ptr<dcp::SubtitleContent> content;
52 content.reset (new dcp::InteropSubtitleContent (file));
54 content.reset (new dcp::SMPTESubtitleContent (file));
57 list<dcp::SubtitleString> subs = content->subtitles ();
58 for (list<dcp::SubtitleString>::const_iterator i = subs.begin(); i != subs.end(); ++i) {
61 sub.vertical_position.proportional = float (i->v_position ()) / 100;
62 switch (i->v_align ()) {
64 sub.vertical_position.reference = TOP_OF_SCREEN;
67 sub.vertical_position.reference = CENTRE_OF_SCREEN;
70 sub.vertical_position.reference = BOTTOM_OF_SCREEN;
74 sub.from.set_metric (dcp_to_metric (i->in ()));
75 sub.to.set_metric (dcp_to_metric (i->out ()));
76 sub.fade_up = dcp_to_metric (i->fade_up_time ());
77 sub.fade_down = dcp_to_metric (i->fade_down_time ());
79 sub.text = i->text ();
80 /* XXX: should sub.font be optional? */
81 sub.font = i->font().get_value_or ("");
82 sub.font_size.set_proportional (float (i->size ()) / (72 * 11));
83 switch (i->effect ()) {
94 sub.effect_colour = dcp_to_colour (i->effect_colour ());
95 sub.colour = dcp_to_colour (i->colour ());
96 sub.italic = i->italic ();
98 _subs.push_back (sub);