Revision 4278e7a6 libavcodec/h263.c

View differences:

libavcodec/h263.c
208 208
    int i, n;
209 209

  
210 210
    for(n=0; n<6; n++){
211
        int x, y, wrap;
212 211
        INT16 *ac_val, *ac_val1;
213 212

  
214
        if (n < 4) {
215
            x = 2 * s->mb_x + 1 + (n & 1);
216
            y = 2 * s->mb_y + 1 + (n >> 1);
217
            wrap = s->mb_width * 2 + 2;
218
            ac_val = s->ac_val[0][0];
219
        } else {
220
            x = s->mb_x + 1;
221
            y = s->mb_y + 1;
222
            wrap = s->mb_width + 2;
223
            ac_val = s->ac_val[n - 4 + 1][0];
224
        }
225
        ac_val += ((y) * wrap + (x)) * 16;
213
        ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
226 214
        ac_val1= ac_val;
227 215
        if(dir[n]){
228
            ac_val-= wrap*16;
216
            ac_val-= s->block_wrap[n]*16;
229 217
            for(i=1; i<8; i++){
230 218
                const int level= block[n][block_permute_op(i   )];
231 219
                score0+= ABS(level);
......
357 345
        if(s->ac_pred){
358 346
            for(i=0; i<6; i++){
359 347
                int j;    
360
                int x, y, wrap;
361 348
                INT16 *ac_val;
362 349

  
363
                if (i < 4) {
364
                    x = 2 * s->mb_x + 1 + (i & 1);
365
                    y = 2 * s->mb_y + 1 + (i >> 1);
366
                    wrap = s->mb_width * 2 + 2;
367
                    ac_val = s->ac_val[0][0];
368
                } else {
369
                    x = s->mb_x + 1;
370
                    y = s->mb_y + 1;
371
                    wrap = s->mb_width + 2;
372
                    ac_val = s->ac_val[i - 4 + 1][0];
373
                }
374
                ac_val += ((y) * wrap + (x)) * 16;
350
                ac_val = s->ac_val[0][0] + s->block_index[i] * 16;
375 351

  
376 352
                if(dir[i]){
377 353
                    for(j=1; j<8; j++) 
......
569 545
INT16 *h263_pred_motion(MpegEncContext * s, int block, 
570 546
                        int *px, int *py)
571 547
{
572
    int xy, y, wrap;
548
    int xy, wrap;
573 549
    INT16 *A, *B, *C, *mot_val;
574 550
    static const int off[4]= {2, 1, 1, -1};
575 551

  
576
    wrap = 2 * s->mb_width + 2;
577
    y = xy = 2 * s->mb_y + 1 + (block >> 1); // y
578
    xy *= wrap; // y * wrap
579
    xy += 2 * s->mb_x + 1 + (block & 1); // x + y * wrap
552
    wrap = s->block_wrap[0];
553
    xy = s->block_index[block];
580 554

  
581 555
    mot_val = s->motion_val[xy];
582 556

  
583 557
    /* special case for first line */
584
    if (y == 1 || s->first_slice_line || s->first_gob_line) {
558
    if (s->mb_y == 0 || s->first_slice_line || s->first_gob_line) {
585 559
        A = s->motion_val[xy - 1];
586 560
        *px = A[0];
587 561
        *py = A[1];
......
890 864

  
891 865
static inline int mpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr)
892 866
{
893
    int a, b, c, xy, wrap, pred, scale;
867
    int a, b, c, wrap, pred, scale;
894 868
    UINT16 *dc_val;
895 869
    int dummy;
896 870

  
897 871
    /* find prediction */
898 872
    if (n < 4) {
899
	wrap = s->mb_width * 2 + 2;
900
	xy = 2 * s->mb_y + 1 + (n >> 1);
901
        xy *= wrap;
902
	xy += 2 * s->mb_x + 1 + (n & 1);
903
	dc_val = s->dc_val[0];
904 873
	scale = s->y_dc_scale;
905 874
    } else {
906
	wrap = s->mb_width + 2;
907
	xy = s->mb_y + 1;
908
	xy *= wrap;
909
	xy += s->mb_x + 1;
910
	dc_val = s->dc_val[n - 4 + 1];
911 875
	scale = s->c_dc_scale;
912 876
    }
877
    wrap= s->block_wrap[n];
878
    dc_val = s->dc_val[0] + s->block_index[n];
913 879

  
914 880
    /* B C
915 881
     * A X 
916 882
     */
917
    a = dc_val[xy - 1];
918
    b = dc_val[xy - 1 - wrap];
919
    c = dc_val[xy - wrap];
883
    a = dc_val[ - 1];
884
    b = dc_val[ - 1 - wrap];
885
    c = dc_val[ - wrap];
920 886

  
921 887
    if (abs(a - b) < abs(b - c)) {
922 888
	pred = c;
......
938 904
#endif
939 905

  
940 906
    /* prepare address for prediction update */
941
    *dc_val_ptr = &dc_val[xy];
907
    *dc_val_ptr = &dc_val[0];
942 908

  
943 909
    return pred;
944 910
}
......
946 912
void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n,
947 913
                   int dir)
948 914
{
949
    int x, y, wrap, i;
915
    int i;
950 916
    INT16 *ac_val, *ac_val1;
951 917

  
952 918
    /* find prediction */
953
    if (n < 4) {
954
	x = 2 * s->mb_x + 1 + (n & 1);
955
	y = 2 * s->mb_y + 1 + (n >> 1);
956
	wrap = s->mb_width * 2 + 2;
957
	ac_val = s->ac_val[0][0];
958
    } else {
959
	x = s->mb_x + 1;
960
	y = s->mb_y + 1;
961
	wrap = s->mb_width + 2;
962
	ac_val = s->ac_val[n - 4 + 1][0];
963
    }
964
    ac_val += ((y) * wrap + (x)) * 16;
919
    ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
965 920
    ac_val1 = ac_val;
966 921
    if (s->ac_pred) {
967 922
        if (dir == 0) {
......
972 927
            }
973 928
        } else {
974 929
            /* top prediction */
975
            ac_val -= 16 * wrap;
930
            ac_val -= 16 * s->block_wrap[n];
976 931
            for(i=1;i<8;i++) {
977 932
                block[block_permute_op(i)] += ac_val[i + 8];
978 933
            }
......
989 944
static void mpeg4_inv_pred_ac(MpegEncContext * s, INT16 *block, int n,
990 945
                              int dir)
991 946
{
992
    int x, y, wrap, i;
947
    int i;
993 948
    INT16 *ac_val;
994 949

  
995 950
    /* find prediction */
996
    if (n < 4) {
997
	x = 2 * s->mb_x + 1 + (n & 1);
998
	y = 2 * s->mb_y + 1 + (n >> 1);
999
	wrap = s->mb_width * 2 + 2;
1000
	ac_val = s->ac_val[0][0];
1001
    } else {
1002
	x = s->mb_x + 1;
1003
	y = s->mb_y + 1;
1004
	wrap = s->mb_width + 2;
1005
	ac_val = s->ac_val[n - 4 + 1][0];
1006
    }
1007
    ac_val += ((y) * wrap + (x)) * 16;
951
    ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
1008 952
 
1009 953
    if (dir == 0) {
1010 954
        /* left prediction */
......
1014 958
        }
1015 959
    } else {
1016 960
        /* top prediction */
1017
        ac_val -= 16 * wrap;
961
        ac_val -= 16 * s->block_wrap[n];
1018 962
        for(i=1;i<8;i++) {
1019 963
            block[block_permute_op(i)] -= ac_val[i + 8];
1020 964
        }
......
1448 1392
            my = h263_decode_motion(s, 0, 1);
1449 1393
        case 4: 
1450 1394
            s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
1451
            xy= (2*s->mb_width + 2)*(2*s->mb_y + 1) + 2*s->mb_x + 1;
1395
            xy= s->block_index[0];
1452 1396
            time_pp= s->last_non_b_time[0] - s->last_non_b_time[1];
1453 1397
            time_pb= s->time - s->last_non_b_time[1];
1454 1398
//if(time_pp>3000 )printf("%d %d  ", time_pp, time_pb);

Also available in: Unified diff