projects
/
libdcp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add constructor of MonoPictureFrame from a JPEG2000 codestream file.
[libdcp.git]
/
src
/
dcp_time.cc
diff --git
a/src/dcp_time.cc
b/src/dcp_time.cc
index 7c7c5298b5d3046080076d854036b9e0a9794588..9ce367645c29e6654bb7471c6246d4743c9434ca 100644
(file)
--- a/
src/dcp_time.cc
+++ b/
src/dcp_time.cc
@@
-1,5
+1,5
@@
/*
/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012
-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
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
@@
-18,20
+18,20
@@
*/
/** @file src/dcp_time.cc
*/
/** @file src/dcp_time.cc
- * @brief
A representation of time within a DCP
.
+ * @brief
Time class
.
*/
*/
+#include "raw_convert.h"
+#include "dcp_time.h"
+#include "exceptions.h"
+#include <boost/algorithm/string.hpp>
#include <iostream>
#include <vector>
#include <iostream>
#include <vector>
-#include <boost/algorithm/string.hpp>
-#include <boost/lexical_cast.hpp>
#include <cmath>
#include <cmath>
-#include "dcp_time.h"
-#include "exceptions.h"
using namespace std;
using namespace boost;
using namespace std;
using namespace boost;
-using namespace
lib
dcp;
+using namespace dcp;
Time::Time (int frame, int frames_per_second)
: h (0)
Time::Time (int frame, int frames_per_second)
: h (0)
@@
-42,18
+42,29
@@
Time::Time (int frame, int frames_per_second)
set (double (frame) / frames_per_second);
}
set (double (frame) / frames_per_second);
}
+Time::Time (int64_t ticks)
+{
+ h = ticks / (60 * 60 * 250);
+ ticks -= int64_t (h) * 60 * 60 * 250;
+ m = ticks / (60 * 250);
+ ticks -= int64_t (m) * 60 * 250;
+ s = ticks / 250;
+ ticks -= int64_t (s) * 250;
+ t = ticks;
+}
+
void
Time::set (double ss)
{
void
Time::set (double ss)
{
- t = (int (round (ss * 1000)) % 1000) / 4;
s = floor (ss);
s = floor (ss);
+ t = int (round (1000 * (ss - s) / 4));
- if (s > 60) {
+ if (s >
=
60) {
m = s / 60;
s -= m * 60;
}
m = s / 60;
s -= m * 60;
}
- if (m > 60) {
+ if (m >
=
60) {
h = m / 60;
m -= h * 60;
}
h = m / 60;
m -= h * 60;
}
@@
-64,29
+75,29
@@
Time::Time (string time)
vector<string> b;
split (b, time, is_any_of (":"));
if (b.size() != 4) {
vector<string> b;
split (b, time, is_any_of (":"));
if (b.size() != 4) {
-
throw DCPReadError ("unrecognised time specification"
);
+
boost::throw_exception (DCPReadError ("unrecognised time specification")
);
}
}
- h =
lexical_cas
t<int> (b[0]);
- m =
lexical_cas
t<int> (b[1]);
- s =
lexical_cas
t<int> (b[2]);
- t =
lexical_cas
t<int> (b[3]);
+ h =
raw_conver
t<int> (b[0]);
+ m =
raw_conver
t<int> (b[1]);
+ s =
raw_conver
t<int> (b[2]);
+ t =
raw_conver
t<int> (b[3]);
}
bool
}
bool
-
lib
dcp::operator== (Time const & a, Time const & b)
+dcp::operator== (Time const & a, Time const & b)
{
return (a.h == b.h && a.m == b.m && a.s == b.s && a.t == b.t);
}
bool
{
return (a.h == b.h && a.m == b.m && a.s == b.s && a.t == b.t);
}
bool
-
lib
dcp::operator!= (Time const & a, Time const & b)
+dcp::operator!= (Time const & a, Time const & b)
{
return !(a == b);
}
bool
{
return !(a == b);
}
bool
-
lib
dcp::operator<= (Time const & a, Time const & b)
+dcp::operator<= (Time const & a, Time const & b)
{
if (a.h != b.h) {
return a.h <= b.h;
{
if (a.h != b.h) {
return a.h <= b.h;
@@
-108,7
+119,7
@@
libdcp::operator<= (Time const & a, Time const & b)
}
bool
}
bool
-
lib
dcp::operator< (Time const & a, Time const & b)
+dcp::operator< (Time const & a, Time const & b)
{
if (a.h != b.h) {
return a.h < b.h;
{
if (a.h != b.h) {
return a.h < b.h;
@@
-130,7
+141,7
@@
libdcp::operator< (Time const & a, Time const & b)
}
bool
}
bool
-
lib
dcp::operator> (Time const & a, Time const & b)
+dcp::operator> (Time const & a, Time const & b)
{
if (a.h != b.h) {
return a.h > b.h;
{
if (a.h != b.h) {
return a.h > b.h;
@@
-152,14
+163,14
@@
libdcp::operator> (Time const & a, Time const & b)
}
ostream &
}
ostream &
-
lib
dcp::operator<< (ostream& s, Time const & t)
+dcp::operator<< (ostream& s, Time const & t)
{
s << t.h << ":" << t.m << ":" << t.s << "." << t.t;
return s;
}
{
s << t.h << ":" << t.m << ":" << t.s << "." << t.t;
return s;
}
-
lib
dcp::Time
-
lib
dcp::operator+ (Time a, Time const & b)
+dcp::Time
+dcp::operator+ (Time a, Time const & b)
{
Time r;
{
Time r;
@@
-186,8
+197,8
@@
libdcp::operator+ (Time a, Time const & b)
return r;
}
return r;
}
-
lib
dcp::Time
-
lib
dcp::operator- (Time a, Time const & b)
+dcp::Time
+dcp::operator- (Time a, Time const & b)
{
Time r;
{
Time r;
@@
-215,7
+226,7
@@
libdcp::operator- (Time a, Time const & b)
}
float
}
float
-
lib
dcp::operator/ (Time a, Time const & b)
+dcp::operator/ (Time a, Time const & b)
{
int64_t const at = a.h * 3600 * 250 + a.m * 60 * 250 + a.s * 250 + a.t;
int64_t const bt = b.h * 3600 * 250 + b.m * 60 * 250 + b.s * 250 + b.t;
{
int64_t const at = a.h * 3600 * 250 + a.m * 60 * 250 + a.s * 250 + a.t;
int64_t const bt = b.h * 3600 * 250 + b.m * 60 * 250 + b.s * 250 + b.t;
@@
-235,6
+246,11
@@
Time::to_string () const
int64_t
Time::to_ticks () const
{
int64_t
Time::to_ticks () const
{
- return
t + s * 25 + m * 60 * 25 + h * 60 * 60 * 25
;
+ return
int64_t(t) + int64_t(s) * 250 + int64_t(m) * 60 * 250 + int64_t(h) * 60 * 60 * 250
;
}
}
+double
+Time::to_seconds () const
+{
+ return double (to_ticks ()) / 250;
+}