40 int td = av_clip_int8(poc1 - poc0);
44 int tb = av_clip_int8(poc - poc0);
45 int tx = (16384 + (
FFABS(td) >> 1)) /
td;
46 return av_clip_intp2((tb * tx + 32) >> 6, 10);
58 for (field = 0; field < 2; field++) {
71 int field,
int colfield,
int mbafi)
74 int j, old_ref, rfield;
75 int start = mbafi ? 16 : 0;
80 memset(map[list], 0,
sizeof(map[list]));
82 for (rfield = 0; rfield < 2; rfield++) {
83 for (old_ref = 0; old_ref < ref1->
ref_count[colfield][list]; old_ref++) {
84 int poc = ref1->
ref_poc[colfield][list][old_ref];
89 else if (interl && (poc & 3) == 3)
90 poc = (poc & ~3) + rfield + 1;
92 for (j = start; j <
end; j++) {
95 int cur_ref = mbafi ? (j - 16) ^ field : j;
97 map[list][2 * old_ref + (rfield ^ field) + 16] = cur_ref;
98 if (rfield == field || !interl)
99 map[list][old_ref] = cur_ref;
113 int ref1sidx = (ref1->
reference & 1) ^ 1;
115 for (list = 0; list < 2; list++) {
134 FFABS(col_poc[1] - cur_poc));
146 for (list = 0; list < 2; list++) {
149 for (field = 0; field < 2; field++)
160 int ref_height = 16 * h->
mb_height >> ref_field_picture;
169 FFMIN(16 * mb_y >> ref_field_picture,
171 ref_field_picture && ref_field);
180 const int16_t (*l1mv0)[2], (*l1mv1)[2];
181 const int8_t *l1ref0, *l1ref1;
182 const int is_b8x8 =
IS_8X8(*mb_type);
194 #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16 | MB_TYPE_INTRA4x4 | \
195 MB_TYPE_INTRA16x16 | MB_TYPE_INTRA_PCM)
198 for (list = 0; list < 2; list++) {
207 ref[list] =
FFMIN3((
unsigned)left_ref,
210 if (ref[list] >= 0) {
216 int match_count = (left_ref == ref[list]) +
217 (top_ref == ref[list]) +
220 if (match_count > 1) {
224 assert(match_count == 1);
225 if (left_ref == ref[list])
227 else if (top_ref == ref[list])
242 if (ref[0] < 0 && ref[1] < 0) {
249 if (!(is_b8x8 | mv[0] | mv[1])) {
287 (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) &&
301 }
else if (!is_b8x8 &&
326 l1mv0 += 2 * b4_stride;
327 l1mv1 += 2 * b4_stride;
333 for (i8 = 0; i8 < 4; i8++) {
336 int xy8 = x8 + y8 * b8_stride;
337 int xy4 = x8 * 3 + y8 * b4_stride;
349 ((l1ref0[xy8] == 0 &&
350 FFABS(l1mv0[xy4][0]) <= 1 &&
351 FFABS(l1mv0[xy4][1]) <= 1) ||
354 FFABS(l1mv1[xy4][0]) <= 1 &&
355 FFABS(l1mv1[xy4][1]) <= 1))) {
370 if (!is_b8x8 && !(n & 3))
381 FFABS(l1mv0[0][0]) <= 1 &&
382 FFABS(l1mv0[0][1]) <= 1) ||
383 (l1ref0[0] < 0 && !l1ref1[0] &&
384 FFABS(l1mv1[0][0]) <= 1 &&
385 FFABS(l1mv1[0][1]) <= 1 &&
400 for (i8 = 0; i8 < 4; i8++) {
401 const int x8 = i8 & 1;
402 const int y8 = i8 >> 1;
415 assert(b8_stride == 2);
422 const int16_t (*l1mv)[2] = l1ref0[i8] == 0 ? l1mv0 : l1mv1;
424 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
425 if (
FFABS(mv_col[0]) <= 1 &&
FFABS(mv_col[1]) <= 1) {
436 for (i4 = 0; i4 < 4; i4++) {
437 const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) +
438 (y8 * 2 + (i4 >> 1)) * b4_stride];
439 if (
FFABS(mv_col[0]) <= 1 &&
FFABS(mv_col[1]) <= 1) {
453 if (!is_b8x8 && !(n & 15))
466 const int16_t (*l1mv0)[2], (*l1mv1)[2];
467 const int8_t *l1ref0, *l1ref1;
468 const int is_b8x8 =
IS_8X8(*mb_type);
506 (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) &&
523 }
else if (!is_b8x8 &&
549 l1mv0 += 2 * b4_stride;
550 l1mv1 += 2 * b4_stride;
565 ref_offset = (h->
ref_list[1][0].
mbaff << 4) & (mb_type_col[0] >> 3);
571 for (i8 = 0; i8 < 4; i8++) {
572 const int x8 = i8 & 1;
573 const int y8 = i8 >> 1;
575 const int16_t (*l1mv)[2] = l1mv0;
589 ref0 = l1ref0[x8 + y8 * b8_stride];
591 ref0 = map_col_to_list0[0][ref0 + ref_offset];
593 ref0 = map_col_to_list0[1][l1ref1[x8 + y8 * b8_stride] +
597 scale = dist_scale_factor[ref0];
602 const int16_t *mv_col = l1mv[x8 * 3 + y8 * b4_stride];
603 int my_col = (mv_col[1] << y_shift) / 2;
604 int mx = (scale * mv_col[0] + 128) >> 8;
605 int my = (scale * my_col + 128) >> 8;
624 const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
625 : map_col_to_list0[1][l1ref1[0] + ref_offset];
626 const int scale = dist_scale_factor[ref0];
627 const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
629 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
630 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
633 mv1 =
pack16to32(mv_l0[0] - mv_col[0], mv_l0[1] - mv_col[1]);
639 for (i8 = 0; i8 < 4; i8++) {
640 const int x8 = i8 & 1;
641 const int y8 = i8 >> 1;
643 const int16_t (*l1mv)[2] = l1mv0;
656 assert(b8_stride == 2);
659 ref0 = map_col_to_list0[0][ref0 + ref_offset];
661 ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset];
664 scale = dist_scale_factor[ref0];
669 const int16_t *mv_col = l1mv[x8 * 3 + y8 * 3 * b4_stride];
670 int mx = (scale * mv_col[0] + 128) >> 8;
671 int my = (scale * mv_col[1] + 128) >> 8;
675 pack16to32(mx - mv_col[0], my - mv_col[1]), 4);
677 for (i4 = 0; i4 < 4; i4++) {
678 const int16_t *mv_col = l1mv[x8 * 2 + (i4 & 1) +
679 (y8 * 2 + (i4 >> 1)) * b4_stride];
681 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
682 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
685 mv_l0[1] - mv_col[1]));