38 int scaledvalue, refdist;
39 int scalesame1, scalesame2;
40 int scalezone1_x, zone1offset_x;
57 if (
FFABS(n) < scalezone1_x)
58 scaledvalue = (n * scalesame1) >> 8;
61 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_x;
63 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_x;
71 int scaledvalue, refdist;
72 int scalesame1, scalesame2;
73 int scalezone1_y, zone1offset_y;
90 if (
FFABS(n) < scalezone1_y)
91 scaledvalue = (n * scalesame1) >> 8;
94 scaledvalue = ((n * scalesame2) >> 8) - zone1offset_y;
96 scaledvalue = ((n * scalesame2) >> 8) + zone1offset_y;
108 int scalezone1_x, zone1offset_x;
109 int scaleopp1, scaleopp2, brfd;
121 if (
FFABS(n) < scalezone1_x)
122 scaledvalue = (n * scaleopp1) >> 8;
125 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_x;
127 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_x;
135 int scalezone1_y, zone1offset_y;
136 int scaleopp1, scaleopp2, brfd;
148 if (
FFABS(n) < scalezone1_y)
149 scaledvalue = (n * scaleopp1) >> 8;
152 scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_y;
154 scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_y;
181 n = (n * scalesame >> 8) * (1 << hpel);
188 int refdist, scaleopp;
203 refdist =
FFMIN(refdist, 3);
206 n = (n * scaleopp >> 8) * (1 << hpel);
213 int mv1,
int r_x,
int r_y, uint8_t* is_intra,
214 int pred_flag,
int dir)
217 int xy,
wrap, off = 0;
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;
234 if (!
s->quarter_sample) {
240 xy =
s->block_index[n];
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;
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;
265 a_valid = !
s->first_slice_line || (n == 2 || n == 3);
267 c_valid =
s->mb_x || (n == 1 || n == 3);
270 off = (
s->mb_x == (
s->mb_width - 1)) ? -2 : 2;
272 off = (
s->mb_x == (
s->mb_width - 1)) ? -1 : 2;
273 b_valid = b_valid &&
s->mb_width > 1;
279 off =
s->mb_x ? -1 : 1;
281 off =
s->mb_x ? -1 : 2 *
s->mb_width -
wrap - 1;
284 off = (
s->mb_x == (
s->mb_width - 1)) ? -1 : 1;
293 b_valid = b_valid && c_valid;
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];
306 num_samefield += 1 - a_f;
307 field_predA[0] =
A[0];
308 field_predA[1] =
A[1];
310 field_predA[0] = field_predA[1] = 0;
314 const int16_t *
B =
s->cur_pic.motion_val[dir][xy -
wrap + off + v->
blocks_off];
317 num_samefield += 1 - b_f;
318 field_predB[0] =
B[0];
319 field_predB[1] =
B[1];
321 field_predB[0] = field_predB[1] = 0;
325 const int16_t *
C =
s->cur_pic.motion_val[dir][xy - 1 + v->
blocks_off];
328 num_samefield += 1 - c_f;
329 field_predC[0] =
C[0];
330 field_predC[1] =
C[1];
332 field_predC[0] = field_predC[1] = 0;
342 if (num_samefield <= num_oppfield)
343 opposite = 1 - pred_flag;
345 opposite = pred_flag;
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);
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);
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);
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);
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);
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);
384 }
else if (c_valid) {
387 }
else if (b_valid) {
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]);
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;
408 if (qx + px <
MV) px =
MV - qx;
409 if (qy + py <
MV) py =
MV - qy;
410 if (qx + px >
X) px =
X - qx;
411 if (qy + py >
Y) py =
Y - qy;
416 hybridmv_thresh = 32;
417 if (a_valid && c_valid) {
418 if (is_intra[xy -
wrap])
421 sum =
FFABS(px - field_predA[0]) +
FFABS(py - field_predA[1]);
422 if (sum > hybridmv_thresh) {
431 if (is_intra[xy - 1])
434 sum =
FFABS(px - field_predC[0]) +
FFABS(py - field_predC[1]);
435 if (sum > hybridmv_thresh) {
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;
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];
470 int mvn,
int r_x,
int r_y,
int dir)
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;
478 int total_valid, num_samefield, num_oppfield;
479 int pos_c, pos_b, n_adj;
482 xy =
s->block_index[n];
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;
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;
507 off = ((n == 0) || (n == 1)) ? 1 : -1;
509 if (
s->mb_x || (n == 1) || (n == 3)) {
512 A[0] =
s->cur_pic.motion_val[dir][xy - 1][0];
513 A[1] =
s->cur_pic.motion_val[dir][xy - 1][1];
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;
522 if (!(n & 1) && v->
is_intra[
s->mb_x - 1]) {
529 B[0] =
B[1] =
C[0] =
C[1] = 0;
531 if (!
s->first_slice_line) {
535 pos_b =
s->block_index[n_adj] - 2 *
wrap;
537 n_adj = (n & 2) | (n & 1);
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;
546 if (
s->mb_width > 1) {
547 if (!v->
is_intra[
s->mb_x -
s->mb_stride + 1]) {
550 pos_c =
s->block_index[2] - 2 *
wrap + 2;
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;
560 if (
s->mb_x ==
s->mb_width - 1) {
561 if (!v->
is_intra[
s->mb_x -
s->mb_stride - 1]) {
564 pos_c =
s->block_index[3] - 2 *
wrap - 2;
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;
581 pos_b =
s->block_index[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];
587 C[0] =
s->cur_pic.motion_val[dir][pos_c][0];
588 C[1] =
s->cur_pic.motion_val[dir][pos_c][1];
591 total_valid = a_valid + b_valid + c_valid;
593 if (!
s->mb_x && !(n == 1 || n == 3)) {
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;
601 if (
s->mb_width == 1) {
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]; }
616 field_a = (
A[1] & 4) ? 1 : 0;
620 field_b = (
B[1] & 4) ? 1 : 0;
624 field_c = (
C[1] & 4) ? 1 : 0;
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) {
637 px = !field_a ?
A[0] :
B[0];
638 py = !field_a ?
A[1] :
B[1];
640 px = field_a ?
A[0] :
B[0];
641 py = field_a ?
A[1] :
B[1];
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) {
657 if (field_a && a_valid) {
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]);
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;
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) {
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];
691 int direct,
int mvtype)
698 const uint8_t *is_intra = v->
mb_type[0];
705 if (!
s->quarter_sample) {
713 xy =
s->block_index[0];
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;
722 if (direct &&
s->next_pic.ptr->field_picture)
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);
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));
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];
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];
749 if (!
s->mb_x)
C[0] =
C[1] = 0;
750 if (!
s->first_slice_line) {
751 if (
s->mb_width == 1) {
758 }
else if (
s->mb_x) {
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;
773 if (qx + px <
MV) px =
MV - qx;
774 if (qy + py <
MV) py =
MV - qy;
775 if (qx + px >
X) px =
X - qx;
776 if (qy + py >
Y) py =
Y - qy;
779 if (0 && !
s->first_slice_line &&
s->mb_x) {
780 if (is_intra[xy -
wrap])
793 if (is_intra[xy - 2])
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;
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];
820 if (!
s->first_slice_line) {
821 if (
s->mb_width == 1) {
828 }
else if (
s->mb_x) {
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;
843 if (qx + px <
MV) px =
MV - qx;
844 if (qy + py <
MV) py =
MV - qy;
845 if (qx + px >
X) px =
X - qx;
846 if (qy + py >
Y) py =
Y - qy;
849 if (0 && !
s->first_slice_line &&
s->mb_x) {
850 if (is_intra[xy -
wrap])
863 if (is_intra[xy - 2])
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;
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];
890 int mv1,
int *pred_flag)
894 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
912 f = (total_opp > 2) ? 1 : 0;
914 s->mv[0][0][0] =
s->mv[0][0][1] = 0;
915 s->mv[1][0][0] =
s->mv[1][0][1] = 0;
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];