FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vc1_pred.c
Date: 2024-07-26 21:54:09
Exec Total Coverage
Lines: 532 572 93.0%
Functions: 10 10 100.0%
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(const 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
2/2
✓ Branch 0 taken 14268 times.
✓ Branch 1 taken 20641 times.
34909 if (v->s.pict_type != AV_PICTURE_TYPE_B)
44 14268 refdist = v->refdist;
45 else
46
2/2
✓ Branch 0 taken 7214 times.
✓ Branch 1 taken 13427 times.
20641 refdist = dir ? v->brfd : v->frfd;
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34909 times.
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
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 34896 times.
34909 if (FFABS(n) > 255)
55 13 scaledvalue = n;
56 else {
57
2/2
✓ Branch 0 taken 25948 times.
✓ Branch 1 taken 8948 times.
34896 if (FFABS(n) < scalezone1_x)
58 25948 scaledvalue = (n * scalesame1) >> 8;
59 else {
60
2/2
✓ Branch 0 taken 4487 times.
✓ Branch 1 taken 4461 times.
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(const VC1Context *v, 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
2/2
✓ Branch 0 taken 14268 times.
✓ Branch 1 taken 20641 times.
34909 if (v->s.pict_type != AV_PICTURE_TYPE_B)
77 14268 refdist = v->refdist;
78 else
79
2/2
✓ Branch 0 taken 7214 times.
✓ Branch 1 taken 13427 times.
20641 refdist = dir ? v->brfd : v->frfd;
80
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34909 times.
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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34909 times.
34909 if (FFABS(n) > 63)
88 scaledvalue = n;
89 else {
90
2/2
✓ Branch 0 taken 27772 times.
✓ Branch 1 taken 7137 times.
34909 if (FFABS(n) < scalezone1_y)
91 27772 scaledvalue = (n * scalesame1) >> 8;
92 else {
93
2/2
✓ Branch 0 taken 3231 times.
✓ Branch 1 taken 3906 times.
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
3/4
✓ Branch 0 taken 18863 times.
✓ Branch 1 taken 16046 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18863 times.
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(const 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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8428 times.
8428 if (FFABS(n) > 255)
119 scaledvalue = n;
120 else {
121
2/2
✓ Branch 0 taken 6150 times.
✓ Branch 1 taken 2278 times.
8428 if (FFABS(n) < scalezone1_x)
122 6150 scaledvalue = (n * scaleopp1) >> 8;
123 else {
124
2/2
✓ Branch 0 taken 1151 times.
✓ Branch 1 taken 1127 times.
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(const 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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8428 times.
8428 if (FFABS(n) > 63)
146 scaledvalue = n;
147 else {
148
2/2
✓ Branch 0 taken 6961 times.
✓ Branch 1 taken 1467 times.
8428 if (FFABS(n) < scalezone1_y)
149 6961 scaledvalue = (n * scaleopp1) >> 8;
150 else {
151
2/2
✓ Branch 0 taken 803 times.
✓ Branch 1 taken 664 times.
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
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8428 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
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(const VC1Context *v, 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
6/6
✓ Branch 0 taken 58188 times.
✓ Branch 1 taken 28536 times.
✓ Branch 2 taken 32076 times.
✓ Branch 3 taken 26112 times.
✓ Branch 4 taken 15170 times.
✓ Branch 5 taken 16906 times.
86724 if (v->s.pict_type != AV_PICTURE_TYPE_B || v->second_field || !dir) {
172
2/2
✓ Branch 0 taken 34909 times.
✓ Branch 1 taken 34909 times.
69818 if (dim)
173 34909 n = scaleforsame_y(v, 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(const 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
6/6
✓ Branch 0 taken 59182 times.
✓ Branch 1 taken 26818 times.
✓ Branch 2 taken 31814 times.
✓ Branch 3 taken 27368 times.
✓ Branch 4 taken 16856 times.
✓ Branch 5 taken 14958 times.
86000 if (v->s.pict_type == AV_PICTURE_TYPE_B && !v->second_field && dir == 1) {
193
2/2
✓ Branch 0 taken 8428 times.
✓ Branch 1 taken 8428 times.
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
2/2
✓ Branch 0 taken 26818 times.
✓ Branch 1 taken 42326 times.
69144 if (v->s.pict_type != AV_PICTURE_TYPE_B)
200 26818 refdist = v->refdist;
201 else
202
2/2
✓ Branch 0 taken 13008 times.
✓ Branch 1 taken 29318 times.
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 398903 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 398903 MpegEncContext *s = &v->s;
217 398903 int xy, wrap, off = 0;
218 int px, py;
219 int sum;
220 398903 int mixedmv_pic, num_samefield = 0, num_oppfield = 0;
221 int opposite, a_f, b_f, c_f;
222 int16_t field_predA[2];
223 int16_t field_predB[2];
224 int16_t field_predC[2];
225 int a_valid, b_valid, c_valid;
226 398903 int hybridmv_thresh, y_bias = 0;
227
228
2/2
✓ Branch 0 taken 147596 times.
✓ Branch 1 taken 251307 times.
398903 if (v->mv_mode == MV_PMODE_MIXED_MV ||
229
3/4
✓ Branch 0 taken 4620 times.
✓ Branch 1 taken 142976 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4620 times.
147596 ((v->mv_mode == MV_PMODE_INTENSITY_COMP) && (v->mv_mode2 == MV_PMODE_MIXED_MV)))
230 251307 mixedmv_pic = 1;
231 else
232 147596 mixedmv_pic = 0;
233 /* scale MV difference to be quad-pel */
234
2/2
✓ Branch 0 taken 115752 times.
✓ Branch 1 taken 283151 times.
398903 if (!s->quarter_sample) {
235 115752 dmv_x *= 2;
236 115752 dmv_y *= 2;
237 }
238
239 398903 wrap = s->b8_stride;
240 398903 xy = s->block_index[n];
241
242
2/2
✓ Branch 0 taken 35551 times.
✓ Branch 1 taken 363352 times.
398903 if (s->mb_intra) {
243 35551 s->mv[0][n][0] = s->cur_pic.motion_val[0][xy + v->blocks_off][0] = 0;
244 35551 s->mv[0][n][1] = s->cur_pic.motion_val[0][xy + v->blocks_off][1] = 0;
245 35551 s->cur_pic.motion_val[1][xy + v->blocks_off][0] = 0;
246 35551 s->cur_pic.motion_val[1][xy + v->blocks_off][1] = 0;
247
2/2
✓ Branch 0 taken 24987 times.
✓ Branch 1 taken 10564 times.
35551 if (mv1) { /* duplicate motion data for 1-MV block */
248 24987 s->cur_pic.motion_val[0][xy + 1 + v->blocks_off][0] = 0;
249 24987 s->cur_pic.motion_val[0][xy + 1 + v->blocks_off][1] = 0;
250 24987 s->cur_pic.motion_val[0][xy + wrap + v->blocks_off][0] = 0;
251 24987 s->cur_pic.motion_val[0][xy + wrap + v->blocks_off][1] = 0;
252 24987 s->cur_pic.motion_val[0][xy + wrap + 1 + v->blocks_off][0] = 0;
253 24987 s->cur_pic.motion_val[0][xy + wrap + 1 + v->blocks_off][1] = 0;
254 24987 v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
255 24987 s->cur_pic.motion_val[1][xy + 1 + v->blocks_off][0] = 0;
256 24987 s->cur_pic.motion_val[1][xy + 1 + v->blocks_off][1] = 0;
257 24987 s->cur_pic.motion_val[1][xy + wrap + v->blocks_off][0] = 0;
258 24987 s->cur_pic.motion_val[1][xy + wrap + v->blocks_off][1] = 0;
259 24987 s->cur_pic.motion_val[1][xy + wrap + 1 + v->blocks_off][0] = 0;
260 24987 s->cur_pic.motion_val[1][xy + wrap + 1 + v->blocks_off][1] = 0;
261 }
262 35551 return;
263 }
264
265
6/6
✓ Branch 0 taken 56538 times.
✓ Branch 1 taken 306814 times.
✓ Branch 2 taken 46881 times.
✓ Branch 3 taken 9657 times.
✓ Branch 4 taken 9674 times.
✓ Branch 5 taken 37207 times.
363352 a_valid = !s->first_slice_line || (n == 2 || n == 3);
266 363352 b_valid = a_valid;
267
6/6
✓ Branch 0 taken 8510 times.
✓ Branch 1 taken 354842 times.
✓ Branch 2 taken 7475 times.
✓ Branch 3 taken 1035 times.
✓ Branch 4 taken 1029 times.
✓ Branch 5 taken 6446 times.
363352 c_valid = s->mb_x || (n == 1 || n == 3);
268
2/2
✓ Branch 0 taken 201708 times.
✓ Branch 1 taken 161644 times.
363352 if (mv1) {
269
4/4
✓ Branch 0 taken 100663 times.
✓ Branch 1 taken 101045 times.
✓ Branch 2 taken 26211 times.
✓ Branch 3 taken 74452 times.
201708 if (v->field_mode && mixedmv_pic)
270
2/2
✓ Branch 0 taken 470 times.
✓ Branch 1 taken 25741 times.
26211 off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
271 else
272
2/2
✓ Branch 0 taken 3853 times.
✓ Branch 1 taken 171644 times.
175497 off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2;
273
3/4
✓ Branch 0 taken 183816 times.
✓ Branch 1 taken 17892 times.
✓ Branch 2 taken 183816 times.
✗ Branch 3 not taken.
201708 b_valid = b_valid && s->mb_width > 1;
274 } else {
275 //in 4-MV mode different blocks have different B predictor position
276
4/5
✓ Branch 0 taken 40502 times.
✓ Branch 1 taken 40397 times.
✓ Branch 2 taken 40382 times.
✓ Branch 3 taken 40363 times.
✗ Branch 4 not taken.
161644 switch (n) {
277 40502 case 0:
278
1/2
✓ Branch 0 taken 40502 times.
✗ Branch 1 not taken.
40502 if (v->res_rtm_flag)
279
2/2
✓ Branch 0 taken 39495 times.
✓ Branch 1 taken 1007 times.
40502 off = s->mb_x ? -1 : 1;
280 else
281 off = s->mb_x ? -1 : 2 * s->mb_width - wrap - 1;
282 40502 break;
283 40397 case 1:
284
2/2
✓ Branch 0 taken 913 times.
✓ Branch 1 taken 39484 times.
40397 off = (s->mb_x == (s->mb_width - 1)) ? -1 : 1;
285 40397 break;
286 40382 case 2:
287 40382 off = 1;
288 40382 break;
289 40363 case 3:
290 40363 off = -1;
291 }
292
3/4
✓ Branch 0 taken 65904 times.
✓ Branch 1 taken 95740 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 65904 times.
161644 if (v->field_mode && s->mb_width == 1)
293 b_valid = b_valid && c_valid;
294 }
295
296
2/2
✓ Branch 0 taken 166567 times.
✓ Branch 1 taken 196785 times.
363352 if (v->field_mode) {
297
4/4
✓ Branch 0 taken 160625 times.
✓ Branch 1 taken 5942 times.
✓ Branch 2 taken 153049 times.
✓ Branch 3 taken 7576 times.
166567 a_valid = a_valid && !is_intra[xy - wrap];
298
4/4
✓ Branch 0 taken 160625 times.
✓ Branch 1 taken 5942 times.
✓ Branch 2 taken 152892 times.
✓ Branch 3 taken 7733 times.
166567 b_valid = b_valid && !is_intra[xy - wrap + off];
299
4/4
✓ Branch 0 taken 164660 times.
✓ Branch 1 taken 1907 times.
✓ Branch 2 taken 156923 times.
✓ Branch 3 taken 7737 times.
166567 c_valid = c_valid && !is_intra[xy - 1];
300 }
301
302
2/2
✓ Branch 0 taken 318569 times.
✓ Branch 1 taken 44783 times.
363352 if (a_valid) {
303 318569 const int16_t *A = s->cur_pic.motion_val[dir][xy - wrap + v->blocks_off];
304 318569 a_f = v->mv_f[dir][xy - wrap + v->blocks_off];
305 318569 num_oppfield += a_f;
306 318569 num_samefield += 1 - a_f;
307 318569 field_predA[0] = A[0];
308 318569 field_predA[1] = A[1];
309 } else {
310 44783 field_predA[0] = field_predA[1] = 0;
311 44783 a_f = 0;
312 }
313
2/2
✓ Branch 0 taken 318412 times.
✓ Branch 1 taken 44940 times.
363352 if (b_valid) {
314 318412 const int16_t *B = s->cur_pic.motion_val[dir][xy - wrap + off + v->blocks_off];
315 318412 b_f = v->mv_f[dir][xy - wrap + off + v->blocks_off];
316 318412 num_oppfield += b_f;
317 318412 num_samefield += 1 - b_f;
318 318412 field_predB[0] = B[0];
319 318412 field_predB[1] = B[1];
320 } else {
321 44940 field_predB[0] = field_predB[1] = 0;
322 44940 b_f = 0;
323 }
324
2/2
✓ Branch 0 taken 349169 times.
✓ Branch 1 taken 14183 times.
363352 if (c_valid) {
325 349169 const int16_t *C = s->cur_pic.motion_val[dir][xy - 1 + v->blocks_off];
326 349169 c_f = v->mv_f[dir][xy - 1 + v->blocks_off];
327 349169 num_oppfield += c_f;
328 349169 num_samefield += 1 - c_f;
329 349169 field_predC[0] = C[0];
330 349169 field_predC[1] = C[1];
331 } else {
332 14183 field_predC[0] = field_predC[1] = 0;
333 14183 c_f = 0;
334 }
335
336
2/2
✓ Branch 0 taken 166567 times.
✓ Branch 1 taken 196785 times.
363352 if (v->field_mode) {
337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 166567 times.
166567 if (!v->numref)
338 // REFFIELD determines if the last field or the second-last field is
339 // to be used as reference
340 opposite = 1 - v->reffield;
341 else {
342
2/2
✓ Branch 0 taken 91071 times.
✓ Branch 1 taken 75496 times.
166567 if (num_samefield <= num_oppfield)
343 91071 opposite = 1 - pred_flag;
344 else
345 75496 opposite = pred_flag;
346 }
347 } else
348 196785 opposite = 0;
349
2/2
✓ Branch 0 taken 89197 times.
✓ Branch 1 taken 274155 times.
363352 if (opposite) {
350 89197 v->mv_f[dir][xy + v->blocks_off] = 1;
351 89197 v->ref_field_type[dir] = !v->cur_field_type;
352
4/4
✓ Branch 0 taken 81172 times.
✓ Branch 1 taken 8025 times.
✓ Branch 2 taken 13504 times.
✓ Branch 3 taken 67668 times.
89197 if (a_valid && !a_f) {
353 13504 field_predA[0] = scaleforopp(v, field_predA[0], 0, dir);
354 13504 field_predA[1] = scaleforopp(v, field_predA[1], 1, dir);
355 }
356
4/4
✓ Branch 0 taken 81065 times.
✓ Branch 1 taken 8132 times.
✓ Branch 2 taken 15275 times.
✓ Branch 3 taken 65790 times.
89197 if (b_valid && !b_f) {
357 15275 field_predB[0] = scaleforopp(v, field_predB[0], 0, dir);
358 15275 field_predB[1] = scaleforopp(v, field_predB[1], 1, dir);
359 }
360
4/4
✓ Branch 0 taken 83263 times.
✓ Branch 1 taken 5934 times.
✓ Branch 2 taken 14221 times.
✓ Branch 3 taken 69042 times.
89197 if (c_valid && !c_f) {
361 14221 field_predC[0] = scaleforopp(v, field_predC[0], 0, dir);
362 14221 field_predC[1] = scaleforopp(v, field_predC[1], 1, dir);
363 }
364 } else {
365 274155 v->mv_f[dir][xy + v->blocks_off] = 0;
366 274155 v->ref_field_type[dir] = v->cur_field_type;
367
4/4
✓ Branch 0 taken 237397 times.
✓ Branch 1 taken 36758 times.
✓ Branch 2 taken 13995 times.
✓ Branch 3 taken 223402 times.
274155 if (a_valid && a_f) {
368 13995 field_predA[0] = scaleforsame(v, field_predA[0], 0, dir);
369 13995 field_predA[1] = scaleforsame(v, field_predA[1], 1, dir);
370 }
371
4/4
✓ Branch 0 taken 237347 times.
✓ Branch 1 taken 36808 times.
✓ Branch 2 taken 15661 times.
✓ Branch 3 taken 221686 times.
274155 if (b_valid && b_f) {
372 15661 field_predB[0] = scaleforsame(v, field_predB[0], 0, dir);
373 15661 field_predB[1] = scaleforsame(v, field_predB[1], 1, dir);
374 }
375
4/4
✓ Branch 0 taken 265906 times.
✓ Branch 1 taken 8249 times.
✓ Branch 2 taken 13706 times.
✓ Branch 3 taken 252200 times.
274155 if (c_valid && c_f) {
376 13706 field_predC[0] = scaleforsame(v, field_predC[0], 0, dir);
377 13706 field_predC[1] = scaleforsame(v, field_predC[1], 1, dir);
378 }
379 }
380
381
2/2
✓ Branch 0 taken 318569 times.
✓ Branch 1 taken 44783 times.
363352 if (a_valid) {
382 318569 px = field_predA[0];
383 318569 py = field_predA[1];
384
2/2
✓ Branch 0 taken 41920 times.
✓ Branch 1 taken 2863 times.
44783 } else if (c_valid) {
385 41920 px = field_predC[0];
386 41920 py = field_predC[1];
387
2/2
✓ Branch 0 taken 1143 times.
✓ Branch 1 taken 1720 times.
2863 } else if (b_valid) {
388 1143 px = field_predB[0];
389 1143 py = field_predB[1];
390 } else {
391 1720 px = 0;
392 1720 py = 0;
393 }
394
395
2/2
✓ Branch 0 taken 321003 times.
✓ Branch 1 taken 42349 times.
363352 if (num_samefield + num_oppfield > 1) {
396 321003 px = mid_pred(field_predA[0], field_predB[0], field_predC[0]);
397 321003 py = mid_pred(field_predA[1], field_predB[1], field_predC[1]);
398 }
399
400 /* Pullback MV as specified in 8.3.5.3.4 */
401
2/2
✓ Branch 0 taken 196785 times.
✓ Branch 1 taken 166567 times.
363352 if (!v->field_mode) {
402 int qx, qy, X, Y;
403
2/2
✓ Branch 0 taken 101045 times.
✓ Branch 1 taken 95740 times.
196785 int MV = mv1 ? -60 : -28;
404
4/4
✓ Branch 0 taken 172864 times.
✓ Branch 1 taken 23921 times.
✓ Branch 2 taken 23887 times.
✓ Branch 3 taken 148977 times.
196785 qx = (s->mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0);
405
4/4
✓ Branch 0 taken 172879 times.
✓ Branch 1 taken 23906 times.
✓ Branch 2 taken 23887 times.
✓ Branch 3 taken 148992 times.
196785 qy = (s->mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0);
406 196785 X = (s->mb_width << 6) - 4;
407 196785 Y = (s->mb_height << 6) - 4;
408
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 196784 times.
196785 if (qx + px < MV) px = MV - qx;
409
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 196776 times.
196785 if (qy + py < MV) py = MV - qy;
410
2/2
✓ Branch 0 taken 341 times.
✓ Branch 1 taken 196444 times.
196785 if (qx + px > X) px = X - qx;
411
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 196734 times.
196785 if (qy + py > Y) py = Y - qy;
412 }
413
414
4/4
✓ Branch 0 taken 166567 times.
✓ Branch 1 taken 196785 times.
✓ Branch 2 taken 48899 times.
✓ Branch 3 taken 117668 times.
363352 if (!v->field_mode || s->pict_type != AV_PICTURE_TYPE_B) {
415 /* Calculate hybrid prediction as specified in 8.3.5.3.5 (also 10.3.5.4.3.5) */
416 245684 hybridmv_thresh = 32;
417
4/4
✓ Branch 0 taken 205159 times.
✓ Branch 1 taken 40525 times.
✓ Branch 2 taken 195137 times.
✓ Branch 3 taken 10022 times.
245684 if (a_valid && c_valid) {
418
2/2
✓ Branch 0 taken 16134 times.
✓ Branch 1 taken 179003 times.
195137 if (is_intra[xy - wrap])
419 16134 sum = FFABS(px) + FFABS(py);
420 else
421 179003 sum = FFABS(px - field_predA[0]) + FFABS(py - field_predA[1]);
422
2/2
✓ Branch 0 taken 12499 times.
✓ Branch 1 taken 182638 times.
195137 if (sum > hybridmv_thresh) {
423
2/2
✓ Branch 1 taken 5136 times.
✓ Branch 2 taken 7363 times.
12499 if (get_bits1(&s->gb)) { // read HYBRIDPRED bit
424 5136 px = field_predA[0];
425 5136 py = field_predA[1];
426 } else {
427 7363 px = field_predC[0];
428 7363 py = field_predC[1];
429 }
430 } else {
431
2/2
✓ Branch 0 taken 16322 times.
✓ Branch 1 taken 166316 times.
182638 if (is_intra[xy - 1])
432 16322 sum = FFABS(px) + FFABS(py);
433 else
434 166316 sum = FFABS(px - field_predC[0]) + FFABS(py - field_predC[1]);
435
2/2
✓ Branch 0 taken 16743 times.
✓ Branch 1 taken 165895 times.
182638 if (sum > hybridmv_thresh) {
436
2/2
✓ Branch 1 taken 8856 times.
✓ Branch 2 taken 7887 times.
16743 if (get_bits1(&s->gb)) {
437 8856 px = field_predA[0];
438 8856 py = field_predA[1];
439 } else {
440 7887 px = field_predC[0];
441 7887 py = field_predC[1];
442 }
443 }
444 }
445 }
446 }
447
448
3/4
✓ Branch 0 taken 166567 times.
✓ Branch 1 taken 196785 times.
✓ Branch 2 taken 166567 times.
✗ Branch 3 not taken.
363352 if (v->field_mode && v->numref)
449 166567 r_y >>= 1;
450
6/6
✓ Branch 0 taken 166567 times.
✓ Branch 1 taken 196785 times.
✓ Branch 2 taken 84551 times.
✓ Branch 3 taken 82016 times.
✓ Branch 4 taken 59202 times.
✓ Branch 5 taken 25349 times.
363352 if (v->field_mode && v->cur_field_type && v->ref_field_type[dir] == 0)
451 59202 y_bias = 1;
452 /* store MV using signed modulus of MV range defined in 4.11 */
453 363352 s->mv[dir][n][0] = s->cur_pic.motion_val[dir][xy + v->blocks_off][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
454 363352 s->mv[dir][n][1] = s->cur_pic.motion_val[dir][xy + v->blocks_off][1] = ((py + dmv_y + r_y - y_bias) & ((r_y << 1) - 1)) - r_y + y_bias;
455
2/2
✓ Branch 0 taken 201708 times.
✓ Branch 1 taken 161644 times.
363352 if (mv1) { /* duplicate motion data for 1-MV block */
456 201708 s->cur_pic.motion_val[dir][xy + 1 + v->blocks_off][0] = s->cur_pic.motion_val[dir][xy + v->blocks_off][0];
457 201708 s->cur_pic.motion_val[dir][xy + 1 + v->blocks_off][1] = s->cur_pic.motion_val[dir][xy + v->blocks_off][1];
458 201708 s->cur_pic.motion_val[dir][xy + wrap + v->blocks_off][0] = s->cur_pic.motion_val[dir][xy + v->blocks_off][0];
459 201708 s->cur_pic.motion_val[dir][xy + wrap + v->blocks_off][1] = s->cur_pic.motion_val[dir][xy + v->blocks_off][1];
460 201708 s->cur_pic.motion_val[dir][xy + wrap + 1 + v->blocks_off][0] = s->cur_pic.motion_val[dir][xy + v->blocks_off][0];
461 201708 s->cur_pic.motion_val[dir][xy + wrap + 1 + v->blocks_off][1] = s->cur_pic.motion_val[dir][xy + v->blocks_off][1];
462 201708 v->mv_f[dir][xy + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off];
463 201708 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];
464 }
465 }
466
467 /** Predict and set motion vector for interlaced frame picture MBs
468 */
469 87401 void ff_vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y,
470 int mvn, int r_x, int r_y, int dir)
471 {
472 87401 MpegEncContext *s = &v->s;
473 87401 int xy, wrap, off = 0;
474 int A[2], B[2], C[2];
475 87401 int px = 0, py = 0;
476 87401 int a_valid = 0, b_valid = 0, c_valid = 0;
477 int field_a, field_b, field_c; // 0: same, 1: opposite
478 int total_valid, num_samefield, num_oppfield;
479 int pos_c, pos_b, n_adj;
480
481 87401 wrap = s->b8_stride;
482 87401 xy = s->block_index[n];
483
484
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 87401 times.
87401 if (s->mb_intra) {
485 s->mv[0][n][0] = s->cur_pic.motion_val[0][xy][0] = 0;
486 s->mv[0][n][1] = s->cur_pic.motion_val[0][xy][1] = 0;
487 s->cur_pic.motion_val[1][xy][0] = 0;
488 s->cur_pic.motion_val[1][xy][1] = 0;
489 if (mvn == 1) { /* duplicate motion data for 1-MV block */
490 s->cur_pic.motion_val[0][xy + 1][0] = 0;
491 s->cur_pic.motion_val[0][xy + 1][1] = 0;
492 s->cur_pic.motion_val[0][xy + wrap][0] = 0;
493 s->cur_pic.motion_val[0][xy + wrap][1] = 0;
494 s->cur_pic.motion_val[0][xy + wrap + 1][0] = 0;
495 s->cur_pic.motion_val[0][xy + wrap + 1][1] = 0;
496 v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
497 s->cur_pic.motion_val[1][xy + 1][0] = 0;
498 s->cur_pic.motion_val[1][xy + 1][1] = 0;
499 s->cur_pic.motion_val[1][xy + wrap][0] = 0;
500 s->cur_pic.motion_val[1][xy + wrap][1] = 0;
501 s->cur_pic.motion_val[1][xy + wrap + 1][0] = 0;
502 s->cur_pic.motion_val[1][xy + wrap + 1][1] = 0;
503 }
504 return;
505 }
506
507
4/4
✓ Branch 0 taken 30480 times.
✓ Branch 1 taken 56921 times.
✓ Branch 2 taken 1788 times.
✓ Branch 3 taken 28692 times.
87401 off = ((n == 0) || (n == 1)) ? 1 : -1;
508 /* predict A */
509
6/6
✓ Branch 0 taken 832 times.
✓ Branch 1 taken 86569 times.
✓ Branch 2 taken 823 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 814 times.
87401 if (s->mb_x || (n == 1) || (n == 3)) {
510
2/2
✓ Branch 0 taken 24418 times.
✓ Branch 1 taken 62169 times.
86587 if ((v->blk_mv_type[xy]) // current block (MB) has a field MV
511
3/4
✓ Branch 0 taken 24418 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11588 times.
✓ Branch 3 taken 12830 times.
24418 || (!v->blk_mv_type[xy] && !v->blk_mv_type[xy - 1])) { // or both have frame MV
512 73757 A[0] = s->cur_pic.motion_val[dir][xy - 1][0];
513 73757 A[1] = s->cur_pic.motion_val[dir][xy - 1][1];
514 73757 a_valid = 1;
515 } else { // current block has frame mv and cand. has field MV (so average)
516 12830 A[0] = (s->cur_pic.motion_val[dir][xy - 1][0]
517 12830 + s->cur_pic.motion_val[dir][xy - 1 + off * wrap][0] + 1) >> 1;
518 12830 A[1] = (s->cur_pic.motion_val[dir][xy - 1][1]
519 12830 + s->cur_pic.motion_val[dir][xy - 1 + off * wrap][1] + 1) >> 1;
520 12830 a_valid = 1;
521 }
522
4/4
✓ Branch 0 taken 83011 times.
✓ Branch 1 taken 3576 times.
✓ Branch 2 taken 830 times.
✓ Branch 3 taken 82181 times.
86587 if (!(n & 1) && v->is_intra[s->mb_x - 1]) {
523 830 a_valid = 0;
524 830 A[0] = A[1] = 0;
525 }
526 } else
527 814 A[0] = A[1] = 0;
528 /* Predict B and C */
529 87401 B[0] = B[1] = C[0] = C[1] = 0;
530
6/6
✓ Branch 0 taken 30480 times.
✓ Branch 1 taken 56921 times.
✓ Branch 2 taken 28692 times.
✓ Branch 3 taken 1788 times.
✓ Branch 4 taken 27284 times.
✓ Branch 5 taken 1408 times.
87401 if (n == 0 || n == 1 || v->blk_mv_type[xy]) {
531
2/2
✓ Branch 0 taken 84676 times.
✓ Branch 1 taken 1317 times.
85993 if (!s->first_slice_line) {
532
2/2
✓ Branch 0 taken 83692 times.
✓ Branch 1 taken 984 times.
84676 if (!v->is_intra[s->mb_x - s->mb_stride]) {
533 83692 b_valid = 1;
534 83692 n_adj = n | 2;
535 83692 pos_b = s->block_index[n_adj] - 2 * wrap;
536
4/4
✓ Branch 0 taken 61316 times.
✓ Branch 1 taken 22376 times.
✓ Branch 2 taken 48511 times.
✓ Branch 3 taken 12805 times.
83692 if (v->blk_mv_type[pos_b] && v->blk_mv_type[xy]) {
537 48511 n_adj = (n & 2) | (n & 1);
538 }
539 83692 B[0] = s->cur_pic.motion_val[dir][s->block_index[n_adj] - 2 * wrap][0];
540 83692 B[1] = s->cur_pic.motion_val[dir][s->block_index[n_adj] - 2 * wrap][1];
541
4/4
✓ Branch 0 taken 61316 times.
✓ Branch 1 taken 22376 times.
✓ Branch 2 taken 12805 times.
✓ Branch 3 taken 48511 times.
83692 if (v->blk_mv_type[pos_b] && !v->blk_mv_type[xy]) {
542 12805 B[0] = (B[0] + s->cur_pic.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap][0] + 1) >> 1;
543 12805 B[1] = (B[1] + s->cur_pic.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap][1] + 1) >> 1;
544 }
545 }
546
1/2
✓ Branch 0 taken 84676 times.
✗ Branch 1 not taken.
84676 if (s->mb_width > 1) {
547
2/2
✓ Branch 0 taken 83548 times.
✓ Branch 1 taken 1128 times.
84676 if (!v->is_intra[s->mb_x - s->mb_stride + 1]) {
548 83548 c_valid = 1;
549 83548 n_adj = 2;
550 83548 pos_c = s->block_index[2] - 2 * wrap + 2;
551
4/4
✓ Branch 0 taken 60020 times.
✓ Branch 1 taken 23528 times.
✓ Branch 2 taken 47104 times.
✓ Branch 3 taken 12916 times.
83548 if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
552 47104 n_adj = n & 2;
553 }
554 83548 C[0] = s->cur_pic.motion_val[dir][s->block_index[n_adj] - 2 * wrap + 2][0];
555 83548 C[1] = s->cur_pic.motion_val[dir][s->block_index[n_adj] - 2 * wrap + 2][1];
556
4/4
✓ Branch 0 taken 60020 times.
✓ Branch 1 taken 23528 times.
✓ Branch 2 taken 12916 times.
✓ Branch 3 taken 47104 times.
83548 if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
557 12916 C[0] = (1 + C[0] + (s->cur_pic.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap + 2][0])) >> 1;
558 12916 C[1] = (1 + C[1] + (s->cur_pic.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap + 2][1])) >> 1;
559 }
560
2/2
✓ Branch 0 taken 802 times.
✓ Branch 1 taken 82746 times.
83548 if (s->mb_x == s->mb_width - 1) {
561
2/2
✓ Branch 0 taken 782 times.
✓ Branch 1 taken 20 times.
802 if (!v->is_intra[s->mb_x - s->mb_stride - 1]) {
562 782 c_valid = 1;
563 782 n_adj = 3;
564 782 pos_c = s->block_index[3] - 2 * wrap - 2;
565
4/4
✓ Branch 0 taken 643 times.
✓ Branch 1 taken 139 times.
✓ Branch 2 taken 551 times.
✓ Branch 3 taken 92 times.
782 if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
566 551 n_adj = n | 1;
567 }
568 782 C[0] = s->cur_pic.motion_val[dir][s->block_index[n_adj] - 2 * wrap - 2][0];
569 782 C[1] = s->cur_pic.motion_val[dir][s->block_index[n_adj] - 2 * wrap - 2][1];
570
4/4
✓ Branch 0 taken 643 times.
✓ Branch 1 taken 139 times.
✓ Branch 2 taken 92 times.
✓ Branch 3 taken 551 times.
782 if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
571 92 C[0] = (1 + C[0] + s->cur_pic.motion_val[dir][s->block_index[1] - 2 * wrap - 2][0]) >> 1;
572 92 C[1] = (1 + C[1] + s->cur_pic.motion_val[dir][s->block_index[1] - 2 * wrap - 2][1]) >> 1;
573 }
574 } else
575 20 c_valid = 0;
576 }
577 }
578 }
579 }
580 } else {
581 1408 pos_b = s->block_index[1];
582 1408 b_valid = 1;
583 1408 B[0] = s->cur_pic.motion_val[dir][pos_b][0];
584 1408 B[1] = s->cur_pic.motion_val[dir][pos_b][1];
585 1408 pos_c = s->block_index[0];
586 1408 c_valid = 1;
587 1408 C[0] = s->cur_pic.motion_val[dir][pos_c][0];
588 1408 C[1] = s->cur_pic.motion_val[dir][pos_c][1];
589 }
590
591 87401 total_valid = a_valid + b_valid + c_valid;
592 // check if predictor A is out of bounds
593
6/6
✓ Branch 0 taken 832 times.
✓ Branch 1 taken 86569 times.
✓ Branch 2 taken 823 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 814 times.
✓ Branch 5 taken 9 times.
87401 if (!s->mb_x && !(n == 1 || n == 3)) {
594 814 A[0] = A[1] = 0;
595 }
596 // check if predictor B is out of bounds
597
8/8
✓ Branch 0 taken 1329 times.
✓ Branch 1 taken 86072 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 1009 times.
✓ Branch 4 taken 320 times.
✓ Branch 5 taken 86072 times.
✓ Branch 6 taken 308 times.
✓ Branch 7 taken 12 times.
87401 if ((s->first_slice_line && v->blk_mv_type[xy]) || (s->first_slice_line && !(n & 2))) {
598 1317 B[0] = B[1] = C[0] = C[1] = 0;
599 }
600
2/2
✓ Branch 0 taken 24624 times.
✓ Branch 1 taken 62777 times.
87401 if (!v->blk_mv_type[xy]) {
601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24624 times.
24624 if (s->mb_width == 1) {
602 px = B[0];
603 py = B[1];
604 } else {
605
2/2
✓ Branch 0 taken 24202 times.
✓ Branch 1 taken 422 times.
24624 if (total_valid >= 2) {
606 24202 px = mid_pred(A[0], B[0], C[0]);
607 24202 py = mid_pred(A[1], B[1], C[1]);
608
2/2
✓ Branch 0 taken 395 times.
✓ Branch 1 taken 27 times.
422 } else if (total_valid) {
609
2/2
✓ Branch 0 taken 356 times.
✓ Branch 1 taken 39 times.
395 if (a_valid) { px = A[0]; py = A[1]; }
610
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 21 times.
39 else if (b_valid) { px = B[0]; py = B[1]; }
611 21 else { px = C[0]; py = C[1]; }
612 }
613 }
614 } else {
615
2/2
✓ Branch 0 taken 61492 times.
✓ Branch 1 taken 1285 times.
62777 if (a_valid)
616 61492 field_a = (A[1] & 4) ? 1 : 0;
617 else
618 1285 field_a = 0;
619
2/2
✓ Branch 0 taken 60944 times.
✓ Branch 1 taken 1833 times.
62777 if (b_valid)
620 60944 field_b = (B[1] & 4) ? 1 : 0;
621 else
622 1833 field_b = 0;
623
2/2
✓ Branch 0 taken 60819 times.
✓ Branch 1 taken 1958 times.
62777 if (c_valid)
624 60819 field_c = (C[1] & 4) ? 1 : 0;
625 else
626 1958 field_c = 0;
627
628 62777 num_oppfield = field_a + field_b + field_c;
629 62777 num_samefield = total_valid - num_oppfield;
630
2/2
✓ Branch 0 taken 59358 times.
✓ Branch 1 taken 3419 times.
62777 if (total_valid == 3) {
631
4/4
✓ Branch 0 taken 45017 times.
✓ Branch 1 taken 14341 times.
✓ Branch 2 taken 13487 times.
✓ Branch 3 taken 31530 times.
59358 if ((num_samefield == 3) || (num_oppfield == 3)) {
632 27828 px = mid_pred(A[0], B[0], C[0]);
633 27828 py = mid_pred(A[1], B[1], C[1]);
634
2/2
✓ Branch 0 taken 15698 times.
✓ Branch 1 taken 15832 times.
31530 } else if (num_samefield >= num_oppfield) {
635 /* take one MV from same field set depending on priority
636 the check for B may not be necessary */
637
2/2
✓ Branch 0 taken 9839 times.
✓ Branch 1 taken 5859 times.
15698 px = !field_a ? A[0] : B[0];
638
2/2
✓ Branch 0 taken 9839 times.
✓ Branch 1 taken 5859 times.
15698 py = !field_a ? A[1] : B[1];
639 } else {
640
2/2
✓ Branch 0 taken 9939 times.
✓ Branch 1 taken 5893 times.
15832 px = field_a ? A[0] : B[0];
641
2/2
✓ Branch 0 taken 9939 times.
✓ Branch 1 taken 5893 times.
15832 py = field_a ? A[1] : B[1];
642 }
643
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 1549 times.
3419 } else if (total_valid == 2) {
644
2/2
✓ Branch 0 taken 1250 times.
✓ Branch 1 taken 620 times.
1870 if (num_samefield >= num_oppfield) {
645
4/4
✓ Branch 0 taken 1167 times.
✓ Branch 1 taken 83 times.
✓ Branch 2 taken 455 times.
✓ Branch 3 taken 712 times.
1250 if (!field_a && a_valid) {
646 455 px = A[0];
647 455 py = A[1];
648
4/4
✓ Branch 0 taken 646 times.
✓ Branch 1 taken 149 times.
✓ Branch 2 taken 605 times.
✓ Branch 3 taken 41 times.
795 } else if (!field_b && b_valid) {
649 605 px = B[0];
650 605 py = B[1];
651 } else /*if (c_valid)*/ {
652 av_assert1(c_valid);
653 190 px = C[0];
654 190 py = C[1];
655 }
656 } else {
657
3/4
✓ Branch 0 taken 303 times.
✓ Branch 1 taken 317 times.
✓ Branch 2 taken 303 times.
✗ Branch 3 not taken.
620 if (field_a && a_valid) {
658 303 px = A[0];
659 303 py = A[1];
660 } else /*if (field_b && b_valid)*/ {
661 av_assert1(field_b && b_valid);
662 317 px = B[0];
663 317 py = B[1];
664 }
665 }
666
2/2
✓ Branch 0 taken 1441 times.
✓ Branch 1 taken 108 times.
1549 } else if (total_valid == 1) {
667
4/4
✓ Branch 0 taken 1293 times.
✓ Branch 1 taken 148 times.
✓ Branch 2 taken 58 times.
✓ Branch 3 taken 90 times.
1441 px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]);
668
4/4
✓ Branch 0 taken 1293 times.
✓ Branch 1 taken 148 times.
✓ Branch 2 taken 58 times.
✓ Branch 3 taken 90 times.
1441 py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]);
669 }
670 }
671
672 /* store MV using signed modulus of MV range defined in 4.11 */
673 87401 s->mv[dir][n][0] = s->cur_pic.motion_val[dir][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
674 87401 s->mv[dir][n][1] = s->cur_pic.motion_val[dir][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
675
2/2
✓ Branch 0 taken 21808 times.
✓ Branch 1 taken 65593 times.
87401 if (mvn == 1) { /* duplicate motion data for 1-MV block */
676 21808 s->cur_pic.motion_val[dir][xy + 1 ][0] = s->cur_pic.motion_val[dir][xy][0];
677 21808 s->cur_pic.motion_val[dir][xy + 1 ][1] = s->cur_pic.motion_val[dir][xy][1];
678 21808 s->cur_pic.motion_val[dir][xy + wrap ][0] = s->cur_pic.motion_val[dir][xy][0];
679 21808 s->cur_pic.motion_val[dir][xy + wrap ][1] = s->cur_pic.motion_val[dir][xy][1];
680 21808 s->cur_pic.motion_val[dir][xy + wrap + 1][0] = s->cur_pic.motion_val[dir][xy][0];
681 21808 s->cur_pic.motion_val[dir][xy + wrap + 1][1] = s->cur_pic.motion_val[dir][xy][1];
682
2/2
✓ Branch 0 taken 58441 times.
✓ Branch 1 taken 7152 times.
65593 } else if (mvn == 2) { /* duplicate motion data for 2-Field MV block */
683 58441 s->cur_pic.motion_val[dir][xy + 1][0] = s->cur_pic.motion_val[dir][xy][0];
684 58441 s->cur_pic.motion_val[dir][xy + 1][1] = s->cur_pic.motion_val[dir][xy][1];
685 58441 s->mv[dir][n + 1][0] = s->mv[dir][n][0];
686 58441 s->mv[dir][n + 1][1] = s->mv[dir][n][1];
687 }
688 }
689
690 20940 void ff_vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2],
691 int direct, int mvtype)
692 {
693 20940 MpegEncContext *s = &v->s;
694 int xy, wrap;
695 int px, py;
696 int sum;
697 int r_x, r_y;
698 20940 const uint8_t *is_intra = v->mb_type[0];
699
700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20940 times.
20940 av_assert0(!v->field_mode);
701
702 20940 r_x = v->range_x;
703 20940 r_y = v->range_y;
704 /* scale MV difference to be quad-pel */
705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20940 times.
20940 if (!s->quarter_sample) {
706 dmv_x[0] *= 2;
707 dmv_y[0] *= 2;
708 dmv_x[1] *= 2;
709 dmv_y[1] *= 2;
710 }
711
712 20940 wrap = s->b8_stride;
713 20940 xy = s->block_index[0];
714
715
2/2
✓ Branch 0 taken 170 times.
✓ Branch 1 taken 20770 times.
20940 if (s->mb_intra) {
716 170 s->cur_pic.motion_val[0][xy][0] =
717 170 s->cur_pic.motion_val[0][xy][1] =
718 170 s->cur_pic.motion_val[1][xy][0] =
719 170 s->cur_pic.motion_val[1][xy][1] = 0;
720 170 return;
721 }
722
3/4
✓ Branch 0 taken 2569 times.
✓ Branch 1 taken 18201 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2569 times.
20770 if (direct && s->next_pic.ptr->field_picture)
723 av_log(s->avctx, AV_LOG_WARNING, "Mixed frame/field direct mode not supported\n");
724
725 20770 s->mv[0][0][0] = scale_mv(s->next_pic.motion_val[1][xy][0], v->bfraction, 0, s->quarter_sample);
726 20770 s->mv[0][0][1] = scale_mv(s->next_pic.motion_val[1][xy][1], v->bfraction, 0, s->quarter_sample);
727 20770 s->mv[1][0][0] = scale_mv(s->next_pic.motion_val[1][xy][0], v->bfraction, 1, s->quarter_sample);
728 20770 s->mv[1][0][1] = scale_mv(s->next_pic.motion_val[1][xy][1], v->bfraction, 1, s->quarter_sample);
729
730 /* Pullback predicted motion vectors as specified in 8.4.5.4 */
731 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));
732 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));
733 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));
734 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));
735
2/2
✓ Branch 0 taken 2569 times.
✓ Branch 1 taken 18201 times.
20770 if (direct) {
736 2569 s->cur_pic.motion_val[0][xy][0] = s->mv[0][0][0];
737 2569 s->cur_pic.motion_val[0][xy][1] = s->mv[0][0][1];
738 2569 s->cur_pic.motion_val[1][xy][0] = s->mv[1][0][0];
739 2569 s->cur_pic.motion_val[1][xy][1] = s->mv[1][0][1];
740 2569 return;
741 }
742
743
4/4
✓ Branch 0 taken 14178 times.
✓ Branch 1 taken 4023 times.
✓ Branch 2 taken 6157 times.
✓ Branch 3 taken 8021 times.
18201 if ((mvtype == BMV_TYPE_FORWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
744 10180 int16_t *C = s->cur_pic.motion_val[0][xy - 2];
745 10180 const int16_t *A = s->cur_pic.motion_val[0][xy - wrap * 2];
746
2/2
✓ Branch 0 taken 226 times.
✓ Branch 1 taken 9954 times.
10180 int off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
747 10180 const int16_t *B = s->cur_pic.motion_val[0][xy - wrap * 2 + off];
748
749
2/2
✓ Branch 0 taken 319 times.
✓ Branch 1 taken 9861 times.
10180 if (!s->mb_x) C[0] = C[1] = 0;
750
2/2
✓ Branch 0 taken 9675 times.
✓ Branch 1 taken 505 times.
10180 if (!s->first_slice_line) { // predictor A is not out of bounds
751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9675 times.
9675 if (s->mb_width == 1) {
752 px = A[0];
753 py = A[1];
754 } else {
755 9675 px = mid_pred(A[0], B[0], C[0]);
756 9675 py = mid_pred(A[1], B[1], C[1]);
757 }
758
2/2
✓ Branch 0 taken 489 times.
✓ Branch 1 taken 16 times.
505 } else if (s->mb_x) { // predictor C is not out of bounds
759 489 px = C[0];
760 489 py = C[1];
761 } else {
762 16 px = py = 0;
763 }
764 /* Pullback MV as specified in 8.3.5.3.4 */
765 {
766 int qx, qy, X, Y;
767
2/2
✓ Branch 0 taken 7513 times.
✓ Branch 1 taken 2667 times.
10180 int sh = v->profile < PROFILE_ADVANCED ? 5 : 6;
768 10180 int MV = 4 - (1 << sh);
769 10180 qx = (s->mb_x << sh);
770 10180 qy = (s->mb_y << sh);
771 10180 X = (s->mb_width << sh) - 4;
772 10180 Y = (s->mb_height << sh) - 4;
773
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10180 times.
10180 if (qx + px < MV) px = MV - qx;
774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10180 times.
10180 if (qy + py < MV) py = MV - qy;
775
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 10165 times.
10180 if (qx + px > X) px = X - qx;
776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10180 times.
10180 if (qy + py > Y) py = Y - qy;
777 }
778 /* Calculate hybrid prediction as specified in 8.3.5.3.5 */
779 if (0 && !s->first_slice_line && s->mb_x) {
780 if (is_intra[xy - wrap])
781 sum = FFABS(px) + FFABS(py);
782 else
783 sum = FFABS(px - A[0]) + FFABS(py - A[1]);
784 if (sum > 32) {
785 if (get_bits1(&s->gb)) {
786 px = A[0];
787 py = A[1];
788 } else {
789 px = C[0];
790 py = C[1];
791 }
792 } else {
793 if (is_intra[xy - 2])
794 sum = FFABS(px) + FFABS(py);
795 else
796 sum = FFABS(px - C[0]) + FFABS(py - C[1]);
797 if (sum > 32) {
798 if (get_bits1(&s->gb)) {
799 px = A[0];
800 py = A[1];
801 } else {
802 px = C[0];
803 py = C[1];
804 }
805 }
806 }
807 }
808 /* store MV using signed modulus of MV range defined in 4.11 */
809 10180 s->mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
810 10180 s->mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
811 }
812
4/4
✓ Branch 0 taken 10180 times.
✓ Branch 1 taken 8021 times.
✓ Branch 2 taken 6157 times.
✓ Branch 3 taken 4023 times.
18201 if ((mvtype == BMV_TYPE_BACKWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) {
813 14178 int16_t *C = s->cur_pic.motion_val[1][xy - 2];
814 14178 const int16_t *A = s->cur_pic.motion_val[1][xy - wrap * 2];
815
2/2
✓ Branch 0 taken 549 times.
✓ Branch 1 taken 13629 times.
14178 int off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
816 14178 const int16_t *B = s->cur_pic.motion_val[1][xy - wrap * 2 + off];
817
818
2/2
✓ Branch 0 taken 389 times.
✓ Branch 1 taken 13789 times.
14178 if (!s->mb_x)
819 389 C[0] = C[1] = 0;
820
2/2
✓ Branch 0 taken 13334 times.
✓ Branch 1 taken 844 times.
14178 if (!s->first_slice_line) { // predictor A is not out of bounds
821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13334 times.
13334 if (s->mb_width == 1) {
822 px = A[0];
823 py = A[1];
824 } else {
825 13334 px = mid_pred(A[0], B[0], C[0]);
826 13334 py = mid_pred(A[1], B[1], C[1]);
827 }
828
2/2
✓ Branch 0 taken 813 times.
✓ Branch 1 taken 31 times.
844 } else if (s->mb_x) { // predictor C is not out of bounds
829 813 px = C[0];
830 813 py = C[1];
831 } else {
832 31 px = py = 0;
833 }
834 /* Pullback MV as specified in 8.3.5.3.4 */
835 {
836 int qx, qy, X, Y;
837
2/2
✓ Branch 0 taken 10397 times.
✓ Branch 1 taken 3781 times.
14178 int sh = v->profile < PROFILE_ADVANCED ? 5 : 6;
838 14178 int MV = 4 - (1 << sh);
839 14178 qx = (s->mb_x << sh);
840 14178 qy = (s->mb_y << sh);
841 14178 X = (s->mb_width << sh) - 4;
842 14178 Y = (s->mb_height << sh) - 4;
843
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 14155 times.
14178 if (qx + px < MV) px = MV - qx;
844
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14174 times.
14178 if (qy + py < MV) py = MV - qy;
845
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14178 times.
14178 if (qx + px > X) px = X - qx;
846
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 14172 times.
14178 if (qy + py > Y) py = Y - qy;
847 }
848 /* Calculate hybrid prediction as specified in 8.3.5.3.5 */
849 if (0 && !s->first_slice_line && s->mb_x) {
850 if (is_intra[xy - wrap])
851 sum = FFABS(px) + FFABS(py);
852 else
853 sum = FFABS(px - A[0]) + FFABS(py - A[1]);
854 if (sum > 32) {
855 if (get_bits1(&s->gb)) {
856 px = A[0];
857 py = A[1];
858 } else {
859 px = C[0];
860 py = C[1];
861 }
862 } else {
863 if (is_intra[xy - 2])
864 sum = FFABS(px) + FFABS(py);
865 else
866 sum = FFABS(px - C[0]) + FFABS(py - C[1]);
867 if (sum > 32) {
868 if (get_bits1(&s->gb)) {
869 px = A[0];
870 py = A[1];
871 } else {
872 px = C[0];
873 py = C[1];
874 }
875 }
876 }
877 }
878 /* store MV using signed modulus of MV range defined in 4.11 */
879
880 14178 s->mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
881 14178 s->mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
882 }
883 18201 s->cur_pic.motion_val[0][xy][0] = s->mv[0][0][0];
884 18201 s->cur_pic.motion_val[0][xy][1] = s->mv[0][0][1];
885 18201 s->cur_pic.motion_val[1][xy][0] = s->mv[1][0][0];
886 18201 s->cur_pic.motion_val[1][xy][1] = s->mv[1][0][1];
887 }
888
889 79716 void ff_vc1_pred_b_mv_intfi(VC1Context *v, int n, int *dmv_x, int *dmv_y,
890 int mv1, int *pred_flag)
891 {
892 79716 int dir = (v->bmvtype == BMV_TYPE_BACKWARD) ? 1 : 0;
893 79716 MpegEncContext *s = &v->s;
894 79716 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
895
896
2/2
✓ Branch 0 taken 6770 times.
✓ Branch 1 taken 72946 times.
79716 if (v->bmvtype == BMV_TYPE_DIRECT) {
897 int total_opp, k, f;
898
2/2
✓ Branch 0 taken 4903 times.
✓ Branch 1 taken 1867 times.
6770 if (s->next_pic.mb_type[mb_pos + v->mb_off] != MB_TYPE_INTRA) {
899 9806 s->mv[0][0][0] = scale_mv(s->next_pic.motion_val[1][s->block_index[0] + v->blocks_off][0],
900 4903 v->bfraction, 0, s->quarter_sample);
901 9806 s->mv[0][0][1] = scale_mv(s->next_pic.motion_val[1][s->block_index[0] + v->blocks_off][1],
902 4903 v->bfraction, 0, s->quarter_sample);
903 9806 s->mv[1][0][0] = scale_mv(s->next_pic.motion_val[1][s->block_index[0] + v->blocks_off][0],
904 4903 v->bfraction, 1, s->quarter_sample);
905 9806 s->mv[1][0][1] = scale_mv(s->next_pic.motion_val[1][s->block_index[0] + v->blocks_off][1],
906 4903 v->bfraction, 1, s->quarter_sample);
907
908 4903 total_opp = v->mv_f_next[0][s->block_index[0] + v->blocks_off]
909 4903 + v->mv_f_next[0][s->block_index[1] + v->blocks_off]
910 4903 + v->mv_f_next[0][s->block_index[2] + v->blocks_off]
911 4903 + v->mv_f_next[0][s->block_index[3] + v->blocks_off];
912 4903 f = (total_opp > 2) ? 1 : 0;
913 } else {
914 1867 s->mv[0][0][0] = s->mv[0][0][1] = 0;
915 1867 s->mv[1][0][0] = s->mv[1][0][1] = 0;
916 1867 f = 0;
917 }
918 6770 v->ref_field_type[0] = v->ref_field_type[1] = v->cur_field_type ^ f;
919
2/2
✓ Branch 0 taken 27080 times.
✓ Branch 1 taken 6770 times.
33850 for (k = 0; k < 4; k++) {
920 27080 s->cur_pic.motion_val[0][s->block_index[k] + v->blocks_off][0] = s->mv[0][0][0];
921 27080 s->cur_pic.motion_val[0][s->block_index[k] + v->blocks_off][1] = s->mv[0][0][1];
922 27080 s->cur_pic.motion_val[1][s->block_index[k] + v->blocks_off][0] = s->mv[1][0][0];
923 27080 s->cur_pic.motion_val[1][s->block_index[k] + v->blocks_off][1] = s->mv[1][0][1];
924 27080 v->mv_f[0][s->block_index[k] + v->blocks_off] = f;
925 27080 v->mv_f[1][s->block_index[k] + v->blocks_off] = f;
926 }
927 6770 return;
928 }
929
2/2
✓ Branch 0 taken 5886 times.
✓ Branch 1 taken 67060 times.
72946 if (v->bmvtype == BMV_TYPE_INTERPOLATED) {
930 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);
931 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);
932 5886 return;
933 }
934
2/2
✓ Branch 0 taken 31989 times.
✓ Branch 1 taken 35071 times.
67060 if (dir) { // backward
935 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);
936
4/4
✓ Branch 0 taken 27473 times.
✓ Branch 1 taken 4516 times.
✓ Branch 2 taken 13925 times.
✓ Branch 3 taken 13548 times.
31989 if (n == 3 || mv1) {
937 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);
938 }
939 } else { // forward
940 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);
941
4/4
✓ Branch 0 taken 30179 times.
✓ Branch 1 taken 4892 times.
✓ Branch 2 taken 15503 times.
✓ Branch 3 taken 14676 times.
35071 if (n == 3 || mv1) {
942 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);
943 }
944 }
945 }
946