Revision 4278e7a6

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);
libavcodec/h263dec.c
140 140
#endif
141 141

  
142 142
    /* decode each macroblock */
143
    s->block_wrap[0]=
144
    s->block_wrap[1]=
145
    s->block_wrap[2]=
146
    s->block_wrap[3]= s->mb_width*2 + 2;
147
    s->block_wrap[4]=
148
    s->block_wrap[5]= s->mb_width + 2;
143 149
    for(s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) {
144 150
        /* Check for GOB headers on H.263 */
145 151
        /* FIXME: In the future H.263+ will have intra prediction */
......
147 153
        if (s->mb_y && !s->h263_pred) {
148 154
            s->first_gob_line = h263_decode_gob_header(s);
149 155
        }
156
        s->block_index[0]= s->block_wrap[0]*(s->mb_y*2 + 1) - 1;
157
        s->block_index[1]= s->block_wrap[0]*(s->mb_y*2 + 1);
158
        s->block_index[2]= s->block_wrap[0]*(s->mb_y*2 + 2) - 1;
159
        s->block_index[3]= s->block_wrap[0]*(s->mb_y*2 + 2);
160
        s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1)                    + s->block_wrap[0]*(s->mb_height*2 + 2);
161
        s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2);
150 162
        for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) {
163
            s->block_index[0]+=2;
164
            s->block_index[1]+=2;
165
            s->block_index[2]+=2;
166
            s->block_index[3]+=2;
167
            s->block_index[4]++;
168
            s->block_index[5]++;
151 169
#ifdef DEBUG
152 170
            printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y);
153 171
#endif
libavcodec/mpegvideo.c
1123 1123
    
1124 1124
    s->avg_mb_var = s->avg_mb_var / s->mb_num;        
1125 1125
    
1126
    s->block_wrap[0]=
1127
    s->block_wrap[1]=
1128
    s->block_wrap[2]=
1129
    s->block_wrap[3]= s->mb_width*2 + 2;
1130
    s->block_wrap[4]=
1131
    s->block_wrap[5]= s->mb_width + 2;
1126 1132
    for(mb_y=0; mb_y < s->mb_height; mb_y++) {
1127 1133
        /* Put GOB header based on RTP MTU */
1128 1134
        /* TODO: Put all this stuff in a separate generic function */
......
1138 1144
            }
1139 1145
        }
1140 1146
        
1147
        s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1;
1148
        s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1);
1149
        s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1;
1150
        s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2);
1151
        s->block_index[4]= s->block_wrap[4]*(mb_y + 1)                    + s->block_wrap[0]*(s->mb_height*2 + 2);
1152
        s->block_index[5]= s->block_wrap[4]*(mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2);
1141 1153
        for(mb_x=0; mb_x < s->mb_width; mb_x++) {
1142 1154

  
1143 1155
            s->mb_x = mb_x;
1144 1156
            s->mb_y = mb_y;
1157
            s->block_index[0]+=2;
1158
            s->block_index[1]+=2;
1159
            s->block_index[2]+=2;
1160
            s->block_index[3]+=2;
1161
            s->block_index[4]++;
1162
            s->block_index[5]++;
1145 1163
#if 0
1146 1164
            /* compute motion vector and macro block type (intra or non intra) */
1147 1165
            motion_x = 0;
libavcodec/mpegvideo.h
72 72
    UINT8 *aux_picture_base[3]; /* real start of the picture */
73 73
    UINT8 *current_picture[3]; /* buffer to store the decompressed current picture */
74 74
    int last_dc[3]; /* last DC values for MPEG1 */
75
    INT16 *dc_val[3]; /* used for mpeg4 DC prediction */
75
    INT16 *dc_val[3]; /* used for mpeg4 DC prediction, all 3 arrays must be continuous */
76 76
    int y_dc_scale, c_dc_scale;
77 77
    UINT8 *coded_block; /* used for coded block pattern prediction */
78
    INT16 (*ac_val[3])[16]; /* used for for mpeg4 AC prediction */
78
    INT16 (*ac_val[3])[16]; /* used for for mpeg4 AC prediction, all 3 arrays must be continuous */
79 79
    int ac_pred;
80 80
    int mb_skiped;              /* MUST BE SET only during DECODING */
81 81
    UINT8 *mbskip_table;        /* used to avoid copy if macroblock
......
123 123
    int mb_intra;
124 124
    INT16 *mb_var;      /* Table for MB variances */
125 125
    char *mb_type;    /* Table for MB type */
126
    
126

  
127
    int block_index[6];
128
    int block_wrap[6];
129

  
127 130
    /* matrix transmitted in the bitstream */
128 131
    UINT16 intra_matrix[64];
129 132
    UINT16 chroma_intra_matrix[64];

Also available in: Unified diff