[FFmpeg-devel] [PATCH] avcodec/pngenc: cast double to integer type to avoid problems with some AV_WB32() implementations

Clément Bœsch u at pkh.me
Mon Mar 2 16:24:42 CET 2015


On Sun, Mar 01, 2015 at 08:07:46PM -0500, Ronald S. Bultje wrote:
> Hi,
> 
> On Sun, Mar 1, 2015 at 7:38 PM, Michael Niedermayer <michaelni at gmx.at>
> wrote:
> 
> > alternatively lrint(f)() could be used
> > or various other options
> >
> > Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> > ---
> >  libavcodec/pngenc.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
> > index 9fd8eef..3a94366 100644
> > --- a/libavcodec/pngenc.c
> > +++ b/libavcodec/pngenc.c
> > @@ -231,7 +231,7 @@ static int png_write_row(PNGEncContext *s, const
> > uint8_t *data, int size)
> >      return 0;
> >  }
> >
> > -#define AV_WB32_PNG(buf, n) (AV_WB32(buf, round((n) * 100000)))
> > +#define AV_WB32_PNG(buf, n) (AV_WB32(buf, (unsigned int)round((n) *
> > 100000))
> >
> 
> The typical solution here is to use lrint(f), and that is the C-recommended
> way of converting a double to a integer(ish). So I'd prefer we use that
> instead of this sort of frankenversion of the same concept.
> 

What about the ~40 other occurrences BTW? (git grep '[^a-zA-Z_]round(')

Also, we have this:
libavutil/libm.h:static av_always_inline av_const double round(double x)
libavutil/libm.h-{
libavutil/libm.h-    return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
libavutil/libm.h-}

So do we support it or not?

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150302/57a2ed70/attachment.asc>


More information about the ffmpeg-devel mailing list