[MPlayer-dev-eng] vf_dsize rounding error

Ivan Kalvachev ikalvachev at gmail.com
Fri May 5 09:04:47 CEST 2006


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?




More information about the MPlayer-dev-eng mailing list