summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-04-12 01:37:00 +0100
committerCarl Hetherington <cth@carlh.net>2016-04-12 01:37:00 +0100
commit4b8c626b7e66ab1d4d69606e10316542c8873842 (patch)
tree94140f93b3911196ab60866fefb5c9f807a7a2ab /src
parent4b8eee1359d817937b84df7e88126fa16040e5c9 (diff)
Add direction support for SMPTE subtitles; fix pragma warnings with non-openmp builds.
Diffstat (limited to 'src')
-rw-r--r--src/mono_picture_asset.cc5
-rw-r--r--src/object.h6
-rw-r--r--src/smpte_subtitle_asset.h4
-rw-r--r--src/subtitle_asset.cc13
-rw-r--r--src/subtitle_string.cc4
-rw-r--r--src/subtitle_string.h6
-rw-r--r--src/text_node.cc6
-rw-r--r--src/text_node.h2
-rw-r--r--src/types.cc33
-rw-r--r--src/types.h12
10 files changed, 89 insertions, 2 deletions
diff --git a/src/mono_picture_asset.cc b/src/mono_picture_asset.cc
index b367a19d..8e09d8c6 100644
--- a/src/mono_picture_asset.cc
+++ b/src/mono_picture_asset.cc
@@ -113,7 +113,10 @@ MonoPictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, No
bool result = true;
+#ifdef LIBDCP_OPENMP
#pragma omp parallel for
+#endif
+
for (int i = 0; i < _intrinsic_duration; ++i) {
if (i >= other_picture->intrinsic_duration()) {
result = false;
@@ -134,7 +137,9 @@ MonoPictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, No
result = false;
}
+#ifdef LIBDCP_OPENMP
#pragma omp critical
+#endif
{
note (DCP_PROGRESS, String::compose ("Compared video frame %1 of %2", i, _intrinsic_duration));
for (list<pair<NoteType, string> >::const_iterator i = notes.begin(); i != notes.end(); ++i) {
diff --git a/src/object.h b/src/object.h
index 303e46d3..0fa11251 100644
--- a/src/object.h
+++ b/src/object.h
@@ -27,7 +27,8 @@
#include <boost/noncopyable.hpp>
#include <string>
-class write_subtitle_test;
+class write_interop_subtitle_test;
+class write_smpte_subtitle_test;
namespace dcp {
@@ -47,7 +48,8 @@ public:
}
protected:
- friend class ::write_subtitle_test;
+ friend class ::write_interop_subtitle_test;
+ friend class ::write_smpte_subtitle_test;
/** ID */
std::string _id;
diff --git a/src/smpte_subtitle_asset.h b/src/smpte_subtitle_asset.h
index a7adee6f..48a0b95c 100644
--- a/src/smpte_subtitle_asset.h
+++ b/src/smpte_subtitle_asset.h
@@ -69,6 +69,10 @@ public:
_language = l;
}
+ void set_issue_date (LocalTime t) {
+ _issue_date = t;
+ }
+
void set_reel_number (int r) {
_reel_number = r;
}
diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc
index 352aff9a..89c96795 100644
--- a/src/subtitle_asset.cc
+++ b/src/subtitle_asset.cc
@@ -153,6 +153,7 @@ SubtitleAsset::maybe_add_subtitle (string text, ParseState const & parse_state)
effective_text.h_align,
effective_text.v_position,
effective_text.v_align,
+ effective_text.direction,
text,
effective_font.effect.get_value_or (NONE),
effective_font.effect_colour.get_value_or (dcp::Colour (0, 0, 0)),
@@ -333,6 +334,7 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Stand
}
xmlpp::Element* text = subtitle_element->add_child ("Text", xmlns);
+
if (i.h_align() != HALIGN_CENTER) {
if (standard == SMPTE) {
text->set_attribute ("Halign", halign_to_string (i.h_align ()));
@@ -340,6 +342,7 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Stand
text->set_attribute ("HAlign", halign_to_string (i.h_align ()));
}
}
+
if (i.h_position() > ALIGN_EPSILON) {
if (standard == SMPTE) {
text->set_attribute ("Hposition", raw_convert<string> (i.h_position() * 100, 6));
@@ -347,11 +350,13 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Stand
text->set_attribute ("HPosition", raw_convert<string> (i.h_position() * 100, 6));
}
}
+
if (standard == SMPTE) {
text->set_attribute ("Valign", valign_to_string (i.v_align()));
} else {
text->set_attribute ("VAlign", valign_to_string (i.v_align()));
}
+
if (i.v_position() > ALIGN_EPSILON) {
if (standard == SMPTE) {
text->set_attribute ("Vposition", raw_convert<string> (i.v_position() * 100, 6));
@@ -365,6 +370,14 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Stand
text->set_attribute ("VPosition", "0");
}
}
+
+ /* Interop only supports "horizontal" or "vertical" for direction, so only write this
+ for SMPTE.
+ */
+ if (i.direction() != DIRECTION_LTR && standard == SMPTE) {
+ text->set_attribute ("Direction", direction_to_string (i.direction ()));
+ }
+
text->add_child_text (i.text());
}
}
diff --git a/src/subtitle_string.cc b/src/subtitle_string.cc
index ea24e37f..7ba6e0e1 100644
--- a/src/subtitle_string.cc
+++ b/src/subtitle_string.cc
@@ -40,6 +40,7 @@ SubtitleString::SubtitleString (
HAlign h_align,
float v_position,
VAlign v_align,
+ Direction direction,
string text,
Effect effect,
Colour effect_colour,
@@ -58,6 +59,7 @@ SubtitleString::SubtitleString (
, _h_align (h_align)
, _v_position (v_position)
, _v_align (v_align)
+ , _direction (direction)
, _text (text)
, _effect (effect)
, _effect_colour (effect_colour)
@@ -94,6 +96,7 @@ dcp::operator== (SubtitleString const & a, SubtitleString const & b)
a.h_align() == b.h_align() &&
a.v_position() == b.v_position() &&
a.v_align() == b.v_align() &&
+ a.direction() == b.direction() &&
a.text() == b.text() &&
a.effect() == b.effect() &&
a.effect_colour() == b.effect_colour() &&
@@ -124,6 +127,7 @@ dcp::operator<< (ostream& s, SubtitleString const & sub)
s << "size " << sub.size() << ", aspect " << sub.aspect_adjust() << ", colour " << sub.colour()
<< ", vpos " << sub.v_position() << ", valign " << ((int) sub.v_align())
<< ", hpos " << sub.h_position() << ", halign " << ((int) sub.h_align())
+ << ", direction " << ((int) sub.direction())
<< ", effect " << ((int) sub.effect()) << ", effect colour " << sub.effect_colour();
return s;
diff --git a/src/subtitle_string.h b/src/subtitle_string.h
index bd71b8da..6cf1713d 100644
--- a/src/subtitle_string.h
+++ b/src/subtitle_string.h
@@ -50,6 +50,7 @@ public:
HAlign h_align,
float v_position,
VAlign v_align,
+ Direction direction,
std::string text,
Effect effect,
Colour effect_colour,
@@ -106,6 +107,10 @@ public:
return _v_align;
}
+ Direction direction () const {
+ return _direction;
+ }
+
Effect effect () const {
return _effect;
}
@@ -189,6 +194,7 @@ private:
*/
float _v_position;
VAlign _v_align;
+ Direction _direction;
std::string _text;
Effect _effect;
Colour _effect_colour;
diff --git a/src/text_node.cc b/src/text_node.cc
index aa318ce7..7618c460 100644
--- a/src/text_node.cc
+++ b/src/text_node.cc
@@ -42,6 +42,7 @@ TextNode::TextNode (boost::shared_ptr<const cxml::Node> node, int tcr, string fo
, h_align (HALIGN_CENTER)
, v_position (0)
, v_align (VALIGN_CENTER)
+ , direction (DIRECTION_LTR)
{
text = node->content ();
@@ -77,6 +78,11 @@ TextNode::TextNode (boost::shared_ptr<const cxml::Node> node, int tcr, string fo
v_align = string_to_valign (va.get ());
}
+ optional<string> d = node->optional_string_attribute ("Direction");
+ if (d) {
+ direction = string_to_direction (d.get ());
+ }
+
list<cxml::NodePtr> f = node->node_children ("Font");
BOOST_FOREACH (cxml::NodePtr& i, f) {
font_nodes.push_back (shared_ptr<FontNode> (new FontNode (i, tcr, font_id_attribute)));
diff --git a/src/text_node.h b/src/text_node.h
index f10d7c4b..753d1a01 100644
--- a/src/text_node.h
+++ b/src/text_node.h
@@ -46,6 +46,7 @@ public:
, h_align (HALIGN_LEFT)
, v_position (0)
, v_align (VALIGN_TOP)
+ , direction (DIRECTION_LTR)
{}
TextNode (boost::shared_ptr<const cxml::Node> node, int tcr, std::string font_id_attribute);
@@ -54,6 +55,7 @@ public:
HAlign h_align;
float v_position;
VAlign v_align;
+ Direction direction;
std::string text;
std::list<boost::shared_ptr<FontNode> > font_nodes;
};
diff --git a/src/types.cc b/src/types.cc
index 687e90f8..30c565c9 100644
--- a/src/types.cc
+++ b/src/types.cc
@@ -232,3 +232,36 @@ dcp::string_to_valign (string s)
boost::throw_exception (DCPReadError ("unknown subtitle valign type"));
}
+
+string
+dcp::direction_to_string (Direction v)
+{
+ switch (v) {
+ case DIRECTION_LTR:
+ return "ltr";
+ case DIRECTION_RTL:
+ return "rtl";
+ case DIRECTION_TTB:
+ return "ttb";
+ case DIRECTION_BTT:
+ return "btt";
+ }
+
+ boost::throw_exception (MiscError ("unknown subtitle direction type"));
+}
+
+Direction
+dcp::string_to_direction (string s)
+{
+ if (s == "ltr") {
+ return DIRECTION_LTR;
+ } else if (s == "rtl") {
+ return DIRECTION_RTL;
+ } else if (s == "ttb") {
+ return DIRECTION_TTB;
+ } else if (s == "btt") {
+ return DIRECTION_BTT;
+ }
+
+ boost::throw_exception (DCPReadError ("unknown subtitle direction type"));
+}
diff --git a/src/types.h b/src/types.h
index 16000daa..0f05d889 100644
--- a/src/types.h
+++ b/src/types.h
@@ -114,6 +114,18 @@ enum VAlign
extern std::string valign_to_string (VAlign a);
extern VAlign string_to_valign (std::string s);
+/** Direction for subtitle test */
+enum Direction
+{
+ DIRECTION_LTR, ///< left-to-right
+ DIRECTION_RTL, ///< right-to-left
+ DIRECTION_TTB, ///< top-to-bottom
+ DIRECTION_BTT ///< bottom-to-top
+};
+
+extern std::string direction_to_string (Direction a);
+extern Direction string_to_direction (std::string s);
+
enum Eye
{
EYE_LEFT,