if (level > 127) level = 127; else if (level < -128) level = -128;
if (level > maxLevel) level = maxLevel; else if (level < minLevel) level = minLevel;
static int dct_quantize_mmx(MpegEncContext *s,                             DCTELEM *block, int n,                            int qscale){    int i, j, level, last_non_zero, q;    const int *qmat;    av_fdct (block);        /* we need this permutation so that we correct the IDCT       permutation. will be moved into DCT code */    block_permute(block);    if (s->mb_intra) {        if (n < 4)            q = s->y_dc_scale;        else            q = s->c_dc_scale;                /* note: block[0] is assumed to be positive */        block[0] = (block[0] + (q >> 1)) / q;        i = 1;        last_non_zero = 0;        if (s->out_format == FMT_H263) {            qmat = s->q_non_intra_matrix;        } else {            qmat = s->q_intra_matrix;        }    } else {        i = 0;        last_non_zero = -1;        qmat = s->q_non_intra_matrix;    }    for(;i<64;i++) {        j = zigzag_direct[i];        level = block[j];        level = level * qmat[j];        /* XXX: slight error for the low range. Test should be equivalent to           (level <= -(1 << (QMAT_SHIFT_MMX - 3)) || level >= (1 <<           (QMAT_SHIFT_MMX - 3)))        */        if (((level << (31 - (QMAT_SHIFT_MMX - 3))) >> (31 - (QMAT_SHIFT_MMX - 3))) !=             level) {            level = level / (1 << (QMAT_SHIFT_MMX - 3));            /* XXX: currently, this code is not optimal. the range should be:               mpeg1: -255..255               mpeg2: -2048..2047               h263:  -128..127               mpeg4: -2048..2047            */            if (level > 127)                level = 127;            else if (level < -128)                level = -128;            block[j] = level;            last_non_zero = i;        } else {            block[j] = 0;        }    }    return last_non_zero;}