]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/vc1dec.c
wmapro: use av_float2int()
[ffmpeg] / libavcodec / vc1dec.c
index 60cca333fe5949cf01d6bf1c1730a25b96fa2a8b..0340dc202d020cc06ffc8f8968fe4c535c2e16ca 100644 (file)
@@ -236,7 +236,7 @@ static void vc1_put_signed_blocks_clamped(VC1Context *v)
         if (s->mb_x) {
             topleft_mb_pos = (s->mb_y - 1) * s->mb_stride + s->mb_x - 1;
             fieldtx        = v->fieldtx_plane[topleft_mb_pos];
-            stride_y       = (s->linesize) << fieldtx;
+            stride_y       = s->linesize << fieldtx;
             v_dist         = (16 - fieldtx) >> (fieldtx == 0);
             s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][0],
                                              s->dest[0] - 16 * s->linesize - 16,
@@ -501,7 +501,8 @@ static void vc1_mc_1mv(VC1Context *v, int dir)
         uvmy = uvmy - 2 + 4 * v->cur_field_type;
     }
 
-    if (v->fastuvmc && (v->fcm != 1)) { // fastuvmc shall be ignored for interlaced frame picture
+    // fastuvmc shall be ignored for interlaced frame picture
+    if (v->fastuvmc && (v->fcm != ILACE_FRAME)) {
         uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1));
         uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1));
     }
@@ -685,7 +686,7 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir)
     uint8_t *srcY;
     int dxy, mx, my, src_x, src_y;
     int off;
-    int fieldmv = (v->fcm == 1) ? v->blk_mv_type[s->block_index[n]] : 0;
+    int fieldmv = (v->fcm == ILACE_FRAME) ? v->blk_mv_type[s->block_index[n]] : 0;
     int v_edge_pos = s->v_edge_pos >> v->field_mode;
 
     if (!v->field_mode && !v->s.last_picture.f.data[0])
@@ -744,7 +745,7 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir)
             v->mv_f[1][s->block_index[k] + v->blocks_off] = f;
     }
 
-    if (v->fcm == 1) {  // not sure if needed for other types of picture
+    if (v->fcm == ILACE_FRAME) {  // not sure if needed for other types of picture
         int qx, qy;
         int width  = s->avctx->coded_width;
         int height = s->avctx->coded_height >> 1;
@@ -761,7 +762,7 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir)
             my -= 8 * (qy - height - 1);
     }
 
-    if ((v->fcm == 1) && fieldmv)
+    if ((v->fcm == ILACE_FRAME) && fieldmv)
         off = ((n > 1) ? s->linesize : 0) + (n & 1) * 8;
     else
         off = s->linesize * 4 * (n & 2) + (n & 1) * 8;
@@ -779,7 +780,7 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir)
         src_y = av_clip(src_y, -16, s->mb_height * 16);
     } else {
         src_x = av_clip(src_x, -17, s->avctx->coded_width);
-        if (v->fcm == 1) {
+        if (v->fcm == ILACE_FRAME) {
             if (src_y & 1)
                 src_y = av_clip(src_y, -17, s->avctx->coded_height + 1);
             else
@@ -930,8 +931,8 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir)
     if (!v->field_mode || (v->field_mode && !v->numref)) {
         valid_count = get_chroma_mv(mvx, mvy, intra, 0, &tx, &ty);
         if (!valid_count) {
-            s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0;
-            s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0;
+            s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0;
+            s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0;
             v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
             return; //no need to do MC for intra blocks
         }
@@ -943,8 +944,8 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir)
         if (dominant)
             chroma_ref_type = !v->cur_field_type;
     }
-    s->current_picture.f.motion_val[1][s->block_index[0]][0] = tx;
-    s->current_picture.f.motion_val[1][s->block_index[0]][1] = ty;
+    s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = tx;
+    s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = ty;
     uvmx = (tx + ((tx & 3) == 3)) >> 1;
     uvmy = (ty + ((ty & 3) == 3)) >> 1;
 
@@ -1422,29 +1423,36 @@ static av_always_inline int scaleforsame(VC1Context *v, int i, int n /* MV */,
                                          int dim, int dir)
 {
     int brfd, scalesame;
+    int hpel = 1 - v->s.quarter_sample;
 
+    n >>= hpel;
     if (v->s.pict_type != AV_PICTURE_TYPE_B || v->second_field || !dir) {
         if (dim)
-            return scaleforsame_y(v, i, n, dir);
+            n = scaleforsame_y(v, i, n, dir) << hpel;
         else
-            return scaleforsame_x(v, n, dir);
+            n = scaleforsame_x(v, n, dir) << hpel;
+        return n;
     }
     brfd      = FFMIN(v->brfd, 3);
     scalesame = vc1_b_field_mvpred_scales[0][brfd];
 
-    return n * scalesame >> 8;
+    n = (n * scalesame >> 8) << hpel;
+    return n;
 }
 
 static av_always_inline int scaleforopp(VC1Context *v, int n /* MV */,
                                         int dim, int dir)
 {
     int refdist, scaleopp;
+    int hpel = 1 - v->s.quarter_sample;
 
+    n >>= hpel;
     if (v->s.pict_type == AV_PICTURE_TYPE_B && !v->second_field && dir == 1) {
         if (dim)
-            return scaleforopp_y(v, n, dir);
+            n = scaleforopp_y(v, n, dir) << hpel;
         else
-            return scaleforopp_x(v, n);
+            n = scaleforopp_x(v, n) << hpel;
+        return n;
     }
     if (v->s.pict_type != AV_PICTURE_TYPE_B)
         refdist = FFMIN(v->refdist, 3);
@@ -1452,7 +1460,8 @@ static av_always_inline int scaleforopp(VC1Context *v, int n /* MV */,
         refdist = dir ? v->brfd : v->frfd;
     scaleopp = vc1_field_mvpred_scales[dir ^ v->second_field][0][refdist];
 
-    return n * scaleopp >> 8;
+    n = (n * scaleopp >> 8) << hpel;
+    return n;
 }
 
 /** Predict and set motion vector
@@ -1467,12 +1476,10 @@ static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y,
     int px, py;
     int sum;
     int mixedmv_pic, num_samefield = 0, num_oppfield = 0;
-    int opposit, f;
-    int16_t samefield_pred[2],  oppfield_pred[2];
-    int16_t samefield_predA[2], oppfield_predA[2];
-    int16_t samefield_predB[2], oppfield_predB[2];
-    int16_t samefield_predC[2], oppfield_predC[2];
-    int16_t *predA, *predC;
+    int opposit, a_f, b_f, c_f;
+    int16_t field_predA[2];
+    int16_t field_predB[2];
+    int16_t field_predC[2];
     int a_valid, b_valid, c_valid;
     int hybridmv_thresh, y_bias = 0;
 
@@ -1546,96 +1553,34 @@ static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y,
     }
 
     if (a_valid) {
-        f = v->mv_f[dir][xy - wrap + v->blocks_off];
-        num_oppfield  += f;
-        num_samefield += 1 - f;
-        if (f) {
-            oppfield_predA[0]  = A[0];
-            oppfield_predA[1]  = A[1];
-            samefield_predA[0] = scaleforsame(v, 0, A[0], 0, dir);
-            samefield_predA[1] = scaleforsame(v, n, A[1], 1, dir);
-        } else {
-            samefield_predA[0] = A[0];
-            samefield_predA[1] = A[1];
-            if (v->numref)
-                oppfield_predA[0] = scaleforopp(v, A[0], 0, dir);
-            if (v->numref)
-                oppfield_predA[1] = scaleforopp(v, A[1], 1, dir);
-        }
-    } else {
-        samefield_predA[0] = samefield_predA[1] = 0;
-        oppfield_predA[0]  = oppfield_predA[1]  = 0;
-    }
-    if (c_valid) {
-        f = v->mv_f[dir][xy - 1 + v->blocks_off];
-        num_oppfield  += f;
-        num_samefield += 1 - f;
-        if (f) {
-            oppfield_predC[0]  = C[0];
-            oppfield_predC[1]  = C[1];
-            samefield_predC[0] = scaleforsame(v, 0, C[0], 0, dir);
-            samefield_predC[1] = scaleforsame(v, n, C[1], 1, dir);
-        } else {
-            samefield_predC[0] = C[0];
-            samefield_predC[1] = C[1];
-            if (v->numref)
-                oppfield_predC[0] = scaleforopp(v, C[0], 0, dir);
-            if (v->numref)
-                oppfield_predC[1] = scaleforopp(v, C[1], 1, dir);
-        }
+        a_f = v->mv_f[dir][xy - wrap + v->blocks_off];
+        num_oppfield  += a_f;
+        num_samefield += 1 - a_f;
+        field_predA[0] = A[0];
+        field_predA[1] = A[1];
     } else {
-        samefield_predC[0] = samefield_predC[1] = 0;
-        oppfield_predC[0]  = oppfield_predC[1]  = 0;
+        field_predA[0] = field_predA[1] = 0;
+        a_f = 0;
     }
     if (b_valid) {
-        f = v->mv_f[dir][xy - wrap + off + v->blocks_off];
-        num_oppfield  += f;
-        num_samefield += 1 - f;
-        if (f) {
-            oppfield_predB[0]  = B[0];
-            oppfield_predB[1]  = B[1];
-            samefield_predB[0] = scaleforsame(v, 0, B[0], 0, dir);
-            samefield_predB[1] = scaleforsame(v, n, B[1], 1, dir);
-        } else {
-            samefield_predB[0] = B[0];
-            samefield_predB[1] = B[1];
-            if (v->numref)
-                oppfield_predB[0] = scaleforopp(v, B[0], 0, dir);
-            if (v->numref)
-                oppfield_predB[1] = scaleforopp(v, B[1], 1, dir);
-        }
+        b_f = v->mv_f[dir][xy - wrap + off + v->blocks_off];
+        num_oppfield  += b_f;
+        num_samefield += 1 - b_f;
+        field_predB[0] = B[0];
+        field_predB[1] = B[1];
     } else {
-        samefield_predB[0] = samefield_predB[1] = 0;
-        oppfield_predB[0]  = oppfield_predB[1]  = 0;
+        field_predB[0] = field_predB[1] = 0;
+        b_f = 0;
     }
-
-    if (a_valid) {
-        samefield_pred[0] = samefield_predA[0];
-        samefield_pred[1] = samefield_predA[1];
-        oppfield_pred[0]  = oppfield_predA[0];
-        oppfield_pred[1]  = oppfield_predA[1];
-    } else if (c_valid) {
-        samefield_pred[0] = samefield_predC[0];
-        samefield_pred[1] = samefield_predC[1];
-        oppfield_pred[0]  = oppfield_predC[0];
-        oppfield_pred[1]  = oppfield_predC[1];
-    } else if (b_valid) {
-        samefield_pred[0] = samefield_predB[0];
-        samefield_pred[1] = samefield_predB[1];
-        oppfield_pred[0]  = oppfield_predB[0];
-        oppfield_pred[1]  = oppfield_predB[1];
+    if (c_valid) {
+        c_f = v->mv_f[dir][xy - 1 + v->blocks_off];
+        num_oppfield  += c_f;
+        num_samefield += 1 - c_f;
+        field_predC[0] = C[0];
+        field_predC[1] = C[1];
     } else {
-        samefield_pred[0] = samefield_pred[1] = 0;
-        oppfield_pred[0]  = oppfield_pred[1]  = 0;
-    }
-
-    if (num_samefield + num_oppfield > 1) {
-        samefield_pred[0] = mid_pred(samefield_predA[0], samefield_predB[0], samefield_predC[0]);
-        samefield_pred[1] = mid_pred(samefield_predA[1], samefield_predB[1], samefield_predC[1]);
-        if (v->numref)
-            oppfield_pred[0] = mid_pred(oppfield_predA[0], oppfield_predB[0], oppfield_predC[0]);
-        if (v->numref)
-            oppfield_pred[1] = mid_pred(oppfield_predA[1], oppfield_predB[1], oppfield_predC[1]);
+        field_predC[0] = field_predC[1] = 0;
+        c_f = 0;
     }
 
     if (v->field_mode) {
@@ -1646,21 +1591,56 @@ static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y,
     } else
         opposit = 0;
     if (opposit) {
-        px    = oppfield_pred[0];
-        py    = oppfield_pred[1];
-        predA = oppfield_predA;
-        predC = oppfield_predC;
-        v->mv_f[dir][xy + v->blocks_off] = f = 1;
+        if (a_valid && !a_f) {
+            field_predA[0] = scaleforopp(v, field_predA[0], 0, dir);
+            field_predA[1] = scaleforopp(v, field_predA[1], 1, dir);
+        }
+        if (b_valid && !b_f) {
+            field_predB[0] = scaleforopp(v, field_predB[0], 0, dir);
+            field_predB[1] = scaleforopp(v, field_predB[1], 1, dir);
+        }
+        if (c_valid && !c_f) {
+            field_predC[0] = scaleforopp(v, field_predC[0], 0, dir);
+            field_predC[1] = scaleforopp(v, field_predC[1], 1, dir);
+        }
+        v->mv_f[dir][xy + v->blocks_off] = 1;
         v->ref_field_type[dir] = !v->cur_field_type;
     } else {
-        px    = samefield_pred[0];
-        py    = samefield_pred[1];
-        predA = samefield_predA;
-        predC = samefield_predC;
-        v->mv_f[dir][xy + v->blocks_off] = f = 0;
+        if (a_valid && a_f) {
+            field_predA[0] = scaleforsame(v, n, field_predA[0], 0, dir);
+            field_predA[1] = scaleforsame(v, n, field_predA[1], 1, dir);
+        }
+        if (b_valid && b_f) {
+            field_predB[0] = scaleforsame(v, n, field_predB[0], 0, dir);
+            field_predB[1] = scaleforsame(v, n, field_predB[1], 1, dir);
+        }
+        if (c_valid && c_f) {
+            field_predC[0] = scaleforsame(v, n, field_predC[0], 0, dir);
+            field_predC[1] = scaleforsame(v, n, field_predC[1], 1, dir);
+        }
+        v->mv_f[dir][xy + v->blocks_off] = 0;
         v->ref_field_type[dir] = v->cur_field_type;
     }
 
+    if (a_valid) {
+        px = field_predA[0];
+        py = field_predA[1];
+    } else if (c_valid) {
+        px = field_predC[0];
+        py = field_predC[1];
+    } else if (b_valid) {
+        px = field_predB[0];
+        py = field_predB[1];
+    } else {
+        px = 0;
+        py = 0;
+    }
+
+    if (num_samefield + num_oppfield > 1) {
+        px = mid_pred(field_predA[0], field_predB[0], field_predC[0]);
+        py = mid_pred(field_predA[1], field_predB[1], field_predC[1]);
+    }
+
     /* Pullback MV as specified in 8.3.5.3.4 */
     if (!v->field_mode) {
         int qx, qy, X, Y;
@@ -1681,35 +1661,32 @@ static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y,
 
     if (!v->field_mode || s->pict_type != AV_PICTURE_TYPE_B) {
         /* Calculate hybrid prediction as specified in 8.3.5.3.5 (also 10.3.5.4.3.5) */
-        if (v->field_mode && !s->quarter_sample)
-            hybridmv_thresh = 16;
-        else
-            hybridmv_thresh = 32;
+        hybridmv_thresh = 32;
         if (a_valid && c_valid) {
             if (is_intra[xy - wrap])
                 sum = FFABS(px) + FFABS(py);
             else
-                sum = FFABS(px - predA[0]) + FFABS(py - predA[1]);
+                sum = FFABS(px - field_predA[0]) + FFABS(py - field_predA[1]);
             if (sum > hybridmv_thresh) {
                 if (get_bits1(&s->gb)) {     // read HYBRIDPRED bit
-                    px = predA[0];
-                    py = predA[1];
+                    px = field_predA[0];
+                    py = field_predA[1];
                 } else {
-                    px = predC[0];
-                    py = predC[1];
+                    px = field_predC[0];
+                    py = field_predC[1];
                 }
             } else {
                 if (is_intra[xy - 1])
                     sum = FFABS(px) + FFABS(py);
                 else
-                    sum = FFABS(px - predC[0]) + FFABS(py - predC[1]);
+                    sum = FFABS(px - field_predC[0]) + FFABS(py - field_predC[1]);
                 if (sum > hybridmv_thresh) {
                     if (get_bits1(&s->gb)) {
-                        px = predA[0];
-                        py = predA[1];
+                        px = field_predA[0];
+                        py = field_predA[1];
                     } else {
-                        px = predC[0];
-                        py = predC[1];
+                        px = field_predC[0];
+                        py = field_predC[1];
                     }
                 }
             }
@@ -2941,7 +2918,7 @@ static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n,
         int k;
 
         if (v->s.ac_pred) {
-            if (!use_pred && v->fcm == 1) {
+            if (!use_pred && v->fcm == ILACE_FRAME) {
                 zz_table = v->zzi_8x8;
             } else {
                 if (!dc_pred_dir) // top
@@ -2950,7 +2927,7 @@ static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n,
                     zz_table = v->zz_8x8[3];
             }
         } else {
-            if (v->fcm != 1)
+            if (v->fcm != ILACE_FRAME)
                 zz_table = v->zz_8x8[1];
             else
                 zz_table = v->zzi_8x8;
@@ -3160,10 +3137,10 @@ static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n,
             i += skip;
             if (i > 63)
                 break;
-            if (v->fcm == 0)
+            if (v->fcm == PROGRESSIVE)
                 block[v->zz_8x8[0][i++]] = value;
             else {
-                if (use_pred && (v->fcm == 1)) {
+                if (use_pred && (v->fcm == ILACE_FRAME)) {
                     if (!dc_pred_dir) // top
                         block[v->zz_8x8[2][i++]] = value;
                     else // left
@@ -3317,7 +3294,7 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n,
             i += skip;
             if (i > 63)
                 break;
-            if (!v->interlace)
+            if (!v->fcm)
                 idx = v->zz_8x8[0][i++];
             else
                 idx = v->zzi_8x8[i++];
@@ -3345,7 +3322,7 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n,
                 i += skip;
                 if (i > 15)
                     break;
-                if (!v->interlace)
+                if (!v->fcm)
                     idx = ff_vc1_simple_progressive_4x4_zz[i++];
                 else
                     idx = ff_vc1_adv_interlaced_4x4_zz[i++];
@@ -3372,7 +3349,7 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n,
                 i += skip;
                 if (i > 31)
                     break;
-                if (!v->interlace)
+                if (!v->fcm)
                     idx = v->zz_8x4[i++] + off;
                 else
                     idx = ff_vc1_adv_interlaced_8x4_zz[i++] + off;
@@ -3399,7 +3376,7 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n,
                 i += skip;
                 if (i > 31)
                     break;
-                if (!v->interlace)
+                if (!v->fcm)
                     idx = v->zz_4x8[i++] + off;
                 else
                     idx = ff_vc1_adv_interlaced_4x8_zz[i++] + off;
@@ -3559,7 +3536,7 @@ static void vc1_apply_p_loop_filter(VC1Context *v)
         vc1_apply_p_v_loop_filter(v, i);
     }
 
-    /* V always preceedes H, therefore we run H one MB before V;
+    /* V always precedes H, therefore we run H one MB before V;
      * at the end of a row, we catch up to complete the row */
     if (s->mb_x) {
         for (i = 0; i < 6; i++) {
@@ -3596,7 +3573,7 @@ static int vc1_decode_p_mb(VC1Context *v)
     int skipped, fourmv;
     int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
 
-    mquant = v->pq; /* Loosy initialization */
+    mquant = v->pq; /* lossy initialization */
 
     if (v->mv_type_is_raw)
         fourmv = get_bits1(gb);
@@ -4164,7 +4141,7 @@ static void vc1_decode_b_mb(VC1Context *v)
     int dmv_x[2], dmv_y[2];
     int bmvtype = BMV_TYPE_BACKWARD;
 
-    mquant      = v->pq; /* Loosy initialization */
+    mquant      = v->pq; /* lossy initialization */
     s->mb_intra = 0;
 
     if (v->dmb_is_raw)
@@ -4763,12 +4740,12 @@ static void vc1_decode_p_blocks(VC1Context *v)
         for (; s->mb_x < s->mb_width; s->mb_x++) {
             ff_update_block_index(s);
 
-            if (v->fcm == 2)
+            if (v->fcm == ILACE_FIELD)
                 vc1_decode_p_mb_intfi(v);
-            else if (v->fcm == 1)
+            else if (v->fcm == ILACE_FRAME)
                 vc1_decode_p_mb_intfr(v);
             else vc1_decode_p_mb(v);
-            if (s->mb_y != s->start_mb_y && apply_loop_filter && v->fcm == 0)
+            if (s->mb_y != s->start_mb_y && apply_loop_filter && v->fcm == PROGRESSIVE)
                 vc1_apply_p_loop_filter(v);
             if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
                 // TODO: may need modification to handle slice coding
@@ -4835,7 +4812,7 @@ static void vc1_decode_b_blocks(VC1Context *v)
         for (; s->mb_x < s->mb_width; s->mb_x++) {
             ff_update_block_index(s);
 
-            if (v->fcm == 2)
+            if (v->fcm == ILACE_FIELD)
                 vc1_decode_b_mb_intfi(v);
             else
                 vc1_decode_b_mb(v);