[MPlayer-dev-eng] autoexpand patch

jan gregor pamela at rak.bb.euroweb.sk
Thu Nov 11 11:40:00 CET 2004


> > > I have inserted aspect option to vf_expand.c as suggested here, with one
> > > exception: aspect is not defined like x/y, but there are 2 separate
> > > parameters named ratio_x and ratio_y. Functionality is the same, only
> > > "/" did problems with buitin checks on parameters, because it expected
> > > it to be one integer value. Maybe there was some workaround (type of
> > > parameter other than integer), but I am not too familiar with mplayer
> > > source code, so I simply split it.
> > 
> > as 4/3 == 1.333, it's not an integer of course. set type to float, and
> > it will work.
> 
> also, it should take care of optional width and height params:
> 
> - if width is given, then your code should calculate height as width/aspect
> - if height is given, it should calculate width as height*aspect
> - if both width & height given, it should check both cases, and choose the
>   one which fits to the width*height window:
>      if(height*aspect>width)
>         height=width/aspect
>      else
>         width=height*aspect

Hello

I'm attaching patch to vf_expand.c which works like suggested above. 
If there is likely going to be image corruption, filter prints out a
warning. This happens when area after aspect "expansion" is smaller than
original movie.
Suggestions are welcome.


Best regards

Jan Gregor

-------------- next part --------------
diff -u -N -b -r ../MPlayer-1.0pre5/libmpcodecs/vf_expand.c ./libmpcodecs/vf_expand.c
--- ../MPlayer-1.0pre5/libmpcodecs/vf_expand.c	2003-06-19 20:26:13.000000000 +0200
+++ ./libmpcodecs/vf_expand.c	2004-11-10 23:08:09.000000000 +0100
@@ -27,11 +27,13 @@
     int exp_w,exp_h;
     int exp_x,exp_y;
     int osd;
+    float aspect;
     unsigned char* fb_ptr;
 } vf_priv_dflt = {
   -1,-1,
   -1,-1,
   0,
+  0,
   NULL
 };
 
@@ -172,6 +174,31 @@
     if ( vf->priv->exp_h == -1 ) vf->priv->exp_h=height;
       else if ( vf->priv->exp_h < -1 ) vf->priv->exp_h=height - vf->priv->exp_h;
         else if( vf->priv->exp_h<height ) vf->priv->exp_h=height;
+    // if no aspect was given, do not apply it
+    if (vf->priv->aspect>0) {
+      if ((vf->priv->exp_h == height) && (vf->priv->exp_w == width)) {
+        // width and height not given. simply apply aspect
+	if (vf->priv->exp_h*vf->priv->aspect < vf->priv->exp_w) vf->priv->exp_h = vf->priv->exp_w/vf->priv->aspect;
+	  else vf->priv->exp_w = vf->priv->exp_h*vf->priv->aspect;
+      } else if (vf->priv->exp_h == height) {
+	// width given, calculate height
+        if (vf->priv->exp_w/vf->priv->aspect < height) mp_msg(MSGT_VFILTER, MSGL_INFO,"Expand: warning, image corruption may occur.\n");
+	vf->priv->exp_h = vf->priv->exp_w/vf->priv->aspect;
+      } else if (vf->priv->exp_w == width) {
+	// height given, calculate width
+	if (vf->priv->exp_h*vf->priv->aspect < width) mp_msg(MSGT_VFILTER, MSGL_INFO,"Expand: warning, image corruption may occur.\n");
+	vf->priv->exp_w = vf->priv->exp_h*vf->priv->aspect;
+      } else {
+	// both width and height given, calculate smallest possible window with one parameter fixed
+	if (vf->priv->exp_h*vf->priv->aspect < vf->priv->exp_w) {
+	  if (vf->priv->exp_h*vf->priv->aspect < width) mp_msg(MSGT_VFILTER, MSGL_INFO,"Expand: warning, image corruption may occur.\n");
+	  vf->priv->exp_w = vf->priv->exp_h*vf->priv->aspect;
+	} else {
+	  if (vf->priv->exp_w/vf->priv->aspect < height) mp_msg(MSGT_VFILTER, MSGL_INFO,"Expand: warning, image corruption may occur.\n");
+	  vf->priv->exp_h = vf->priv->exp_w/vf->priv->aspect;
+	}
+      }
+    }
 #endif
     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;
@@ -340,21 +367,26 @@
     vf->priv->exp_y=
     vf->priv->exp_w=
     vf->priv->exp_h=-1;
+    vf->priv->aspect=0;
     vf->priv->osd=0;
     //  parse args ->
     } // if(!vf->priv)
-    if(args) sscanf(args, "%d:%d:%d:%d:%d", 
+    if(args) sscanf(args, "%d:%d:%d:%d:%d:%f", 
     &vf->priv->exp_w,
     &vf->priv->exp_h,
     &vf->priv->exp_x,
     &vf->priv->exp_y,
-    &vf->priv->osd);
-    mp_msg(MSGT_VFILTER, MSGL_INFO, "Expand: %d x %d, %d ; %d  (-1=autodetect) osd: %d\n",
+    &vf->priv->osd,
+    &vf->priv->aspect
+    );
+    mp_msg(MSGT_VFILTER, MSGL_INFO, "Expand: %d x %d, %d ; %d  (-1=autodetect) osd: %d ratio: %f\n",
     vf->priv->exp_w,
     vf->priv->exp_h,
     vf->priv->exp_x,
     vf->priv->exp_y,
-    vf->priv->osd);
+    vf->priv->osd,
+    vf->priv->aspect
+    );
     return 1;
 }
 
@@ -365,6 +397,7 @@
   {"x", ST_OFF(exp_x), CONF_TYPE_INT, M_OPT_MIN, -1, 0, NULL},
   {"y", ST_OFF(exp_y), CONF_TYPE_INT, M_OPT_MIN, -1, 0, NULL},
   {"osd", ST_OFF(osd), CONF_TYPE_FLAG, 0 , 0, 1, NULL},
+  {"aspect", ST_OFF(aspect), CONF_TYPE_FLOAT, M_OPT_MIN , 0, 0, NULL},
   { NULL, NULL, 0, 0, 0, 0,  NULL }
 };
 


More information about the MPlayer-dev-eng mailing list