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 px, py;
220 int sum;
221 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 int hybridmv_thresh, y_bias = 0;
228
231 mixedmv_pic = 1;
232 else
233 mixedmv_pic = 0;
234 /* scale MV difference to be quad-pel */
235 if (!
s->quarter_sample) {
236 dmv_x *= 2;
237 dmv_y *= 2;
238 }
239
241 xy =
s->block_index[n];
242
244 s->mv[0][n][0] =
s->current_picture.motion_val[0][xy + v->
blocks_off][0] = 0;
245 s->mv[0][n][1] =
s->current_picture.motion_val[0][xy + v->
blocks_off][1] = 0;
246 s->current_picture.motion_val[1][xy + v->
blocks_off][0] = 0;
247 s->current_picture.motion_val[1][xy + v->
blocks_off][1] = 0;
248 if (mv1) { /* duplicate motion data for 1-MV block */
249 s->current_picture.motion_val[0][xy + 1 + v->
blocks_off][0] = 0;
250 s->current_picture.motion_val[0][xy + 1 + v->
blocks_off][1] = 0;
253 s->current_picture.motion_val[0][xy +
wrap + 1 + v->
blocks_off][0] = 0;
254 s->current_picture.motion_val[0][xy +
wrap + 1 + v->
blocks_off][1] = 0;
256 s->current_picture.motion_val[1][xy + 1 + v->
blocks_off][0] = 0;
257 s->current_picture.motion_val[1][xy + 1 + v->
blocks_off][1] = 0;
260 s->current_picture.motion_val[1][xy +
wrap + 1 + v->
blocks_off][0] = 0;
261 s->current_picture.motion_val[1][xy +
wrap + 1 + v->
blocks_off][1] = 0;
262 }
263 return;
264 }
265
266 a_valid = !
s->first_slice_line || (n == 2 || n == 3);
267 b_valid = a_valid;
268 c_valid =
s->mb_x || (n == 1 || n == 3);
269 if (mv1) {
271 off = (
s->mb_x == (
s->mb_width - 1)) ? -2 : 2;
272 else
273 off = (
s->mb_x == (
s->mb_width - 1)) ? -1 : 2;
274 b_valid = b_valid &&
s->mb_width > 1;
275 } else {
276 //in 4-MV mode different blocks have different B predictor position
277 switch (n) {
278 case 0:
280 off =
s->mb_x ? -1 : 1;
281 else
282 off =
s->mb_x ? -1 : 2 *
s->mb_width -
wrap - 1;
283 break;
284 case 1:
285 off = (
s->mb_x == (
s->mb_width - 1)) ? -1 : 1;
286 break;
287 case 2:
288 off = 1;
289 break;
290 case 3:
291 off = -1;
292 }
294 b_valid = b_valid && c_valid;
295 }
296
298 a_valid = a_valid && !is_intra[xy -
wrap];
299 b_valid = b_valid && !is_intra[xy -
wrap + off];
300 c_valid = c_valid && !is_intra[xy - 1];
301 }
302
303 if (a_valid) {
306 num_oppfield += a_f;
307 num_samefield += 1 - a_f;
308 field_predA[0] =
A[0];
309 field_predA[1] =
A[1];
310 } else {
311 field_predA[0] = field_predA[1] = 0;
312 a_f = 0;
313 }
314 if (b_valid) {
317 num_oppfield += b_f;
318 num_samefield += 1 - b_f;
319 field_predB[0] =
B[0];
320 field_predB[1] =
B[1];
321 } else {
322 field_predB[0] = field_predB[1] = 0;
323 b_f = 0;
324 }
325 if (c_valid) {
326 C =
s->current_picture.motion_val[dir][xy - 1 + v->
blocks_off];
328 num_oppfield += c_f;
329 num_samefield += 1 - c_f;
330 field_predC[0] =
C[0];
331 field_predC[1] =
C[1];
332 } else {
333 field_predC[0] = field_predC[1] = 0;
334 c_f = 0;
335 }
336
339 // REFFIELD determines if the last field or the second-last field is
340 // to be used as reference
342 else {
343 if (num_samefield <= num_oppfield)
344 opposite = 1 - pred_flag;
345 else
346 opposite = pred_flag;
347 }
348 } else
349 opposite = 0;
350 if (opposite) {
353 if (a_valid && !a_f) {
354 field_predA[0] =
scaleforopp(v, field_predA[0], 0, dir);
355 field_predA[1] =
scaleforopp(v, field_predA[1], 1, dir);
356 }
357 if (b_valid && !b_f) {
358 field_predB[0] =
scaleforopp(v, field_predB[0], 0, dir);
359 field_predB[1] =
scaleforopp(v, field_predB[1], 1, dir);
360 }
361 if (c_valid && !c_f) {
362 field_predC[0] =
scaleforopp(v, field_predC[0], 0, dir);
363 field_predC[1] =
scaleforopp(v, field_predC[1], 1, dir);
364 }
365 } else {
368 if (a_valid && a_f) {
369 field_predA[0] =
scaleforsame(v, n, field_predA[0], 0, dir);
370 field_predA[1] =
scaleforsame(v, n, field_predA[1], 1, dir);
371 }
372 if (b_valid && b_f) {
373 field_predB[0] =
scaleforsame(v, n, field_predB[0], 0, dir);
374 field_predB[1] =
scaleforsame(v, n, field_predB[1], 1, dir);
375 }
376 if (c_valid && c_f) {
377 field_predC[0] =
scaleforsame(v, n, field_predC[0], 0, dir);
378 field_predC[1] =
scaleforsame(v, n, field_predC[1], 1, dir);
379 }
380 }
381
382 if (a_valid) {
383 px = field_predA[0];
384 py = field_predA[1];
385 } else if (c_valid) {
386 px = field_predC[0];
387 py = field_predC[1];
388 } else if (b_valid) {
389 px = field_predB[0];
390 py = field_predB[1];
391 } else {
392 px = 0;
393 py = 0;
394 }
395
396 if (num_samefield + num_oppfield > 1) {
397 px =
mid_pred(field_predA[0], field_predB[0], field_predC[0]);
398 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 */
404 int MV = mv1 ? -60 : -28;
405 qx = (
s->mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0);
406 qy = (
s->mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0);
407 X = (
s->mb_width << 6) - 4;
408 Y = (
s->mb_height << 6) - 4;
409 if (qx + px <
MV) px =
MV - qx;
410 if (qy + py <
MV) py =
MV - qy;
411 if (qx + px >
X) px =
X - qx;
412 if (qy + py >
Y) py =
Y - qy;
413 }
414
416 /* Calculate hybrid prediction as specified in 8.3.5.3.5 (also 10.3.5.4.3.5) */
417 hybridmv_thresh = 32;
418 if (a_valid && c_valid) {
419 if (is_intra[xy -
wrap])
421 else
422 sum =
FFABS(px - field_predA[0]) +
FFABS(py - field_predA[1]);
423 if (sum > hybridmv_thresh) {
424 if (
get_bits1(&
s->gb)) {
// read HYBRIDPRED bit
425 px = field_predA[0];
426 py = field_predA[1];
427 } else {
428 px = field_predC[0];
429 py = field_predC[1];
430 }
431 } else {
432 if (is_intra[xy - 1])
434 else
435 sum =
FFABS(px - field_predC[0]) +
FFABS(py - field_predC[1]);
436 if (sum > hybridmv_thresh) {
438 px = field_predA[0];
439 py = field_predA[1];
440 } else {
441 px = field_predC[0];
442 py = field_predC[1];
443 }
444 }
445 }
446 }
447 }
448
450 r_y >>= 1;
452 y_bias = 1;
453 /* store MV using signed modulus of MV range defined in 4.11 */
454 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 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 if (mv1) { /* duplicate motion data for 1-MV block */
457 s->current_picture.motion_val[dir][xy + 1 + v->
blocks_off][0] =
s->current_picture.motion_val[dir][xy + v->
blocks_off][0];
458 s->current_picture.motion_val[dir][xy + 1 + v->
blocks_off][1] =
s->current_picture.motion_val[dir][xy + v->
blocks_off][1];
461 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 s->current_picture.motion_val[dir][xy +
wrap + 1 + v->
blocks_off][1] =
s->current_picture.motion_val[dir][xy + v->
blocks_off][1];
465 }
466 }
467
468 /** Predict and set motion vector for interlaced frame picture MBs
469 */
471 int mvn, int r_x, int r_y, int dir)
472 {
474 int xy,
wrap, off = 0;
475 int A[2],
B[2],
C[2];
476 int px = 0, py = 0;
477 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
483 xy =
s->block_index[n];
484
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;
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 off = ((n == 0) || (n == 1)) ? 1 : -1;
509 /* predict A */
510 if (
s->mb_x || (n == 1) || (n == 3)) {
511 if ((v->
blk_mv_type[xy])
// current block (MB) has a field MV
513 A[0] =
s->current_picture.motion_val[dir][xy - 1][0];
514 A[1] =
s->current_picture.motion_val[dir][xy - 1][1];
515 a_valid = 1;
516 } else { // current block has frame mv and cand. has field MV (so average)
517 A[0] = (
s->current_picture.motion_val[dir][xy - 1][0]
518 +
s->current_picture.motion_val[dir][xy - 1 + off *
wrap][0] + 1) >> 1;
519 A[1] = (
s->current_picture.motion_val[dir][xy - 1][1]
520 +
s->current_picture.motion_val[dir][xy - 1 + off *
wrap][1] + 1) >> 1;
521 a_valid = 1;
522 }
523 if (!(n & 1) && v->
is_intra[
s->mb_x - 1]) {
524 a_valid = 0;
526 }
527 } else
529 /* Predict B and C */
530 B[0] =
B[1] =
C[0] =
C[1] = 0;
532 if (!
s->first_slice_line) {
534 b_valid = 1;
535 n_adj = n | 2;
536 pos_b =
s->block_index[n_adj] - 2 *
wrap;
538 n_adj = (n & 2) | (n & 1);
539 }
540 B[0] =
s->current_picture.motion_val[dir][
s->block_index[n_adj] - 2 *
wrap][0];
541 B[1] =
s->current_picture.motion_val[dir][
s->block_index[n_adj] - 2 *
wrap][1];
543 B[0] = (
B[0] +
s->current_picture.motion_val[dir][
s->block_index[n_adj ^ 2] - 2 *
wrap][0] + 1) >> 1;
544 B[1] = (
B[1] +
s->current_picture.motion_val[dir][
s->block_index[n_adj ^ 2] - 2 *
wrap][1] + 1) >> 1;
545 }
546 }
547 if (
s->mb_width > 1) {
548 if (!v->
is_intra[
s->mb_x -
s->mb_stride + 1]) {
549 c_valid = 1;
550 n_adj = 2;
551 pos_c =
s->block_index[2] - 2 *
wrap + 2;
553 n_adj = n & 2;
554 }
555 C[0] =
s->current_picture.motion_val[dir][
s->block_index[n_adj] - 2 *
wrap + 2][0];
556 C[1] =
s->current_picture.motion_val[dir][
s->block_index[n_adj] - 2 *
wrap + 2][1];
558 C[0] = (1 +
C[0] + (
s->current_picture.motion_val[dir][
s->block_index[n_adj ^ 2] - 2 *
wrap + 2][0])) >> 1;
559 C[1] = (1 +
C[1] + (
s->current_picture.motion_val[dir][
s->block_index[n_adj ^ 2] - 2 *
wrap + 2][1])) >> 1;
560 }
561 if (
s->mb_x ==
s->mb_width - 1) {
562 if (!v->
is_intra[
s->mb_x -
s->mb_stride - 1]) {
563 c_valid = 1;
564 n_adj = 3;
565 pos_c =
s->block_index[3] - 2 *
wrap - 2;
567 n_adj = n | 1;
568 }
569 C[0] =
s->current_picture.motion_val[dir][
s->block_index[n_adj] - 2 *
wrap - 2][0];
570 C[1] =
s->current_picture.motion_val[dir][
s->block_index[n_adj] - 2 *
wrap - 2][1];
572 C[0] = (1 +
C[0] +
s->current_picture.motion_val[dir][
s->block_index[1] - 2 *
wrap - 2][0]) >> 1;
573 C[1] = (1 +
C[1] +
s->current_picture.motion_val[dir][
s->block_index[1] - 2 *
wrap - 2][1]) >> 1;
574 }
575 } else
576 c_valid = 0;
577 }
578 }
579 }
580 }
581 } else {
582 pos_b =
s->block_index[1];
583 b_valid = 1;
584 B[0] =
s->current_picture.motion_val[dir][pos_b][0];
585 B[1] =
s->current_picture.motion_val[dir][pos_b][1];
586 pos_c =
s->block_index[0];
587 c_valid = 1;
588 C[0] =
s->current_picture.motion_val[dir][pos_c][0];
589 C[1] =
s->current_picture.motion_val[dir][pos_c][1];
590 }
591
592 total_valid = a_valid + b_valid + c_valid;
593 // check if predictor A is out of bounds
594 if (!
s->mb_x && !(n == 1 || n == 3)) {
596 }
597 // check if predictor B is out of bounds
598 if ((
s->first_slice_line && v->
blk_mv_type[xy]) || (
s->first_slice_line && !(n & 2))) {
599 B[0] =
B[1] =
C[0] =
C[1] = 0;
600 }
602 if (
s->mb_width == 1) {
605 } else {
606 if (total_valid >= 2) {
609 } else if (total_valid) {
610 if (a_valid) { px =
A[0]; py =
A[1]; }
611 else if (b_valid) { px =
B[0]; py =
B[1]; }
612 else { px =
C[0]; py =
C[1]; }
613 }
614 }
615 } else {
616 if (a_valid)
617 field_a = (
A[1] & 4) ? 1 : 0;
618 else
619 field_a = 0;
620 if (b_valid)
621 field_b = (
B[1] & 4) ? 1 : 0;
622 else
623 field_b = 0;
624 if (c_valid)
625 field_c = (
C[1] & 4) ? 1 : 0;
626 else
627 field_c = 0;
628
629 num_oppfield = field_a + field_b + field_c;
630 num_samefield = total_valid - num_oppfield;
631 if (total_valid == 3) {
632 if ((num_samefield == 3) || (num_oppfield == 3)) {
635 } 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 px = !field_a ?
A[0] :
B[0];
639 py = !field_a ?
A[1] :
B[1];
640 } else {
641 px = field_a ?
A[0] :
B[0];
642 py = field_a ?
A[1] :
B[1];
643 }
644 } else if (total_valid == 2) {
645 if (num_samefield >= num_oppfield) {
646 if (!field_a && a_valid) {
649 } else if (!field_b && b_valid) {
652 } else /*if (c_valid)*/ {
656 }
657 } else {
658 if (field_a && a_valid) {
661 } else /*if (field_b && b_valid)*/ {
665 }
666 }
667 } else if (total_valid == 1) {
668 px = (a_valid) ?
A[0] : ((b_valid) ?
B[0] :
C[0]);
669 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 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 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 if (mvn == 1) { /* duplicate motion data for 1-MV block */
677 s->current_picture.motion_val[dir][xy + 1 ][0] =
s->current_picture.motion_val[dir][xy][0];
678 s->current_picture.motion_val[dir][xy + 1 ][1] =
s->current_picture.motion_val[dir][xy][1];
679 s->current_picture.motion_val[dir][xy +
wrap ][0] =
s->current_picture.motion_val[dir][xy][0];
680 s->current_picture.motion_val[dir][xy +
wrap ][1] =
s->current_picture.motion_val[dir][xy][1];
681 s->current_picture.motion_val[dir][xy +
wrap + 1][0] =
s->current_picture.motion_val[dir][xy][0];
682 s->current_picture.motion_val[dir][xy +
wrap + 1][1] =
s->current_picture.motion_val[dir][xy][1];
683 } else if (mvn == 2) { /* duplicate motion data for 2-Field MV block */
684 s->current_picture.motion_val[dir][xy + 1][0] =
s->current_picture.motion_val[dir][xy][0];
685 s->current_picture.motion_val[dir][xy + 1][1] =
s->current_picture.motion_val[dir][xy][1];
686 s->mv[dir][n + 1][0] =
s->mv[dir][n][0];
687 s->mv[dir][n + 1][1] =
s->mv[dir][n][1];
688 }
689 }
690
693 {
695 int xy,
wrap, off = 0;
697 int px, py;
698 int sum;
699 int r_x, r_y;
700 const uint8_t *is_intra = v->
mb_type[0];
701
703
706 /* scale MV difference to be quad-pel */
707 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
715 xy =
s->block_index[0];
716
718 s->current_picture.motion_val[0][xy][0] =
719 s->current_picture.motion_val[0][xy][1] =
720 s->current_picture.motion_val[1][xy][0] =
721 s->current_picture.motion_val[1][xy][1] = 0;
722 return;
723 }
724 if (
direct &&
s->next_picture_ptr->field_picture)
726
727 s->mv[0][0][0] =
scale_mv(
s->next_picture.motion_val[1][xy][0], v->
bfraction, 0,
s->quarter_sample);
728 s->mv[0][0][1] =
scale_mv(
s->next_picture.motion_val[1][xy][1], v->
bfraction, 0,
s->quarter_sample);
729 s->mv[1][0][0] =
scale_mv(
s->next_picture.motion_val[1][xy][0], v->
bfraction, 1,
s->quarter_sample);
730 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 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 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 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 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));
738 s->current_picture.motion_val[0][xy][0] =
s->mv[0][0][0];
739 s->current_picture.motion_val[0][xy][1] =
s->mv[0][0][1];
740 s->current_picture.motion_val[1][xy][0] =
s->mv[1][0][0];
741 s->current_picture.motion_val[1][xy][1] =
s->mv[1][0][1];
742 return;
743 }
744
746 C =
s->current_picture.motion_val[0][xy - 2];
747 A =
s->current_picture.motion_val[0][xy -
wrap * 2];
748 off = (
s->mb_x == (
s->mb_width - 1)) ? -2 : 2;
749 B =
s->current_picture.motion_val[0][xy -
wrap * 2 + off];
750
751 if (!
s->mb_x)
C[0] =
C[1] = 0;
752 if (!
s->first_slice_line) {
// predictor A is not out of bounds
753 if (
s->mb_width == 1) {
756 } else {
759 }
760 }
else if (
s->mb_x) {
// predictor C is not out of bounds
763 } else {
764 px = py = 0;
765 }
766 /* Pullback MV as specified in 8.3.5.3.4 */
767 {
770 int MV = 4 - (1 << sh);
771 qx = (
s->mb_x << sh);
772 qy = (
s->mb_y << sh);
773 X = (
s->mb_width << sh) - 4;
774 Y = (
s->mb_height << sh) - 4;
775 if (qx + px <
MV) px =
MV - qx;
776 if (qy + py <
MV) py =
MV - qy;
777 if (qx + px >
X) px =
X - qx;
778 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])
784 else
786 if (sum > 32) {
790 } else {
793 }
794 } else {
795 if (is_intra[xy - 2])
797 else
799 if (sum > 32) {
803 } else {
806 }
807 }
808 }
809 }
810 /* store MV using signed modulus of MV range defined in 4.11 */
811 s->mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x;
812 s->mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y;
813 }
815 C =
s->current_picture.motion_val[1][xy - 2];
816 A =
s->current_picture.motion_val[1][xy -
wrap * 2];
817 off = (
s->mb_x == (
s->mb_width - 1)) ? -2 : 2;
818 B =
s->current_picture.motion_val[1][xy -
wrap * 2 + off];
819
822 if (!
s->first_slice_line) {
// predictor A is not out of bounds
823 if (
s->mb_width == 1) {
826 } else {
829 }
830 }
else if (
s->mb_x) {
// predictor C is not out of bounds
833 } else {
834 px = py = 0;
835 }
836 /* Pullback MV as specified in 8.3.5.3.4 */
837 {
840 int MV = 4 - (1 << sh);
841 qx = (
s->mb_x << sh);
842 qy = (
s->mb_y << sh);
843 X = (
s->mb_width << sh) - 4;
844 Y = (
s->mb_height << sh) - 4;
845 if (qx + px <
MV) px =
MV - qx;
846 if (qy + py <
MV) py =
MV - qy;
847 if (qx + px >
X) px =
X - qx;
848 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])
854 else
856 if (sum > 32) {
860 } else {
863 }
864 } else {
865 if (is_intra[xy - 2])
867 else
869 if (sum > 32) {
873 } else {
876 }
877 }
878 }
879 }
880 /* store MV using signed modulus of MV range defined in 4.11 */
881
882 s->mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x;
883 s->mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y;
884 }
885 s->current_picture.motion_val[0][xy][0] =
s->mv[0][0][0];
886 s->current_picture.motion_val[0][xy][1] =
s->mv[0][0][1];
887 s->current_picture.motion_val[1][xy][0] =
s->mv[1][0][0];
888 s->current_picture.motion_val[1][xy][1] =
s->mv[1][0][1];
889 }
890
892 int mv1, int *pred_flag)
893 {
896 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
897
909
914 f = (total_opp > 2) ? 1 : 0;
915 } else {
916 s->mv[0][0][0] =
s->mv[0][0][1] = 0;
917 s->mv[1][0][0] =
s->mv[1][0][1] = 0;
919 }
921 for (k = 0; k < 4; k++) {
922 s->current_picture.motion_val[0][
s->block_index[k] + v->
blocks_off][0] =
s->mv[0][0][0];
923 s->current_picture.motion_val[0][
s->block_index[k] + v->
blocks_off][1] =
s->mv[0][0][1];
924 s->current_picture.motion_val[1][
s->block_index[k] + v->
blocks_off][0] =
s->mv[1][0][0];
925 s->current_picture.motion_val[1][
s->block_index[k] + v->
blocks_off][1] =
s->mv[1][0][1];
928 }
929 return;
930 }
934 return;
935 }
936 if (dir) { // backward
938 if (n == 3 || mv1) {
940 }
941 } else { // forward
943 if (n == 3 || mv1) {
945 }
946 }
947 }