changeset 34268:d4d4fe2184a4

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.
author reimar
date Tue, 22 Nov 2011 19:33:29 +0000
parents 4807501b7405
children 99fceaf417ad
files libmpcodecs/vf_expand.c
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/vf_expand.c	Tue Nov 22 19:31:29 2011 +0000
+++ b/libmpcodecs/vf_expand.c	Tue Nov 22 19:33:29 2011 +0000
@@ -218,11 +218,13 @@
 static int config(struct vf_instance *vf,
         int width, int height, int d_width, int d_height,
 	unsigned int flags, unsigned int outfmt){
+    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;
@@ -255,6 +257,23 @@
 
     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);
+        }
+    }
     vf->priv->fb_ptr=NULL;
 
     if(!opt_screen_size_x && !opt_screen_size_y){