comparison 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
comparison
equal deleted inserted replaced
2001:7523553ca85f 2002:b737b5e96ee0
25 */ 25 */
26 26
27 #include "avcodec.h" 27 #include "avcodec.h"
28 #include "dsputil.h" 28 #include "dsputil.h"
29 #include "mpegvideo.h" 29 #include "mpegvideo.h"
30 #include "integer.h"
30 #include <stdarg.h> 31 #include <stdarg.h>
32 #include <limits.h>
31 33
32 static void avcodec_default_free_buffers(AVCodecContext *s); 34 static void avcodec_default_free_buffers(AVCodecContext *s);
33 35
34 void *av_mallocz(unsigned int size) 36 void *av_mallocz(unsigned int size)
35 { 37 {
814 *dst_den = den; 816 *dst_den = den;
815 817
816 return exact; 818 return exact;
817 } 819 }
818 820
819 int64_t av_rescale(int64_t a, int b, int c){ 821 int64_t av_rescale(int64_t a, int64_t b, int64_t c){
820 uint64_t h, l; 822 AVInteger ai, ci;
821 assert(c > 0); 823 assert(c > 0);
822 assert(b >=0); 824 assert(b >=0);
823 825
824 if(a<0) return -av_rescale(-a, b, c); 826 if(a<0) return -av_rescale(-a, b, c);
825 827
826 h= a>>32; 828 if(b<=INT_MAX && c<=INT_MAX){
827 if(h==0) return a*b/c; 829 if(a<=INT_MAX)
828 830 return (a * b + c/2)/c;
829 l= a&0xFFFFFFFF; 831 else
830 l *= b; 832 return a/c*b + (a%c*b + c/2)/c;
831 h *= b; 833 }
832 834
833 l += (h%c)<<32; 835 ai= av_mul_i(av_int2i(a), av_int2i(b));
834 836 ci= av_int2i(c);
835 return ((h/c)<<32) + l/c; 837 ai= av_add_i(ai, av_shr_i(ci,1));
838
839 return av_i2int(av_div_i(ai, ci));
836 } 840 }
837 841
838 /* av_log API */ 842 /* av_log API */
839 843
840 static int av_log_level = AV_LOG_DEBUG; 844 static int av_log_level = AV_LOG_DEBUG;