[MPlayer-dev-eng] [PATCH] fix vf scale with negative values

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Fri Nov 12 00:58:33 CET 2004


Hi,
> > > This patch is to fix a problem when using scale with negative values.
> > >  While scale=-1:-2 worked fine, scale=-2:-1 did not (though, according
> > > to the man page, it should have).
> > >
> > > I've done a few minutes of testing with this patch, and it doesn't seem
> > > to break anything, just fixes what was already broken.
> >
> > Are you sure it doesn't break scale=-1:-2? Anyway, this chaos-code
> > should really be cleaned up. Having the same code (expect for the
> > rounding) three times seems very bad to me.
> 
> thanks for volunteering to clean it up :)

That's what you get when I volunteer. You now all have to test.

Greetings,
Reimar Döffinger

> "I do not agree with what you have to say, but I'll defend to the death your
> right to say it." -- Voltaire

I like that one. But I doubt he said it in English. Do you by chance have the original somewhere? :-)

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpcodecs/vf_scale.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vf_scale.c,v
retrieving revision 1.55
diff -u -r1.55 vf_scale.c
--- libmpcodecs/vf_scale.c	18 Sep 2004 00:08:16 -0000	1.55
+++ libmpcodecs/vf_scale.c	11 Nov 2004 23:48:56 -0000
@@ -141,40 +141,46 @@
 	}
     }
 
+    if (vf->priv->w < -3 || vf->priv->h < -3 ||
+         (vf->priv->w < -1 && vf->priv->h < -1)) {
+      // TODO: establish a direct connection to the user's brain
+      // and find out what the heck he thinks MPlayer should do
+      // with this nonsense.
+      mp_msg(MSGT_VFILTER, MSGL_ERR, "SwScale: EUSERBROKEN Check your parameters, they make no sense!\n");
+      return 0;
+    }
+
+    if (vf->priv->w == -1)
+      vf->priv->w = width;
+    if (vf->priv->w == 0)
+      vf->priv->w = d_width;
+
+    if (vf->priv->h == -1)
+      vf->priv->h = height;
+    if (vf->priv->h == 0)
+      vf->priv->h = d_height;
+
+    if (vf->priv->w == -3)
+      vf->priv->w = vf->priv->h * width / height;
+    if (vf->priv->w == -2)
+      vf->priv->w = vf->priv->h * d_width / d_height;
+
+    if (vf->priv->h == -3)
+      vf->priv->h = vf->priv->w * height / width;
+    if (vf->priv->h == -2)
+      vf->priv->h = vf->priv->w * d_height / d_width;
+
     // calculate the missing parameters:
     switch(best) {
-    case IMGFMT_YUY2:		/* YUY2 needs w rounded to 2 */
-    case IMGFMT_UYVY:
-	if(vf->priv->w==-3) vf->priv->w=(vf->priv->h*width/height+1)&~1; else
-	if(vf->priv->w==-2) vf->priv->w=(vf->priv->h*d_width/d_height+1)&~1;
-	if(vf->priv->w<0) vf->priv->w=width; else
-	if(vf->priv->w==0) vf->priv->w=d_width;
-	if(vf->priv->h==-3) vf->priv->h=vf->priv->w*height/width; else
-	if(vf->priv->h==-2) vf->priv->h=vf->priv->w*d_height/d_width;
-	break;
     case IMGFMT_YV12:		/* YV12 needs w & h rounded to 2 */
     case IMGFMT_I420:
     case IMGFMT_IYUV:
-	if(vf->priv->w==-3) vf->priv->w=(vf->priv->h*width/height+1)&~1; else
-	if(vf->priv->w==-2) vf->priv->w=(vf->priv->h*d_width/d_height+1)&~1;
-	if(vf->priv->w<0) vf->priv->w=width; else
-	if(vf->priv->w==0) vf->priv->w=d_width;
-	if(vf->priv->h==-3) vf->priv->h=(vf->priv->w*height/width+1)&~1; else
-	if(vf->priv->h==-2) vf->priv->h=(vf->priv->w*d_height/d_width+1)&~1;
-	break;
-    default:
-    if(vf->priv->w==-3) vf->priv->w=vf->priv->h*width/height; else
-    if(vf->priv->w==-2) vf->priv->w=vf->priv->h*d_width/d_height;
-    if(vf->priv->w<0) vf->priv->w=width; else
-    if(vf->priv->w==0) vf->priv->w=d_width;
-    if(vf->priv->h==-3) vf->priv->h=vf->priv->w*height/width; else
-    if(vf->priv->h==-2) vf->priv->h=vf->priv->w*d_height/d_width;
-    break;
+      vf->priv->h = (vf->priv->h + 1) & ~1;
+    case IMGFMT_YUY2:		/* YUY2 needs w rounded to 2 */
+    case IMGFMT_UYVY:
+      vf->priv->w = (vf->priv->w + 1) & ~1;
     }
     
-    if(vf->priv->h<0) vf->priv->h=height; else
-    if(vf->priv->h==0) vf->priv->h=d_height;
-    
     mp_msg(MSGT_VFILTER,MSGL_DBG2,"SwScale: scaling %dx%d %s to %dx%d %s  \n",
 	width,height,vo_format_name(outfmt),
 	vf->priv->w,vf->priv->h,vo_format_name(best));


More information about the MPlayer-dev-eng mailing list