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;
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;
235 if (!
s->quarter_sample) {
241 xy =
s->block_index[n];
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;
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;
266 a_valid = !
s->first_slice_line || (n == 2 || n == 3);
268 c_valid =
s->mb_x || (n == 1 || n == 3);
271 off = (
s->mb_x == (
s->mb_width - 1)) ? -2 : 2;
273 off = (
s->mb_x == (
s->mb_width - 1)) ? -1 : 2;
274 b_valid = b_valid &&
s->mb_width > 1;
280 off =
s->mb_x ? -1 : 1;
282 off =
s->mb_x ? -1 : 2 *
s->mb_width -
wrap - 1;
285 off = (
s->mb_x == (
s->mb_width - 1)) ? -1 : 1;
294 b_valid = b_valid && c_valid;
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];
307 num_samefield += 1 - a_f;
308 field_predA[0] =
A[0];
309 field_predA[1] =
A[1];
311 field_predA[0] = field_predA[1] = 0;
318 num_samefield += 1 - b_f;
319 field_predB[0] =
B[0];
320 field_predB[1] =
B[1];
322 field_predB[0] = field_predB[1] = 0;
326 C =
s->current_picture.motion_val[dir][xy - 1 + v->
blocks_off];
329 num_samefield += 1 - c_f;
330 field_predC[0] =
C[0];
331 field_predC[1] =
C[1];
333 field_predC[0] = field_predC[1] = 0;
343 if (num_samefield <= num_oppfield)
344 opposite = 1 - pred_flag;
346 opposite = pred_flag;
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);
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);
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);
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);
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);
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);
385 }
else if (c_valid) {
388 }
else if (b_valid) {
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]);
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;
417 hybridmv_thresh = 32;
418 if (a_valid && c_valid) {
419 if (is_intra[xy -
wrap])
422 sum =
FFABS(px - field_predA[0]) +
FFABS(py - field_predA[1]);
423 if (sum > hybridmv_thresh) {
432 if (is_intra[xy - 1])
435 sum =
FFABS(px - field_predC[0]) +
FFABS(py - field_predC[1]);
436 if (sum > hybridmv_thresh) {
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;
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];
471 int mvn,
int r_x,
int r_y,
int dir)
474 int xy,
wrap, off = 0;
475 int A[2],
B[2],
C[2];
477 int a_valid = 0, b_valid = 0, c_valid = 0;
478 int field_a, field_b, field_c;
479 int total_valid, num_samefield, num_oppfield;
480 int pos_c, pos_b, n_adj;
483 xy =
s->block_index[n];
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;
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;
508 off = ((n == 0) || (n == 1)) ? 1 : -1;
510 if (
s->mb_x || (n == 1) || (n == 3)) {
513 A[0] =
s->current_picture.motion_val[dir][xy - 1][0];
514 A[1] =
s->current_picture.motion_val[dir][xy - 1][1];
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;
523 if (!(n & 1) && v->
is_intra[
s->mb_x - 1]) {
530 B[0] =
B[1] =
C[0] =
C[1] = 0;
532 if (!
s->first_slice_line) {
536 pos_b =
s->block_index[n_adj] - 2 *
wrap;
538 n_adj = (n & 2) | (n & 1);
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;
547 if (
s->mb_width > 1) {
548 if (!v->
is_intra[
s->mb_x -
s->mb_stride + 1]) {
551 pos_c =
s->block_index[2] - 2 *
wrap + 2;
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;
561 if (
s->mb_x ==
s->mb_width - 1) {
562 if (!v->
is_intra[
s->mb_x -
s->mb_stride - 1]) {
565 pos_c =
s->block_index[3] - 2 *
wrap - 2;
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;
582 pos_b =
s->block_index[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];
588 C[0] =
s->current_picture.motion_val[dir][pos_c][0];
589 C[1] =
s->current_picture.motion_val[dir][pos_c][1];
592 total_valid = a_valid + b_valid + c_valid;
594 if (!
s->mb_x && !(n == 1 || n == 3)) {
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;
602 if (
s->mb_width == 1) {
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]; }
617 field_a = (
A[1] & 4) ? 1 : 0;
621 field_b = (
B[1] & 4) ? 1 : 0;
625 field_c = (
C[1] & 4) ? 1 : 0;
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) {
638 px = !field_a ?
A[0] :
B[0];
639 py = !field_a ?
A[1] :
B[1];
641 px = field_a ?
A[0] :
B[0];
642 py = field_a ?
A[1] :
B[1];
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) {
658 if (field_a && a_valid) {
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]);
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;
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) {
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];
695 int xy,
wrap, off = 0;
700 const uint8_t *is_intra = v->
mb_type[0];
707 if (!
s->quarter_sample) {
715 xy =
s->block_index[0];
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;
724 if (
direct &&
s->next_picture_ptr->field_picture)
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);
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];
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];
751 if (!
s->mb_x)
C[0] =
C[1] = 0;
752 if (!
s->first_slice_line) {
753 if (
s->mb_width == 1) {
760 }
else if (
s->mb_x) {
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;
781 if (0 && !
s->first_slice_line &&
s->mb_x) {
782 if (is_intra[xy -
wrap])
795 if (is_intra[xy - 2])
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;
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];
822 if (!
s->first_slice_line) {
823 if (
s->mb_width == 1) {
830 }
else if (
s->mb_x) {
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;
851 if (0 && !
s->first_slice_line &&
s->mb_x) {
852 if (is_intra[xy -
wrap])
865 if (is_intra[xy - 2])
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;
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];
892 int mv1,
int *pred_flag)
896 int mb_pos =
s->mb_x +
s->mb_y *
s->mb_stride;
914 f = (total_opp > 2) ? 1 : 0;
916 s->mv[0][0][0] =
s->mv[0][0][1] = 0;
917 s->mv[1][0][0] =
s->mv[1][0][1] = 0;
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];