GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/vc1_pred.c Lines: 533 573 93.0 %
Date: 2020-10-23 17:01:47 Branches: 419 457 91.7 %

Line Branch Exec Source
1
/*
2
 * VC-1 and WMV3 decoder
3
 * Copyright (c) 2011 Mashiat Sarker Shakkhar
4
 * Copyright (c) 2006-2007 Konstantin Shishkov
5
 * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
6
 *
7
 * This file is part of FFmpeg.
8
 *
9
 * FFmpeg is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 of the License, or (at your option) any later version.
13
 *
14
 * FFmpeg is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with FFmpeg; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
 */
23
24
/**
25
 * @file
26
 * VC-1 and WMV3 block decoding routines
27
 */
28
29
#include "mathops.h"
30
#include "mpegutils.h"
31
#include "mpegvideo.h"
32
#include "vc1.h"
33
#include "vc1_pred.h"
34
#include "vc1data.h"
35
36
34909
static av_always_inline int scaleforsame_x(VC1Context *v, int n /* MV */, int dir)
37
{
38
    int scaledvalue, refdist;
39
    int scalesame1, scalesame2;
40
    int scalezone1_x, zone1offset_x;
41
34909
    int table_index = dir ^ v->second_field;
42
43
34909
    if (v->s.pict_type != AV_PICTURE_TYPE_B)
44
14268
        refdist = v->refdist;
45
    else
46
20641
        refdist = dir ? v->brfd : v->frfd;
47
34909
    if (refdist > 3)
48
        refdist = 3;
49
34909
    scalesame1    = ff_vc1_field_mvpred_scales[table_index][1][refdist];
50
34909
    scalesame2    = ff_vc1_field_mvpred_scales[table_index][2][refdist];
51
34909
    scalezone1_x  = ff_vc1_field_mvpred_scales[table_index][3][refdist];
52
34909
    zone1offset_x = ff_vc1_field_mvpred_scales[table_index][5][refdist];
53
54
34909
    if (FFABS(n) > 255)
55
13
        scaledvalue = n;
56
    else {
57
34896
        if (FFABS(n) < scalezone1_x)
58
25948
            scaledvalue = (n * scalesame1) >> 8;
59
        else {
60
8948
            if (n < 0)
61
4487
                scaledvalue = ((n * scalesame2) >> 8) - zone1offset_x;
62
            else
63
4461
                scaledvalue = ((n * scalesame2) >> 8) + zone1offset_x;
64
        }
65
    }
66
34909
    return av_clip(scaledvalue, -v->range_x, v->range_x - 1);
67
}
68
69
34909
static av_always_inline int scaleforsame_y(VC1Context *v, int i, int n /* MV */, int dir)
70
{
71
    int scaledvalue, refdist;
72
    int scalesame1, scalesame2;
73
    int scalezone1_y, zone1offset_y;
74
34909
    int table_index = dir ^ v->second_field;
75
76
34909
    if (v->s.pict_type != AV_PICTURE_TYPE_B)
77
14268
        refdist = v->refdist;
78
    else
79
20641
        refdist = dir ? v->brfd : v->frfd;
80
34909
    if (refdist > 3)
81
        refdist = 3;
82
34909
    scalesame1    = ff_vc1_field_mvpred_scales[table_index][1][refdist];
83
34909
    scalesame2    = ff_vc1_field_mvpred_scales[table_index][2][refdist];
84
34909
    scalezone1_y  = ff_vc1_field_mvpred_scales[table_index][4][refdist];
85
34909
    zone1offset_y = ff_vc1_field_mvpred_scales[table_index][6][refdist];
86
87
34909
    if (FFABS(n) > 63)
88
        scaledvalue = n;
89
    else {
90
34909
        if (FFABS(n) < scalezone1_y)
91
27772
            scaledvalue = (n * scalesame1) >> 8;
92
        else {
93
7137
            if (n < 0)
94
3231
                scaledvalue = ((n * scalesame2) >> 8) - zone1offset_y;
95
            else
96
3906
                scaledvalue = ((n * scalesame2) >> 8) + zone1offset_y;
97
        }
98
    }
99
100

34909
    if (v->cur_field_type && !v->ref_field_type[dir])
101
        return av_clip(scaledvalue, -v->range_y / 2 + 1, v->range_y / 2);
102
    else
103
34909
        return av_clip(scaledvalue, -v->range_y / 2, v->range_y / 2 - 1);
104
}
105
106
8428
static av_always_inline int scaleforopp_x(VC1Context *v, int n /* MV */)
107
{
108
    int scalezone1_x, zone1offset_x;
109
    int scaleopp1, scaleopp2, brfd;
110
    int scaledvalue;
111
112
8428
    brfd = FFMIN(v->brfd, 3);
113
8428
    scalezone1_x  = ff_vc1_b_field_mvpred_scales[3][brfd];
114
8428
    zone1offset_x = ff_vc1_b_field_mvpred_scales[5][brfd];
115
8428
    scaleopp1     = ff_vc1_b_field_mvpred_scales[1][brfd];
116
8428
    scaleopp2     = ff_vc1_b_field_mvpred_scales[2][brfd];
117
118
8428
    if (FFABS(n) > 255)
119
        scaledvalue = n;
120
    else {
121
8428
        if (FFABS(n) < scalezone1_x)
122
6150
            scaledvalue = (n * scaleopp1) >> 8;
123
        else {
124
2278
            if (n < 0)
125
1151
                scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_x;
126
            else
127
1127
                scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_x;
128
        }
129
    }
130
8428
    return av_clip(scaledvalue, -v->range_x, v->range_x - 1);
131
}
132
133
8428
static av_always_inline int scaleforopp_y(VC1Context *v, int n /* MV */, int dir)
134
{
135
    int scalezone1_y, zone1offset_y;
136
    int scaleopp1, scaleopp2, brfd;
137
    int scaledvalue;
138
139
8428
    brfd = FFMIN(v->brfd, 3);
140
8428
    scalezone1_y  = ff_vc1_b_field_mvpred_scales[4][brfd];
141
8428
    zone1offset_y = ff_vc1_b_field_mvpred_scales[6][brfd];
142
8428
    scaleopp1     = ff_vc1_b_field_mvpred_scales[1][brfd];
143
8428
    scaleopp2     = ff_vc1_b_field_mvpred_scales[2][brfd];
144
145
8428
    if (FFABS(n) > 63)
146
        scaledvalue = n;
147
    else {
148
8428
        if (FFABS(n) < scalezone1_y)
149
6961
            scaledvalue = (n * scaleopp1) >> 8;
150
        else {
151
1467
            if (n < 0)
152
803
                scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_y;
153
            else
154
664
                scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_y;
155
        }
156
    }
157

8428
    if (v->cur_field_type && !v->ref_field_type[dir]) {
158
        return av_clip(scaledvalue, -v->range_y / 2 + 1, v->range_y / 2);
159
    } else {
160
8428
        return av_clip(scaledvalue, -v->range_y / 2, v->range_y / 2 - 1);
161
    }
162
}
163
164
86724
static av_always_inline int scaleforsame(VC1Context *v, int i, int n /* MV */,
165
                                         int dim, int dir)
166
{
167
    int brfd, scalesame;
168
86724
    int hpel = 1 - v->s.quarter_sample;
169
170
86724
    n >>= hpel;
171

86724
    if (v->s.pict_type != AV_PICTURE_TYPE_B || v->second_field || !dir) {
172
69818
        if (dim)
173
34909
            n = scaleforsame_y(v, i, n, dir) * (1 << hpel);
174
        else
175
34909
            n = scaleforsame_x(v, n, dir) * (1 << hpel);
176
69818
        return n;
177
    }
178
16906
    brfd      = FFMIN(v->brfd, 3);
179
16906
    scalesame = ff_vc1_b_field_mvpred_scales[0][brfd];
180
181
16906
    n = (n * scalesame >> 8) * (1 << hpel);
182
16906
    return n;
183
}
184
185
86000
static av_always_inline int scaleforopp(VC1Context *v, int n /* MV */,
186
                                        int dim, int dir)
187
{
188
    int refdist, scaleopp;
189
86000
    int hpel = 1 - v->s.quarter_sample;
190
191
86000
    n >>= hpel;
192

86000
    if (v->s.pict_type == AV_PICTURE_TYPE_B && !v->second_field && dir == 1) {
193
16856
        if (dim)
194
8428
            n = scaleforopp_y(v, n, dir) * (1 << hpel);
195
        else
196
8428
            n = scaleforopp_x(v, n)      * (1 << hpel);
197
16856
        return n;
198
    }
199
69144
    if (v->s.pict_type != AV_PICTURE_TYPE_B)
200
26818
        refdist = v->refdist;
201
    else
202
42326
        refdist = dir ? v->brfd : v->frfd;
203
69144
    refdist = FFMIN(refdist, 3);
204
69144
    scaleopp = ff_vc1_field_mvpred_scales[dir ^ v->second_field][0][refdist];
205
206
69144
    n = (n * scaleopp >> 8) * (1 << hpel);
207
69144
    return n;
208
}
209
210
/** Predict and set motion vector
211
 */
212
397785
void ff_vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y,
213
                    int mv1, int r_x, int r_y, uint8_t* is_intra,
214
                    int pred_flag, int dir)
215
{
216
397785
    MpegEncContext *s = &v->s;
217
397785
    int xy, wrap, off = 0;
218
    int16_t *A, *B, *C;
219
    int px, py;
220
    int sum;
221
397785
    int mixedmv_pic, num_samefield = 0, num_oppfield = 0;
222
    int opposite, a_f, b_f, c_f;
223
    int16_t field_predA[2];
224
    int16_t field_predB[2];
225
    int16_t field_predC[2];
226
    int a_valid, b_valid, c_valid;
227
397785
    int hybridmv_thresh, y_bias = 0;
228
229
397785
    if (v->mv_mode == MV_PMODE_MIXED_MV ||
230

147572
        ((v->mv_mode == MV_PMODE_INTENSITY_COMP) && (v->mv_mode2 == MV_PMODE_MIXED_MV)))
231
250213
        mixedmv_pic = 1;
232
    else
233
147572
        mixedmv_pic = 0;
234
    /* scale MV difference to be quad-pel */
235
397785
    if (!s->quarter_sample) {
236
115752
        dmv_x *= 2;
237
115752
        dmv_y *= 2;
238
    }
239
240
397785
    wrap = s->b8_stride;
241
397785
    xy   = s->block_index[n];
242
243
397785
    if (s->mb_intra) {
244
35549
        s->mv[0][n][0] = s->current_picture.motion_val[0][xy + v->blocks_off][0] = 0;
245
35549
        s->mv[0][n][1] = s->current_picture.motion_val[0][xy + v->blocks_off][1] = 0;
246
35549
        s->current_picture.motion_val[1][xy + v->blocks_off][0] = 0;
247
35549
        s->current_picture.motion_val[1][xy + v->blocks_off][1] = 0;
248
35549
        if (mv1) { /* duplicate motion data for 1-MV block */
249
24985
            s->current_picture.motion_val[0][xy + 1 + v->blocks_off][0]        = 0;
250
24985
            s->current_picture.motion_val[0][xy + 1 + v->blocks_off][1]        = 0;
251
24985
            s->current_picture.motion_val[0][xy + wrap + v->blocks_off][0]     = 0;
252
24985
            s->current_picture.motion_val[0][xy + wrap + v->blocks_off][1]     = 0;
253
24985
            s->current_picture.motion_val[0][xy + wrap + 1 + v->blocks_off][0] = 0;
254
24985
            s->current_picture.motion_val[0][xy + wrap + 1 + v->blocks_off][1] = 0;
255
24985
            v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
256
24985
            s->current_picture.motion_val[1][xy + 1 + v->blocks_off][0]        = 0;
257
24985
            s->current_picture.motion_val[1][xy + 1 + v->blocks_off][1]        = 0;
258
24985
            s->current_picture.motion_val[1][xy + wrap + v->blocks_off][0]     = 0;
259
24985
            s->current_picture.motion_val[1][xy + wrap + v->blocks_off][1]     = 0;
260
24985
            s->current_picture.motion_val[1][xy + wrap + 1 + v->blocks_off][0] = 0;
261
24985
            s->current_picture.motion_val[1][xy + wrap + 1 + v->blocks_off][1] = 0;
262
        }
263
35549
        return;
264
    }
265
266

362236
    a_valid = !s->first_slice_line || (n == 2 || n == 3);
267
362236
    b_valid = a_valid;
268

362236
    c_valid = s->mb_x || (n == 1 || n == 3);
269
362236
    if (mv1) {
270

201464
        if (v->field_mode && mixedmv_pic)
271
25989
            off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
272
        else
273
175475
            off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2;
274

201464
        b_valid = b_valid && s->mb_width > 1;
275
    } else {
276
        //in 4-MV mode different blocks have different B predictor position
277

160772
        switch (n) {
278
40284
        case 0:
279
40284
            if (v->res_rtm_flag)
280
40284
                off = s->mb_x ? -1 : 1;
281
            else
282
                off = s->mb_x ? -1 : 2 * s->mb_width - wrap - 1;
283
40284
            break;
284
40179
        case 1:
285
40179
            off = (s->mb_x == (s->mb_width - 1)) ? -1 : 1;
286
40179
            break;
287
40164
        case 2:
288
40164
            off = 1;
289
40164
            break;
290
40145
        case 3:
291
40145
            off = -1;
292
        }
293

160772
        if (v->field_mode && s->mb_width == 1)
294
            b_valid = b_valid && c_valid;
295
    }
296
297
362236
    if (v->field_mode) {
298

165473
        a_valid = a_valid && !is_intra[xy - wrap];
299

165473
        b_valid = b_valid && !is_intra[xy - wrap + off];
300

165473
        c_valid = c_valid && !is_intra[xy - 1];
301
    }
302
303
362236
    if (a_valid) {
304
317709
        A = s->current_picture.motion_val[dir][xy - wrap + v->blocks_off];
305
317709
        a_f = v->mv_f[dir][xy - wrap + v->blocks_off];
306
317709
        num_oppfield  += a_f;
307
317709
        num_samefield += 1 - a_f;
308
317709
        field_predA[0] = A[0];
309
317709
        field_predA[1] = A[1];
310
    } else {
311
44527
        field_predA[0] = field_predA[1] = 0;
312
44527
        a_f = 0;
313
    }
314
362236
    if (b_valid) {
315
317577
        B = s->current_picture.motion_val[dir][xy - wrap + off + v->blocks_off];
316
317577
        b_f = v->mv_f[dir][xy - wrap + off + v->blocks_off];
317
317577
        num_oppfield  += b_f;
318
317577
        num_samefield += 1 - b_f;
319
317577
        field_predB[0] = B[0];
320
317577
        field_predB[1] = B[1];
321
    } else {
322
44659
        field_predB[0] = field_predB[1] = 0;
323
44659
        b_f = 0;
324
    }
325
362236
    if (c_valid) {
326
348273
        C = s->current_picture.motion_val[dir][xy - 1 + v->blocks_off];
327
348273
        c_f = v->mv_f[dir][xy - 1 + v->blocks_off];
328
348273
        num_oppfield  += c_f;
329
348273
        num_samefield += 1 - c_f;
330
348273
        field_predC[0] = C[0];
331
348273
        field_predC[1] = C[1];
332
    } else {
333
13963
        field_predC[0] = field_predC[1] = 0;
334
13963
        c_f = 0;
335
    }
336
337
362236
    if (v->field_mode) {
338
165473
        if (!v->numref)
339
            // REFFIELD determines if the last field or the second-last field is
340
            // to be used as reference
341
            opposite = 1 - v->reffield;
342
        else {
343
165473
            if (num_samefield <= num_oppfield)
344
89977
                opposite = 1 - pred_flag;
345
            else
346
75496
                opposite = pred_flag;
347
        }
348
    } else
349
196763
        opposite = 0;
350
362236
    if (opposite) {
351
88103
        v->mv_f[dir][xy + v->blocks_off] = 1;
352
88103
        v->ref_field_type[dir] = !v->cur_field_type;
353

88103
        if (a_valid && !a_f) {
354
13504
            field_predA[0] = scaleforopp(v, field_predA[0], 0, dir);
355
13504
            field_predA[1] = scaleforopp(v, field_predA[1], 1, dir);
356
        }
357

88103
        if (b_valid && !b_f) {
358
15275
            field_predB[0] = scaleforopp(v, field_predB[0], 0, dir);
359
15275
            field_predB[1] = scaleforopp(v, field_predB[1], 1, dir);
360
        }
361

88103
        if (c_valid && !c_f) {
362
14221
            field_predC[0] = scaleforopp(v, field_predC[0], 0, dir);
363
14221
            field_predC[1] = scaleforopp(v, field_predC[1], 1, dir);
364
        }
365
    } else {
366
274133
        v->mv_f[dir][xy + v->blocks_off] = 0;
367
274133
        v->ref_field_type[dir] = v->cur_field_type;
368

274133
        if (a_valid && a_f) {
369
13995
            field_predA[0] = scaleforsame(v, n, field_predA[0], 0, dir);
370
13995
            field_predA[1] = scaleforsame(v, n, field_predA[1], 1, dir);
371
        }
372

274133
        if (b_valid && b_f) {
373
15661
            field_predB[0] = scaleforsame(v, n, field_predB[0], 0, dir);
374
15661
            field_predB[1] = scaleforsame(v, n, field_predB[1], 1, dir);
375
        }
376

274133
        if (c_valid && c_f) {
377
13706
            field_predC[0] = scaleforsame(v, n, field_predC[0], 0, dir);
378
13706
            field_predC[1] = scaleforsame(v, n, field_predC[1], 1, dir);
379
        }
380
    }
381
382
362236
    if (a_valid) {
383
317709
        px = field_predA[0];
384
317709
        py = field_predA[1];
385
44527
    } else if (c_valid) {
386
41718
        px = field_predC[0];
387
41718
        py = field_predC[1];
388
2809
    } else if (b_valid) {
389
1119
        px = field_predB[0];
390
1119
        py = field_predB[1];
391
    } else {
392
1690
        px = 0;
393
1690
        py = 0;
394
    }
395
396
362236
    if (num_samefield + num_oppfield > 1) {
397
320091
        px = mid_pred(field_predA[0], field_predB[0], field_predC[0]);
398
320091
        py = mid_pred(field_predA[1], field_predB[1], field_predC[1]);
399
    }
400
401
    /* Pullback MV as specified in 8.3.5.3.4 */
402
362236
    if (!v->field_mode) {
403
        int qx, qy, X, Y;
404
196763
        int MV = mv1 ? -60 : -28;
405

196763
        qx = (s->mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0);
406

196763
        qy = (s->mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0);
407
196763
        X  = (s->mb_width  << 6) - 4;
408
196763
        Y  = (s->mb_height << 6) - 4;
409
196763
        if (qx + px < MV) px = MV - qx;
410
196763
        if (qy + py < MV) py = MV - qy;
411
196763
        if (qx + px > X) px = X - qx;
412
196763
        if (qy + py > Y) py = Y - qy;
413
    }
414
415

362236
    if (!v->field_mode || s->pict_type != AV_PICTURE_TYPE_B) {
416
        /* Calculate hybrid prediction as specified in 8.3.5.3.5 (also 10.3.5.4.3.5) */
417
244568
        hybridmv_thresh = 32;
418

244568
        if (a_valid && c_valid) {
419
194443
            if (is_intra[xy - wrap])
420
16134
                sum = FFABS(px) + FFABS(py);
421
            else
422
178309
                sum = FFABS(px - field_predA[0]) + FFABS(py - field_predA[1]);
423
194443
            if (sum > hybridmv_thresh) {
424
12490
                if (get_bits1(&s->gb)) {     // read HYBRIDPRED bit
425
5134
                    px = field_predA[0];
426
5134
                    py = field_predA[1];
427
                } else {
428
7356
                    px = field_predC[0];
429
7356
                    py = field_predC[1];
430
                }
431
            } else {
432
181953
                if (is_intra[xy - 1])
433
16322
                    sum = FFABS(px) + FFABS(py);
434
                else
435
165631
                    sum = FFABS(px - field_predC[0]) + FFABS(py - field_predC[1]);
436
181953
                if (sum > hybridmv_thresh) {
437
16715
                    if (get_bits1(&s->gb)) {
438
8844
                        px = field_predA[0];
439
8844
                        py = field_predA[1];
440
                    } else {
441
7871
                        px = field_predC[0];
442
7871
                        py = field_predC[1];
443
                    }
444
                }
445
            }
446
        }
447
    }
448
449

362236
    if (v->field_mode && v->numref)
450
165473
        r_y >>= 1;
451

362236
    if (v->field_mode && v->cur_field_type && v->ref_field_type[dir] == 0)
452
58108
        y_bias = 1;
453
    /* store MV using signed modulus of MV range defined in 4.11 */
454
362236
    s->mv[dir][n][0] = s->current_picture.motion_val[dir][xy + v->blocks_off][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
455
362236
    s->mv[dir][n][1] = s->current_picture.motion_val[dir][xy + v->blocks_off][1] = ((py + dmv_y + r_y - y_bias) & ((r_y << 1) - 1)) - r_y + y_bias;
456
362236
    if (mv1) { /* duplicate motion data for 1-MV block */
457
201464
        s->current_picture.motion_val[dir][xy +    1 +     v->blocks_off][0] = s->current_picture.motion_val[dir][xy + v->blocks_off][0];
458
201464
        s->current_picture.motion_val[dir][xy +    1 +     v->blocks_off][1] = s->current_picture.motion_val[dir][xy + v->blocks_off][1];
459
201464
        s->current_picture.motion_val[dir][xy + wrap +     v->blocks_off][0] = s->current_picture.motion_val[dir][xy + v->blocks_off][0];
460
201464
        s->current_picture.motion_val[dir][xy + wrap +     v->blocks_off][1] = s->current_picture.motion_val[dir][xy + v->blocks_off][1];
461
201464
        s->current_picture.motion_val[dir][xy + wrap + 1 + v->blocks_off][0] = s->current_picture.motion_val[dir][xy + v->blocks_off][0];
462
201464
        s->current_picture.motion_val[dir][xy + wrap + 1 + v->blocks_off][1] = s->current_picture.motion_val[dir][xy + v->blocks_off][1];
463
201464
        v->mv_f[dir][xy +    1 + v->blocks_off] = v->mv_f[dir][xy +            v->blocks_off];
464
201464
        v->mv_f[dir][xy + wrap + v->blocks_off] = v->mv_f[dir][xy + wrap + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off];
465
    }
466
}
467
468
/** Predict and set motion vector for interlaced frame picture MBs
469
 */
470
87401
void ff_vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y,
471
                          int mvn, int r_x, int r_y, uint8_t* is_intra, int dir)
472
{
473
87401
    MpegEncContext *s = &v->s;
474
87401
    int xy, wrap, off = 0;
475
    int A[2], B[2], C[2];
476
87401
    int px = 0, py = 0;
477
87401
    int a_valid = 0, b_valid = 0, c_valid = 0;
478
    int field_a, field_b, field_c; // 0: same, 1: opposite
479
    int total_valid, num_samefield, num_oppfield;
480
    int pos_c, pos_b, n_adj;
481
482
87401
    wrap = s->b8_stride;
483
87401
    xy = s->block_index[n];
484
485
87401
    if (s->mb_intra) {
486
        s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = 0;
487
        s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = 0;
488
        s->current_picture.motion_val[1][xy][0] = 0;
489
        s->current_picture.motion_val[1][xy][1] = 0;
490
        if (mvn == 1) { /* duplicate motion data for 1-MV block */
491
            s->current_picture.motion_val[0][xy + 1][0]        = 0;
492
            s->current_picture.motion_val[0][xy + 1][1]        = 0;
493
            s->current_picture.motion_val[0][xy + wrap][0]     = 0;
494
            s->current_picture.motion_val[0][xy + wrap][1]     = 0;
495
            s->current_picture.motion_val[0][xy + wrap + 1][0] = 0;
496
            s->current_picture.motion_val[0][xy + wrap + 1][1] = 0;
497
            v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
498
            s->current_picture.motion_val[1][xy + 1][0]        = 0;
499
            s->current_picture.motion_val[1][xy + 1][1]        = 0;
500
            s->current_picture.motion_val[1][xy + wrap][0]     = 0;
501
            s->current_picture.motion_val[1][xy + wrap][1]     = 0;
502
            s->current_picture.motion_val[1][xy + wrap + 1][0] = 0;
503
            s->current_picture.motion_val[1][xy + wrap + 1][1] = 0;
504
        }
505
        return;
506
    }
507
508

87401
    off = ((n == 0) || (n == 1)) ? 1 : -1;
509
    /* predict A */
510

87401
    if (s->mb_x || (n == 1) || (n == 3)) {
511
86587
        if ((v->blk_mv_type[xy]) // current block (MB) has a field MV
512

24418
            || (!v->blk_mv_type[xy] && !v->blk_mv_type[xy - 1])) { // or both have frame MV
513
73757
            A[0] = s->current_picture.motion_val[dir][xy - 1][0];
514
73757
            A[1] = s->current_picture.motion_val[dir][xy - 1][1];
515
73757
            a_valid = 1;
516
        } else { // current block has frame mv and cand. has field MV (so average)
517
12830
            A[0] = (s->current_picture.motion_val[dir][xy - 1][0]
518
12830
                    + s->current_picture.motion_val[dir][xy - 1 + off * wrap][0] + 1) >> 1;
519
12830
            A[1] = (s->current_picture.motion_val[dir][xy - 1][1]
520
12830
                    + s->current_picture.motion_val[dir][xy - 1 + off * wrap][1] + 1) >> 1;
521
12830
            a_valid = 1;
522
        }
523

86587
        if (!(n & 1) && v->is_intra[s->mb_x - 1]) {
524
830
            a_valid = 0;
525
830
            A[0] = A[1] = 0;
526
        }
527
    } else
528
814
        A[0] = A[1] = 0;
529
    /* Predict B and C */
530
87401
    B[0] = B[1] = C[0] = C[1] = 0;
531

87401
    if (n == 0 || n == 1 || v->blk_mv_type[xy]) {
532
85993
        if (!s->first_slice_line) {
533
84676
            if (!v->is_intra[s->mb_x - s->mb_stride]) {
534
83692
                b_valid = 1;
535
83692
                n_adj   = n | 2;
536
83692
                pos_b   = s->block_index[n_adj] - 2 * wrap;
537

83692
                if (v->blk_mv_type[pos_b] && v->blk_mv_type[xy]) {
538
48511
                    n_adj = (n & 2) | (n & 1);
539
                }
540
83692
                B[0] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap][0];
541
83692
                B[1] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap][1];
542

83692
                if (v->blk_mv_type[pos_b] && !v->blk_mv_type[xy]) {
543
12805
                    B[0] = (B[0] + s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap][0] + 1) >> 1;
544
12805
                    B[1] = (B[1] + s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap][1] + 1) >> 1;
545
                }
546
            }
547
84676
            if (s->mb_width > 1) {
548
84676
                if (!v->is_intra[s->mb_x - s->mb_stride + 1]) {
549
83548
                    c_valid = 1;
550
83548
                    n_adj   = 2;
551
83548
                    pos_c   = s->block_index[2] - 2 * wrap + 2;
552

83548
                    if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
553
47104
                        n_adj = n & 2;
554
                    }
555
83548
                    C[0] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap + 2][0];
556
83548
                    C[1] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap + 2][1];
557

83548
                    if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
558
12916
                        C[0] = (1 + C[0] + (s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap + 2][0])) >> 1;
559
12916
                        C[1] = (1 + C[1] + (s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap + 2][1])) >> 1;
560
                    }
561
83548
                    if (s->mb_x == s->mb_width - 1) {
562
802
                        if (!v->is_intra[s->mb_x - s->mb_stride - 1]) {
563
782
                            c_valid = 1;
564
782
                            n_adj   = 3;
565
782
                            pos_c   = s->block_index[3] - 2 * wrap - 2;
566

782
                            if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
567
551
                                n_adj = n | 1;
568
                            }
569
782
                            C[0] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap - 2][0];
570
782
                            C[1] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap - 2][1];
571

782
                            if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
572
92
                                C[0] = (1 + C[0] + s->current_picture.motion_val[dir][s->block_index[1] - 2 * wrap - 2][0]) >> 1;
573
92
                                C[1] = (1 + C[1] + s->current_picture.motion_val[dir][s->block_index[1] - 2 * wrap - 2][1]) >> 1;
574
                            }
575
                        } else
576
20
                            c_valid = 0;
577
                    }
578
                }
579
            }
580
        }
581
    } else {
582
1408
        pos_b   = s->block_index[1];
583
1408
        b_valid = 1;
584
1408
        B[0]    = s->current_picture.motion_val[dir][pos_b][0];
585
1408
        B[1]    = s->current_picture.motion_val[dir][pos_b][1];
586
1408
        pos_c   = s->block_index[0];
587
1408
        c_valid = 1;
588
1408
        C[0]    = s->current_picture.motion_val[dir][pos_c][0];
589
1408
        C[1]    = s->current_picture.motion_val[dir][pos_c][1];
590
    }
591
592
87401
    total_valid = a_valid + b_valid + c_valid;
593
    // check if predictor A is out of bounds
594

87401
    if (!s->mb_x && !(n == 1 || n == 3)) {
595
814
        A[0] = A[1] = 0;
596
    }
597
    // check if predictor B is out of bounds
598


87401
    if ((s->first_slice_line && v->blk_mv_type[xy]) || (s->first_slice_line && !(n & 2))) {
599
1317
        B[0] = B[1] = C[0] = C[1] = 0;
600
    }
601
87401
    if (!v->blk_mv_type[xy]) {
602
24624
        if (s->mb_width == 1) {
603
            px = B[0];
604
            py = B[1];
605
        } else {
606
24624
            if (total_valid >= 2) {
607
24202
                px = mid_pred(A[0], B[0], C[0]);
608
24202
                py = mid_pred(A[1], B[1], C[1]);
609
422
            } else if (total_valid) {
610
395
                if      (a_valid) { px = A[0]; py = A[1]; }
611
39
                else if (b_valid) { px = B[0]; py = B[1]; }
612
21
                else              { px = C[0]; py = C[1]; }
613
            }
614
        }
615
    } else {
616
62777
        if (a_valid)
617
61492
            field_a = (A[1] & 4) ? 1 : 0;
618
        else
619
1285
            field_a = 0;
620
62777
        if (b_valid)
621
60944
            field_b = (B[1] & 4) ? 1 : 0;
622
        else
623
1833
            field_b = 0;
624
62777
        if (c_valid)
625
60819
            field_c = (C[1] & 4) ? 1 : 0;
626
        else
627
1958
            field_c = 0;
628
629
62777
        num_oppfield  = field_a + field_b + field_c;
630
62777
        num_samefield = total_valid - num_oppfield;
631
62777
        if (total_valid == 3) {
632

59358
            if ((num_samefield == 3) || (num_oppfield == 3)) {
633
27828
                px = mid_pred(A[0], B[0], C[0]);
634
27828
                py = mid_pred(A[1], B[1], C[1]);
635
31530
            } else if (num_samefield >= num_oppfield) {
636
                /* take one MV from same field set depending on priority
637
                the check for B may not be necessary */
638
15698
                px = !field_a ? A[0] : B[0];
639
15698
                py = !field_a ? A[1] : B[1];
640
            } else {
641
15832
                px =  field_a ? A[0] : B[0];
642
15832
                py =  field_a ? A[1] : B[1];
643
            }
644
3419
        } else if (total_valid == 2) {
645
1870
            if (num_samefield >= num_oppfield) {
646

1250
                if (!field_a && a_valid) {
647
455
                    px = A[0];
648
455
                    py = A[1];
649

795
                } else if (!field_b && b_valid) {
650
605
                    px = B[0];
651
605
                    py = B[1];
652
                } else /*if (c_valid)*/ {
653
                    av_assert1(c_valid);
654
190
                    px = C[0];
655
190
                    py = C[1];
656
                }
657
            } else {
658

620
                if (field_a && a_valid) {
659
303
                    px = A[0];
660
303
                    py = A[1];
661
                } else /*if (field_b && b_valid)*/ {
662
                    av_assert1(field_b && b_valid);
663
317
                    px = B[0];
664
317
                    py = B[1];
665
                }
666
            }
667
1549
        } else if (total_valid == 1) {
668

1441
            px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]);
669

1441
            py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]);
670
        }
671
    }
672
673
    /* store MV using signed modulus of MV range defined in 4.11 */
674
87401
    s->mv[dir][n][0] = s->current_picture.motion_val[dir][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
675
87401
    s->mv[dir][n][1] = s->current_picture.motion_val[dir][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
676
87401
    if (mvn == 1) { /* duplicate motion data for 1-MV block */
677
21808
        s->current_picture.motion_val[dir][xy +    1    ][0] = s->current_picture.motion_val[dir][xy][0];
678
21808
        s->current_picture.motion_val[dir][xy +    1    ][1] = s->current_picture.motion_val[dir][xy][1];
679
21808
        s->current_picture.motion_val[dir][xy + wrap    ][0] = s->current_picture.motion_val[dir][xy][0];
680
21808
        s->current_picture.motion_val[dir][xy + wrap    ][1] = s->current_picture.motion_val[dir][xy][1];
681
21808
        s->current_picture.motion_val[dir][xy + wrap + 1][0] = s->current_picture.motion_val[dir][xy][0];
682
21808
        s->current_picture.motion_val[dir][xy + wrap + 1][1] = s->current_picture.motion_val[dir][xy][1];
683
65593
    } else if (mvn == 2) { /* duplicate motion data for 2-Field MV block */
684
58441
        s->current_picture.motion_val[dir][xy + 1][0] = s->current_picture.motion_val[dir][xy][0];
685
58441
        s->current_picture.motion_val[dir][xy + 1][1] = s->current_picture.motion_val[dir][xy][1];
686
58441
        s->mv[dir][n + 1][0] = s->mv[dir][n][0];
687
58441
        s->mv[dir][n + 1][1] = s->mv[dir][n][1];
688
    }
689
}
690
691
20940
void ff_vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2],
692
                      int direct, int mvtype)
693
{
694
20940
    MpegEncContext *s = &v->s;
695
20940
    int xy, wrap, off = 0;
696
    int16_t *A, *B, *C;
697
    int px, py;
698
    int sum;
699
    int r_x, r_y;
700
20940
    const uint8_t *is_intra = v->mb_type[0];
701
702
20940
    av_assert0(!v->field_mode);
703
704
20940
    r_x = v->range_x;
705
20940
    r_y = v->range_y;
706
    /* scale MV difference to be quad-pel */
707
20940
    if (!s->quarter_sample) {
708
        dmv_x[0] *= 2;
709
        dmv_y[0] *= 2;
710
        dmv_x[1] *= 2;
711
        dmv_y[1] *= 2;
712
    }
713
714
20940
    wrap = s->b8_stride;
715
20940
    xy = s->block_index[0];
716
717
20940
    if (s->mb_intra) {
718
170
        s->current_picture.motion_val[0][xy][0] =
719
170
        s->current_picture.motion_val[0][xy][1] =
720
170
        s->current_picture.motion_val[1][xy][0] =
721
170
        s->current_picture.motion_val[1][xy][1] = 0;
722
170
        return;
723
    }
724

20770
        if (direct && s->next_picture_ptr->field_picture)
725
            av_log(s->avctx, AV_LOG_WARNING, "Mixed frame/field direct mode not supported\n");
726
727
20770
        s->mv[0][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 0, s->quarter_sample);
728
20770
        s->mv[0][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 0, s->quarter_sample);
729
20770
        s->mv[1][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 1, s->quarter_sample);
730
20770
        s->mv[1][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 1, s->quarter_sample);
731
732
        /* Pullback predicted motion vectors as specified in 8.4.5.4 */
733
20770
        s->mv[0][0][0] = av_clip(s->mv[0][0][0], -60 - (s->mb_x << 6), (s->mb_width  << 6) - 4 - (s->mb_x << 6));
734
20770
        s->mv[0][0][1] = av_clip(s->mv[0][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6));
735
20770
        s->mv[1][0][0] = av_clip(s->mv[1][0][0], -60 - (s->mb_x << 6), (s->mb_width  << 6) - 4 - (s->mb_x << 6));
736
20770
        s->mv[1][0][1] = av_clip(s->mv[1][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6));
737
20770
    if (direct) {
738
2569
        s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0];
739
2569
        s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1];
740
2569
        s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0];
741
2569
        s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1];
742
2569
        return;
743
    }
744
745

18201
    if ((mvtype == BMV_TYPE_FORWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
746
10180
        C   = s->current_picture.motion_val[0][xy - 2];
747
10180
        A   = s->current_picture.motion_val[0][xy - wrap * 2];
748
10180
        off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
749
10180
        B   = s->current_picture.motion_val[0][xy - wrap * 2 + off];
750
751
10180
        if (!s->mb_x) C[0] = C[1] = 0;
752
10180
        if (!s->first_slice_line) { // predictor A is not out of bounds
753
9675
            if (s->mb_width == 1) {
754
                px = A[0];
755
                py = A[1];
756
            } else {
757
9675
                px = mid_pred(A[0], B[0], C[0]);
758
9675
                py = mid_pred(A[1], B[1], C[1]);
759
            }
760
505
        } else if (s->mb_x) { // predictor C is not out of bounds
761
489
            px = C[0];
762
489
            py = C[1];
763
        } else {
764
16
            px = py = 0;
765
        }
766
        /* Pullback MV as specified in 8.3.5.3.4 */
767
        {
768
            int qx, qy, X, Y;
769
10180
            int sh = v->profile < PROFILE_ADVANCED ? 5 : 6;
770
10180
            int MV = 4 - (1 << sh);
771
10180
            qx = (s->mb_x << sh);
772
10180
            qy = (s->mb_y << sh);
773
10180
            X  = (s->mb_width  << sh) - 4;
774
10180
            Y  = (s->mb_height << sh) - 4;
775
10180
            if (qx + px < MV) px = MV - qx;
776
10180
            if (qy + py < MV) py = MV - qy;
777
10180
            if (qx + px > X) px = X - qx;
778
10180
            if (qy + py > Y) py = Y - qy;
779
        }
780
        /* Calculate hybrid prediction as specified in 8.3.5.3.5 */
781
        if (0 && !s->first_slice_line && s->mb_x) {
782
            if (is_intra[xy - wrap])
783
                sum = FFABS(px) + FFABS(py);
784
            else
785
                sum = FFABS(px - A[0]) + FFABS(py - A[1]);
786
            if (sum > 32) {
787
                if (get_bits1(&s->gb)) {
788
                    px = A[0];
789
                    py = A[1];
790
                } else {
791
                    px = C[0];
792
                    py = C[1];
793
                }
794
            } else {
795
                if (is_intra[xy - 2])
796
                    sum = FFABS(px) + FFABS(py);
797
                else
798
                    sum = FFABS(px - C[0]) + FFABS(py - C[1]);
799
                if (sum > 32) {
800
                    if (get_bits1(&s->gb)) {
801
                        px = A[0];
802
                        py = A[1];
803
                    } else {
804
                        px = C[0];
805
                        py = C[1];
806
                    }
807
                }
808
            }
809
        }
810
        /* store MV using signed modulus of MV range defined in 4.11 */
811
10180
        s->mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
812
10180
        s->mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
813
    }
814

18201
    if ((mvtype == BMV_TYPE_BACKWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
815
14178
        C   = s->current_picture.motion_val[1][xy - 2];
816
14178
        A   = s->current_picture.motion_val[1][xy - wrap * 2];
817
14178
        off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
818
14178
        B   = s->current_picture.motion_val[1][xy - wrap * 2 + off];
819
820
14178
        if (!s->mb_x)
821
389
            C[0] = C[1] = 0;
822
14178
        if (!s->first_slice_line) { // predictor A is not out of bounds
823
13334
            if (s->mb_width == 1) {
824
                px = A[0];
825
                py = A[1];
826
            } else {
827
13334
                px = mid_pred(A[0], B[0], C[0]);
828
13334
                py = mid_pred(A[1], B[1], C[1]);
829
            }
830
844
        } else if (s->mb_x) { // predictor C is not out of bounds
831
813
            px = C[0];
832
813
            py = C[1];
833
        } else {
834
31
            px = py = 0;
835
        }
836
        /* Pullback MV as specified in 8.3.5.3.4 */
837
        {
838
            int qx, qy, X, Y;
839
14178
            int sh = v->profile < PROFILE_ADVANCED ? 5 : 6;
840
14178
            int MV = 4 - (1 << sh);
841
14178
            qx = (s->mb_x << sh);
842
14178
            qy = (s->mb_y << sh);
843
14178
            X  = (s->mb_width  << sh) - 4;
844
14178
            Y  = (s->mb_height << sh) - 4;
845
14178
            if (qx + px < MV) px = MV - qx;
846
14178
            if (qy + py < MV) py = MV - qy;
847
14178
            if (qx + px > X) px = X - qx;
848
14178
            if (qy + py > Y) py = Y - qy;
849
        }
850
        /* Calculate hybrid prediction as specified in 8.3.5.3.5 */
851
        if (0 && !s->first_slice_line && s->mb_x) {
852
            if (is_intra[xy - wrap])
853
                sum = FFABS(px) + FFABS(py);
854
            else
855
                sum = FFABS(px - A[0]) + FFABS(py - A[1]);
856
            if (sum > 32) {
857
                if (get_bits1(&s->gb)) {
858
                    px = A[0];
859
                    py = A[1];
860
                } else {
861
                    px = C[0];
862
                    py = C[1];
863
                }
864
            } else {
865
                if (is_intra[xy - 2])
866
                    sum = FFABS(px) + FFABS(py);
867
                else
868
                    sum = FFABS(px - C[0]) + FFABS(py - C[1]);
869
                if (sum > 32) {
870
                    if (get_bits1(&s->gb)) {
871
                        px = A[0];
872
                        py = A[1];
873
                    } else {
874
                        px = C[0];
875
                        py = C[1];
876
                    }
877
                }
878
            }
879
        }
880
        /* store MV using signed modulus of MV range defined in 4.11 */
881
882
14178
        s->mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
883
14178
        s->mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
884
    }
885
18201
    s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0];
886
18201
    s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1];
887
18201
    s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0];
888
18201
    s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1];
889
}
890
891
79716
void ff_vc1_pred_b_mv_intfi(VC1Context *v, int n, int *dmv_x, int *dmv_y,
892
                            int mv1, int *pred_flag)
893
{
894
79716
    int dir = (v->bmvtype == BMV_TYPE_BACKWARD) ? 1 : 0;
895
79716
    MpegEncContext *s = &v->s;
896
79716
    int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
897
898
79716
    if (v->bmvtype == BMV_TYPE_DIRECT) {
899
        int total_opp, k, f;
900
6770
        if (s->next_picture.mb_type[mb_pos + v->mb_off] != MB_TYPE_INTRA) {
901
9806
            s->mv[0][0][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[0] + v->blocks_off][0],
902
4903
                                      v->bfraction, 0, s->quarter_sample);
903
9806
            s->mv[0][0][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[0] + v->blocks_off][1],
904
4903
                                      v->bfraction, 0, s->quarter_sample);
905
9806
            s->mv[1][0][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[0] + v->blocks_off][0],
906
4903
                                      v->bfraction, 1, s->quarter_sample);
907
9806
            s->mv[1][0][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[0] + v->blocks_off][1],
908
4903
                                      v->bfraction, 1, s->quarter_sample);
909
910
4903
            total_opp = v->mv_f_next[0][s->block_index[0] + v->blocks_off]
911
4903
                      + v->mv_f_next[0][s->block_index[1] + v->blocks_off]
912
4903
                      + v->mv_f_next[0][s->block_index[2] + v->blocks_off]
913
4903
                      + v->mv_f_next[0][s->block_index[3] + v->blocks_off];
914
4903
            f = (total_opp > 2) ? 1 : 0;
915
        } else {
916
1867
            s->mv[0][0][0] = s->mv[0][0][1] = 0;
917
1867
            s->mv[1][0][0] = s->mv[1][0][1] = 0;
918
1867
            f = 0;
919
        }
920
6770
        v->ref_field_type[0] = v->ref_field_type[1] = v->cur_field_type ^ f;
921
33850
        for (k = 0; k < 4; k++) {
922
27080
            s->current_picture.motion_val[0][s->block_index[k] + v->blocks_off][0] = s->mv[0][0][0];
923
27080
            s->current_picture.motion_val[0][s->block_index[k] + v->blocks_off][1] = s->mv[0][0][1];
924
27080
            s->current_picture.motion_val[1][s->block_index[k] + v->blocks_off][0] = s->mv[1][0][0];
925
27080
            s->current_picture.motion_val[1][s->block_index[k] + v->blocks_off][1] = s->mv[1][0][1];
926
27080
            v->mv_f[0][s->block_index[k] + v->blocks_off] = f;
927
27080
            v->mv_f[1][s->block_index[k] + v->blocks_off] = f;
928
        }
929
6770
        return;
930
    }
931
72946
    if (v->bmvtype == BMV_TYPE_INTERPOLATED) {
932
5886
        ff_vc1_pred_mv(v, 0, dmv_x[0], dmv_y[0],   1, v->range_x, v->range_y, v->mb_type[0], pred_flag[0], 0);
933
5886
        ff_vc1_pred_mv(v, 0, dmv_x[1], dmv_y[1],   1, v->range_x, v->range_y, v->mb_type[0], pred_flag[1], 1);
934
5886
        return;
935
    }
936
67060
    if (dir) { // backward
937
31989
        ff_vc1_pred_mv(v, n, dmv_x[1], dmv_y[1], mv1, v->range_x, v->range_y, v->mb_type[0], pred_flag[1], 1);
938

31989
        if (n == 3 || mv1) {
939
18441
            ff_vc1_pred_mv(v, 0, dmv_x[0], dmv_y[0],   1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
940
        }
941
    } else { // forward
942
35071
        ff_vc1_pred_mv(v, n, dmv_x[0], dmv_y[0], mv1, v->range_x, v->range_y, v->mb_type[0], pred_flag[0], 0);
943

35071
        if (n == 3 || mv1) {
944
20395
            ff_vc1_pred_mv(v, 0, dmv_x[1], dmv_y[1],   1, v->range_x, v->range_y, v->mb_type[0], 0, 1);
945
        }
946
    }
947
}