Revision 8f8402e4 libavcodec/h263.c

View differences:

libavcodec/h263.c
50 50
static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
51 51
                              int n, int coded);
52 52
static int h263_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr);
53
static inline int mpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr);
54 53
static void mpeg4_inv_pred_ac(MpegEncContext * s, INT16 *block, int n,
55 54
                              int dir);
56 55
static void mpeg4_decode_sprite_trajectory(MpegEncContext * s);
......
176 175
    }
177 176

  
178 177
    put_bits(&s->pb, 1, 0);	/* no PEI */
178

  
179
    if(s->h263_aic){
180
         s->y_dc_scale_table= 
181
         s->c_dc_scale_table= h263_aic_dc_scale_table;
182
    }else{
183
        s->y_dc_scale_table=
184
        s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
185
    }
179 186
}
180 187

  
181 188
int h263_encode_gob_header(MpegEncContext * s, int mb_line)
......
496 503
            const int level= block[i][0];
497 504
            UINT16 *dc_ptr;
498 505

  
499
            dc_diff[i]= level - mpeg4_pred_dc(s, i, &dc_ptr, &dir[i]);
506
            dc_diff[i]= level - ff_mpeg4_pred_dc(s, i, &dc_ptr, &dir[i]);
500 507
            if (i < 4) {
501 508
                *dc_ptr = level * s->y_dc_scale;
502 509
            } else {
......
1098 1105
        s->min_qcoeff= -128;
1099 1106
        s->max_qcoeff=  127;
1100 1107
        break;
1108
        //Note for mpeg4 & h263 the dc-scale table will be set per frame as needed later 
1101 1109
    default: //nothing needed default table allready set in mpegvideo.c
1102 1110
        s->min_qcoeff= -128;
1103 1111
        s->max_qcoeff=  127;
1112
        s->y_dc_scale_table=
1113
        s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
1104 1114
    }
1105 1115

  
1106 1116
    /* h263 type bias */
......
1326 1336
    if (s->pict_type == B_TYPE)
1327 1337
	put_bits(&s->pb, 3, s->b_code);	/* fcode_back */
1328 1338
    //    printf("****frame %d\n", picture_number);
1339

  
1340
     s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; //FIXME add short header support 
1341
     s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
1329 1342
}
1330 1343

  
1331
void h263_dc_scale(MpegEncContext * s)
1344
static void h263_dc_scale(MpegEncContext * s)
1332 1345
{
1333
#if 1
1334
    const static UINT8 y_tab[32]={
1335
    //  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
1336
        0, 8, 8, 8, 8,10,12,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,34,36,38,40,42,44,46
1337
    };
1338
    const static UINT8 c_tab[32]={
1339
    //  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
1340
        0, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,20,21,22,23,24,25
1341
    };
1342
    s->y_dc_scale = y_tab[s->qscale];
1343
    s->c_dc_scale = c_tab[s->qscale];
1344
#else
1345
    int quant;
1346
    quant = s->qscale;
1347
    /* luminance */
1348
    if (quant < 5)
1349
	s->y_dc_scale = 8;
1350
    else if (quant > 4 && quant < 9)
1351
	s->y_dc_scale = (2 * quant);
1352
    else if (quant > 8 && quant < 25)
1353
	s->y_dc_scale = (quant + 8);
1354
    else
1355
	s->y_dc_scale = (2 * quant - 16);
1356
    /* chrominance */
1357
    if (quant < 5)
1358
	s->c_dc_scale = 8;
1359
    else if (quant > 4 && quant < 25)
1360
	s->c_dc_scale = ((quant + 13) / 2);
1361
    else
1362
	s->c_dc_scale = (quant - 6);
1363
#endif
1346
    s->y_dc_scale= s->y_dc_scale_table[ s->qscale ];
1347
    s->c_dc_scale= s->c_dc_scale_table[ s->qscale ];
1364 1348
}
1365 1349

  
1366
static inline int mpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr)
1350
inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr)
1367 1351
{
1368 1352
    int a, b, c, wrap, pred, scale;
1369 1353
    UINT16 *dc_val;
......
2653 2637
            if (s->ac_pred && s->h263_aic)
2654 2638
                s->h263_aic_dir = get_bits1(&s->gb);
2655 2639
        }
2656
        if (s->h263_aic) {
2657
            s->y_dc_scale = 2 * s->qscale;
2658
            s->c_dc_scale = 2 * s->qscale;
2659
        }
2660 2640
        cbpy = get_vlc(&s->gb, &cbpy_vlc);
2661 2641
        if(cbpy<0) return -1;
2662 2642
        cbp = (cbpc & 3) | (cbpy << 2);
......
2867 2847
        }
2868 2848
    }
2869 2849

  
2870
    pred = mpeg4_pred_dc(s, n, &dc_val, dir_ptr);
2850
    pred = ff_mpeg4_pred_dc(s, n, &dc_val, dir_ptr);
2871 2851
    level += pred;
2872 2852
    if (level < 0)
2873 2853
        level = 0;
......
2956 2936
#if 1 
2957 2937
                    {
2958 2938
                        const int abs_level= ABS(level);
2959
                        int run1;
2960 2939
                        if(abs_level<=MAX_LEVEL && run<=MAX_RUN && s->error_resilience>=0){
2940
                            const int run1= run - rl->max_run[last][abs_level] - 1;
2961 2941
                            if(abs_level <= rl->max_level[last][run]){
2962 2942
                                fprintf(stderr, "illegal 3. esc, vlc encoding possible\n");
2963 2943
                                return DECODING_AC_LOST;
......
2966 2946
                                fprintf(stderr, "illegal 3. esc, esc 1 encoding possible\n");
2967 2947
                                return DECODING_AC_LOST;
2968 2948
                            }
2969
                            run1 = run - rl->max_run[last][abs_level] - 1;
2970 2949
                            if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){
2971 2950
                                fprintf(stderr, "illegal 3. esc, esc 2 encoding possible\n");
2972 2951
                                return DECODING_AC_LOST;
......
3185 3164
        skip_bits(&s->gb, 8);
3186 3165
    }
3187 3166
    s->f_code = 1;
3167
    
3168
    if(s->h263_aic){
3169
         s->y_dc_scale_table= 
3170
         s->c_dc_scale_table= h263_aic_dc_scale_table;
3171
    }else{
3172
        s->y_dc_scale_table=
3173
        s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
3174
    }
3175

  
3188 3176
    return 0;
3189 3177
}
3190 3178

  
......
3626 3614
                }else{
3627 3615
                    printf("hmm, i havnt seen that version of divx yet, lets assume they fixed these bugs ...\n"
3628 3616
                           "using mpeg4 decoder, if it fails contact the developers (of ffmpeg)\n");
3629
#endif 
3617
#endif
3630 3618
                }
3631 3619
            }
3632 3620
        }
......
3760 3748
     s->picture_number++; // better than pic number==0 allways ;)
3761 3749
//printf("done\n");
3762 3750

  
3751
     s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; //FIXME add short header support 
3752
     s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
3753

  
3763 3754
     return 0;
3764 3755
}
3765 3756

  

Also available in: Unified diff