summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-02-05 16:35:34 +0000
committerCarl Hetherington <cth@carlh.net>2014-02-05 16:35:34 +0000
commit6c5e5435d105685a537561ca0e6a223d34af85e1 (patch)
treeb2415a607f5fdaadc4a37edb7e7a68a5ef0bc7cc /src
parent095dcf9a0fb075ca84537beff2fe6a41c837e8da (diff)
Support for conversions of things that have multiple representations.
Diffstat (limited to 'src')
-rw-r--r--src/convert_time.cc36
-rw-r--r--src/convert_time.h28
-rw-r--r--src/frame_time.h16
-rw-r--r--src/metric_time.cc25
-rw-r--r--src/metric_time.h5
-rw-r--r--src/subtitle.cc32
-rw-r--r--src/subtitle.h6
-rw-r--r--src/wscript2
8 files changed, 150 insertions, 0 deletions
diff --git a/src/convert_time.cc b/src/convert_time.cc
new file mode 100644
index 0000000..95cad64
--- /dev/null
+++ b/src/convert_time.cc
@@ -0,0 +1,36 @@
+/*
+ Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "metric_time.h"
+#include "frame_time.h"
+#include "convert_time.h"
+
+using namespace sub;
+
+FrameTime
+sub::metric_to_frame (MetricTime t, float frames_per_second)
+{
+ return FrameTime (t.hours(), t.minutes(), t.seconds(), t.milliseconds() * frames_per_second / 1000);
+}
+
+MetricTime
+sub::frame_to_metric (FrameTime t, float frames_per_second)
+{
+ return MetricTime (t.hours(), t.minutes(), t.seconds(), t.frames() * 1000 / frames_per_second);
+}
diff --git a/src/convert_time.h b/src/convert_time.h
new file mode 100644
index 0000000..92ec737
--- /dev/null
+++ b/src/convert_time.h
@@ -0,0 +1,28 @@
+/*
+ Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "metric_time.h"
+#include "frame_time.h"
+
+namespace sub {
+
+FrameTime metric_to_frame (MetricTime, float frames_per_second);
+MetricTime frame_to_metric (FrameTime, float frames_per_second);
+
+}
diff --git a/src/frame_time.h b/src/frame_time.h
index 045b833..9443676 100644
--- a/src/frame_time.h
+++ b/src/frame_time.h
@@ -41,6 +41,22 @@ public:
, _frames (f)
{}
+ int hours () const {
+ return _hours;
+ }
+
+ int minutes () const {
+ return _minutes;
+ }
+
+ int seconds () const {
+ return _seconds;
+ }
+
+ int frames () const {
+ return _frames;
+ }
+
std::string timecode () const;
private:
diff --git a/src/metric_time.cc b/src/metric_time.cc
index 3fc7874..d505a97 100644
--- a/src/metric_time.cc
+++ b/src/metric_time.cc
@@ -20,6 +20,7 @@
#include "metric_time.h"
#include "compose.hpp"
#include <iostream>
+#include <cmath>
using std::ostream;
using std::string;
@@ -31,6 +32,30 @@ MetricTime::MetricTime (int h, int m, int s, int ms)
}
+int
+MetricTime::hours () const
+{
+ return floor (_milliseconds / (3600 * 1000));
+}
+
+int
+MetricTime::minutes () const
+{
+ return int64_t (floor (_milliseconds / (60 * 1000))) % 60;
+}
+
+int
+MetricTime::seconds () const
+{
+ return int64_t (floor (_milliseconds / (1000))) % 3600;
+}
+
+int
+MetricTime::milliseconds () const
+{
+ return _milliseconds % (3600 * 1000);
+}
+
bool
sub::operator== (MetricTime const & a, MetricTime const & b)
{
diff --git a/src/metric_time.h b/src/metric_time.h
index 5a35176..4cea7f7 100644
--- a/src/metric_time.h
+++ b/src/metric_time.h
@@ -33,6 +33,11 @@ public:
{}
MetricTime (int h, int m, int s, int ms);
+
+ int hours () const;
+ int minutes () const;
+ int seconds () const;
+ int milliseconds () const;
private:
friend bool operator== (MetricTime const & a, MetricTime const & b);
diff --git a/src/subtitle.cc b/src/subtitle.cc
index d637ed9..26c4fd9 100644
--- a/src/subtitle.cc
+++ b/src/subtitle.cc
@@ -18,7 +18,9 @@
*/
#include "subtitle.h"
+#include "convert_time.h"
+using std::list;
using namespace sub;
bool
@@ -34,3 +36,33 @@ sub::operator< (Subtitle const & a, Subtitle const & b)
assert (false);
}
+
+void
+sub::convert_font_sizes (list<Subtitle>& subs, int screen_height_in_points)
+{
+ for (list<Subtitle>::iterator i = subs.begin(); i != subs.end(); ++i) {
+ if (i->font_size.proportional) {
+ i->font_size.points = i->font_size.proportional.get() * screen_height_in_points;
+ } else {
+ i->font_size.proportional = float (i->font_size.points.get()) / screen_height_in_points;
+ }
+ }
+}
+
+void
+sub::convert_times (list<Subtitle>& subs, float frames_per_second)
+{
+ for (list<Subtitle>::iterator i = subs.begin(); i != subs.end(); ++i) {
+ if (i->from.frame) {
+ i->from.metric = frame_to_metric (i->from.frame.get(), frames_per_second);
+ } else {
+ i->from.frame = metric_to_frame (i->from.metric.get(), frames_per_second);
+ }
+
+ if (i->to.frame) {
+ i->to.metric = frame_to_metric (i->to.frame.get(), frames_per_second);
+ } else {
+ i->to.frame = metric_to_frame (i->to.metric.get(), frames_per_second);
+ }
+ }
+}
diff --git a/src/subtitle.h b/src/subtitle.h
index b60b7f7..889f405 100644
--- a/src/subtitle.h
+++ b/src/subtitle.h
@@ -27,6 +27,7 @@
#include "effect.h"
#include <boost/optional.hpp>
#include <string>
+#include <list>
namespace sub {
@@ -50,6 +51,8 @@ public:
boost::optional<float> proportional;
/** in points */
boost::optional<int> points;
+
+ void convert ();
} font_size;
/** vertical position of the baseline of the text */
@@ -87,6 +90,9 @@ public:
bool operator< (Subtitle const & a, Subtitle const & b);
+void convert_font_sizes (std::list<Subtitle> &, int screen_height_in_points);
+void convert_times (std::list<Subtitle> &, float frames_per_second);
+
}
#endif
diff --git a/src/wscript b/src/wscript
index 11c7ac5..7e91edb 100644
--- a/src/wscript
+++ b/src/wscript
@@ -12,6 +12,7 @@ def build(bld):
obj.export_includes = ['.']
obj.source = """
colour.cc
+ convert_time.cc
dcp_reader.cc
effect.cc
frame_time.cc
@@ -25,6 +26,7 @@ def build(bld):
headers = """
colour.h
+ convert_time.h
dcp_reader.h
effect.h
frame_time.h