Mercurial > libavcodec.hg
diff utils.c @ 2002:b737b5e96ee0 libavcodec
use AVInteger in av_rescale() so it can finally do 64*64/64 instead of just 64*32/32
author | michael |
---|---|
date | Tue, 04 May 2004 02:58:30 +0000 |
parents | f481d3309ad0 |
children | 85e547a18d87 |
line wrap: on
line diff
--- a/utils.c Tue May 04 02:51:18 2004 +0000 +++ b/utils.c Tue May 04 02:58:30 2004 +0000 @@ -27,7 +27,9 @@ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" +#include "integer.h" #include <stdarg.h> +#include <limits.h> static void avcodec_default_free_buffers(AVCodecContext *s); @@ -816,23 +818,25 @@ return exact; } -int64_t av_rescale(int64_t a, int b, int c){ - uint64_t h, l; +int64_t av_rescale(int64_t a, int64_t b, int64_t c){ + AVInteger ai, ci; assert(c > 0); assert(b >=0); if(a<0) return -av_rescale(-a, b, c); - h= a>>32; - if(h==0) return a*b/c; + if(b<=INT_MAX && c<=INT_MAX){ + if(a<=INT_MAX) + return (a * b + c/2)/c; + else + return a/c*b + (a%c*b + c/2)/c; + } - l= a&0xFFFFFFFF; - l *= b; - h *= b; - - l += (h%c)<<32; - - return ((h/c)<<32) + l/c; + ai= av_mul_i(av_int2i(a), av_int2i(b)); + ci= av_int2i(c); + ai= av_add_i(ai, av_shr_i(ci,1)); + + return av_i2int(av_div_i(ai, ci)); } /* av_log API */