2 Copyright (C) 2014-2017 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 "compose.hpp"
22 #include "exceptions.h"
23 #include <dcp/subtitle_string.h>
24 #include <dcp/interop_subtitle_asset.h>
25 #include <dcp/smpte_subtitle_asset.h>
26 #include <boost/foreach.hpp>
27 #include <boost/filesystem.hpp>
33 using boost::shared_ptr;
34 using boost::optional;
38 dcp_to_sub_time (dcp::Time t)
40 return Time::from_hms (t.h, t.m, t.s, t.e * 1000.0 / t.tcr);
44 dcp_to_sub_colour (dcp::Colour c)
46 return Colour (c.r / 255.0, c.g / 255.0, c.b / 255.0);
49 DCPReader::DCPReader (boost::filesystem::path file)
51 shared_ptr<dcp::SubtitleAsset> sc;
56 sc.reset (new dcp::InteropSubtitleAsset (file));
57 } catch (exception& e) {
58 interop_error = e.what ();
63 sc.reset (new dcp::SMPTESubtitleAsset (file));
64 } catch (exception& e) {
65 smpte_error = e.what();
70 throw DCPError (String::compose ("Could not read subtitles (%1 / %2)", interop_error, smpte_error));
74 BOOST_FOREACH (dcp::SubtitleString const & i, sc->subtitles ()) {
78 rs.font_size = FontSize::from_proportional (i.size() / (72.0 * 11.0));
80 switch (i.effect ()) {
91 rs.effect_colour = dcp_to_sub_colour (i.effect_colour());
93 rs.colour = dcp_to_sub_colour (i.colour());
95 rs.italic = i.italic ();
96 rs.underline = i.underline ();
98 switch (i.h_align()) {
99 case dcp::HALIGN_LEFT:
100 rs.horizontal_position.reference = LEFT_OF_SCREEN;
102 case dcp::HALIGN_CENTER:
103 rs.horizontal_position.reference = HORIZONTAL_CENTRE_OF_SCREEN;
105 case dcp::HALIGN_RIGHT:
106 rs.horizontal_position.reference = RIGHT_OF_SCREEN;
110 rs.vertical_position.proportional = i.v_position();
111 switch (i.v_align()) {
112 case dcp::VALIGN_TOP:
113 rs.vertical_position.reference = TOP_OF_SCREEN;
115 case dcp::VALIGN_CENTER:
116 rs.vertical_position.reference = VERTICAL_CENTRE_OF_SCREEN;
118 case dcp::VALIGN_BOTTOM:
119 rs.vertical_position.reference = BOTTOM_OF_SCREEN;
123 rs.from = dcp_to_sub_time (i.in ());
124 rs.to = dcp_to_sub_time (i.out ());
126 rs.fade_up = dcp_to_sub_time (i.fade_up_time ());
127 rs.fade_down = dcp_to_sub_time (i.fade_down_time ());
129 _subs.push_back (rs);