Revision 7bc9090a libavcodec/motion_est.c

View differences:

libavcodec/motion_est.c
775 775

  
776 776
static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4)
777 777
{
778
    const int xy= s->mb_x + 1 + (s->mb_y + 1)*(s->mb_width + 2);
778
    const int xy= s->mb_x + s->mb_y*s->mb_stride;
779 779
    
780 780
    s->p_mv_table[xy][0] = mx;
781 781
    s->p_mv_table[xy][1] = my;
......
1076 1076
    vard = (s->dsp.sse[0](NULL, pix, ppix, s->linesize)+128)>>8;
1077 1077

  
1078 1078
//printf("%d %d %d %X %X %X\n", s->mb_width, mb_x, mb_y,(int)s, (int)s->mb_var, (int)s->mc_mb_var); fflush(stdout);
1079
    pic->mb_var   [s->mb_width * mb_y + mb_x] = varc;
1080
    pic->mc_mb_var[s->mb_width * mb_y + mb_x] = vard;
1081
    pic->mb_mean  [s->mb_width * mb_y + mb_x] = (sum+128)>>8;
1082
//    pic->mb_cmp_score[s->mb_width * mb_y + mb_x] = dmin; 
1079
    pic->mb_var   [s->mb_stride * mb_y + mb_x] = varc;
1080
    pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = vard;
1081
    pic->mb_mean  [s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
1082
//    pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin; 
1083 1083
    pic->mb_var_sum    += varc;
1084 1084
    pic->mc_mb_var_sum += vard;
1085 1085
//printf("E%d %d %d %X %X %X\n", s->mb_width, mb_x, mb_y,(int)s, (int)s->mb_var, (int)s->mc_mb_var); fflush(stdout);
......
1129 1129
                dmin=dmin4;
1130 1130
            }
1131 1131
        }
1132
        pic->mb_cmp_score[s->mb_width * mb_y + mb_x] = dmin; 
1132
        pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin; 
1133 1133
        set_p_mv_tables(s, mx, my, mb_type!=MB_TYPE_INTER4V);
1134 1134
        
1135 1135
        if (vard <= 64 || vard < varc) {
......
1139 1139
        }
1140 1140
    }
1141 1141

  
1142
    s->mb_type[mb_y*s->mb_width + mb_x]= mb_type;
1142
    s->mb_type[mb_y*s->mb_stride + mb_x]= mb_type;
1143 1143
}
1144 1144

  
1145 1145
int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
......
1152 1152
    int P[10][2];
1153 1153
    const int shift= 1+s->quarter_sample;
1154 1154
    uint8_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;
1155
    const int mv_stride= s->mb_width + 2;
1156
    const int xy= mb_x + 1 + (mb_y + 1)*mv_stride;
1155
    const int xy= mb_x + mb_y*s->mb_stride;
1157 1156
    
1158 1157
    assert(s->quarter_sample==0 || s->quarter_sample==1);
1159 1158

  
......
1178 1177
        P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=
1179 1178
        P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME 
1180 1179
    } else {
1181
        P_TOP[0]      = s->p_mv_table[xy + mv_stride    ][0];
1182
        P_TOP[1]      = s->p_mv_table[xy + mv_stride    ][1];
1183
        P_TOPRIGHT[0] = s->p_mv_table[xy + mv_stride - 1][0];
1184
        P_TOPRIGHT[1] = s->p_mv_table[xy + mv_stride - 1][1];
1180
        P_TOP[0]      = s->p_mv_table[xy + s->mb_stride    ][0];
1181
        P_TOP[1]      = s->p_mv_table[xy + s->mb_stride    ][1];
1182
        P_TOPRIGHT[0] = s->p_mv_table[xy + s->mb_stride - 1][0];
1183
        P_TOPRIGHT[1] = s->p_mv_table[xy + s->mb_stride - 1][1];
1185 1184
        if(P_TOP[1]      < (rel_ymin<<shift)) P_TOP[1]     = (rel_ymin<<shift);
1186 1185
        if(P_TOPRIGHT[0] > (rel_xmax<<shift)) P_TOPRIGHT[0]= (rel_xmax<<shift);
1187 1186
        if(P_TOPRIGHT[1] < (rel_ymin<<shift)) P_TOPRIGHT[1]= (rel_ymin<<shift);
......
1210 1209
    int pred_x=0, pred_y=0;
1211 1210
    int P[10][2];
1212 1211
    const int shift= 1+s->quarter_sample;
1213
    const int mot_stride = s->mb_width + 2;
1214
    const int mot_xy = (mb_y + 1)*mot_stride + mb_x + 1;
1212
    const int mot_stride = s->mb_stride;
1213
    const int mot_xy = mb_y*mot_stride + mb_x;
1215 1214
    uint8_t * const ref_picture= picture->data[0];
1216 1215
    uint8_t * const mv_penalty= s->me.mv_penalty[f_code] + MAX_MV;
1217 1216
    int mv_scale;
......
1370 1369
static inline int bidir_refine(MpegEncContext * s,
1371 1370
                                  int mb_x, int mb_y)
1372 1371
{
1373
    const int mot_stride = s->mb_width + 2;
1374
    const int xy = (mb_y + 1)*mot_stride + mb_x + 1;
1372
    const int mot_stride = s->mb_stride;
1373
    const int xy = mb_y *mot_stride + mb_x;
1375 1374
    int fbmin;
1376 1375
    int pred_fx= s->b_bidir_forw_mv_table[xy-1][0];
1377 1376
    int pred_fy= s->b_bidir_forw_mv_table[xy-1][1];
......
1397 1396
                                int mb_x, int mb_y)
1398 1397
{
1399 1398
    int P[10][2];
1400
    const int mot_stride = s->mb_width + 2;
1401
    const int mot_xy = (mb_y + 1)*mot_stride + mb_x + 1;
1399
    const int mot_stride = s->mb_stride;
1400
    const int mot_xy = mb_y*mot_stride + mb_x;
1402 1401
    const int shift= 1+s->quarter_sample;
1403 1402
    int dmin, i;
1404 1403
    const int time_pp= s->pp_time;
......
1410 1409
    ymin= xmin=(-32)>>shift;
1411 1410
    ymax= xmax=   31>>shift;
1412 1411

  
1413
    if(s->co_located_type_table[mb_x + mb_y*s->mb_width]==CO_LOCATED_TYPE_4MV){
1412
    if(IS_8X8(s->next_picture.mb_type[mot_xy])){
1414 1413
        s->mv_type= MV_TYPE_8X8;
1415 1414
    }else{
1416 1415
        s->mv_type= MV_TYPE_16X16;
......
1526 1525
        
1527 1526
        score= ((unsigned)(score*score + 128*256))>>16;
1528 1527
        s->current_picture.mc_mb_var_sum += score;
1529
        s->current_picture.mc_mb_var[mb_y*s->mb_width + mb_x] = score; //FIXME use SSE
1528
        s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
1530 1529
    }
1531 1530

  
1532 1531
    if(s->flags&CODEC_FLAG_HQ){
......
1534 1533
        if(dmin>256*256*16) type&= ~MB_TYPE_DIRECT; //dont try direct mode if its invalid for this MB
1535 1534
    }
1536 1535

  
1537
    s->mb_type[mb_y*s->mb_width + mb_x]= type;
1536
    s->mb_type[mb_y*s->mb_stride + mb_x]= type;
1538 1537
}
1539 1538

  
1540 1539
/* find best f_code for ME which do unlimited searches */
......
1551 1550

  
1552 1551
        for(y=0; y<s->mb_height; y++){
1553 1552
            int x;
1554
            int xy= (y+1)* (s->mb_width+2) + 1;
1555
            i= y*s->mb_width;
1553
            int xy= y*s->mb_stride;
1556 1554
            for(x=0; x<s->mb_width; x++){
1557
                if(s->mb_type[i] & type){
1555
                if(s->mb_type[xy] & type){
1558 1556
                    int fcode= FFMAX(fcode_tab[mv_table[xy][0] + MAX_MV],
1559 1557
                                     fcode_tab[mv_table[xy][1] + MAX_MV]);
1560 1558
                    int j;
1561 1559
                    
1562 1560
                    for(j=0; j<fcode && j<8; j++){
1563
                        if(s->pict_type==B_TYPE || s->current_picture.mc_mb_var[i] < s->current_picture.mb_var[i])
1561
                        if(s->pict_type==B_TYPE || s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy])
1564 1562
                            score[j]-= 170;
1565 1563
                    }
1566 1564
                }
1567
                i++;
1568 1565
                xy++;
1569 1566
            }
1570 1567
        }
......
1602 1599
    /* clip / convert to intra 16x16 type MVs */
1603 1600
    for(y=0; y<s->mb_height; y++){
1604 1601
        int x;
1605
        int xy= (y+1)* (s->mb_width+2)+1;
1606
        int i= y*s->mb_width;
1602
        int xy= y*s->mb_stride;
1607 1603
        for(x=0; x<s->mb_width; x++){
1608
            if(s->mb_type[i]&MB_TYPE_INTER){
1604
            if(s->mb_type[xy]&MB_TYPE_INTER){
1609 1605
                if(   s->p_mv_table[xy][0] >=range || s->p_mv_table[xy][0] <-range
1610 1606
                   || s->p_mv_table[xy][1] >=range || s->p_mv_table[xy][1] <-range){
1611
                    s->mb_type[i] &= ~MB_TYPE_INTER;
1612
                    s->mb_type[i] |= MB_TYPE_INTRA;
1607
                    s->mb_type[xy] &= ~MB_TYPE_INTER;
1608
                    s->mb_type[xy] |= MB_TYPE_INTRA;
1613 1609
                    s->p_mv_table[xy][0] = 0;
1614 1610
                    s->p_mv_table[xy][1] = 0;
1615
//clip++;
1616 1611
                }
1617
//else
1618
//  noclip++;
1619 1612
            }
1620 1613
            xy++;
1621
            i++;
1622 1614
        }
1623 1615
    }
1624 1616
//printf("%d no:%d %d//\n", clip, noclip, f_code);
......
1628 1620
        /* clip / convert to intra 8x8 type MVs */
1629 1621
        for(y=0; y<s->mb_height; y++){
1630 1622
            int xy= (y*2 + 1)*wrap + 1;
1631
            int i= y*s->mb_width;
1623
            int i= y*s->mb_stride;
1632 1624
            int x;
1633 1625

  
1634 1626
            for(x=0; x<s->mb_width; x++){
......
1665 1657
    /* clip / convert to intra 16x16 type MVs */
1666 1658
    for(y=0; y<s->mb_height; y++){
1667 1659
        int x;
1668
        int xy= (y+1)* (s->mb_width+2)+1;
1669
        int i= y*s->mb_width;
1660
        int xy= y*s->mb_stride;
1670 1661
        for(x=0; x<s->mb_width; x++){
1671
            if (s->mb_type[i] & type){    // RAL: "type" test added...
1662
            if (s->mb_type[xy] & type){    // RAL: "type" test added...
1672 1663
                if(   mv_table[xy][0] >=range || mv_table[xy][0] <-range
1673 1664
                   || mv_table[xy][1] >=range || mv_table[xy][1] <-range){
1674 1665

  
......
1682 1673
                }
1683 1674
            }
1684 1675
            xy++;
1685
            i++;
1686 1676
        }
1687 1677
    }
1688 1678
}

Also available in: Unified diff