summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-01-12 21:06:29 +0000
committerCarl Hetherington <cth@carlh.net>2015-01-12 21:06:29 +0000
commit68560d1e94ee311d7fbfcdf98a704decef232108 (patch)
tree2456ee37413e4b0b34a6ccfc783c4ed751c94be1 /src
parent670020792233d50b14363e54db6808733d5d2171 (diff)
Various fixes.
Diffstat (limited to 'src')
-rw-r--r--src/dcp/font.cc10
-rw-r--r--src/dcp/font.h2
-rw-r--r--src/dcp/subtitle.cc107
-rw-r--r--src/dcp/subtitle.h13
-rw-r--r--src/dcp/text.cc4
-rw-r--r--src/dcp/text.h2
-rw-r--r--src/dcp_reader.cc2
-rw-r--r--src/interop_dcp_reader.cc2
-rw-r--r--src/raw_subtitle.h2
-rw-r--r--src/smpte_dcp_reader.cc2
-rw-r--r--src/subtitle.h2
11 files changed, 97 insertions, 51 deletions
diff --git a/src/dcp/font.cc b/src/dcp/font.cc
index 6368703..26a02d9 100644
--- a/src/dcp/font.cc
+++ b/src/dcp/font.cc
@@ -28,7 +28,7 @@ using boost::shared_ptr;
using boost::optional;
using namespace sub;
-dcp::Font::Font (cxml::ConstNodePtr node, int tcr)
+dcp::Font::Font (cxml::ConstNodePtr node, bool smpte)
{
text = node->content ();
@@ -43,24 +43,24 @@ dcp::Font::Font (cxml::ConstNodePtr node, int tcr)
if (e) {
effect = string_to_effect (e.get ());
}
- c = node->optional_string_attribute ( "EffectColor");
+ c = node->optional_string_attribute ("EffectColor");
if (c) {
effect_colour = Colour (c.get ());
}
list<cxml::NodePtr> s = node->node_children ("Subtitle");
BOOST_FOREACH (cxml::NodePtr& i, s) {
- subtitle_nodes.push_back (shared_ptr<Subtitle> (new Subtitle (i, tcr)));
+ subtitle_nodes.push_back (shared_ptr<Subtitle> (new Subtitle (i, smpte)));
}
list<cxml::NodePtr> f = node->node_children ("Font");
BOOST_FOREACH (cxml::NodePtr& i, f) {
- font_nodes.push_back (shared_ptr<Font> (new Font (i, tcr)));
+ font_nodes.push_back (shared_ptr<Font> (new Font (i, smpte)));
}
list<cxml::NodePtr> t = node->node_children ("Text");
BOOST_FOREACH (cxml::NodePtr& i, t) {
- text_nodes.push_back (shared_ptr<Text> (new Text (i, tcr)));
+ text_nodes.push_back (shared_ptr<Text> (new Text (i, smpte)));
}
}
diff --git a/src/dcp/font.h b/src/dcp/font.h
index 2b4a5fc..564e365 100644
--- a/src/dcp/font.h
+++ b/src/dcp/font.h
@@ -42,7 +42,7 @@ public:
: size (0)
{}
- Font (cxml::ConstNodePtr node, int tcr);
+ Font (cxml::ConstNodePtr node, bool smpte);
Font (std::list<boost::shared_ptr<Font> > const & font_nodes);
std::string text;
diff --git a/src/dcp/subtitle.cc b/src/dcp/subtitle.cc
index 1b65475..20b8d6b 100644
--- a/src/dcp/subtitle.cc
+++ b/src/dcp/subtitle.cc
@@ -35,54 +35,99 @@ using boost::lexical_cast;
using boost::is_any_of;
using namespace sub;
-dcp::Subtitle::Subtitle (boost::shared_ptr<const cxml::Node> node, int tcr)
+dcp::Subtitle::Subtitle (boost::shared_ptr<const cxml::Node> node, bool smpte)
{
- in = time (node, "TimeIn");
- out = time (node, "TimeOut");
+ if (smpte) {
+ in = smpte_time (node, "TimeIn").get ();
+ out = smpte_time (node, "TimeOut").get ();
+ } else {
+ in = interop_time (node, "TimeIn").get ();
+ out = interop_time (node, "TimeOut").get ();
+ }
list<cxml::NodePtr> f = node->node_children ("Font");
for (list<cxml::NodePtr>::iterator i = f.begin(); i != f.end(); ++i) {
- font_nodes.push_back (shared_ptr<Font> (new Font (*i, tcr)));
+ font_nodes.push_back (shared_ptr<Font> (new Font (*i, smpte)));
}
list<cxml::NodePtr> t = node->node_children ("Text");
for (list<cxml::NodePtr>::iterator i = t.begin(); i != t.end(); ++i) {
- text_nodes.push_back (shared_ptr<Text> (new Text (*i, tcr)));
+ text_nodes.push_back (shared_ptr<Text> (new Text (*i, smpte)));
+ }
+
+ if (smpte) {
+ fade_up_time = smpte_time (node, "FadeUpTime").get_value_or (FrameTime (0, 0, 0, 2));
+ fade_down_time = smpte_time (node, "FadeDownTime").get_value_or (FrameTime (0, 0, 0, 2));
+ } else {
+ fade_up_time = interop_time (node, "FadeUpTime").get_value_or (MetricTime (0, 0, 0, 80));
+ if (fade_up_time.metric() > MetricTime (0, 0, 8, 0)) {
+ fade_up_time = MetricTime (0, 0, 8, 0);
+ }
+ fade_down_time = interop_time (node, "FadeDownTime").get_value_or (MetricTime (0, 0, 0, 80));
+ if (fade_down_time.metric() > MetricTime (0, 0, 8, 0)) {
+ fade_down_time = MetricTime (0, 0, 8, 0);
+ }
}
-
- fade_up_time = time (node, "FadeUpTime", FrameTime (0, 0, 8, 0));
- fade_down_time = time (node, "FadeDownTime", FrameTime (0, 0, 8, 0));
}
-FrameTime
-dcp::Subtitle::time (shared_ptr<const cxml::Node> node, string name, optional<FrameTime> maximum)
+optional<FrameTime>
+dcp::Subtitle::smpte_time (shared_ptr<const cxml::Node> node, string name)
{
- string const u = node->optional_string_attribute (name).get_value_or ("");
- FrameTime t;
+ optional<string> u = node->optional_string_attribute (name);
+ if (!u) {
+ return optional<FrameTime> ();
+ }
+
+ vector<string> b;
+ split (b, u.get (), is_any_of (":"));
+ if (b.size() != 4) {
+ boost::throw_exception (DCPError ("unrecognised time specification " + u.get ()));
+ }
- if (u.empty ()) {
- t = FrameTime (0, 0, 0, 2);
- } else if (u.find (":") != string::npos) {
+ return FrameTime (
+ raw_convert<int> (b[0]),
+ raw_convert<int> (b[1]),
+ raw_convert<int> (b[2]),
+ raw_convert<int> (b[3])
+ );
+}
+
+optional<MetricTime>
+dcp::Subtitle::interop_time (shared_ptr<const cxml::Node> node, string name)
+{
+ optional<string> u = node->optional_string_attribute (name);
+ if (!u) {
+ return optional<MetricTime> ();
+ }
+
+ MetricTime t;
+
+ if (u.get().find (":") != string::npos) {
+ /* HH:MM:SS:TTT or HH:MM:SS.sss */
vector<string> b;
- split (b, u, is_any_of (":"));
+ split (b, u.get(), is_any_of (":."));
if (b.size() != 4) {
- boost::throw_exception (DCPError ("unrecognised time specification " + u));
+ boost::throw_exception (DCPError ("unrecognised time specification " + u.get ()));
}
-
- t = FrameTime (
- raw_convert<int> (b[0]),
- raw_convert<int> (b[1]),
- raw_convert<int> (b[2]),
- raw_convert<int> (b[3])
- );
-
- } else {
- t = FrameTime (0, 0, 0, lexical_cast<int> (u));
- }
- if (maximum && t > maximum.get ()) {
- t = maximum.get ();
+ if (u.get().find (".") != string::npos) {
+ return MetricTime (
+ raw_convert<int> (b[0]),
+ raw_convert<int> (b[1]),
+ raw_convert<int> (b[2]),
+ raw_convert<int> ("." + b[3])
+ );
+ } else {
+ return MetricTime (
+ raw_convert<int> (b[0]),
+ raw_convert<int> (b[1]),
+ raw_convert<int> (b[2]),
+ raw_convert<int> (b[3]) * 4
+ );
+ }
+ } else {
+ return MetricTime (0, 0, 0, raw_convert<int> (u.get ()) * 4);
}
- return t;
+ assert (false);
}
diff --git a/src/dcp/subtitle.h b/src/dcp/subtitle.h
index f5d4002..8808dfb 100644
--- a/src/dcp/subtitle.h
+++ b/src/dcp/subtitle.h
@@ -39,17 +39,18 @@ class Subtitle
{
public:
Subtitle () {}
- Subtitle (boost::shared_ptr<const cxml::Node> node, int tcr);
+ Subtitle (boost::shared_ptr<const cxml::Node> node, bool smpte);
- FrameTime in;
- FrameTime out;
- FrameTime fade_up_time;
- FrameTime fade_down_time;
+ TimePair in;
+ TimePair out;
+ TimePair fade_up_time;
+ TimePair fade_down_time;
std::list<boost::shared_ptr<Font> > font_nodes;
std::list<boost::shared_ptr<Text> > text_nodes;
private:
- FrameTime time (boost::shared_ptr<const cxml::Node>, std::string name, boost::optional<FrameTime> maximum = boost::optional<FrameTime> ());
+ boost::optional<FrameTime> smpte_time (boost::shared_ptr<const cxml::Node> node, std::string name);
+ boost::optional<MetricTime> interop_time (boost::shared_ptr<const cxml::Node> node, std::string name);
};
}
diff --git a/src/dcp/text.cc b/src/dcp/text.cc
index 03d86d3..dde5320 100644
--- a/src/dcp/text.cc
+++ b/src/dcp/text.cc
@@ -37,7 +37,7 @@ using namespace sub;
* in this object's member variables.
* @param node Node to read.
*/
-dcp::Text::Text (boost::shared_ptr<const cxml::Node> node, int tcr)
+dcp::Text::Text (boost::shared_ptr<const cxml::Node> node, bool smpte)
: v_align (CENTRE_OF_SCREEN)
{
text = node->content ();
@@ -66,6 +66,6 @@ dcp::Text::Text (boost::shared_ptr<const cxml::Node> node, int tcr)
list<cxml::NodePtr> f = node->node_children ("Font");
BOOST_FOREACH (cxml::NodePtr& i, f) {
- font_nodes.push_back (shared_ptr<Font> (new Font (i, tcr)));
+ font_nodes.push_back (shared_ptr<Font> (new Font (i, smpte)));
}
}
diff --git a/src/dcp/text.h b/src/dcp/text.h
index a9c0358..64ee2da 100644
--- a/src/dcp/text.h
+++ b/src/dcp/text.h
@@ -46,7 +46,7 @@ public:
, v_align (TOP_OF_SCREEN)
{}
- Text (boost::shared_ptr<const cxml::Node> node, int tcr);
+ Text (boost::shared_ptr<const cxml::Node> node, bool smpte);
float v_position;
VerticalReference v_align;
diff --git a/src/dcp_reader.cc b/src/dcp_reader.cc
index e511912..d8c90c0 100644
--- a/src/dcp_reader.cc
+++ b/src/dcp_reader.cc
@@ -101,7 +101,7 @@ DCPReader::maybe_add_subtitle (string text, ParseState const & parse_state)
RawSubtitle rs;
rs.text = text;
- rs.font = effective_font.id.get ();
+ rs.font = effective_font.id;
rs.font_size.set_proportional (float (effective_font.size) / (72 * 11));
rs.effect = effective_font.effect;
rs.effect_colour = effective_font.effect_colour;
diff --git a/src/interop_dcp_reader.cc b/src/interop_dcp_reader.cc
index 5cbb1a2..41e127b 100644
--- a/src/interop_dcp_reader.cc
+++ b/src/interop_dcp_reader.cc
@@ -40,7 +40,7 @@ InteropDCPReader::InteropDCPReader (boost::filesystem::path file)
list<cxml::NodePtr> f = xml->node_children ("Font");
list<shared_ptr<dcp::Font> > font_nodes;
BOOST_FOREACH (cxml::NodePtr& i, f) {
- font_nodes.push_back (shared_ptr<dcp::Font> (new dcp::Font (i, 250)));
+ font_nodes.push_back (shared_ptr<dcp::Font> (new dcp::Font (i, false)));
}
parse_common (xml, font_nodes);
diff --git a/src/raw_subtitle.h b/src/raw_subtitle.h
index fd31561..fdd7331 100644
--- a/src/raw_subtitle.h
+++ b/src/raw_subtitle.h
@@ -51,7 +51,7 @@ public:
std::string text;
/* XXX: this probably needs to be a cleverer type */
- std::string font;
+ boost::optional<std::string> font;
/** font size */
FontSize font_size;
diff --git a/src/smpte_dcp_reader.cc b/src/smpte_dcp_reader.cc
index 5999fa8..f8cc5df 100644
--- a/src/smpte_dcp_reader.cc
+++ b/src/smpte_dcp_reader.cc
@@ -70,7 +70,7 @@ SMPTEDCPReader::SMPTEDCPReader (boost::filesystem::path file, bool mxf)
list<cxml::NodePtr> f = subtitle_list->node_children ("Font");
list<shared_ptr<dcp::Font> > font_nodes;
BOOST_FOREACH (cxml::NodePtr& i, f) {
- font_nodes.push_back (shared_ptr<dcp::Font> (new dcp::Font (i, _timecode_rate)));
+ font_nodes.push_back (shared_ptr<dcp::Font> (new dcp::Font (i, true)));
}
parse_common (xml, font_nodes);
diff --git a/src/subtitle.h b/src/subtitle.h
index 840ee23..71dff80 100644
--- a/src/subtitle.h
+++ b/src/subtitle.h
@@ -55,7 +55,7 @@ public:
/** Subtitle text in UTF-8 */
std::string text;
- std::string font;
+ boost::optional<std::string> font;
/** font size */
FontSize font_size;