static void render_fragments(Vp3DecodeContext *s,

                             int first_fragment,

                             int width,

                             int height,

                             int plane /* 0 = Y, 1 = U, 2 = V */) 

{

    int x, y;

    int m, n;

    int i = first_fragment;

    int j;

    int16_t *dequantizer;

    DCTELEM dequant_block[64];

    unsigned char *output_plane;

    unsigned char *last_plane;

    unsigned char *golden_plane;

    int stride;

    int motion_x, motion_y;

    int motion_x_limit, motion_y_limit;

    int motion_halfpel_index;

    unsigned int motion_source;



    debug_vp3("  vp3: rendering final fragments for %s\n",

        (plane == 0) ? "Y plane" : (plane == 1) ? "U plane" : "V plane");



    /* set up plane-specific parameters */

    if (plane == 0) {

        dequantizer = s->intra_y_dequant;

        output_plane = s->current_frame.data[0];

        last_plane = s->last_frame.data[0];

        golden_plane = s->golden_frame.data[0];

        stride = -s->current_frame.linesize[0];

    } else if (plane == 1) {

        dequantizer = s->intra_c_dequant;

        output_plane = s->current_frame.data[1];

        last_plane = s->last_frame.data[1];

        golden_plane = s->golden_frame.data[1];

        stride = -s->current_frame.linesize[1];

    } else {

        dequantizer = s->intra_c_dequant;

        output_plane = s->current_frame.data[2];

        last_plane = s->last_frame.data[2];

        golden_plane = s->golden_frame.data[2];

        stride = -s->current_frame.linesize[2];

    }



    motion_x_limit = width - 8;

    motion_y_limit = height - 8;



    /* for each fragment row... */

    for (y = 0; y < height; y += 8) {



        /* for each fragment in a row... */

        for (x = 0; x < width; x += 8, i++) {



            /* transform if this block was coded */

            if (s->all_fragments[i].coding_method != MODE_COPY) {



                /* sort out the motion vector */

                motion_x = s->all_fragments[i].motion_x;

                motion_y = s->all_fragments[i].motion_y;

                motion_halfpel_index = s->all_fragments[i].motion_halfpel_index;

/*



                if (motion_x < 0)

                    motion_x = 0;

                if (motion_y < 0)

                    motion_y = 0;

                if (motion_x > motion_x_limit)

                    motion_x = motion_x_limit;

                if (motion_y > motion_y_limit)

                    motion_y = motion_y_limit;

*/

                motion_source = s->all_fragments[i].first_pixel;

                motion_source += motion_x;

                motion_source += (motion_y * stride);



                /* first, take care of copying a block from either the

                 * previous or the golden frame */

                if ((s->all_fragments[i].coding_method == MODE_USING_GOLDEN) ||

                    (s->all_fragments[i].coding_method == MODE_GOLDEN_MV)) {



                    s->dsp.put_pixels_tab[1][motion_halfpel_index](

                        output_plane + s->all_fragments[i].first_pixel,

                        golden_plane + motion_source,

                        stride, 8);



                } else 

                if (s->all_fragments[i].coding_method != MODE_INTRA) {



                    s->dsp.put_pixels_tab[1][motion_halfpel_index](

                        output_plane + s->all_fragments[i].first_pixel,

                        last_plane + motion_source,

                        stride, 8);

                }



                /* dequantize the DCT coefficients */

                debug_idct("fragment %d, coding mode %d, DC = %d, dequant = %d:\n", 

                    i, s->all_fragments[i].coding_method, 

                    s->all_fragments[i].coeffs[0], dequantizer[0]);

                for (j = 0; j < 64; j++)

                    dequant_block[dequant_index[j]] =

                        s->all_fragments[i].coeffs[j] *

                        dequantizer[j];



                debug_idct("dequantized block:\n");

                for (m = 0; m < 8; m++) {

                    for (n = 0; n < 8; n++) {

                        debug_idct(" %5d", dequant_block[m * 8 + n]);

                    }

                    debug_idct("\n");

                }

                debug_idct("\n");



                /* invert DCT and place (or add) in final output */



                if (s->all_fragments[i].coding_method == MODE_INTRA) {

                    dequant_block[0] += 1024;

                    s->dsp.idct_put(

                        output_plane + s->all_fragments[i].first_pixel,

                        stride, dequant_block);

                } else {

                    s->dsp.idct_add(

                        output_plane + s->all_fragments[i].first_pixel,

                        stride, dequant_block);

                }



                debug_idct("block after idct_%s():\n",

                    (s->all_fragments[i].coding_method == MODE_INTRA)?

                    "put" : "add");

                for (m = 0; m < 8; m++) {

                    for (n = 0; n < 8; n++) {

                        debug_idct(" %3d", *(output_plane + 

                            s->all_fragments[i].first_pixel + (m * stride + n)));

                    }

                    debug_idct("\n");

                }

                debug_idct("\n");



            } else {



                /* copy directly from the previous frame */

                s->dsp.put_pixels_tab[1][0](

                    output_plane + s->all_fragments[i].first_pixel,

                    last_plane + s->all_fragments[i].first_pixel,

                    stride, 8);



            }

        }

    }



    emms_c();



}

static void render_fragments(Vp3DecodeContext *s,

                             int first_fragment,

                             int width,

                             int height,

                             int plane ) 

{

    int x, y;

    int m, n;

    int i = first_fragment;

    int j;

    int16_t *dequantizer;

    DCTELEM dequant_block[64];

    unsigned char *output_plane;

    unsigned char *last_plane;

    unsigned char *golden_plane;

    int stride;

    int motion_x, motion_y;

    int motion_x_limit, motion_y_limit;

    int motion_halfpel_index;

    unsigned int motion_source;



    debug_vp3("  vp3: rendering final fragments for %s\n",

        (plane == 0) ? "Y plane" : (plane == 1) ? "U plane" : "V plane");



    

    if (plane == 0) {

        dequantizer = s->intra_y_dequant;

        output_plane = s->current_frame.data[0];

        last_plane = s->last_frame.data[0];

        golden_plane = s->golden_frame.data[0];

        stride = -s->current_frame.linesize[0];

    } else if (plane == 1) {

        dequantizer = s->intra_c_dequant;

        output_plane = s->current_frame.data[1];

        last_plane = s->last_frame.data[1];

        golden_plane = s->golden_frame.data[1];

        stride = -s->current_frame.linesize[1];

    } else {

        dequantizer = s->intra_c_dequant;

        output_plane = s->current_frame.data[2];

        last_plane = s->last_frame.data[2];

        golden_plane = s->golden_frame.data[2];

        stride = -s->current_frame.linesize[2];

    }



    motion_x_limit = width - 8;

    motion_y_limit = height - 8;



    

    for (y = 0; y < height; y += 8) {



        

        for (x = 0; x < width; x += 8, i++) {



            

            if (s->all_fragments[i].coding_method != MODE_COPY) {



                

                motion_x = s->all_fragments[i].motion_x;

                motion_y = s->all_fragments[i].motion_y;

                motion_halfpel_index = s->all_fragments[i].motion_halfpel_index;























                motion_source = s->all_fragments[i].first_pixel;

                motion_source += motion_x;

                motion_source += (motion_y * stride);



                



                if ((s->all_fragments[i].coding_method == MODE_USING_GOLDEN) ||

                    (s->all_fragments[i].coding_method == MODE_GOLDEN_MV)) {



                    s->dsp.put_pixels_tab[1][motion_halfpel_index](

                        output_plane + s->all_fragments[i].first_pixel,

                        golden_plane + motion_source,

                        stride, 8);



                } else 

                if (s->all_fragments[i].coding_method != MODE_INTRA) {



                    s->dsp.put_pixels_tab[1][motion_halfpel_index](

                        output_plane + s->all_fragments[i].first_pixel,

                        last_plane + motion_source,

                        stride, 8);

                }



                

                debug_idct("fragment %d, coding mode %d, DC = %d, dequant = %d:\n", 

                    i, s->all_fragments[i].coding_method, 

                    s->all_fragments[i].coeffs[0], dequantizer[0]);

                for (j = 0; j < 64; j++)

                    dequant_block[dequant_index[j]] =

                        s->all_fragments[i].coeffs[j] *

                        dequantizer[j];



                debug_idct("dequantized block:\n");

                for (m = 0; m < 8; m++) {

                    for (n = 0; n < 8; n++) {

                        debug_idct(" %5d", dequant_block[m * 8 + n]);

                    }

                    debug_idct("\n");

                }

                debug_idct("\n");



                



                if (s->all_fragments[i].coding_method == MODE_INTRA) {

                    dequant_block[0] += 1024;

                    s->dsp.idct_put(

                        output_plane + s->all_fragments[i].first_pixel,

                        stride, dequant_block);

                } else {

                    s->dsp.idct_add(

                        output_plane + s->all_fragments[i].first_pixel,

                        stride, dequant_block);

                }



                debug_idct("block after idct_%s():\n",

                    (s->all_fragments[i].coding_method == MODE_INTRA)?

                    "put" : "add");

                for (m = 0; m < 8; m++) {

                    for (n = 0; n < 8; n++) {

                        debug_idct(" %3d", *(output_plane + 

                            s->all_fragments[i].first_pixel + (m * stride + n)));

                    }

                    debug_idct("\n");

                }

                debug_idct("\n");



            } else {



                

                s->dsp.put_pixels_tab[1][0](

                    output_plane + s->all_fragments[i].first_pixel,

                    last_plane + s->all_fragments[i].first_pixel,

                    stride, 8);



            }

        }

    }



    emms_c();



}

static void FUNC_0(Vp3DecodeContext *VAR_0,

                             int VAR_1,

                             int VAR_2,

                             int VAR_3,

                             int VAR_4 ) 

{

    int VAR_5, VAR_6;

    int VAR_7, VAR_8;

    int VAR_9 = VAR_1;

    int VAR_10;

    int16_t *dequantizer;

    DCTELEM dequant_block[64];

    unsigned char *VAR_11;

    unsigned char *VAR_12;

    unsigned char *VAR_13;

    int VAR_14;

    int VAR_15, VAR_16;

    int VAR_17, VAR_18;

    int VAR_19;

    unsigned int VAR_20;



    debug_vp3("  vp3: rendering final fragments for %VAR_0\VAR_8",

        (VAR_4 == 0) ? "Y VAR_4" : (VAR_4 == 1) ? "U VAR_4" : "V VAR_4");



    

    if (VAR_4 == 0) {

        dequantizer = VAR_0->intra_y_dequant;

        VAR_11 = VAR_0->current_frame.data[0];

        VAR_12 = VAR_0->last_frame.data[0];

        VAR_13 = VAR_0->golden_frame.data[0];

        VAR_14 = -VAR_0->current_frame.linesize[0];

    } else if (VAR_4 == 1) {

        dequantizer = VAR_0->intra_c_dequant;

        VAR_11 = VAR_0->current_frame.data[1];

        VAR_12 = VAR_0->last_frame.data[1];

        VAR_13 = VAR_0->golden_frame.data[1];

        VAR_14 = -VAR_0->current_frame.linesize[1];

    } else {

        dequantizer = VAR_0->intra_c_dequant;

        VAR_11 = VAR_0->current_frame.data[2];

        VAR_12 = VAR_0->last_frame.data[2];

        VAR_13 = VAR_0->golden_frame.data[2];

        VAR_14 = -VAR_0->current_frame.linesize[2];

    }



    VAR_17 = VAR_2 - 8;

    VAR_18 = VAR_3 - 8;



    

    for (VAR_6 = 0; VAR_6 < VAR_3; VAR_6 += 8) {



        

        for (VAR_5 = 0; VAR_5 < VAR_2; VAR_5 += 8, VAR_9++) {



            

            if (VAR_0->all_fragments[VAR_9].coding_method != MODE_COPY) {



                

                VAR_15 = VAR_0->all_fragments[VAR_9].VAR_15;

                VAR_16 = VAR_0->all_fragments[VAR_9].VAR_16;

                VAR_19 = VAR_0->all_fragments[VAR_9].VAR_19;























                VAR_20 = VAR_0->all_fragments[VAR_9].first_pixel;

                VAR_20 += VAR_15;

                VAR_20 += (VAR_16 * VAR_14);



                



                if ((VAR_0->all_fragments[VAR_9].coding_method == MODE_USING_GOLDEN) ||

                    (VAR_0->all_fragments[VAR_9].coding_method == MODE_GOLDEN_MV)) {



                    VAR_0->dsp.put_pixels_tab[1][VAR_19](

                        VAR_11 + VAR_0->all_fragments[VAR_9].first_pixel,

                        VAR_13 + VAR_20,

                        VAR_14, 8);



                } else 

                if (VAR_0->all_fragments[VAR_9].coding_method != MODE_INTRA) {



                    VAR_0->dsp.put_pixels_tab[1][VAR_19](

                        VAR_11 + VAR_0->all_fragments[VAR_9].first_pixel,

                        VAR_12 + VAR_20,

                        VAR_14, 8);

                }



                

                debug_idct("fragment %d, coding mode %d, DC = %d, dequant = %d:\VAR_8", 

                    VAR_9, VAR_0->all_fragments[VAR_9].coding_method, 

                    VAR_0->all_fragments[VAR_9].coeffs[0], dequantizer[0]);

                for (VAR_10 = 0; VAR_10 < 64; VAR_10++)

                    dequant_block[dequant_index[VAR_10]] =

                        VAR_0->all_fragments[VAR_9].coeffs[VAR_10] *

                        dequantizer[VAR_10];



                debug_idct("dequantized block:\VAR_8");

                for (VAR_7 = 0; VAR_7 < 8; VAR_7++) {

                    for (VAR_8 = 0; VAR_8 < 8; VAR_8++) {

                        debug_idct(" %5d", dequant_block[VAR_7 * 8 + VAR_8]);

                    }

                    debug_idct("\VAR_8");

                }

                debug_idct("\VAR_8");



                



                if (VAR_0->all_fragments[VAR_9].coding_method == MODE_INTRA) {

                    dequant_block[0] += 1024;

                    VAR_0->dsp.idct_put(

                        VAR_11 + VAR_0->all_fragments[VAR_9].first_pixel,

                        VAR_14, dequant_block);

                } else {

                    VAR_0->dsp.idct_add(

                        VAR_11 + VAR_0->all_fragments[VAR_9].first_pixel,

                        VAR_14, dequant_block);

                }



                debug_idct("block after idct_%VAR_0():\VAR_8",

                    (VAR_0->all_fragments[VAR_9].coding_method == MODE_INTRA)?

                    "put" : "add");

                for (VAR_7 = 0; VAR_7 < 8; VAR_7++) {

                    for (VAR_8 = 0; VAR_8 < 8; VAR_8++) {

                        debug_idct(" %3d", *(VAR_11 + 

                            VAR_0->all_fragments[VAR_9].first_pixel + (VAR_7 * VAR_14 + VAR_8)));

                    }

                    debug_idct("\VAR_8");

                }

                debug_idct("\VAR_8");



            } else {



                

                VAR_0->dsp.put_pixels_tab[1][0](

                    VAR_11 + VAR_0->all_fragments[VAR_9].first_pixel,

                    VAR_12 + VAR_0->all_fragments[VAR_9].first_pixel,

                    VAR_14, 8);



            }

        }

    }



    emms_c();



}

static void FUNC_0(Vp3DecodeContext *VAR_0,
int VAR_1,
int VAR_2,
int VAR_3,
int VAR_4 )
{ int VAR_5, VAR_6; int VAR_7, VAR_8; int VAR_9 = VAR_1; int VAR_10; int16_t *dequantizer; DCTELEM dequant_block[64]; unsigned char *VAR_11; unsigned char *VAR_12; unsigned char *VAR_13; int VAR_14; int VAR_15, VAR_16; int VAR_17, VAR_18; int VAR_19; unsigned int VAR_20; debug_vp3("  vp3: rendering final fragments for %VAR_0\VAR_8",
(VAR_4 == 0) ? "Y VAR_4" : (VAR_4 == 1) ? "U VAR_4" : "V VAR_4"); if (VAR_4 == 0) { dequantizer = VAR_0->intra_y_dequant; VAR_11 = VAR_0->current_frame.data[0]; VAR_12 = VAR_0->last_frame.data[0]; VAR_13 = VAR_0->golden_frame.data[0]; VAR_14 = -VAR_0->current_frame.linesize[0]; } else if (VAR_4 == 1) { dequantizer = VAR_0->intra_c_dequant; VAR_11 = VAR_0->current_frame.data[1]; VAR_12 = VAR_0->last_frame.data[1]; VAR_13 = VAR_0->golden_frame.data[1]; VAR_14 = -VAR_0->current_frame.linesize[1]; } else { dequantizer = VAR_0->intra_c_dequant; VAR_11 = VAR_0->current_frame.data[2]; VAR_12 = VAR_0->last_frame.data[2]; VAR_13 = VAR_0->golden_frame.data[2]; VAR_14 = -VAR_0->current_frame.linesize[2]; } VAR_17 = VAR_2 - 8; VAR_18 = VAR_3 - 8; for (VAR_6 = 0; VAR_6 < VAR_3; VAR_6 += 8) { for (VAR_5 = 0; VAR_5 < VAR_2; VAR_5 += 8, VAR_9++) { if (VAR_0->all_fragments[VAR_9].coding_method != MODE_COPY) { VAR_15 = VAR_0->all_fragments[VAR_9].VAR_15; VAR_16 = VAR_0->all_fragments[VAR_9].VAR_16; VAR_19 = VAR_0->all_fragments[VAR_9].VAR_19; VAR_20 = VAR_0->all_fragments[VAR_9].first_pixel; VAR_20 += VAR_15; VAR_20 += (VAR_16 * VAR_14); if ((VAR_0->all_fragments[VAR_9].coding_method == MODE_USING_GOLDEN) ||
(VAR_0->all_fragments[VAR_9].coding_method == MODE_GOLDEN_MV)) { VAR_0->dsp.put_pixels_tab[1][VAR_19](
VAR_11 + VAR_0->all_fragments[VAR_9].first_pixel,
VAR_13 + VAR_20,
VAR_14, 8); } else if (VAR_0->all_fragments[VAR_9].coding_method != MODE_INTRA) { VAR_0->dsp.put_pixels_tab[1][VAR_19](
VAR_11 + VAR_0->all_fragments[VAR_9].first_pixel,
VAR_12 + VAR_20,
VAR_14, 8); } debug_idct("fragment %d, coding mode %d, DC = %d, dequant = %d:\VAR_8",
VAR_9, VAR_0->all_fragments[VAR_9].coding_method,
VAR_0->all_fragments[VAR_9].coeffs[0], dequantizer[0]); for (VAR_10 = 0; VAR_10 < 64; VAR_10++) dequant_block[dequant_index[VAR_10]] =
VAR_0->all_fragments[VAR_9].coeffs[VAR_10] *
dequantizer[VAR_10]; debug_idct("dequantized block:\VAR_8"); for (VAR_7 = 0; VAR_7 < 8; VAR_7++) { for (VAR_8 = 0; VAR_8 < 8; VAR_8++) { debug_idct(" %5d", dequant_block[VAR_7 * 8 + VAR_8]); } debug_idct("\VAR_8"); } debug_idct("\VAR_8"); if (VAR_0->all_fragments[VAR_9].coding_method == MODE_INTRA) { dequant_block[0] += 1024; VAR_0->dsp.idct_put(
VAR_11 + VAR_0->all_fragments[VAR_9].first_pixel,
VAR_14, dequant_block); } else { VAR_0->dsp.idct_add(
VAR_11 + VAR_0->all_fragments[VAR_9].first_pixel,
VAR_14, dequant_block); } debug_idct("block after idct_%VAR_0():\VAR_8",
(VAR_0->all_fragments[VAR_9].coding_method == MODE_INTRA)?
"put" : "add"); for (VAR_7 = 0; VAR_7 < 8; VAR_7++) { for (VAR_8 = 0; VAR_8 < 8; VAR_8++) { debug_idct(" %3d", *(VAR_11 +
VAR_0->all_fragments[VAR_9].first_pixel + (VAR_7 * VAR_14 + VAR_8))); } debug_idct("\VAR_8"); } debug_idct("\VAR_8"); } else { VAR_0->dsp.put_pixels_tab[1][0](
VAR_11 + VAR_0->all_fragments[VAR_9].first_pixel,
VAR_12 + VAR_0->all_fragments[VAR_9].first_pixel,
VAR_14, 8); } } } emms_c(); }