simplify
Originally committed as revision 3314 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
@@ -786,49 +786,36 @@ char av_get_pict_type_char(int pict_type){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
|
int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
|
||||||
int exact=1, sign=0;
|
|
||||||
int64_t gcd;
|
|
||||||
|
|
||||||
assert(den != 0);
|
|
||||||
|
|
||||||
if(den < 0)
|
|
||||||
return av_reduce(dst_nom, dst_den, -nom, -den, max);
|
|
||||||
|
|
||||||
sign= nom < 0;
|
|
||||||
nom= ABS(nom);
|
|
||||||
|
|
||||||
gcd = ff_gcd(nom, den);
|
|
||||||
nom /= gcd;
|
|
||||||
den /= gcd;
|
|
||||||
|
|
||||||
if(nom > max || den > max){
|
|
||||||
AVRational a0={0,1}, a1={1,0};
|
AVRational a0={0,1}, a1={1,0};
|
||||||
exact=0;
|
int sign= (nom<0) ^ (den<0);
|
||||||
|
int64_t gcd= ff_gcd(ABS(nom), ABS(den));
|
||||||
|
|
||||||
for(;;){
|
nom = ABS(nom)/gcd;
|
||||||
int64_t x= nom / den;
|
den = ABS(den)/gcd;
|
||||||
|
if(nom<=max && den<=max){
|
||||||
|
a1= (AVRational){nom, den};
|
||||||
|
den=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(den){
|
||||||
|
int64_t x = nom / den;
|
||||||
|
int64_t next_den= nom - den*x;
|
||||||
int64_t a2n= x*a1.num + a0.num;
|
int64_t a2n= x*a1.num + a0.num;
|
||||||
int64_t a2d= x*a1.den + a0.den;
|
int64_t a2d= x*a1.den + a0.den;
|
||||||
|
|
||||||
if(a2n > max || a2d > max) break;
|
if(a2n > max || a2d > max) break;
|
||||||
|
|
||||||
nom %= den;
|
|
||||||
|
|
||||||
a0= a1;
|
a0= a1;
|
||||||
a1= (AVRational){a2n, a2d};
|
a1= (AVRational){a2n, a2d};
|
||||||
if(nom==0) break;
|
nom= den;
|
||||||
x= nom; nom=den; den=x;
|
den= next_den;
|
||||||
}
|
|
||||||
nom= a1.num;
|
|
||||||
den= a1.den;
|
|
||||||
}
|
}
|
||||||
|
assert(ff_gcd(a1.num, a1.den) == 1);
|
||||||
|
|
||||||
assert(ff_gcd(nom, den) == 1);
|
*dst_nom = sign ? -a1.num : a1.num;
|
||||||
|
*dst_den = a1.den;
|
||||||
|
|
||||||
*dst_nom = sign ? -nom : nom;
|
return den==0;
|
||||||
*dst_den = den;
|
|
||||||
|
|
||||||
return exact;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t av_rescale(int64_t a, int64_t b, int64_t c){
|
int64_t av_rescale(int64_t a, int64_t b, int64_t c){
|
||||||
|
Reference in New Issue
Block a user