40 int td = av_clip(poc1 - poc0, -128, 127);
44 int tb = av_clip(poc - poc0, -128, 127);
45 int tx = (16384 + (
FFABS(td) >> 1)) /
td;
46 return av_clip((tb*tx + 32) >> 6, -1024, 1023);
58 for (field = 0; field < 2; field++){
73 int j, old_ref, rfield;
74 int start= mbafi ? 16 : 0;
79 memset(map[list], 0,
sizeof(map[list]));
81 for(rfield=0; rfield<2; rfield++){
82 for(old_ref=0; old_ref<ref1->
ref_count[colfield][list]; old_ref++){
83 int poc = ref1->
ref_poc[colfield][list][old_ref];
87 else if( interl && (poc&3) == 3)
88 poc= (poc&~3) + rfield + 1;
90 for(j=start; j<
end; j++){
92 int cur_ref= mbafi ? (j-16)^field : j;
94 map[list][2 * old_ref + (rfield^field) + 16] = cur_ref;
95 if(rfield == field || !interl)
96 map[list][old_ref] = cur_ref;
111 for(list=0; list<2; list++){
137 for(list=0; list<2; list++){
140 for(field=0; field<2; field++)
149 int ref_height = 16*h->
mb_height >> ref_field_picture;
158 FFMIN(16 * mb_y >> ref_field_picture, ref_height - 1),
159 ref_field_picture && ref_field);
167 const int16_t (*l1mv0)[2], (*l1mv1)[2];
168 const int8_t *l1ref0, *l1ref1;
169 const int is_b8x8 =
IS_8X8(*mb_type);
180 #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
184 for(list=0; list<2; list++){
193 ref[list] =
FFMIN3((
unsigned)left_ref, (
unsigned)top_ref, (
unsigned)refc);
199 int match_count= (left_ref==ref[list]) + (top_ref==ref[list]) + (refc==ref[list]);
204 assert(match_count==1);
205 if(left_ref==ref[list]){
207 }
else if(top_ref==ref[list]){
223 if(ref[0] < 0 && ref[1] < 0){
230 if(!(is_b8x8|mv[0]|mv[1])){
264 && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)
301 l1mv0 += 2*b4_stride;
302 l1mv1 += 2*b4_stride;
309 for(i8=0; i8<4; i8++){
312 int xy8 = x8+y8*b8_stride;
313 int xy4 = 3*x8+y8*b4_stride;
323 && ( (l1ref0[xy8] == 0 &&
FFABS(l1mv0[xy4][0]) <= 1 &&
FFABS(l1mv0[xy4][1]) <= 1)
324 || (l1ref0[xy8] < 0 && l1ref1[xy8] == 0 &&
FFABS(l1mv1[xy4][0]) <= 1 &&
FFABS(l1mv1[xy4][1]) <= 1))){
338 if(!is_b8x8 && !(n&3))
346 && ( (l1ref0[0] == 0 &&
FFABS(l1mv0[0][0]) <= 1 &&
FFABS(l1mv0[0][1]) <= 1)
347 || (l1ref0[0] < 0 && l1ref1[0] == 0 &&
FFABS(l1mv1[0][0]) <= 1 &&
FFABS(l1mv1[0][1]) <= 1
362 for(i8=0; i8<4; i8++){
364 const int y8 = i8>>1;
375 assert(b8_stride==2);
378 || (l1ref0[i8] < 0 && l1ref1[i8] == 0
380 const int16_t (*l1mv)[2]= l1ref0[i8] == 0 ? l1mv0 : l1mv1;
382 const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
383 if(
FFABS(mv_col[0]) <= 1 &&
FFABS(mv_col[1]) <= 1){
392 for(i4=0; i4<4; i4++){
393 const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
394 if(
FFABS(mv_col[0]) <= 1 &&
FFABS(mv_col[1]) <= 1){
408 if(!is_b8x8 && !(n&15))
418 const int16_t (*l1mv0)[2], (*l1mv1)[2];
419 const int8_t *l1ref0, *l1ref1;
420 const int is_b8x8 =
IS_8X8(*mb_type);
454 && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)
491 l1mv0 += 2*b4_stride;
492 l1mv1 += 2*b4_stride;
506 ref_offset = (h->
ref_list[1][0].
mbaff<<4) & (mb_type_col[0]>>3);
512 for(i8=0; i8<4; i8++){
514 const int y8 = i8>>1;
516 const int16_t (*l1mv)[2]= l1mv0;
530 ref0 = l1ref0[x8 + y8*b8_stride];
532 ref0 = map_col_to_list0[0][ref0 + ref_offset];
534 ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
537 scale = dist_scale_factor[ref0];
541 const int16_t *mv_col = l1mv[x8*3 + y8*b4_stride];
542 int my_col = (mv_col[1]<<y_shift)/2;
543 int mx = (scale * mv_col[0] + 128) >> 8;
544 int my = (scale * my_col + 128) >> 8;
561 const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
562 : map_col_to_list0[1][l1ref1[0] + ref_offset];
563 const int scale = dist_scale_factor[ref0];
564 const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
566 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
567 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
570 mv1=
pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
576 for(i8=0; i8<4; i8++){
578 const int y8 = i8>>1;
580 const int16_t (*l1mv)[2]= l1mv0;
593 assert(b8_stride == 2);
596 ref0 = map_col_to_list0[0][ref0 + ref_offset];
598 ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset];
601 scale = dist_scale_factor[ref0];
605 const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
606 int mx = (scale * mv_col[0] + 128) >> 8;
607 int my = (scale * mv_col[1] + 128) >> 8;
611 for(i4=0; i4<4; i4++){
612 const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
614 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
615 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
617 pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]));