]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mpegvideo.c
10l to Benoit, poll.h is already included below, and this broke compilation on mingw
[ffmpeg] / libavcodec / mpegvideo.c
index 68ee6125d1a4c2e822767f3898c4ffc2caec9773..8152288258e73601779b917e0e0b8b5118911567 100644 (file)
@@ -70,11 +70,6 @@ void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w)= draw_e
 //#define DEBUG
 
 
-static const uint8_t h263_chroma_roundtab[16] = {
-//  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
-    0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
-};
-
 static const uint8_t ff_default_chroma_qscale_table[32]={
 //  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
     0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
@@ -742,6 +737,59 @@ void init_rl(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 3])
     }
 }
 
+void init_vlc_rl(RLTable *rl, int use_static)
+{
+    int i, q;
+
+    /* Return if static table is already initialized */
+    if(use_static && rl->rl_vlc[0])
+        return;
+
+    init_vlc(&rl->vlc, 9, rl->n + 1,
+             &rl->table_vlc[0][1], 4, 2,
+             &rl->table_vlc[0][0], 4, 2, use_static);
+
+
+    for(q=0; q<32; q++){
+        int qmul= q*2;
+        int qadd= (q-1)|1;
+
+        if(q==0){
+            qmul=1;
+            qadd=0;
+        }
+        if(use_static)
+            rl->rl_vlc[q]= av_mallocz_static(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
+        else
+            rl->rl_vlc[q]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
+        for(i=0; i<rl->vlc.table_size; i++){
+            int code= rl->vlc.table[i][0];
+            int len = rl->vlc.table[i][1];
+            int level, run;
+
+            if(len==0){ // illegal code
+                run= 66;
+                level= MAX_LEVEL;
+            }else if(len<0){ //more bits needed
+                run= 0;
+                level= code;
+            }else{
+                if(code==rl->n){ //esc
+                    run= 66;
+                    level= 0;
+                }else{
+                    run=   rl->table_run  [code] + 1;
+                    level= rl->table_level[code] * qmul + qadd;
+                    if(code >= rl->last) run+=192;
+                }
+            }
+            rl->rl_vlc[q][i].len= len;
+            rl->rl_vlc[q][i].level= level;
+            rl->rl_vlc[q][i].run= run;
+        }
+    }
+}
+
 /* draw the edges of width 'w' of an image of size width, height */
 //FIXME check that this is ok for mpeg4 interlaced
 static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w)
@@ -1539,15 +1587,6 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
     //FIXME h261 lowres loop filter
 }
 
-inline int ff_h263_round_chroma(int x){
-    if (x >= 0)
-        return  (h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1));
-    else {
-        x = -x;
-        return -(h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1));
-    }
-}
-
 static inline void chroma_4mv_motion_lowres(MpegEncContext *s,
                                      uint8_t *dest_cb, uint8_t *dest_cr,
                                      uint8_t **ref_picture,
@@ -2352,3 +2391,19 @@ static void dct_unquantize_h263_inter_c(MpegEncContext *s,
     }
 }
 
+/**
+ * set qscale and update qscale dependent variables.
+ */
+void ff_set_qscale(MpegEncContext * s, int qscale)
+{
+    if (qscale < 1)
+        qscale = 1;
+    else if (qscale > 31)
+        qscale = 31;
+
+    s->qscale = qscale;
+    s->chroma_qscale= s->chroma_qscale_table[qscale];
+
+    s->y_dc_scale= s->y_dc_scale_table[ qscale ];
+    s->c_dc_scale= s->c_dc_scale_table[ s->chroma_qscale ];
+}