[MPlayer-dev-eng] vf_dsize rounding error

Rich Felker dalias at aerifal.cx
Fri May 5 17:17:34 CEST 2006


On Fri, May 05, 2006 at 10:04:47AM +0300, Ivan Kalvachev wrote:
> 2006/5/4, Alan Curry <pacman at theworld.com>:
> >In -vf dsize, resolution is calculated as a float and then assigned to an 
> >int
> >without any explicit rounding, so unlucky sizes can be computed as X.999999
> >and rounded down, ending up 1 less than the correct size. It would be 
> >better
> >to round to the nearest int.
> >
> >Index: libmpcodecs/vf_dsize.c
> >===================================================================
> >RCS file: /cvsroot/mplayer/main/libmpcodecs/vf_dsize.c,v
> >retrieving revision 1.4
> >diff -u -r1.4 vf_dsize.c
> >--- libmpcodecs/vf_dsize.c      20 Dec 2005 17:38:43 -0000      1.4
> >+++ libmpcodecs/vf_dsize.c      4 May 2006 17:38:06 -0000
> >@@ -46,10 +46,10 @@
> >                d_height = vf->priv->h;
> >        } else {
> >                if (vf->priv->aspect * height > width) {
> >-                       d_width = height * vf->priv->aspect;
> >+                       d_width = height * vf->priv->aspect + .5;
> >                        d_height = height;
> >                } else {
> >-                       d_height = width / vf->priv->aspect;
> >+                       d_height = width / vf->priv->aspect + .5;
> >                        d_width = width;
> >                }
> >        }
> 
> Why not use round() that rounds to the nearest integer, away from zero?

Because the effect is the same except it depends on a library routine
and that's caused more problems in the past... And it's less obvious
what it does.

Rich




More information about the MPlayer-dev-eng mailing list