if(s->all_fragments[i].coeffs[0] && s->all_fragments[i].last_coeff<0) s->all_fragments[i].last_coeff= 0;
static void reverse_dc_prediction(Vp3DecodeContext *s,                                  int first_fragment,                                  int fragment_width,                                  int fragment_height) {#define PUL 8#define PU 4#define PUR 2#define PL 1    int x, y;    int i = first_fragment;    /*     * Fragment prediction groups:     *     * 32222222226     * 10000000004     * 10000000004     * 10000000004     * 10000000004     *     * Note: Groups 5 and 7 do not exist as it would mean that the      * fragment's x coordinate is both 0 and (width - 1) at the same time.     */    int predictor_group;    short predicted_dc;    /* validity flags for the left, up-left, up, and up-right fragments */    int fl, ful, fu, fur;    /* DC values for the left, up-left, up, and up-right fragments */    int vl, vul, vu, vur;    /* indices for the left, up-left, up, and up-right fragments */    int l, ul, u, ur;    /*      * The 6 fields mean:     *   0: up-left multiplier     *   1: up multiplier     *   2: up-right multiplier     *   3: left multiplier     *   4: mask     *   5: right bit shift divisor (e.g., 7 means >>=7, a.k.a. div by 128)     */    int predictor_transform[16][6] = {        {  0,  0,  0,  0,   0,  0 },        {  0,  0,  0,  1,   0,  0 },        // PL        {  0,  0,  1,  0,   0,  0 },        // PUR        {  0,  0, 53, 75, 127,  7 },        // PUR|PL        {  0,  1,  0,  0,   0,  0 },        // PU        {  0,  1,  0,  1,   1,  1 },        // PU|PL        {  0,  1,  0,  0,   0,  0 },        // PU|PUR        {  0,  0, 53, 75, 127,  7 },        // PU|PUR|PL        {  1,  0,  0,  0,   0,  0 },        // PUL        {  0,  0,  0,  1,   0,  0 },        // PUL|PL        {  1,  0,  1,  0,   1,  1 },        // PUL|PUR        {  0,  0, 53, 75, 127,  7 },        // PUL|PUR|PL        {  0,  1,  0,  0,   0,  0 },        // PUL|PU        {-26, 29,  0, 29,  31,  5 },        // PUL|PU|PL        {  3, 10,  3,  0,  15,  4 },        // PUL|PU|PUR        {-26, 29,  0, 29,  31,  5 }         // PUL|PU|PUR|PL    };    /* This table shows which types of blocks can use other blocks for     * prediction. For example, INTRA is the only mode in this table to     * have a frame number of 0. That means INTRA blocks can only predict     * from other INTRA blocks. There are 2 golden frame coding types;      * blocks encoding in these modes can only predict from other blocks     * that were encoded with these 1 of these 2 modes. */    unsigned char compatible_frame[8] = {        1,    /* MODE_INTER_NO_MV */        0,    /* MODE_INTRA */        1,    /* MODE_INTER_PLUS_MV */        1,    /* MODE_INTER_LAST_MV */        1,    /* MODE_INTER_PRIOR_MV */        2,    /* MODE_USING_GOLDEN */        2,    /* MODE_GOLDEN_MV */        1     /* MODE_INTER_FOUR_MV */    };    int current_frame_type;    /* there is a last DC predictor for each of the 3 frame types */    short last_dc[3];    int transform = 0;    debug_vp3("  vp3: reversing DC prediction\n");    vul = vu = vur = vl = 0;    last_dc[0] = last_dc[1] = last_dc[2] = 0;    /* for each fragment row... */    for (y = 0; y < fragment_height; y++) {        /* for each fragment in a row... */        for (x = 0; x < fragment_width; x++, i++) {            /* reverse prediction if this block was coded */            if (s->all_fragments[i].coding_method != MODE_COPY) {                current_frame_type =                     compatible_frame[s->all_fragments[i].coding_method];                predictor_group = (x == 0) + ((y == 0) << 1) +                    ((x + 1 == fragment_width) << 2);                debug_dc_pred(" frag %d: group %d, orig DC = %d, ",                    i, predictor_group, s->all_fragments[i].coeffs[0]);                switch (predictor_group) {                case 0:                    /* main body of fragments; consider all 4 possible                     * fragments for prediction */                    /* calculate the indices of the predicting fragments */                    ul = i - fragment_width - 1;                    u = i - fragment_width;                    ur = i - fragment_width + 1;                    l = i - 1;                    /* fetch the DC values for the predicting fragments */                    vul = s->all_fragments[ul].coeffs[0];                    vu = s->all_fragments[u].coeffs[0];                    vur = s->all_fragments[ur].coeffs[0];                    vl = s->all_fragments[l].coeffs[0];                    /* figure out which fragments are valid */                    ful = FRAME_CODED(ul) && COMPATIBLE_FRAME(ul);                    fu = FRAME_CODED(u) && COMPATIBLE_FRAME(u);                    fur = FRAME_CODED(ur) && COMPATIBLE_FRAME(ur);                    fl = FRAME_CODED(l) && COMPATIBLE_FRAME(l);                    /* decide which predictor transform to use */                    transform = (fl*PL) | (fu*PU) | (ful*PUL) | (fur*PUR);                    break;                case 1:                    /* left column of fragments, not including top corner;                     * only consider up and up-right fragments */                    /* calculate the indices of the predicting fragments */                    u = i - fragment_width;                    ur = i - fragment_width + 1;                    /* fetch the DC values for the predicting fragments */                    vu = s->all_fragments[u].coeffs[0];                    vur = s->all_fragments[ur].coeffs[0];                    /* figure out which fragments are valid */                    fur = FRAME_CODED(ur) && COMPATIBLE_FRAME(ur);                    fu = FRAME_CODED(u) && COMPATIBLE_FRAME(u);                    /* decide which predictor transform to use */                    transform = (fu*PU) | (fur*PUR);                    break;                case 2:                case 6:                    /* top row of fragments, not including top-left frag;                     * only consider the left fragment for prediction */                    /* calculate the indices of the predicting fragments */                    l = i - 1;                    /* fetch the DC values for the predicting fragments */                    vl = s->all_fragments[l].coeffs[0];                    /* figure out which fragments are valid */                    fl = FRAME_CODED(l) && COMPATIBLE_FRAME(l);                    /* decide which predictor transform to use */                    transform = (fl*PL);                    break;                case 3:                    /* top-left fragment */                    /* nothing to predict from in this case */                    transform = 0;                    break;                case 4:                    /* right column of fragments, not including top corner;                     * consider up-left, up, and left fragments for                     * prediction */                    /* calculate the indices of the predicting fragments */                    ul = i - fragment_width - 1;                    u = i - fragment_width;                    l = i - 1;                    /* fetch the DC values for the predicting fragments */                    vul = s->all_fragments[ul].coeffs[0];                    vu = s->all_fragments[u].coeffs[0];                    vl = s->all_fragments[l].coeffs[0];                    /* figure out which fragments are valid */                    ful = FRAME_CODED(ul) && COMPATIBLE_FRAME(ul);                    fu = FRAME_CODED(u) && COMPATIBLE_FRAME(u);                    fl = FRAME_CODED(l) && COMPATIBLE_FRAME(l);                    /* decide which predictor transform to use */                    transform = (fl*PL) | (fu*PU) | (ful*PUL);                    break;                }                debug_dc_pred("transform = %d, ", transform);                if (transform == 0) {                    /* if there were no fragments to predict from, use last                     * DC saved */                    s->all_fragments[i].coeffs[0] += last_dc[current_frame_type];                    debug_dc_pred("from last DC (%d) = %d\n",                         current_frame_type, s->all_fragments[i].coeffs[0]);                } else {                    /* apply the appropriate predictor transform */                    predicted_dc =                        (predictor_transform[transform][0] * vul) +                        (predictor_transform[transform][1] * vu) +                        (predictor_transform[transform][2] * vur) +                        (predictor_transform[transform][3] * vl);                    /* if there is a shift value in the transform, add                     * the sign bit before the shift */                    if (predictor_transform[transform][5] != 0) {                        predicted_dc += ((predicted_dc >> 15) &                             predictor_transform[transform][4]);                        predicted_dc >>= predictor_transform[transform][5];                    }                    /* check for outranging on the [ul u l] and                     * [ul u ur l] predictors */                    if ((transform == 13) || (transform == 15)) {                        if (iabs(predicted_dc - vu) > 128)                            predicted_dc = vu;                        else if (iabs(predicted_dc - vl) > 128)                            predicted_dc = vl;                        else if (iabs(predicted_dc - vul) > 128)                            predicted_dc = vul;                    }                    /* at long last, apply the predictor */                    s->all_fragments[i].coeffs[0] += predicted_dc;                    debug_dc_pred("from pred DC = %d\n",                     s->all_fragments[i].coeffs[0]);                }                /* save the DC */                last_dc[current_frame_type] = s->all_fragments[i].coeffs[0];            }        }    }}