Revision f66e4f5f libavcodec/h264.c

View differences:

libavcodec/h264.c
1322 1322
    int i;
1323 1323
    for(i=0; i<h->ref_count[0]; i++){
1324 1324
        int poc0 = h->ref_list[0][i].poc;
1325
        int td = clip(poc1 - poc0, -128, 127);
1325
        int td = av_clip(poc1 - poc0, -128, 127);
1326 1326
        if(td == 0 /* FIXME || pic0 is a long-term ref */){
1327 1327
            h->dist_scale_factor[i] = 256;
1328 1328
        }else{
1329
            int tb = clip(poc - poc0, -128, 127);
1329
            int tb = av_clip(poc - poc0, -128, 127);
1330 1330
            int tx = (16384 + (FFABS(td) >> 1)) / td;
1331
            h->dist_scale_factor[i] = clip((tb*tx + 32) >> 6, -1024, 1023);
1331
            h->dist_scale_factor[i] = av_clip((tb*tx + 32) >> 6, -1024, 1023);
1332 1332
        }
1333 1333
    }
1334 1334
    if(FRAME_MBAFF){
......
1948 1948
 */
1949 1949
static inline int get_chroma_qp(int chroma_qp_index_offset, int qscale){
1950 1950

  
1951
    return chroma_qp[clip(qscale + chroma_qp_index_offset, 0, 51)];
1951
    return chroma_qp[av_clip(qscale + chroma_qp_index_offset, 0, 51)];
1952 1952
}
1953 1953

  
1954 1954
//FIXME need to check that this doesnt overflow signed 32 bit for low qp, i am not sure, it's very close
......
4122 4122
        int poc0 = h->ref_list[0][ref0].poc;
4123 4123
        for(ref1=0; ref1 < h->ref_count[1]; ref1++){
4124 4124
            int poc1 = h->ref_list[1][ref1].poc;
4125
            int td = clip(poc1 - poc0, -128, 127);
4125
            int td = av_clip(poc1 - poc0, -128, 127);
4126 4126
            if(td){
4127
                int tb = clip(cur_poc - poc0, -128, 127);
4127
                int tb = av_clip(cur_poc - poc0, -128, 127);
4128 4128
                int tx = (16384 + (FFABS(td) >> 1)) / td;
4129
                int dist_scale_factor = clip((tb*tx + 32) >> 6, -1024, 1023) >> 2;
4129
                int dist_scale_factor = av_clip((tb*tx + 32) >> 6, -1024, 1023) >> 2;
4130 4130
                if(dist_scale_factor < -64 || dist_scale_factor > 128)
4131 4131
                    h->implicit_weight[ref0][ref1] = 32;
4132 4132
                else
......
6814 6814
                int i_delta;
6815 6815

  
6816 6816
                if( FFABS( p2 - p0 ) < beta ) {
6817
                    pix[-2] = p1 + clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 );
6817
                    pix[-2] = p1 + av_clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 );
6818 6818
                    tc++;
6819 6819
                }
6820 6820
                if( FFABS( q2 - q0 ) < beta ) {
6821
                    pix[1] = q1 + clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 );
6821
                    pix[1] = q1 + av_clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 );
6822 6822
                    tc++;
6823 6823
                }
6824 6824

  
6825
                i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
6826
                pix[-1] = clip_uint8( p0 + i_delta );    /* p0' */
6827
                pix[0]  = clip_uint8( q0 - i_delta );    /* q0' */
6825
                i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
6826
                pix[-1] = av_clip_uint8( p0 + i_delta );    /* p0' */
6827
                pix[0]  = av_clip_uint8( q0 - i_delta );    /* q0' */
6828 6828
                tprintf("filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1);
6829 6829
            }
6830 6830
        }else{
......
6902 6902
            if( FFABS( p0 - q0 ) < alpha &&
6903 6903
                FFABS( p1 - p0 ) < beta &&
6904 6904
                FFABS( q1 - q0 ) < beta ) {
6905
                const int i_delta = clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
6905
                const int i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );
6906 6906

  
6907
                pix[-1] = clip_uint8( p0 + i_delta );    /* p0' */
6908
                pix[0]  = clip_uint8( q0 - i_delta );    /* q0' */
6907
                pix[-1] = av_clip_uint8( p0 + i_delta );    /* p0' */
6908
                pix[0]  = av_clip_uint8( q0 - i_delta );    /* q0' */
6909 6909
                tprintf("filter_mb_mbaff_edgecv i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1);
6910 6910
            }
6911 6911
        }else{
......
7387 7387
        for( i= 0; i < 460; i++ ) {
7388 7388
            int pre;
7389 7389
            if( h->slice_type == I_TYPE )
7390
                pre = clip( ((cabac_context_init_I[i][0] * s->qscale) >>4 ) + cabac_context_init_I[i][1], 1, 126 );
7390
                pre = av_clip( ((cabac_context_init_I[i][0] * s->qscale) >>4 ) + cabac_context_init_I[i][1], 1, 126 );
7391 7391
            else
7392
                pre = clip( ((cabac_context_init_PB[h->cabac_init_idc][i][0] * s->qscale) >>4 ) + cabac_context_init_PB[h->cabac_init_idc][i][1], 1, 126 );
7392
                pre = av_clip( ((cabac_context_init_PB[h->cabac_init_idc][i][0] * s->qscale) >>4 ) + cabac_context_init_PB[h->cabac_init_idc][i][1], 1, 126 );
7393 7393

  
7394 7394
            if( pre <= 63 )
7395 7395
                h->cabac_state[i] = 2 * ( 63 - pre ) + 0;

Also available in: Unified diff