summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-07-07 23:16:45 +0100
committerCarl Hetherington <cth@carlh.net>2018-07-07 23:16:45 +0100
commitba5915461f1622715a69fa25579e5e27e64fb079 (patch)
tree221ce87dfbac455c32459e07beb92b6003243e89 /src
parenta4fb6290e31f7e197cc399c745d320442eb093d4 (diff)
SubtitleString -> shared_ptr<Subtitle>
Diffstat (limited to 'src')
-rw-r--r--src/data.cc6
-rw-r--r--src/data.h2
-rw-r--r--src/smpte_subtitle_asset.cc2
-rw-r--r--src/smpte_subtitle_asset.h2
-rw-r--r--src/subtitle.h8
-rw-r--r--src/subtitle_asset.cc155
-rw-r--r--src/subtitle_asset.h10
-rw-r--r--src/subtitle_asset_internal.cc27
-rw-r--r--src/subtitle_asset_internal.h2
-rw-r--r--src/subtitle_image.cc34
-rw-r--r--src/subtitle_image.h8
-rw-r--r--src/subtitle_string.cc6
-rw-r--r--src/subtitle_string.h1
13 files changed, 180 insertions, 83 deletions
diff --git a/src/data.cc b/src/data.cc
index 1971a261..9fcf9601 100644
--- a/src/data.cc
+++ b/src/data.cc
@@ -107,3 +107,9 @@ Data::write_via_temp (boost::filesystem::path temp, boost::filesystem::path fina
write (temp);
boost::filesystem::rename (temp, final);
}
+
+bool
+dcp::operator== (Data const & a, Data const & b)
+{
+ return (a.size() == b.size() && memcmp (a.data().get(), b.data().get(), a.size() == 0));
+}
diff --git a/src/data.h b/src/data.h
index d06b2f49..fd6eb22b 100644
--- a/src/data.h
+++ b/src/data.h
@@ -72,6 +72,8 @@ private:
int _size;
};
+bool operator==(Data const & a, Data const & b);
+
}
#endif
diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc
index cd692736..07d8f7eb 100644
--- a/src/smpte_subtitle_asset.cc
+++ b/src/smpte_subtitle_asset.cc
@@ -443,7 +443,7 @@ SMPTESubtitleAsset::add_font (string load_id, boost::filesystem::path file)
}
void
-SMPTESubtitleAsset::add (dcp::SubtitleString s)
+SMPTESubtitleAsset::add (shared_ptr<Subtitle> s)
{
SubtitleAsset::add (s);
_intrinsic_duration = latest_subtitle_out().as_editable_units (_edit_rate.numerator / _edit_rate.denominator);
diff --git a/src/smpte_subtitle_asset.h b/src/smpte_subtitle_asset.h
index 9169a3d6..6631b31e 100644
--- a/src/smpte_subtitle_asset.h
+++ b/src/smpte_subtitle_asset.h
@@ -73,7 +73,7 @@ public:
std::string xml_as_string () const;
void write (boost::filesystem::path path) const;
- void add (SubtitleString);
+ void add (boost::shared_ptr<Subtitle>);
void add_font (std::string id, boost::filesystem::path file);
void set_key (Key key);
diff --git a/src/subtitle.h b/src/subtitle.h
index 32f7457a..8dba299d 100644
--- a/src/subtitle.h
+++ b/src/subtitle.h
@@ -31,6 +31,9 @@
files in the program, then also delete it here.
*/
+#ifndef LIBDCP_SUBTITLE_H
+#define LIBDCP_SUBTITLE_H
+
/** @file src/subtitle.h
* @brief Subtitle class.
*/
@@ -53,6 +56,8 @@ public:
Time fade_down_time
);
+ virtual ~Subtitle () {}
+
Time in () const {
return _in;
}
@@ -61,7 +66,6 @@ public:
return _out;
}
-
float h_position () const {
return _h_position;
}
@@ -136,3 +140,5 @@ protected:
};
}
+
+#endif
diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc
index be49d8cf..3ecd16a7 100644
--- a/src/subtitle_asset.cc
+++ b/src/subtitle_asset.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
This file is part of libdcp.
@@ -38,6 +38,7 @@
#include "util.h"
#include "xml.h"
#include "subtitle_string.h"
+#include "subtitle_image.h"
#include "dcp_assert.h"
#include <asdcp/AS_DCP.h>
#include <asdcp/KM_util.h>
@@ -329,36 +330,38 @@ SubtitleAsset::maybe_add_subtitle (string text, list<ParseState> const & parse_s
}
_subtitles.push_back (
- SubtitleString (
- ps.font_id,
- ps.italic.get_value_or (false),
- ps.bold.get_value_or (false),
- ps.underline.get_value_or (false),
- ps.colour.get_value_or (dcp::Colour (255, 255, 255)),
- ps.size.get_value_or (42),
- ps.aspect_adjust.get_value_or (1.0),
- ps.in.get(),
- ps.out.get(),
- ps.h_position.get_value_or(0),
- ps.h_align.get_value_or(HALIGN_CENTER),
- ps.v_position.get_value_or(0),
- ps.v_align.get_value_or(VALIGN_CENTER),
- ps.direction.get_value_or (DIRECTION_LTR),
- text,
- ps.effect.get_value_or (NONE),
- ps.effect_colour.get_value_or (dcp::Colour (0, 0, 0)),
- ps.fade_up_time.get_value_or(Time()),
- ps.fade_down_time.get_value_or(Time())
+ shared_ptr<Subtitle> (
+ new SubtitleString (
+ ps.font_id,
+ ps.italic.get_value_or (false),
+ ps.bold.get_value_or (false),
+ ps.underline.get_value_or (false),
+ ps.colour.get_value_or (dcp::Colour (255, 255, 255)),
+ ps.size.get_value_or (42),
+ ps.aspect_adjust.get_value_or (1.0),
+ ps.in.get(),
+ ps.out.get(),
+ ps.h_position.get_value_or(0),
+ ps.h_align.get_value_or(HALIGN_CENTER),
+ ps.v_position.get_value_or(0),
+ ps.v_align.get_value_or(VALIGN_CENTER),
+ ps.direction.get_value_or (DIRECTION_LTR),
+ text,
+ ps.effect.get_value_or (NONE),
+ ps.effect_colour.get_value_or (dcp::Colour (0, 0, 0)),
+ ps.fade_up_time.get_value_or(Time()),
+ ps.fade_down_time.get_value_or(Time())
+ )
)
);
}
-list<SubtitleString>
+list<shared_ptr<Subtitle> >
SubtitleAsset::subtitles_during (Time from, Time to, bool starting) const
{
- list<SubtitleString> s;
- BOOST_FOREACH (SubtitleString const & i, _subtitles) {
- if ((starting && from <= i.in() && i.in() < to) || (!starting && i.out() >= from && i.in() <= to)) {
+ list<shared_ptr<Subtitle> > s;
+ BOOST_FOREACH (shared_ptr<Subtitle> i, _subtitles) {
+ if ((starting && from <= i->in() && i->in() < to) || (!starting && i->out() >= from && i->in() <= to)) {
s.push_back (i);
}
}
@@ -367,7 +370,7 @@ SubtitleAsset::subtitles_during (Time from, Time to, bool starting) const
}
void
-SubtitleAsset::add (SubtitleString s)
+SubtitleAsset::add (shared_ptr<Subtitle> s)
{
_subtitles.push_back (s);
}
@@ -376,9 +379,9 @@ Time
SubtitleAsset::latest_subtitle_out () const
{
Time t;
- BOOST_FOREACH (SubtitleString const & i, _subtitles) {
- if (i.out() > t) {
- t = i.out ();
+ BOOST_FOREACH (shared_ptr<Subtitle> i, _subtitles) {
+ if (i->out() > t) {
+ t = i->out ();
}
}
@@ -397,21 +400,46 @@ SubtitleAsset::equals (shared_ptr<const Asset> other_asset, EqualityOptions opti
return false;
}
- if (_subtitles != other->_subtitles) {
+ if (_subtitles.size() != other->_subtitles.size()) {
note (DCP_ERROR, "subtitles differ");
return false;
}
+ list<shared_ptr<Subtitle> >::const_iterator i = _subtitles.begin ();
+ list<shared_ptr<Subtitle> >::const_iterator j = other->_subtitles.begin ();
+
+ while (i != _subtitles.end()) {
+ shared_ptr<SubtitleString> string_i = dynamic_pointer_cast<SubtitleString> (*i);
+ shared_ptr<SubtitleString> string_j = dynamic_pointer_cast<SubtitleString> (*j);
+ shared_ptr<SubtitleImage> image_i = dynamic_pointer_cast<SubtitleImage> (*i);
+ shared_ptr<SubtitleImage> image_j = dynamic_pointer_cast<SubtitleImage> (*j);
+
+ if ((string_i && !string_j) || (image_i && !image_j)) {
+ note (DCP_ERROR, "subtitles differ");
+ return false;
+ }
+
+ if (string_i && *string_i != *string_j) {
+ note (DCP_ERROR, "subtitles differ");
+ return false;
+ }
+
+ if (image_i && *image_i != *image_j) {
+ note (DCP_ERROR, "subtitles differ");
+ return false;
+ }
+ }
+
return true;
}
struct SubtitleSorter
{
- bool operator() (SubtitleString const & a, SubtitleString const & b) {
- if (a.in() != b.in()) {
- return a.in() < b.in();
+ bool operator() (shared_ptr<Subtitle> a, shared_ptr<Subtitle> b) {
+ if (a->in() != b->in()) {
+ return a->in() < b->in();
}
- return a.v_position() < b.v_position();
+ return a->v_position() < b->v_position();
}
};
@@ -481,7 +509,7 @@ SubtitleAsset::pull_fonts (shared_ptr<order::Part> part)
void
SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, Standard standard) const
{
- list<SubtitleString> sorted = _subtitles;
+ list<shared_ptr<Subtitle> > sorted = _subtitles;
sorted.sort (SubtitleSorter ());
/* Gather our subtitles into a hierarchy of Subtitle/Text/String objects, writing
@@ -502,43 +530,48 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* xml_root, int time_code_rate, S
float last_v_position;
Direction last_direction;
- BOOST_FOREACH (SubtitleString const & i, sorted) {
+ BOOST_FOREACH (shared_ptr<Subtitle> i, sorted) {
if (!subtitle ||
- (last_in != i.in() ||
- last_out != i.out() ||
- last_fade_up_time != i.fade_up_time() ||
- last_fade_down_time != i.fade_down_time())
+ (last_in != i->in() ||
+ last_out != i->out() ||
+ last_fade_up_time != i->fade_up_time() ||
+ last_fade_down_time != i->fade_down_time())
) {
- subtitle.reset (new order::Subtitle (root, i.in(), i.out(), i.fade_up_time(), i.fade_down_time()));
+ subtitle.reset (new order::Subtitle (root, i->in(), i->out(), i->fade_up_time(), i->fade_down_time()));
root->children.push_back (subtitle);
- last_in = i.in ();
- last_out = i.out ();
- last_fade_up_time = i.fade_up_time ();
- last_fade_down_time = i.fade_down_time ();
+ last_in = i->in ();
+ last_out = i->out ();
+ last_fade_up_time = i->fade_up_time ();
+ last_fade_down_time = i->fade_down_time ();
text.reset ();
}
- if (!text ||
- last_h_align != i.h_align() ||
- fabs(last_h_position - i.h_position()) > ALIGN_EPSILON ||
- last_v_align != i.v_align() ||
- fabs(last_v_position - i.v_position()) > ALIGN_EPSILON ||
- last_direction != i.direction()
- ) {
-
- text.reset (new order::Text (subtitle, i.h_align(), i.h_position(), i.v_align(), i.v_position(), i.direction()));
- subtitle->children.push_back (text);
+ shared_ptr<SubtitleString> is = dynamic_pointer_cast<SubtitleString>(i);
+
+ if (is) {
+ if (!text ||
+ last_h_align != is->h_align() ||
+ fabs(last_h_position - is->h_position()) > ALIGN_EPSILON ||
+ last_v_align != is->v_align() ||
+ fabs(last_v_position - is->v_position()) > ALIGN_EPSILON ||
+ last_direction != is->direction()
+ ) {
+ text.reset (new order::Text (subtitle, is->h_align(), is->h_position(), is->v_align(), is->v_position(), is->direction()));
+ subtitle->children.push_back (text);
+
+ last_h_align = is->h_align ();
+ last_h_position = is->h_position ();
+ last_v_align = is->v_align ();
+ last_v_position = is->v_position ();
+ last_direction = is->direction ();
+ }
- last_h_align = i.h_align ();
- last_h_position = i.h_position ();
- last_v_align = i.v_align ();
- last_v_position = i.v_position ();
- last_direction = i.direction ();
+ text->children.push_back (shared_ptr<order::String> (new order::String (text, order::Font (is, standard), is->text())));
}
- text->children.push_back (shared_ptr<order::String> (new order::String (text, order::Font (i, standard), i.text())));
+ /* XXX: image */
}
/* Pull font changes as high up the hierarchy as we can */
diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h
index ce76eb3b..1108514a 100644
--- a/src/subtitle_asset.h
+++ b/src/subtitle_asset.h
@@ -69,7 +69,7 @@ namespace order {
/** @class SubtitleAsset
* @brief A parent for classes representing a file containing subtitles.
*
- * This class holds a list of SubtitleString objects which it can extract
+ * This class holds a list of Subtitle objects which it can extract
* from the appropriate part of either an Interop or SMPTE XML file.
* Its subclasses InteropSubtitleAsset and SMPTESubtitleAsset handle the
* differences between the two types.
@@ -86,12 +86,12 @@ public:
NoteHandler note
) const;
- std::list<SubtitleString> subtitles_during (Time from, Time to, bool starting) const;
- std::list<SubtitleString> const & subtitles () const {
+ std::list<boost::shared_ptr<Subtitle> > subtitles_during (Time from, Time to, bool starting) const;
+ std::list<boost::shared_ptr<Subtitle> > const & subtitles () const {
return _subtitles;
}
- virtual void add (SubtitleString);
+ virtual void add (boost::shared_ptr<Subtitle>);
virtual void add_font (std::string id, boost::filesystem::path file) = 0;
std::map<std::string, Data> fonts_with_load_ids () const;
@@ -136,7 +136,7 @@ protected:
void subtitles_as_xml (xmlpp::Element* root, int time_code_rate, Standard standard) const;
/** All our subtitles, in no particular order */
- std::list<SubtitleString> _subtitles;
+ std::list<boost::shared_ptr<Subtitle> > _subtitles;
class Font
{
diff --git a/src/subtitle_asset_internal.cc b/src/subtitle_asset_internal.cc
index 4ae90461..c525256d 100644
--- a/src/subtitle_asset_internal.cc
+++ b/src/subtitle_asset_internal.cc
@@ -37,6 +37,7 @@
using std::string;
using std::map;
+using boost::shared_ptr;
using namespace dcp;
string
@@ -45,28 +46,28 @@ order::Context::xmlns () const
return standard == SMPTE ? "dcst" : "";
}
-order::Font::Font (SubtitleString const & s, Standard standard)
+order::Font::Font (shared_ptr<SubtitleString> s, Standard standard)
{
- if (s.font()) {
+ if (s->font()) {
if (standard == SMPTE) {
- _values["ID"] = s.font().get ();
+ _values["ID"] = s->font().get ();
} else {
- _values["Id"] = s.font().get ();
+ _values["Id"] = s->font().get ();
}
}
- _values["Italic"] = s.italic() ? "yes" : "no";
- _values["Color"] = s.colour().to_argb_string();
- _values["Size"] = raw_convert<string> (s.size());
- _values["AspectAdjust"] = raw_convert<string>(s.aspect_adjust(), 1, true);
- _values["Effect"] = effect_to_string (s.effect());
- _values["EffectColor"] = s.effect_colour().to_argb_string();
+ _values["Italic"] = s->italic() ? "yes" : "no";
+ _values["Color"] = s->colour().to_argb_string();
+ _values["Size"] = raw_convert<string> (s->size());
+ _values["AspectAdjust"] = raw_convert<string>(s->aspect_adjust(), 1, true);
+ _values["Effect"] = effect_to_string (s->effect());
+ _values["EffectColor"] = s->effect_colour().to_argb_string();
_values["Script"] = "normal";
if (standard == SMPTE) {
- _values["Underline"] = s.underline() ? "yes" : "no";
+ _values["Underline"] = s->underline() ? "yes" : "no";
} else {
- _values["Underlined"] = s.underline() ? "yes" : "no";
+ _values["Underlined"] = s->underline() ? "yes" : "no";
}
- _values["Weight"] = s.bold() ? "bold" : "normal";
+ _values["Weight"] = s->bold() ? "bold" : "normal";
}
xmlpp::Element*
diff --git a/src/subtitle_asset_internal.h b/src/subtitle_asset_internal.h
index cd6e2b9f..fad65a91 100644
--- a/src/subtitle_asset_internal.h
+++ b/src/subtitle_asset_internal.h
@@ -66,7 +66,7 @@ class Font
public:
Font () {}
- Font (SubtitleString const & s, Standard standard);
+ Font (boost::shared_ptr<SubtitleString> s, Standard standard);
xmlpp::Element* as_xml (xmlpp::Element* parent, Context& context) const;
diff --git a/src/subtitle_image.cc b/src/subtitle_image.cc
index 90aadf29..974b496f 100644
--- a/src/subtitle_image.cc
+++ b/src/subtitle_image.cc
@@ -33,6 +33,7 @@
#include "subtitle_image.h"
+using std::ostream;
using namespace dcp;
SubtitleImage::SubtitleImage (
@@ -51,3 +52,36 @@ SubtitleImage::SubtitleImage (
{
}
+
+bool
+dcp::operator== (SubtitleImage const & a, SubtitleImage const & b)
+{
+ return (
+ a.png_image() == b.png_image(),
+ a.in() == b.in() &&
+ a.out() == b.out() &&
+ a.h_position() == b.h_position() &&
+ a.h_align() == b.h_align() &&
+ a.v_position() == b.v_position() &&
+ a.v_align() == b.v_align() &&
+ a.fade_up_time() == b.fade_up_time() &&
+ a.fade_down_time() == b.fade_down_time()
+ );
+}
+
+bool
+dcp::operator!= (SubtitleImage const & a, SubtitleImage const & b)
+{
+ return !(a == b);
+}
+
+ostream&
+dcp::operator<< (ostream& s, SubtitleImage const & sub)
+{
+ s << "\n[IMAGE] from " << sub.in() << " to " << sub.out() << ";\n"
+ << "fade up " << sub.fade_up_time() << ", fade down " << sub.fade_down_time() << ";\n"
+ << "v pos " << sub.v_position() << ", valign " << ((int) sub.v_align())
+ << ", hpos " << sub.h_position() << ", halign " << ((int) sub.h_align()) << "\n";
+
+ return s;
+}
diff --git a/src/subtitle_image.h b/src/subtitle_image.h
index e12c5733..d0c47328 100644
--- a/src/subtitle_image.h
+++ b/src/subtitle_image.h
@@ -65,10 +65,18 @@ public:
Time fade_down_time
);
+ Data png_image () const {
+ return _png_image;
+ }
+
private:
Data _png_image;
};
+bool operator== (SubtitleImage const & a, SubtitleImage const & b);
+bool operator!= (SubtitleImage const & a, SubtitleImage const & b);
+std::ostream& operator<< (std::ostream& s, SubtitleImage const & sub);
+
}
#endif
diff --git a/src/subtitle_string.cc b/src/subtitle_string.cc
index 6d1e8cdb..f5f8c8ac 100644
--- a/src/subtitle_string.cc
+++ b/src/subtitle_string.cc
@@ -115,6 +115,12 @@ dcp::operator== (SubtitleString const & a, SubtitleString const & b)
);
}
+bool
+dcp::operator!= (SubtitleString const & a, SubtitleString const & b)
+{
+ return !(a == b);
+}
+
ostream&
dcp::operator<< (ostream& s, SubtitleString const & sub)
{
diff --git a/src/subtitle_string.h b/src/subtitle_string.h
index fc88c15b..08e4da5d 100644
--- a/src/subtitle_string.h
+++ b/src/subtitle_string.h
@@ -172,6 +172,7 @@ private:
};
bool operator== (SubtitleString const & a, SubtitleString const & b);
+bool operator!= (SubtitleString const & a, SubtitleString const & b);
std::ostream& operator<< (std::ostream& s, SubtitleString const & sub);
}