--- /dev/null
+/*
+ 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);
+}
--- /dev/null
+/*
+ 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);
+
+}
, _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:
#include "metric_time.h"
#include "compose.hpp"
#include <iostream>
+#include <cmath>
using std::ostream;
using std::string;
}
+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)
{
{}
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);
*/
#include "subtitle.h"
+#include "convert_time.h"
+using std::list;
using namespace sub;
bool
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);
+ }
+ }
+}
#include "effect.h"
#include <boost/optional.hpp>
#include <string>
+#include <list>
namespace sub {
boost::optional<float> proportional;
/** in points */
boost::optional<int> points;
+
+ void convert ();
} font_size;
/** vertical position of the baseline of the text */
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
obj.export_includes = ['.']
obj.source = """
colour.cc
+ convert_time.cc
dcp_reader.cc
effect.cc
frame_time.cc
headers = """
colour.h
+ convert_time.h
dcp_reader.h
effect.h
frame_time.h
--- /dev/null
+/*
+ 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 <boost/test/unit_test.hpp>
+#include "metric_time.h"
+#include "frame_time.h"
+#include "convert_time.h"
+
+/* Check time conversions */
+BOOST_AUTO_TEST_CASE (time_test)
+{
+ BOOST_CHECK_EQUAL (metric_to_frame (sub::MetricTime (3, 5, 7, 40), 25), sub::FrameTime (3, 5, 7, 1));
+ BOOST_CHECK_EQUAL (frame_to_metric (sub::FrameTime (3, 5, 7, 1), 25), sub::MetricTime (3, 5, 7, 40));
+ BOOST_CHECK_EQUAL (metric_to_frame (sub::MetricTime (3, 5, 7, 120), 25), sub::FrameTime (3, 5, 7, 3));
+ BOOST_CHECK_EQUAL (frame_to_metric (sub::FrameTime (3, 5, 7, 3), 25), sub::MetricTime (3, 5, 7, 120));
+}
+
dcp_reader_test.cc
stl_reader_test.cc
stl_writer_test.cc
+ time_test.cc
test.cc
"""
obj.target = 'tests'