summaryrefslogtreecommitdiffstats
path: root/sub/sd_lavc.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/sd_lavc.c
parent7c7d214775f87e82312aa1441d59ddf7c0df9d2e (diff)
downloadmpv-fcfd04409008cf1eed62b778f0b388023f00c005.tar.bz2
mpv-fcfd04409008cf1eed62b778f0b388023f00c005.tar.xz
sd_lavc: factor out bitmap positioning code
Diffstat (limited to 'sub/sd_lavc.c')
-rw-r--r--sub/sd_lavc.c44
1 files changed, 14 insertions, 30 deletions
diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c
index 9741b0de70..724a4fe77c 100644
--- a/sub/sd_lavc.c
+++ b/sub/sd_lavc.c
@@ -212,45 +212,29 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts,
if (priv->endpts != MP_NOPTS_VALUE && (pts >= priv->endpts ||
pts < priv->endpts - 300))
clear(priv);
- if (priv->bitmaps_changed && priv->count > 0)
- priv->outbitmaps = talloc_memdup(priv, priv->inbitmaps,
- talloc_get_size(priv->inbitmaps));
+ size_t size = talloc_get_size(priv->inbitmaps);
+ if (!priv->outbitmaps)
+ priv->outbitmaps = talloc_size(priv, size);
+ memcpy(priv->outbitmaps, priv->inbitmaps, size);
int inw = priv->avctx->width;
int inh = priv->avctx->height;
guess_resolution(priv->avctx->codec_id, &inw, &inh);
- int vidw = d.w - d.ml - d.mr;
- int vidh = d.h - d.mt - d.mb;
- double xscale = (double)vidw / inw;
- double yscale = (double)vidh / inh;
- if (priv->avctx->codec_id == AV_CODEC_ID_DVD_SUBTITLE &&
- opts->stretch_dvd_subs) {
- // For DVD subs, try to keep the subtitle PAR at display PAR.
- double video_par =
- (priv->video_params.d_w / (double)priv->video_params.d_h)
- / (priv->video_params.w / (double)priv->video_params.h);
- if (video_par > 1.0) {
- xscale /= video_par;
- } else {
- yscale *= video_par;
- }
- }
- int cx = vidw / 2 - (int)(inw * xscale) / 2;
- int cy = vidh / 2 - (int)(inh * yscale) / 2;
- for (int i = 0; i < priv->count; i++) {
- struct sub_bitmap *bi = &priv->inbitmaps[i];
- struct sub_bitmap *bo = &priv->outbitmaps[i];
- bo->x = bi->x * xscale + cx + d.ml;
- bo->y = bi->y * yscale + cy + d.mt;
- bo->dw = bi->w * xscale;
- bo->dh = bi->h * yscale;
- }
res->parts = priv->outbitmaps;
res->num_parts = priv->count;
if (priv->bitmaps_changed)
res->bitmap_id = ++res->bitmap_pos_id;
priv->bitmaps_changed = false;
res->format = SUBBITMAP_INDEXED;
- res->scaled = xscale != 1 || yscale != 1;
+
+ double video_par = -1;
+ if (priv->avctx->codec_id == AV_CODEC_ID_DVD_SUBTITLE &&
+ opts->stretch_dvd_subs) {
+ // For DVD subs, try to keep the subtitle PAR at display PAR.
+ video_par =
+ (priv->video_params.d_w / (double)priv->video_params.d_h)
+ / (priv->video_params.w / (double)priv->video_params.h);
+ }
+ osd_rescale_bitmaps(res, inw, inh, d, video_par);
}
static void reset(struct sd *sd)