summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-10-14 00:24:26 +0100
committerCarl Hetherington <cth@carlh.net>2012-10-14 00:24:26 +0100
commit01f91d3d743b1d9c5306e8817cfd926eddc61736 (patch)
tree849b17a202e81ed40f4016c3361aa5d35facab04 /src/lib
parent5ec4cafd9ed9966c0af6b3f33f78cc833950ee0c (diff)
Fix up tests; possibly working subtitle transforms.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/subtitle.cc36
-rw-r--r--src/lib/subtitle.h15
2 files changed, 51 insertions, 0 deletions
diff --git a/src/lib/subtitle.cc b/src/lib/subtitle.cc
index 18dded02c..3559197a0 100644
--- a/src/lib/subtitle.cc
+++ b/src/lib/subtitle.cc
@@ -20,6 +20,7 @@
#include "subtitle.h"
#include "image.h"
#include "exceptions.h"
+#include "film_state.h"
using namespace std;
using namespace boost;
@@ -68,3 +69,38 @@ SubtitleImage::SubtitleImage (AVSubtitleRect const * rect)
sub_p += rect->pict.linesize[0];
}
}
+
+SubtitleTransform
+subtitle_transform (
+ int target_base_width, int target_base_height,
+ float target_x_scale, float target_y_scale,
+ Position sub_pos, int sub_width, int sub_height,
+ shared_ptr<FilmState> fs
+ )
+{
+ SubtitleTransform tx;
+
+ Rectangle sub_area (sub_pos.x, sub_pos.y + fs->subtitle_offset, sub_width, sub_height);
+
+ Rectangle cropped_target_area (
+ fs->crop.left,
+ fs->crop.top,
+ target_base_width - (fs->crop.left + fs->crop.right),
+ target_base_height - (fs->crop.top + fs->crop.bottom)
+ );
+
+ Rectangle cropped_sub_area = sub_area.intersection (cropped_target_area);
+
+ tx.crop.x = cropped_sub_area.x - sub_area.x;
+ tx.crop.y = cropped_sub_area.y - sub_area.y;
+ tx.crop.w = cropped_sub_area.w;
+ tx.crop.h = cropped_sub_area.h;
+
+ tx.transformed.w = cropped_sub_area.w * target_x_scale * fs->subtitle_scale;
+ tx.transformed.h = cropped_sub_area.h * target_y_scale * fs->subtitle_scale;
+
+ tx.transformed.x = target_x_scale * ((sub_area.x - fs->crop.left) + (cropped_sub_area.w * (1 - fs->subtitle_scale) / 2));
+ tx.transformed.y = target_y_scale * ((sub_area.y - fs->crop.top) + (cropped_sub_area.h * (1 - fs->subtitle_scale) / 2));
+
+ return tx;
+}
diff --git a/src/lib/subtitle.h b/src/lib/subtitle.h
index 18d2590eb..fcb6bc70c 100644
--- a/src/lib/subtitle.h
+++ b/src/lib/subtitle.h
@@ -24,6 +24,7 @@
struct AVSubtitle;
class SubtitleImage;
class SimpleImage;
+class FilmState;
class Subtitle
{
@@ -44,6 +45,20 @@ private:
std::list<boost::shared_ptr<SubtitleImage> > _images;
};
+struct SubtitleTransform
+{
+public:
+ Rectangle crop;
+ Rectangle transformed;
+};
+
+extern SubtitleTransform subtitle_transform (
+ int target_base_width, int target_base_height,
+ float target_x_scale, float target_y_scale,
+ Position sub_pos, int sub_width, int sub_height,
+ boost::shared_ptr<FilmState> fs
+ );
+
class SubtitleImage
{
public: