summaryrefslogtreecommitdiffstats
path: root/sub/osd.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-11 23:15:29 +0100
committerwm4 <wm4@nowhere>2013-12-12 01:25:21 +0100
commitfcfd04409008cf1eed62b778f0b388023f00c005 (patch)
tree692b19f8010d36b086b802d2b7d7dfd4fc816271 /sub/osd.c
parent7c7d214775f87e82312aa1441d59ddf7c0df9d2e (diff)
downloadmpv-fcfd04409008cf1eed62b778f0b388023f00c005.tar.bz2
mpv-fcfd04409008cf1eed62b778f0b388023f00c005.tar.xz
sd_lavc: factor out bitmap positioning code
Diffstat (limited to 'sub/osd.c')
-rw-r--r--sub/osd.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/sub/osd.c b/sub/osd.c
index bd06dbf8d4..66b79f7bb8 100644
--- a/sub/osd.c
+++ b/sub/osd.c
@@ -322,3 +322,34 @@ void osd_object_get_scale_factor(struct osd_state *osd, struct osd_object *obj,
*sw = nw / (double)obj->vo_res.w;
*sh = nh / (double)obj->vo_res.h;
}
+
+// Position the subbitmaps in imgs on the screen. Basically, this fits the
+// subtitle canvas (of size frame_w x frame_h) onto the screen, such that it
+// fills the whole video area (especially if the video is magnified, e.g. on
+// fullscreen). If compensate_par is given, adjust the way the subtitles are
+// "stretched" on the screen, and letter-box the result.
+void osd_rescale_bitmaps(struct sub_bitmaps *imgs, int frame_w, int frame_h,
+ struct mp_osd_res res, double compensate_par)
+{
+ int vidw = res.w - res.ml - res.mr;
+ int vidh = res.h - res.mt - res.mb;
+ double xscale = (double)vidw / frame_w;
+ double yscale = (double)vidh / frame_h;
+ if (compensate_par > 0) {
+ if (compensate_par > 1.0) {
+ xscale /= compensate_par;
+ } else {
+ yscale *= compensate_par;
+ }
+ }
+ int cx = vidw / 2 - (int)(frame_w * xscale) / 2;
+ int cy = vidh / 2 - (int)(frame_h * yscale) / 2;
+ for (int i = 0; i < imgs->num_parts; i++) {
+ struct sub_bitmap *bi = &imgs->parts[i];
+ bi->x = bi->x * xscale + cx + res.ml;
+ bi->y = bi->y * yscale + cy + res.mt;
+ bi->dw = bi->w * xscale;
+ bi->dh = bi->h * yscale;
+ }
+ imgs->scaled = xscale != 1 || yscale != 1;
+}