Mercurial > libavcodec.hg
comparison common.c @ 1548:dd544554ed42 libavcodec
AVRational
sample_aspect_ratio
aspect ratio in JPEG JFIF is SAR not DAR !
removed nonsense SAR guessing code
various related cleanups
bugs?
author | michael |
---|---|
date | Mon, 20 Oct 2003 20:23:46 +0000 |
parents | 79dddc5cd990 |
children | 932d306bf1dc |
comparison
equal
deleted
inserted
replaced
1547:0183874861fd | 1548:dd544554ed42 |
---|---|
384 | 384 |
385 int64_t ff_gcd(int64_t a, int64_t b){ | 385 int64_t ff_gcd(int64_t a, int64_t b){ |
386 if(b) return ff_gcd(b, a%b); | 386 if(b) return ff_gcd(b, a%b); |
387 else return a; | 387 else return a; |
388 } | 388 } |
389 | |
390 void ff_float2fraction(int *nom_arg, int *denom_arg, double f, int max){ | |
391 double best_diff=1E10, diff; | |
392 int best_denom=1, best_nom=1; | |
393 int nom, denom, gcd; | |
394 | |
395 //brute force here, perhaps we should try continued fractions if we need large max ... | |
396 for(denom=1; denom<=max; denom++){ | |
397 nom= (int)(f*denom + 0.5); | |
398 if(nom<=0 || nom>max) continue; | |
399 | |
400 diff= ABS( f - (double)nom / (double)denom ); | |
401 if(diff < best_diff){ | |
402 best_diff= diff; | |
403 best_nom= nom; | |
404 best_denom= denom; | |
405 } | |
406 } | |
407 | |
408 gcd= ff_gcd(best_nom, best_denom); | |
409 best_nom /= gcd; | |
410 best_denom /= gcd; | |
411 | |
412 *nom_arg= best_nom; | |
413 *denom_arg= best_denom; | |
414 } |