From d9d80705e62c99e4a3d3dbc56684a66aa63b4412 Mon Sep 17 00:00:00 2001 From: mplayer-svn Date: Tue, 22 Nov 2011 19:33:29 +0000 Subject: vf_expand: add sanity checks Make vf expand more picky: refuse operating on compressed or hwaccel formats and fix up offsets that would cause color corruption for YUV formats with downsampled chroma. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34356 b3059339-0415-0410-9bf9-f77b7e298cf2 Author: reimar --- libmpcodecs/vf_expand.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libmpcodecs/vf_expand.c b/libmpcodecs/vf_expand.c index 6cc7a810b6..a5ce57fa98 100644 --- a/libmpcodecs/vf_expand.c +++ b/libmpcodecs/vf_expand.c @@ -132,11 +132,13 @@ static int config(struct vf_instance *vf, unsigned int flags, unsigned int outfmt) { struct MPOpts *opts = vf->opts; + mp_image_t test_mpi; if(outfmt == IMGFMT_MPEGPES) { vf->priv->passthrough = 1; return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); } - if (outfmt == IMGFMT_IF09) return 0; + mp_image_setfmt(&test_mpi, outfmt); + if (outfmt == IMGFMT_IF09 || !test_mpi.bpp) return 0; vf->priv->exp_x = vf->priv->cfg_exp_x; vf->priv->exp_y = vf->priv->cfg_exp_y; vf->priv->exp_w = vf->priv->cfg_exp_w; @@ -169,6 +171,23 @@ static int config(struct vf_instance *vf, if(vf->priv->exp_x<0 || vf->priv->exp_x+width>vf->priv->exp_w) vf->priv->exp_x=(vf->priv->exp_w-width)/2; if(vf->priv->exp_y<0 || vf->priv->exp_y+height>vf->priv->exp_h) vf->priv->exp_y=(vf->priv->exp_h-height)/2; + if(test_mpi.flags & MP_IMGFLAG_YUV) { + int x_align_mask = (1 << test_mpi.chroma_x_shift) - 1; + int y_align_mask = (1 << test_mpi.chroma_y_shift) - 1; + // For 1-plane format non-aligned offsets will completely + // destroy the colours, for planar it will break the chroma + // sampling position. + if (vf->priv->exp_x & x_align_mask) { + vf->priv->exp_x &= ~x_align_mask; + mp_msg(MSGT_VFILTER, MSGL_ERR, "Specified x offset not supported " + "for YUV, reduced to %i.\n", vf->priv->exp_x); + } + if (vf->priv->exp_y & y_align_mask) { + vf->priv->exp_y &= ~y_align_mask; + mp_msg(MSGT_VFILTER, MSGL_ERR, "Specified y offset not supported " + "for YUV, reduced to %i.\n", vf->priv->exp_y); + } + } if(!opts->screen_size_x && !opts->screen_size_y){ d_width=d_width*vf->priv->exp_w/width; -- cgit v1.2.3