+ const int *map_col_to_list0[2] = {h->map_col_to_list0[0], h->map_col_to_list0[1]};
+ const int *dist_scale_factor = h->dist_scale_factor;
+
+ if(FRAME_MBAFF){
+ if(IS_INTERLACED(*mb_type)){
+ map_col_to_list0[0] = h->map_col_to_list0_field[0];
+ map_col_to_list0[1] = h->map_col_to_list0_field[1];
+ dist_scale_factor = h->dist_scale_factor_field;
+ }
+ if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col)){
+ /* FIXME assumes direct_8x8_inference == 1 */
+ const int pair_xy = s->mb_x + (s->mb_y&~1)*s->mb_stride;
+ int mb_types_col[2];
+ int y_shift;
+
+ *mb_type = MB_TYPE_8x8|MB_TYPE_L0L1
+ | (is_b8x8 ? 0 : MB_TYPE_DIRECT2)
+ | (*mb_type & MB_TYPE_INTERLACED);
+ sub_mb_type = MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2|MB_TYPE_16x16;
+
+ if(IS_INTERLACED(*mb_type)){
+ /* frame to field scaling */
+ mb_types_col[0] = h->ref_list[1][0].mb_type[pair_xy];
+ mb_types_col[1] = h->ref_list[1][0].mb_type[pair_xy+s->mb_stride];
+ if(s->mb_y&1){
+ l1ref0 -= 2*h->b8_stride;
+ l1ref1 -= 2*h->b8_stride;
+ l1mv0 -= 4*h->b_stride;
+ l1mv1 -= 4*h->b_stride;
+ }
+ y_shift = 0;
+
+ if( (mb_types_col[0] & MB_TYPE_16x16_OR_INTRA)
+ && (mb_types_col[1] & MB_TYPE_16x16_OR_INTRA)
+ && !is_b8x8)
+ *mb_type |= MB_TYPE_16x8;
+ else
+ *mb_type |= MB_TYPE_8x8;
+ }else{
+ /* field to frame scaling */
+ /* col_mb_y = (mb_y&~1) + (topAbsDiffPOC < bottomAbsDiffPOC ? 0 : 1)
+ * but in MBAFF, top and bottom POC are equal */
+ int dy = (s->mb_y&1) ? 1 : 2;
+ mb_types_col[0] =
+ mb_types_col[1] = h->ref_list[1][0].mb_type[pair_xy+s->mb_stride];
+ l1ref0 += dy*h->b8_stride;
+ l1ref1 += dy*h->b8_stride;
+ l1mv0 += 2*dy*h->b_stride;
+ l1mv1 += 2*dy*h->b_stride;
+ y_shift = 2;
+
+ if((mb_types_col[0] & (MB_TYPE_16x16_OR_INTRA|MB_TYPE_16x8))
+ && !is_b8x8)
+ *mb_type |= MB_TYPE_16x16;
+ else
+ *mb_type |= MB_TYPE_8x8;
+ }
+
+ for(i8=0; i8<4; i8++){
+ const int x8 = i8&1;
+ const int y8 = i8>>1;
+ int ref0, scale;
+ const int16_t (*l1mv)[2]= l1mv0;
+
+ if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
+ continue;
+ h->sub_mb_type[i8] = sub_mb_type;
+
+ fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
+ if(IS_INTRA(mb_types_col[y8])){
+ fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
+ fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
+ fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
+ continue;
+ }
+
+ ref0 = l1ref0[x8 + (y8*2>>y_shift)*h->b8_stride];
+ if(ref0 >= 0)
+ ref0 = map_col_to_list0[0][ref0*2>>y_shift];
+ else{
+ ref0 = map_col_to_list0[1][l1ref1[x8 + (y8*2>>y_shift)*h->b8_stride]*2>>y_shift];
+ l1mv= l1mv1;
+ }
+ scale = dist_scale_factor[ref0];
+ fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
+
+ {
+ const int16_t *mv_col = l1mv[x8*3 + (y8*6>>y_shift)*h->b_stride];
+ int my_col = (mv_col[1]<<y_shift)/2;
+ int mx = (scale * mv_col[0] + 128) >> 8;
+ int my = (scale * my_col + 128) >> 8;
+ fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
+ fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-my_col), 4);
+ }
+ }
+ return;
+ }
+ }
+
+ /* one-to-one mv scaling */
+