[Mplayer-cvslog] CVS: main/libmpcodecs ve_xvid4.c,1.8,1.9

Guillaume Poirier CVS syncmail at mplayerhq.hu
Sat Oct 2 00:53:16 CEST 2004


CVS change done by Guillaume Poirier CVS

Update of /cvsroot/mplayer/main/libmpcodecs
In directory mail:/var2/tmp/cvs-serv18415

Modified Files:
	ve_xvid4.c 
Log Message:
Moves around some functions, which makes the code clearer (it groups helper functions together) is one step closer to a nice 1.1 front-end.


Index: ve_xvid4.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/ve_xvid4.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ve_xvid4.c	13 Jul 2004 18:09:58 -0000	1.8
+++ ve_xvid4.c	1 Oct 2004 22:53:14 -0000	1.9
@@ -61,85 +61,6 @@
 #define FINE (!0)
 #define BAD (!FINE)
 
-// Code taken from Libavcodec and ve_lavc.c to handle Aspect Ratio calculation
-
-typedef struct XVIDRational{
-    int num; 
-    int den;
-} XVIDRational;
-
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-#define ABS(a) ((a) >= 0 ? (a) : (-(a)))
-
-
-static int64_t xvid_gcd(int64_t a, int64_t b){
-    if(b) return xvid_gcd(b, a%b);
-    else  return a;
-}
-
-static int xvid_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){
-        den= -den;
-        nom= -nom;
-    }
-    
-    if(nom < 0){
-        nom= -nom;
-        sign= 1;
-    }
-    
-    gcd = xvid_gcd(nom, den);
-    nom /= gcd;
-    den /= gcd;
-    
-    if(nom > max || den > max){
-        XVIDRational a0={0,1}, a1={1,0};
-        exact=0;
-
-        for(;;){
-            int64_t x= nom / den;
-            int64_t a2n= x*a1.num + a0.num;
-            int64_t a2d= x*a1.den + a0.den;
-
-            if(a2n > max || a2d > max) break;
-
-            nom %= den;
-        
-            a0= a1;
-            a1= (XVIDRational){a2n, a2d};
-            if(nom==0) break;
-            x= nom; nom=den; den=x;
-        }
-        nom= a1.num;
-        den= a1.den;
-    }
-    
-    assert(xvid_gcd(nom, den) == 1);
-    
-    if(sign) nom= -nom;
-    
-    *dst_nom = nom;
-    *dst_den = den;
-    
-    return exact;
-}
-
-
-static XVIDRational xvid_d2q(double d, int max){
-    XVIDRational a;
-    int exponent= MAX( (int)(log(ABS(d) + 1e-20)/log(2)), 0);
-    int64_t den= 1LL << (61 - exponent);
-    xvid_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max);
-
-    return a;
-}
-
-
 
 /*****************************************************************************
  * Configuration options
@@ -313,9 +234,15 @@
 	int d_width, d_height;
 } xvid_mplayer_module_t;
 
+typedef struct XVIDRational{
+    int num; 
+    int den;
+} XVIDRational;
+
 static void dispatch_settings(xvid_mplayer_module_t *mod);
 static int set_create_struct(xvid_mplayer_module_t *mod);
 static int set_frame_struct(xvid_mplayer_module_t *mod, mp_image_t *mpi);
+static XVIDRational xvid_d2q(double d, int max);
 static const char *errorstring(int err);
 
 /*****************************************************************************
@@ -1157,6 +1084,76 @@
 	
 }
 
+/* Code taken from Libavcodec and ve_lavc.c to handle Aspect Ratio calculation */
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#define ABS(a) ((a) >= 0 ? (a) : (-(a)))
+
+static int64_t xvid_gcd(int64_t a, int64_t b){
+    if(b) return xvid_gcd(b, a%b);
+    else  return a;
+}
+
+static int xvid_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){
+        den= -den;
+        nom= -nom;
+    }
+    
+    if(nom < 0){
+        nom= -nom;
+        sign= 1;
+    }
+    
+    gcd = xvid_gcd(nom, den);
+    nom /= gcd;
+    den /= gcd;
+    
+    if(nom > max || den > max){
+        XVIDRational a0={0,1}, a1={1,0};
+        exact=0;
+
+        for(;;){
+            int64_t x= nom / den;
+            int64_t a2n= x*a1.num + a0.num;
+            int64_t a2d= x*a1.den + a0.den;
+
+            if(a2n > max || a2d > max) break;
+
+            nom %= den;
+        
+            a0= a1;
+            a1= (XVIDRational){a2n, a2d};
+            if(nom==0) break;
+            x= nom; nom=den; den=x;
+        }
+        nom= a1.num;
+        den= a1.den;
+    }
+    
+    assert(xvid_gcd(nom, den) == 1);
+    
+    if(sign) nom= -nom;
+    
+    *dst_nom = nom;
+    *dst_den = den;
+    
+    return exact;
+}
+
+static XVIDRational xvid_d2q(double d, int max){
+    XVIDRational a;
+    int exponent= MAX( (int)(log(ABS(d) + 1e-20)/log(2)), 0);
+    int64_t den= 1LL << (61 - exponent);
+    xvid_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max);
+
+    return a;
+}
+
 static const char *errorstring(int err)
 {
 	char *error;




More information about the MPlayer-cvslog mailing list