diff mpeg12.c @ 281:1fc96b02142e libavcodec

mpeg4 aspect_ratio_info in AVCodecContext (requested by alex) experimental (& faster) motion estimation squished a dirty uninitialized var bug mpeg1 fcode>1 support
author michaelni
date Fri, 22 Mar 2002 23:22:08 +0000
parents 5cb2978e701f
children 73a9ce3d9715
line wrap: on
line diff
--- a/mpeg12.c	Fri Mar 22 16:51:44 2002 +0000
+++ b/mpeg12.c	Fri Mar 22 23:22:08 2002 +0000
@@ -51,6 +51,9 @@
                                     int n);
 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred);
 
+static UINT16 mv_penalty[MAX_FCODE][MAX_MV*2+1];
+static UINT8 fcode_tab[MAX_MV*2+1];
+
 static void put_header(MpegEncContext *s, int header)
 {
     align_put_bits(&s->pb);
@@ -353,6 +356,53 @@
     }
 }
 
+void mpeg1_encode_init(MpegEncContext *s)
+{
+    static int done=0;
+    if(!done){
+        int f_code;
+        int mv;
+
+        done=1;
+        for(f_code=1; f_code<=MAX_FCODE; f_code++){
+            for(mv=-MAX_MV; mv<=MAX_MV; mv++){
+                int len;
+
+                if(mv==0) len= mbMotionVectorTable[0][1];
+                else{
+                    int val, bit_size, range, code;
+
+                    bit_size = s->f_code - 1;
+                    range = 1 << bit_size;
+
+                    val=mv;
+                    if (val < 0) 
+                        val = -val;
+                    val--;
+                    code = (val >> bit_size) + 1;
+                    if(code<17){
+                        len= mbMotionVectorTable[code][1] + 1 + bit_size;
+                    }else{
+                        len= mbMotionVectorTable[16][1] + 2 + bit_size;
+                    }
+                }
+
+                mv_penalty[f_code][mv+MAX_MV]= len;
+            }
+        }
+        
+
+        for(f_code=MAX_FCODE; f_code>0; f_code--){
+            for(mv=-(8<<f_code); mv<(8<<f_code); mv++){
+                fcode_tab[mv+MAX_MV]= f_code;
+            }
+        }
+    }
+    s->mv_penalty= mv_penalty;
+    
+    s->fcode_tab= fcode_tab;
+}
+ 
 static inline void encode_dc(MpegEncContext *s, int diff, int component)
 {
     if (component == 0) {