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; } }
2006/5/4, Alan Curry <pacman@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?
On Fri, May 05, 2006 at 10:04:47AM +0300, Ivan Kalvachev wrote:
2006/5/4, Alan Curry <pacman@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
On Thu, May 04, 2006 at 01:49:44PM -0400, Alan Curry wrote:
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.
Committed - ods15
2006/5/5, Oded Shimon <ods15@ods15.dyndns.org>:
On Thu, May 04, 2006 at 01:49:44PM -0400, Alan Curry wrote:
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.
Committed
I though Alan is developer now and can apply his path by himself.
On Sat, May 06, 2006 at 01:49:23AM +0300, Ivan Kalvachev wrote:
2006/5/5, Oded Shimon <ods15@ods15.dyndns.org>:
On Thu, May 04, 2006 at 01:49:44PM -0400, Alan Curry wrote:
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.
Committed
I though Alan is developer now and can apply his path by himself.
Hmm, there wasn't a threat of commit in the mail, and it is my code... - ods15
Ivan Kalvachev writes the following:
2006/5/5, Oded Shimon <ods15@ods15.dyndns.org>:
Committed
I though Alan is developer now and can apply his path by himself.
I would have, but I expected the debate over the merits of round() to go on longer, with rintf() making an appearance, and a simultaneous discussion on whether the floats should be doubles.
participants (4)
-
Alan Curry -
Ivan Kalvachev -
Oded Shimon -
Rich Felker