summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-01-29 22:03:05 +0000
committerCarl Hetherington <cth@carlh.net>2014-01-29 22:03:05 +0000
commit62a1e9d6cda70050b813d4ba0c3e83b7350f360d (patch)
treea2aaf87d4f41544a497b9a9ea65203048b1406d5 /src/lib
parent4c2ae591ee17599b4fbb7ffc24a06f27ed985c05 (diff)
Add subtitle X offset option.
Suggested-by: Thierry Journet
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ffmpeg_content.cc2
-rw-r--r--src/lib/film.cc4
-rw-r--r--src/lib/player.cc9
-rw-r--r--src/lib/subtitle_content.cc51
-rw-r--r--src/lib/subtitle_content.h29
5 files changed, 69 insertions, 26 deletions
diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc
index f59551d1d..2c5fcf70e 100644
--- a/src/lib/ffmpeg_content.cc
+++ b/src/lib/ffmpeg_content.cc
@@ -62,7 +62,7 @@ FFmpegContent::FFmpegContent (shared_ptr<const Film> f, shared_ptr<const cxml::N
: Content (f, node)
, VideoContent (f, node)
, AudioContent (f, node)
- , SubtitleContent (f, node)
+ , SubtitleContent (f, node, version)
{
list<cxml::NodePtr> c = node->node_children ("SubtitleStream");
for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) {
diff --git a/src/lib/film.cc b/src/lib/film.cc
index 1290cbda2..8690d3ee0 100644
--- a/src/lib/film.cc
+++ b/src/lib/film.cc
@@ -83,8 +83,10 @@ using libdcp::Signer;
/* 5 -> 6
* AudioMapping XML changed.
+ * 6 -> 7
+ * Subtitle offset changed to subtitle y offset, and subtitle x offset added.
*/
-int const Film::state_version = 6;
+int const Film::state_version = 7;
/** Construct a Film object in a given directory.
*
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 1c54d0fc5..e661a7b36 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -521,7 +521,11 @@ Player::content_changed (weak_ptr<Content> w, int property, bool frequent)
_have_valid_pieces = false;
Changed (frequent);
- } else if (property == SubtitleContentProperty::SUBTITLE_OFFSET || property == SubtitleContentProperty::SUBTITLE_SCALE) {
+ } else if (
+ property == SubtitleContentProperty::SUBTITLE_X_OFFSET ||
+ property == SubtitleContentProperty::SUBTITLE_Y_OFFSET ||
+ property == SubtitleContentProperty::SUBTITLE_SCALE
+ ) {
update_subtitle ();
Changed (frequent);
@@ -658,7 +662,8 @@ Player::update_subtitle ()
dcpomatic::Rect<double> in_rect = _in_subtitle.rect;
libdcp::Size scaled_size;
- in_rect.y += sc->subtitle_offset ();
+ in_rect.x += sc->subtitle_x_offset ();
+ in_rect.y += sc->subtitle_y_offset ();
/* We will scale the subtitle up to fit _video_container_size, and also by the additional subtitle_scale */
scaled_size.width = in_rect.width * _video_container_size.width * sc->subtitle_scale ();
diff --git a/src/lib/subtitle_content.cc b/src/lib/subtitle_content.cc
index 6c0d3af86..8f88574e5 100644
--- a/src/lib/subtitle_content.cc
+++ b/src/lib/subtitle_content.cc
@@ -30,25 +30,34 @@ using boost::shared_ptr;
using boost::lexical_cast;
using boost::dynamic_pointer_cast;
-int const SubtitleContentProperty::SUBTITLE_OFFSET = 500;
-int const SubtitleContentProperty::SUBTITLE_SCALE = 501;
+int const SubtitleContentProperty::SUBTITLE_X_OFFSET = 500;
+int const SubtitleContentProperty::SUBTITLE_Y_OFFSET = 501;
+int const SubtitleContentProperty::SUBTITLE_SCALE = 502;
SubtitleContent::SubtitleContent (shared_ptr<const Film> f, boost::filesystem::path p)
: Content (f, p)
- , _subtitle_offset (0)
+ , _subtitle_x_offset (0)
+ , _subtitle_y_offset (0)
, _subtitle_scale (1)
{
}
-SubtitleContent::SubtitleContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
+SubtitleContent::SubtitleContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node, int version)
: Content (f, node)
- , _subtitle_offset (0)
+ , _subtitle_x_offset (0)
+ , _subtitle_y_offset (0)
, _subtitle_scale (1)
{
LocaleGuard lg;
+
+ if (version >= 7) {
+ _subtitle_x_offset = node->number_child<float> ("SubtitleXOffset");
+ _subtitle_y_offset = node->number_child<float> ("SubtitleYOffset");
+ } else {
+ _subtitle_y_offset = node->number_child<float> ("SubtitleOffset");
+ }
- _subtitle_offset = node->number_child<float> ("SubtitleOffset");
_subtitle_scale = node->number_child<float> ("SubtitleScale");
}
@@ -61,8 +70,12 @@ SubtitleContent::SubtitleContent (shared_ptr<const Film> f, vector<shared_ptr<Co
for (size_t i = 0; i < c.size(); ++i) {
shared_ptr<SubtitleContent> sc = dynamic_pointer_cast<SubtitleContent> (c[i]);
- if (sc->subtitle_offset() != ref->subtitle_offset()) {
- throw JoinError (_("Content to be joined must have the same subtitle offset."));
+ if (sc->subtitle_x_offset() != ref->subtitle_x_offset()) {
+ throw JoinError (_("Content to be joined must have the same subtitle X offset."));
+ }
+
+ if (sc->subtitle_y_offset() != ref->subtitle_y_offset()) {
+ throw JoinError (_("Content to be joined must have the same subtitle Y offset."));
}
if (sc->subtitle_scale() != ref->subtitle_scale()) {
@@ -70,7 +83,8 @@ SubtitleContent::SubtitleContent (shared_ptr<const Film> f, vector<shared_ptr<Co
}
}
- _subtitle_offset = ref->subtitle_offset ();
+ _subtitle_x_offset = ref->subtitle_x_offset ();
+ _subtitle_y_offset = ref->subtitle_y_offset ();
_subtitle_scale = ref->subtitle_scale ();
}
@@ -79,18 +93,29 @@ SubtitleContent::as_xml (xmlpp::Node* root) const
{
LocaleGuard lg;
- root->add_child("SubtitleOffset")->add_child_text (lexical_cast<string> (_subtitle_offset));
+ root->add_child("SubtitleXOffset")->add_child_text (lexical_cast<string> (_subtitle_x_offset));
+ root->add_child("SubtitleYOffset")->add_child_text (lexical_cast<string> (_subtitle_y_offset));
root->add_child("SubtitleScale")->add_child_text (lexical_cast<string> (_subtitle_scale));
}
void
-SubtitleContent::set_subtitle_offset (double o)
+SubtitleContent::set_subtitle_x_offset (double o)
+{
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _subtitle_x_offset = o;
+ }
+ signal_changed (SubtitleContentProperty::SUBTITLE_X_OFFSET);
+}
+
+void
+SubtitleContent::set_subtitle_y_offset (double o)
{
{
boost::mutex::scoped_lock lm (_mutex);
- _subtitle_offset = o;
+ _subtitle_y_offset = o;
}
- signal_changed (SubtitleContentProperty::SUBTITLE_OFFSET);
+ signal_changed (SubtitleContentProperty::SUBTITLE_Y_OFFSET);
}
void
diff --git a/src/lib/subtitle_content.h b/src/lib/subtitle_content.h
index 854647d18..388637688 100644
--- a/src/lib/subtitle_content.h
+++ b/src/lib/subtitle_content.h
@@ -25,7 +25,8 @@
class SubtitleContentProperty
{
public:
- static int const SUBTITLE_OFFSET;
+ static int const SUBTITLE_X_OFFSET;
+ static int const SUBTITLE_Y_OFFSET;
static int const SUBTITLE_SCALE;
};
@@ -33,17 +34,23 @@ class SubtitleContent : public virtual Content
{
public:
SubtitleContent (boost::shared_ptr<const Film>, boost::filesystem::path);
- SubtitleContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>);
+ SubtitleContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>, int version);
SubtitleContent (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
void as_xml (xmlpp::Node *) const;
- void set_subtitle_offset (double);
+ void set_subtitle_x_offset (double);
+ void set_subtitle_y_offset (double);
void set_subtitle_scale (double);
- double subtitle_offset () const {
+ double subtitle_x_offset () const {
boost::mutex::scoped_lock lm (_mutex);
- return _subtitle_offset;
+ return _subtitle_x_offset;
+ }
+
+ double subtitle_y_offset () const {
+ boost::mutex::scoped_lock lm (_mutex);
+ return _subtitle_y_offset;
}
double subtitle_scale () const {
@@ -53,11 +60,15 @@ public:
private:
friend class ffmpeg_pts_offset_test;
-
+
+ /** x offset for placing subtitles, as a proportion of the container width;
+ * +ve is further right, -ve is further left.
+ */
+ double _subtitle_x_offset;
/** y offset for placing subtitles, as a proportion of the container height;
- +ve is further down the frame, -ve is further up.
- */
- double _subtitle_offset;
+ * +ve is further down the frame, -ve is further up.
+ */
+ double _subtitle_y_offset;
/** scale factor to apply to subtitles */
double _subtitle_scale;
};