1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

use AVInteger in av_rescale() so it can finally do 64*64/64 instead of just 64*32/32

Originally committed as revision 3106 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Michael Niedermayer 2004-05-04 02:58:30 +00:00
parent 29adde838c
commit 4c263142c5
2 changed files with 17 additions and 13 deletions

View File

@ -17,7 +17,7 @@ extern "C" {
#define FFMPEG_VERSION_INT 0x000408 #define FFMPEG_VERSION_INT 0x000408
#define FFMPEG_VERSION "0.4.8" #define FFMPEG_VERSION "0.4.8"
#define LIBAVCODEC_BUILD 4711 #define LIBAVCODEC_BUILD 4712
#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVCODEC_VERSION FFMPEG_VERSION #define LIBAVCODEC_VERSION FFMPEG_VERSION
@ -1986,7 +1986,7 @@ int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max)
* rescale a 64bit integer. * rescale a 64bit integer.
* a simple a*b/c isnt possible as it can overflow * a simple a*b/c isnt possible as it can overflow
*/ */
int64_t av_rescale(int64_t a, int b, int c); int64_t av_rescale(int64_t a, int64_t b, int64_t c);
/** /**

View File

@ -27,7 +27,9 @@
#include "avcodec.h" #include "avcodec.h"
#include "dsputil.h" #include "dsputil.h"
#include "mpegvideo.h" #include "mpegvideo.h"
#include "integer.h"
#include <stdarg.h> #include <stdarg.h>
#include <limits.h>
static void avcodec_default_free_buffers(AVCodecContext *s); static void avcodec_default_free_buffers(AVCodecContext *s);
@ -816,23 +818,25 @@ int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max)
return exact; return exact;
} }
int64_t av_rescale(int64_t a, int b, int c){ int64_t av_rescale(int64_t a, int64_t b, int64_t c){
uint64_t h, l; AVInteger ai, ci;
assert(c > 0); assert(c > 0);
assert(b >=0); assert(b >=0);
if(a<0) return -av_rescale(-a, b, c); if(a<0) return -av_rescale(-a, b, c);
h= a>>32; if(b<=INT_MAX && c<=INT_MAX){
if(h==0) return a*b/c; if(a<=INT_MAX)
return (a * b + c/2)/c;
else
return a/c*b + (a%c*b + c/2)/c;
}
l= a&0xFFFFFFFF; ai= av_mul_i(av_int2i(a), av_int2i(b));
l *= b; ci= av_int2i(c);
h *= b; ai= av_add_i(ai, av_shr_i(ci,1));
l += (h%c)<<32; return av_i2int(av_div_i(ai, ci));
return ((h/c)<<32) + l/c;
} }
/* av_log API */ /* av_log API */