Merge branch 'master' of ssh://houllier/home/carl/git/dvdomatic
[dcpomatic.git] / src / lib / subtitle.cc
index dcb747828a954598074619e6ecf57833aa6ffcf4..282a2cde1a68b9e494af6fcc005d3f88b8f7b4d2 100644 (file)
@@ -24,7 +24,6 @@
 #include "subtitle.h"
 #include "image.h"
 #include "exceptions.h"
-#include "film_state.h"
 
 using namespace std;
 using namespace boost;
@@ -32,11 +31,14 @@ using namespace boost;
 /** Construct a TimedSubtitle.  This is a subtitle image, position,
  *  and a range of time over which it should be shown.
  *  @param sub AVSubtitle to read.
+ *  @param c Fractional seconds that should be subtracted from the AVSubtitle's PTS.
  */
-TimedSubtitle::TimedSubtitle (AVSubtitle const & sub)
+TimedSubtitle::TimedSubtitle (AVSubtitle const & sub, double c)
 {
+       assert (sub.rects > 0);
+       
        /* subtitle PTS in seconds */
-       float const packet_time = (sub.pts / AV_TIME_BASE) + float (sub.pts % AV_TIME_BASE) / 1e6;
+       double const packet_time = ((sub.pts / AV_TIME_BASE) + float (sub.pts % AV_TIME_BASE) / 1e6) - c;
        
        /* hence start time for this sub */
        _from = packet_time + (double (sub.start_display_time) / 1e3);
@@ -102,13 +104,13 @@ Subtitle::Subtitle (Position p, shared_ptr<Image> i)
  *  in the coordinate space of the source.
  *  @param subtitle_scale scaling factor to apply to the subtitle image.
  */
-Rectangle
+Rect
 subtitle_transformed_area (
        float target_x_scale, float target_y_scale,
-       Rectangle sub_area, int subtitle_offset, float subtitle_scale
+       Rect sub_area, int subtitle_offset, float subtitle_scale
        )
 {
-       Rectangle tx;
+       Rect tx;
 
        sub_area.y += subtitle_offset;
 
@@ -137,8 +139,8 @@ subtitle_transformed_area (
 }
 
 /** @return area that this subtitle take up, in the original uncropped source's coordinate space */
-Rectangle
+Rect
 Subtitle::area () const
 {
-       return Rectangle (_position.x, _position.y, _image->size().width, _image->size().height);
+       return Rect (_position.x, _position.y, _image->size().width, _image->size().height);
 }