From fcfd04409008cf1eed62b778f0b388023f00c005 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 11 Dec 2013 23:15:29 +0100 Subject: sd_lavc: factor out bitmap positioning code --- sub/osd.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'sub/osd.c') 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; +} -- cgit v1.2.3