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
35
37 {
38 int scaledvalue, refdist;
39 int scalesame1, scalesame2;
40 int scalezone1_x, zone1offset_x;
42
45 else
47 if (refdist > 3)
48 refdist = 3;
53
55 scaledvalue = n;
56 else {
57 if (
FFABS(n) < scalezone1_x)
58 scaledvalue = (n * scalesame1) >> 8;
59 else {
60 if (n < 0)
61 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_x;
62 else
63 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_x;
64 }
65 }
67 }
68
70 {
71 int scaledvalue, refdist;
72 int scalesame1, scalesame2;
73 int scalezone1_y, zone1offset_y;
75
78 else
80 if (refdist > 3)
81 refdist = 3;
86
88 scaledvalue = n;
89 else {
90 if (
FFABS(n) < scalezone1_y)
91 scaledvalue = (n * scalesame1) >> 8;
92 else {
93 if (n < 0)
94 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_y;
95 else
96 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_y;
97 }
98 }
99
102 else
104 }
105
107 {
108 int scalezone1_x, zone1offset_x;
109 int scaleopp1, scaleopp2, brfd;
110 int scaledvalue;
111
117
119 scaledvalue = n;
120 else {
121 if (
FFABS(n) < scalezone1_x)
122 scaledvalue = (n * scaleopp1) >> 8;
123 else {
124 if (n < 0)
125 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_x;
126 else
127 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_x;
128 }
129 }
131 }
132
134 {
135 int scalezone1_y, zone1offset_y;
136 int scaleopp1, scaleopp2, brfd;
137 int scaledvalue;
138
144
146 scaledvalue = n;
147 else {
148 if (
FFABS(n) < scalezone1_y)
149 scaledvalue = (n * scaleopp1) >> 8;
150 else {
151 if (n < 0)
152 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_y;
153 else
154 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_y;
155 }
156 }
159 } else {
161 }
162 }
163
166 {
167 int brfd, scalesame;
169
170 n >>= hpel;
174 else
176 return n;
177 }
180
181 n = (n * scalesame >> 8) * (1 << hpel);
182 return n;
183 }
184
187 {
188 int refdist, scaleopp;
190
191 n >>= hpel;
195 else
197 return n;
198 }
201 else
203 refdist =
FFMIN(refdist, 3);
205
206 n = (n * scaleopp >> 8) * (1 << hpel);
207 return n;
208 }
209
210 /** Predict and set motion vector
211 */
213 int mv1, int r_x, int r_y, uint8_t* is_intra,
214 int pred_flag, int dir)
215 {
217 int xy,
wrap, off = 0;
219 int sum;
220 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 int hybridmv_thresh, y_bias = 0;
227
230 mixedmv_pic = 1;
231 else
232 mixedmv_pic = 0;
233 /* scale MV difference to be quad-pel */
234 if (!
s->quarter_sample) {
235 dmv_x *= 2;
236 dmv_y *= 2;
237 }
238
240 xy =
s->block_index[n];
241
243 s->mv[0][n][0] =
s->cur_pic.motion_val[0][xy + v->
blocks_off][0] = 0;
244 s->mv[0][n][1] =
s->cur_pic.motion_val[0][xy + v->
blocks_off][1] = 0;
245 s->cur_pic.motion_val[1][xy + v->
blocks_off][0] = 0;
246 s->cur_pic.motion_val[1][xy + v->
blocks_off][1] = 0;
247 if (mv1) { /* duplicate motion data for 1-MV block */
248 s->cur_pic.motion_val[0][xy + 1 + v->
blocks_off][0] = 0;
249 s->cur_pic.motion_val[0][xy + 1 + v->
blocks_off][1] = 0;
255 s->cur_pic.motion_val[1][xy + 1 + v->
blocks_off][0] = 0;
256 s->cur_pic.motion_val[1][xy + 1 + v->
blocks_off][1] = 0;
261 }
262 return;
263 }
264
265 a_valid = !
s->first_slice_line || (n == 2 || n == 3);
266 b_valid = a_valid;
267 c_valid =
s->mb_x || (n == 1 || n == 3);
268 if (mv1) {
270 off = (
s->mb_x == (
s->mb_width - 1)) ? -2 : 2;
271 else
272 off = (
s->mb_x == (
s->mb_width - 1)) ? -1 : 2;
273 b_valid = b_valid &&
s->mb_width > 1;
274 } else {
275 //in 4-MV mode different blocks have different B predictor position
276 switch (n) {
277 case 0:
279 off =
s->mb_x ? -1 : 1;
280 else
281 off =
s->mb_x ? -1 : 2 *
s->mb_width -
wrap - 1;
282 break;
283 case 1:
284 off = (
s->mb_x == (
s->mb_width - 1)) ? -1 : 1;
285 break;
286 case 2:
287 off = 1;
288 break;
289 case 3:
290 off = -1;
291 }
293 b_valid = b_valid && c_valid;
294 }
295
297 a_valid = a_valid && !is_intra[xy -
wrap];
298 b_valid = b_valid && !is_intra[xy -
wrap + off];
299 c_valid = c_valid && !is_intra[xy - 1];
300 }
301
302 if (a_valid) {
305 num_oppfield += a_f;
306 num_samefield += 1 - a_f;
307 field_predA[0] =
A[0];
308 field_predA[1] =
A[1];
309 } else {
310 field_predA[0] = field_predA[1] = 0;
311 a_f = 0;
312 }
313 if (b_valid) {
314 const int16_t *
B =
s->cur_pic.motion_val[dir][xy -
wrap + off + v->
blocks_off];
316 num_oppfield += b_f;
317 num_samefield += 1 - b_f;
318 field_predB[0] =
B[0];
319 field_predB[1] =
B[1];
320 } else {
321 field_predB[0] = field_predB[1] = 0;
322 b_f = 0;
323 }
324 if (c_valid) {
325 const int16_t *
C =
s->cur_pic.motion_val[dir][xy - 1 + v->
blocks_off];
327 num_oppfield += c_f;
328 num_samefield += 1 - c_f;
329 field_predC[0] =
C[0];
330 field_predC[1] =
C[1];
331 } else {
332 field_predC[0] = field_predC[1] = 0;
333 c_f = 0;
334 }
335
338 // REFFIELD determines if the last field or the second-last field is
339 // to be used as reference
341 else {
342 if (num_samefield <= num_oppfield)
343 opposite = 1 - pred_flag;
344 else
345 opposite = pred_flag;
346 }
347 } else
348 opposite = 0;
349 if (opposite) {
352 if (a_valid && !a_f) {
353 field_predA[0] =
scaleforopp(v, field_predA[0], 0, dir);
354 field_predA[1] =
scaleforopp(v, field_predA[1], 1, dir);
355 }
356 if (b_valid && !b_f) {
357 field_predB[0] =
scaleforopp(v, field_predB[0], 0, dir);
358 field_predB[1] =
scaleforopp(v, field_predB[1], 1, dir);
359 }
360 if (c_valid && !c_f) {
361 field_predC[0] =
scaleforopp(v, field_predC[0], 0, dir);
362 field_predC[1] =
scaleforopp(v, field_predC[1], 1, dir);
363 }
364 } else {
367 if (a_valid && a_f) {
368 field_predA[0] =
scaleforsame(v, field_predA[0], 0, dir);
369 field_predA[1] =
scaleforsame(v, field_predA[1], 1, dir);
370 }
371 if (b_valid && b_f) {
372 field_predB[0] =
scaleforsame(v, field_predB[0], 0, dir);
373 field_predB[1] =
scaleforsame(v, field_predB[1], 1, dir);
374 }
375 if (c_valid && c_f) {
376 field_predC[0] =
scaleforsame(v, field_predC[0], 0, dir);
377 field_predC[1] =
scaleforsame(v, field_predC[1], 1, dir);
378 }
379 }
380
381 if (a_valid) {
383 py = field_predA[1];
384 } else if (c_valid) {
386 py = field_predC[1];
387 } else if (b_valid) {
389 py = field_predB[1];
390 } else {
392 py = 0;
393 }
394
395 if (num_samefield + num_oppfield > 1) {
396 px =
mid_pred(field_predA[0], field_predB[0], field_predC[0]);
397 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 */
403 int MV = mv1 ? -60 : -28;
404 qx = (
s->mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0);
405 qy = (
s->mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0);
406 X = (
s->mb_width << 6) - 4;
407 Y = (
s->mb_height << 6) - 4;
409 if (qy + py <
MV) py =
MV - qy;
410 if (qx +
px >
X)
px =
X - qx;
411 if (qy + py >
Y) py =
Y - qy;
412 }
413
415 /* Calculate hybrid prediction as specified in 8.3.5.3.5 (also 10.3.5.4.3.5) */
416 hybridmv_thresh = 32;
417 if (a_valid && c_valid) {
418 if (is_intra[xy -
wrap])
420 else
421 sum =
FFABS(
px - field_predA[0]) +
FFABS(py - field_predA[1]);
422 if (sum > hybridmv_thresh) {
425 py = field_predA[1];
426 } else {
428 py = field_predC[1];
429 }
430 } else {
431 if (is_intra[xy - 1])
433 else
434 sum =
FFABS(
px - field_predC[0]) +
FFABS(py - field_predC[1]);
435 if (sum > hybridmv_thresh) {
438 py = field_predA[1];
439 } else {
441 py = field_predC[1];
442 }
443 }
444 }
445 }
446 }
447
449 r_y >>= 1;
451 y_bias = 1;
452 /* store MV using signed modulus of MV range defined in 4.11 */
453 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 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 if (mv1) { /* duplicate motion data for 1-MV block */
456 s->cur_pic.motion_val[dir][xy + 1 + v->
blocks_off][0] =
s->cur_pic.motion_val[dir][xy + v->
blocks_off][0];
457 s->cur_pic.motion_val[dir][xy + 1 + v->
blocks_off][1] =
s->cur_pic.motion_val[dir][xy + v->
blocks_off][1];
464 }
465 }
466
467 /** Predict and set motion vector for interlaced frame picture MBs
468 */
470 int mvn, int r_x, int r_y, int dir)
471 {
473 int xy,
wrap, off = 0;
474 int A[2],
B[2],
C[2];
476 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
482 xy =
s->block_index[n];
483
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;
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 off = ((n == 0) || (n == 1)) ? 1 : -1;
508 /* predict A */
509 if (
s->mb_x || (n == 1) || (n == 3)) {
510 if ((v->
blk_mv_type[xy])
// current block (MB) has a field MV
512 A[0] =
s->cur_pic.motion_val[dir][xy - 1][0];
513 A[1] =
s->cur_pic.motion_val[dir][xy - 1][1];
514 a_valid = 1;
515 } else { // current block has frame mv and cand. has field MV (so average)
516 A[0] = (
s->cur_pic.motion_val[dir][xy - 1][0]
517 +
s->cur_pic.motion_val[dir][xy - 1 + off *
wrap][0] + 1) >> 1;
518 A[1] = (
s->cur_pic.motion_val[dir][xy - 1][1]
519 +
s->cur_pic.motion_val[dir][xy - 1 + off *
wrap][1] + 1) >> 1;
520 a_valid = 1;
521 }
522 if (!(n & 1) && v->
is_intra[
s->mb_x - 1]) {
523 a_valid = 0;
525 }
526 } else
528 /* Predict B and C */
529 B[0] =
B[1] =
C[0] =
C[1] = 0;
531 if (!
s->first_slice_line) {
533 b_valid = 1;
534 n_adj = n | 2;
535 pos_b =
s->block_index[n_adj] - 2 *
wrap;
537 n_adj = (n & 2) | (n & 1);
538 }
539 B[0] =
s->cur_pic.motion_val[dir][
s->block_index[n_adj] - 2 *
wrap][0];
540 B[1] =
s->cur_pic.motion_val[dir][
s->block_index[n_adj] - 2 *
wrap][1];
542 B[0] = (
B[0] +
s->cur_pic.motion_val[dir][
s->block_index[n_adj ^ 2] - 2 *
wrap][0] + 1) >> 1;
543 B[1] = (
B[1] +
s->cur_pic.motion_val[dir][
s->block_index[n_adj ^ 2] - 2 *
wrap][1] + 1) >> 1;
544 }
545 }
546 if (
s->mb_width > 1) {
547 if (!v->
is_intra[
s->mb_x -
s->mb_stride + 1]) {
548 c_valid = 1;
549 n_adj = 2;
550 pos_c =
s->block_index[2] - 2 *
wrap + 2;
552 n_adj = n & 2;
553 }
554 C[0] =
s->cur_pic.motion_val[dir][
s->block_index[n_adj] - 2 *
wrap + 2][0];
555 C[1] =
s->cur_pic.motion_val[dir][
s->block_index[n_adj] - 2 *
wrap + 2][1];
557 C[0] = (1 +
C[0] + (
s->cur_pic.motion_val[dir][
s->block_index[n_adj ^ 2] - 2 *
wrap + 2][0])) >> 1;
558 C[1] = (1 +
C[1] + (
s->cur_pic.motion_val[dir][
s->block_index[n_adj ^ 2] - 2 *
wrap + 2][1])) >> 1;
559 }
560 if (
s->mb_x ==
s->mb_width - 1) {
561 if (!v->
is_intra[
s->mb_x -
s->mb_stride - 1]) {
562 c_valid = 1;
563 n_adj = 3;
564 pos_c =
s->block_index[3] - 2 *
wrap - 2;
566 n_adj = n | 1;
567 }
568 C[0] =
s->cur_pic.motion_val[dir][
s->block_index[n_adj] - 2 *
wrap - 2][0];
569 C[1] =
s->cur_pic.motion_val[dir][
s->block_index[n_adj] - 2 *
wrap - 2][1];
571 C[0] = (1 +
C[0] +
s->cur_pic.motion_val[dir][
s->block_index[1] - 2 *
wrap - 2][0]) >> 1;
572 C[1] = (1 +
C[1] +
s->cur_pic.motion_val[dir][
s->block_index[1] - 2 *
wrap - 2][1]) >> 1;
573 }
574 } else
575 c_valid = 0;
576 }
577 }
578 }
579 }
580 } else {
581 pos_b =
s->block_index[1];
582 b_valid = 1;
583 B[0] =
s->cur_pic.motion_val[dir][pos_b][0];
584 B[1] =
s->cur_pic.motion_val[dir][pos_b][1];
585 pos_c =
s->block_index[0];
586 c_valid = 1;
587 C[0] =
s->cur_pic.motion_val[dir][pos_c][0];
588 C[1] =
s->cur_pic.motion_val[dir][pos_c][1];
589 }
590
591 total_valid = a_valid + b_valid + c_valid;
592 // check if predictor A is out of bounds
593 if (!
s->mb_x && !(n == 1 || n == 3)) {
595 }
596 // check if predictor B is out of bounds
597 if ((
s->first_slice_line && v->
blk_mv_type[xy]) || (
s->first_slice_line && !(n & 2))) {
598 B[0] =
B[1] =
C[0] =
C[1] = 0;
599 }
601 if (
s->mb_width == 1) {
604 } else {
605 if (total_valid >= 2) {
608 } else if (total_valid) {
609 if (a_valid) {
px =
A[0]; py =
A[1]; }
610 else if (b_valid) {
px =
B[0]; py =
B[1]; }
611 else {
px =
C[0]; py =
C[1]; }
612 }
613 }
614 } else {
615 if (a_valid)
616 field_a = (
A[1] & 4) ? 1 : 0;
617 else
618 field_a = 0;
619 if (b_valid)
620 field_b = (
B[1] & 4) ? 1 : 0;
621 else
622 field_b = 0;
623 if (c_valid)
624 field_c = (
C[1] & 4) ? 1 : 0;
625 else
626 field_c = 0;
627
628 num_oppfield = field_a + field_b + field_c;
629 num_samefield = total_valid - num_oppfield;
630 if (total_valid == 3) {
631 if ((num_samefield == 3) || (num_oppfield == 3)) {
634 } 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 px = !field_a ?
A[0] :
B[0];
638 py = !field_a ?
A[1] :
B[1];
639 } else {
640 px = field_a ?
A[0] :
B[0];
641 py = field_a ?
A[1] :
B[1];
642 }
643 } else if (total_valid == 2) {
644 if (num_samefield >= num_oppfield) {
645 if (!field_a && a_valid) {
648 } else if (!field_b && b_valid) {
651 } else /*if (c_valid)*/ {
655 }
656 } else {
657 if (field_a && a_valid) {
660 } else /*if (field_b && b_valid)*/ {
664 }
665 }
666 } else if (total_valid == 1) {
667 px = (a_valid) ?
A[0] : ((b_valid) ?
B[0] :
C[0]);
668 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 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 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 if (mvn == 1) { /* duplicate motion data for 1-MV block */
676 s->cur_pic.motion_val[dir][xy + 1 ][0] =
s->cur_pic.motion_val[dir][xy][0];
677 s->cur_pic.motion_val[dir][xy + 1 ][1] =
s->cur_pic.motion_val[dir][xy][1];
678 s->cur_pic.motion_val[dir][xy +
wrap ][0] =
s->cur_pic.motion_val[dir][xy][0];
679 s->cur_pic.motion_val[dir][xy +
wrap ][1] =
s->cur_pic.motion_val[dir][xy][1];
680 s->cur_pic.motion_val[dir][xy +
wrap + 1][0] =
s->cur_pic.motion_val[dir][xy][0];
681 s->cur_pic.motion_val[dir][xy +
wrap + 1][1] =
s->cur_pic.motion_val[dir][xy][1];
682 } else if (mvn == 2) { /* duplicate motion data for 2-Field MV block */
683 s->cur_pic.motion_val[dir][xy + 1][0] =
s->cur_pic.motion_val[dir][xy][0];
684 s->cur_pic.motion_val[dir][xy + 1][1] =
s->cur_pic.motion_val[dir][xy][1];
685 s->mv[dir][n + 1][0] =
s->mv[dir][n][0];
686 s->mv[dir][n + 1][1] =
s->mv[dir][n][1];
687 }
688 }
689
691 int direct, int mvtype)
692 {
696 int sum;
697 int r_x, r_y;
698 const uint8_t *is_intra = v->
mb_type;
699
701
704 /* scale MV difference to be quad-pel */
705 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
713 xy =
s->block_index[0];
714
716 s->cur_pic.motion_val[0][xy][0] =
717 s->cur_pic.motion_val[0][xy][1] =
718 s->cur_pic.motion_val[1][xy][0] =
719 s->cur_pic.motion_val[1][xy][1] = 0;
720 return;
721 }
722 if (direct &&
s->next_pic.ptr->field_picture)
724
725 s->mv[0][0][0] =
scale_mv(
s->next_pic.motion_val[1][xy][0], v->
bfraction, 0,
s->quarter_sample);
726 s->mv[0][0][1] =
scale_mv(
s->next_pic.motion_val[1][xy][1], v->
bfraction, 0,
s->quarter_sample);
727 s->mv[1][0][0] =
scale_mv(
s->next_pic.motion_val[1][xy][0], v->
bfraction, 1,
s->quarter_sample);
728 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 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 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 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 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 if (direct) {
736 s->cur_pic.motion_val[0][xy][0] =
s->mv[0][0][0];
737 s->cur_pic.motion_val[0][xy][1] =
s->mv[0][0][1];
738 s->cur_pic.motion_val[1][xy][0] =
s->mv[1][0][0];
739 s->cur_pic.motion_val[1][xy][1] =
s->mv[1][0][1];
740 return;
741 }
742
744 int16_t *
C =
s->cur_pic.motion_val[0][xy - 2];
745 const int16_t *
A =
s->cur_pic.motion_val[0][xy -
wrap * 2];
746 int off = (
s->mb_x == (
s->mb_width - 1)) ? -2 : 2;
747 const int16_t *
B =
s->cur_pic.motion_val[0][xy -
wrap * 2 + off];
748
749 if (!
s->mb_x)
C[0] =
C[1] = 0;
750 if (!
s->first_slice_line) {
// predictor A is not out of bounds
751 if (
s->mb_width == 1) {
754 } else {
757 }
758 }
else if (
s->mb_x) {
// predictor C is not out of bounds
761 } else {
763 }
764 /* Pullback MV as specified in 8.3.5.3.4 */
765 {
768 int MV = 4 - (1 << sh);
769 qx = (
s->mb_x << sh);
770 qy = (
s->mb_y << sh);
771 X = (
s->mb_width << sh) - 4;
772 Y = (
s->mb_height << sh) - 4;
774 if (qy + py <
MV) py =
MV - qy;
775 if (qx +
px >
X)
px =
X - qx;
776 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])
782 else
784 if (sum > 32) {
788 } else {
791 }
792 } else {
793 if (is_intra[xy - 2])
795 else
797 if (sum > 32) {
801 } else {
804 }
805 }
806 }
807 }
808 /* store MV using signed modulus of MV range defined in 4.11 */
809 s->mv[0][0][0] = ((
px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
810 s->mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
811 }
813 int16_t *
C =
s->cur_pic.motion_val[1][xy - 2];
814 const int16_t *
A =
s->cur_pic.motion_val[1][xy -
wrap * 2];
815 int off = (
s->mb_x == (
s->mb_width - 1)) ? -2 : 2;
816 const int16_t *
B =
s->cur_pic.motion_val[1][xy -
wrap * 2 + off];
817
820 if (!
s->first_slice_line) {
// predictor A is not out of bounds
821 if (
s->mb_width == 1) {
824 } else {
827 }
828 }
else if (
s->mb_x) {
// predictor C is not out of bounds
831 } else {
833 }
834 /* Pullback MV as specified in 8.3.5.3.4 */
835 {
838 int MV = 4 - (1 << sh);
839 qx = (
s->mb_x << sh);
840 qy = (
s->mb_y << sh);
841 X = (
s->mb_width << sh) - 4;
842 Y = (
s->mb_height << sh) - 4;
844 if (qy + py <
MV) py =
MV - qy;
845 if (qx +
px >
X)
px =
X - qx;
846 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])
852 else
854 if (sum > 32) {
858 } else {
861 }
862 } else {
863 if (is_intra[xy - 2])
865 else
867 if (sum > 32) {
871 } else {
874 }
875 }
876 }
877 }
878 /* store MV using signed modulus of MV range defined in 4.11 */
879
880 s->mv[1][0][0] = ((
px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
881 s->mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
882 }
883 s->cur_pic.motion_val[0][xy][0] =
s->mv[0][0][0];
884 s->cur_pic.motion_val[0][xy][1] =
s->mv[0][0][1];
885 s->cur_pic.motion_val[1][xy][0] =
s->mv[1][0][0];
886 s->cur_pic.motion_val[1][xy][1] =
s->mv[1][0][1];
887 }
888
890 int mv1, int *pred_flag)
891 {
894 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
895
907
912 f = (total_opp > 2) ? 1 : 0;
913 } else {
914 s->mv[0][0][0] =
s->mv[0][0][1] = 0;
915 s->mv[1][0][0] =
s->mv[1][0][1] = 0;
917 }
919 for (k = 0; k < 4; k++) {
920 s->cur_pic.motion_val[0][
s->block_index[k] + v->
blocks_off][0] =
s->mv[0][0][0];
921 s->cur_pic.motion_val[0][
s->block_index[k] + v->
blocks_off][1] =
s->mv[0][0][1];
922 s->cur_pic.motion_val[1][
s->block_index[k] + v->
blocks_off][0] =
s->mv[1][0][0];
923 s->cur_pic.motion_val[1][
s->block_index[k] + v->
blocks_off][1] =
s->mv[1][0][1];
926 }
927 return;
928 }
932 return;
933 }
934 if (dir) { // backward
936 if (n == 3 || mv1) {
938 }
939 } else { // forward
941 if (n == 3 || mv1) {
943 }
944 }
945 }