static void guess_dc(MpegEncContext *s, int16_t *dc, int w,

                     int h, int stride, int is_luma)

{

    int b_x, b_y;

    int16_t  (*col )[4] = av_malloc(stride*h*sizeof( int16_t)*4);

    uint32_t (*dist)[4] = av_malloc(stride*h*sizeof(uint32_t)*4);



    for(b_y=0; b_y<h; b_y++){

        int color= 1024;

        int distance= -1;

        for(b_x=0; b_x<w; b_x++){

            int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;

            int error_j= s->error_status_table[mb_index_j];

            int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);

            if(intra_j==0 || !(error_j&ER_DC_ERROR)){

                color= dc[b_x + b_y*stride];

                distance= b_x;

            }

            col [b_x + b_y*stride][1]= color;

            dist[b_x + b_y*stride][1]= distance >= 0 ? b_x-distance : 9999;

        }

        color= 1024;

        distance= -1;

        for(b_x=w-1; b_x>=0; b_x--){

            int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;

            int error_j= s->error_status_table[mb_index_j];

            int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);

            if(intra_j==0 || !(error_j&ER_DC_ERROR)){

                color= dc[b_x + b_y*stride];

                distance= b_x;

            }

            col [b_x + b_y*stride][0]= color;

            dist[b_x + b_y*stride][0]= distance >= 0 ? distance-b_x : 9999;

        }

    }

    for(b_x=0; b_x<w; b_x++){

        int color= 1024;

        int distance= -1;

        for(b_y=0; b_y<h; b_y++){

            int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;

            int error_j= s->error_status_table[mb_index_j];

            int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);

            if(intra_j==0 || !(error_j&ER_DC_ERROR)){

                color= dc[b_x + b_y*stride];

                distance= b_y;

            }

            col [b_x + b_y*stride][3]= color;

            dist[b_x + b_y*stride][3]= distance >= 0 ? b_y-distance : 9999;

        }

        color= 1024;

        distance= -1;

        for(b_y=h-1; b_y>=0; b_y--){

            int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;

            int error_j= s->error_status_table[mb_index_j];

            int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);

            if(intra_j==0 || !(error_j&ER_DC_ERROR)){

                color= dc[b_x + b_y*stride];

                distance= b_y;

            }

            col [b_x + b_y*stride][2]= color;

            dist[b_x + b_y*stride][2]= distance >= 0 ? distance-b_y : 9999;

        }

    }



    for (b_y = 0; b_y < h; b_y++) {

        for (b_x = 0; b_x < w; b_x++) {

            int mb_index, error, j;

            int64_t guess, weight_sum;

            mb_index = (b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride;

            error    = s->error_status_table[mb_index];



            if (IS_INTER(s->current_picture.f.mb_type[mb_index]))

                continue; // inter

            if (!(error & ER_DC_ERROR))

                continue; // dc-ok



            weight_sum = 0;

            guess      = 0;

            for (j = 0; j < 4; j++) {

                int64_t weight  = 256 * 256 * 256 * 16 / dist[b_x + b_y*stride][j];

                guess          += weight*(int64_t)col[b_x + b_y*stride][j];

                weight_sum     += weight;

            }

            guess = (guess + weight_sum / 2) / weight_sum;

            dc[b_x + b_y * stride] = guess;

        }

    }

    av_freep(&col);

    av_freep(&dist);

}

static void guess_dc(MpegEncContext *s, int16_t *dc, int w,

                     int h, int stride, int is_luma)

{

    int b_x, b_y;

    int16_t  (*col )[4] = av_malloc(stride*h*sizeof( int16_t)*4);

    uint32_t (*dist)[4] = av_malloc(stride*h*sizeof(uint32_t)*4);



    for(b_y=0; b_y<h; b_y++){

        int color= 1024;

        int distance= -1;

        for(b_x=0; b_x<w; b_x++){

            int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;

            int error_j= s->error_status_table[mb_index_j];

            int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);

            if(intra_j==0 || !(error_j&ER_DC_ERROR)){

                color= dc[b_x + b_y*stride];

                distance= b_x;

            }

            col [b_x + b_y*stride][1]= color;

            dist[b_x + b_y*stride][1]= distance >= 0 ? b_x-distance : 9999;

        }

        color= 1024;

        distance= -1;

        for(b_x=w-1; b_x>=0; b_x--){

            int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;

            int error_j= s->error_status_table[mb_index_j];

            int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);

            if(intra_j==0 || !(error_j&ER_DC_ERROR)){

                color= dc[b_x + b_y*stride];

                distance= b_x;

            }

            col [b_x + b_y*stride][0]= color;

            dist[b_x + b_y*stride][0]= distance >= 0 ? distance-b_x : 9999;

        }

    }

    for(b_x=0; b_x<w; b_x++){

        int color= 1024;

        int distance= -1;

        for(b_y=0; b_y<h; b_y++){

            int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;

            int error_j= s->error_status_table[mb_index_j];

            int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);

            if(intra_j==0 || !(error_j&ER_DC_ERROR)){

                color= dc[b_x + b_y*stride];

                distance= b_y;

            }

            col [b_x + b_y*stride][3]= color;

            dist[b_x + b_y*stride][3]= distance >= 0 ? b_y-distance : 9999;

        }

        color= 1024;

        distance= -1;

        for(b_y=h-1; b_y>=0; b_y--){

            int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;

            int error_j= s->error_status_table[mb_index_j];

            int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);

            if(intra_j==0 || !(error_j&ER_DC_ERROR)){

                color= dc[b_x + b_y*stride];

                distance= b_y;

            }

            col [b_x + b_y*stride][2]= color;

            dist[b_x + b_y*stride][2]= distance >= 0 ? distance-b_y : 9999;

        }

    }



    for (b_y = 0; b_y < h; b_y++) {

        for (b_x = 0; b_x < w; b_x++) {

            int mb_index, error, j;

            int64_t guess, weight_sum;

            mb_index = (b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride;

            error    = s->error_status_table[mb_index];



            if (IS_INTER(s->current_picture.f.mb_type[mb_index]))

                continue; 

            if (!(error & ER_DC_ERROR))

                continue; 



            weight_sum = 0;

            guess      = 0;

            for (j = 0; j < 4; j++) {

                int64_t weight  = 256 * 256 * 256 * 16 / dist[b_x + b_y*stride][j];

                guess          += weight*(int64_t)col[b_x + b_y*stride][j];

                weight_sum     += weight;

            }

            guess = (guess + weight_sum / 2) / weight_sum;

            dc[b_x + b_y * stride] = guess;

        }

    }

    av_freep(&col);

    av_freep(&dist);

}

                int64_t weight  = 256 * 256 * 256 * 16 / dist[b_x + b_y*stride][j];
static void FUNC_0(MpegEncContext *VAR_0, int16_t *VAR_1, int VAR_2,

                     int VAR_3, int VAR_4, int VAR_5)

{

    int VAR_6, VAR_7;

    int16_t  (*col )[4] = av_malloc(VAR_4*VAR_3*sizeof( int16_t)*4);

    uint32_t (*dist)[4] = av_malloc(VAR_4*VAR_3*sizeof(uint32_t)*4);



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

        int VAR_13= 1024;

        int VAR_13= -1;

        for(VAR_6=0; VAR_6<VAR_2; VAR_6++){

            int VAR_13= (VAR_6>>VAR_5) + (VAR_7>>VAR_5)*VAR_0->mb_stride;

            int VAR_13= VAR_0->error_status_table[VAR_13];

            int VAR_13 = IS_INTRA(VAR_0->current_picture.f.mb_type[VAR_13]);

            if(VAR_13==0 || !(VAR_13&ER_DC_ERROR)){

                VAR_13= VAR_1[VAR_6 + VAR_7*VAR_4];

                VAR_13= VAR_6;

            }

            col [VAR_6 + VAR_7*VAR_4][1]= VAR_13;

            dist[VAR_6 + VAR_7*VAR_4][1]= VAR_13 >= 0 ? VAR_6-VAR_13 : 9999;

        }

        VAR_13= 1024;

        VAR_13= -1;

        for(VAR_6=VAR_2-1; VAR_6>=0; VAR_6--){

            int VAR_13= (VAR_6>>VAR_5) + (VAR_7>>VAR_5)*VAR_0->mb_stride;

            int VAR_13= VAR_0->error_status_table[VAR_13];

            int VAR_13 = IS_INTRA(VAR_0->current_picture.f.mb_type[VAR_13]);

            if(VAR_13==0 || !(VAR_13&ER_DC_ERROR)){

                VAR_13= VAR_1[VAR_6 + VAR_7*VAR_4];

                VAR_13= VAR_6;

            }

            col [VAR_6 + VAR_7*VAR_4][0]= VAR_13;

            dist[VAR_6 + VAR_7*VAR_4][0]= VAR_13 >= 0 ? VAR_13-VAR_6 : 9999;

        }

    }

    for(VAR_6=0; VAR_6<VAR_2; VAR_6++){

        int VAR_13= 1024;

        int VAR_13= -1;

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

            int VAR_13= (VAR_6>>VAR_5) + (VAR_7>>VAR_5)*VAR_0->mb_stride;

            int VAR_13= VAR_0->error_status_table[VAR_13];

            int VAR_13 = IS_INTRA(VAR_0->current_picture.f.mb_type[VAR_13]);

            if(VAR_13==0 || !(VAR_13&ER_DC_ERROR)){

                VAR_13= VAR_1[VAR_6 + VAR_7*VAR_4];

                VAR_13= VAR_7;

            }

            col [VAR_6 + VAR_7*VAR_4][3]= VAR_13;

            dist[VAR_6 + VAR_7*VAR_4][3]= VAR_13 >= 0 ? VAR_7-VAR_13 : 9999;

        }

        VAR_13= 1024;

        VAR_13= -1;

        for(VAR_7=VAR_3-1; VAR_7>=0; VAR_7--){

            int VAR_13= (VAR_6>>VAR_5) + (VAR_7>>VAR_5)*VAR_0->mb_stride;

            int VAR_13= VAR_0->error_status_table[VAR_13];

            int VAR_13 = IS_INTRA(VAR_0->current_picture.f.mb_type[VAR_13]);

            if(VAR_13==0 || !(VAR_13&ER_DC_ERROR)){

                VAR_13= VAR_1[VAR_6 + VAR_7*VAR_4];

                VAR_13= VAR_7;

            }

            col [VAR_6 + VAR_7*VAR_4][2]= VAR_13;

            dist[VAR_6 + VAR_7*VAR_4][2]= VAR_13 >= 0 ? VAR_13-VAR_7 : 9999;

        }

    }



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

        for (VAR_6 = 0; VAR_6 < VAR_2; VAR_6++) {

            int VAR_13, VAR_14, VAR_15;

            int64_t guess, weight_sum;

            VAR_13 = (VAR_6 >> VAR_5) + (VAR_7 >> VAR_5) * VAR_0->mb_stride;

            VAR_14    = VAR_0->error_status_table[VAR_13];



            if (IS_INTER(VAR_0->current_picture.f.mb_type[VAR_13]))

                continue; 

            if (!(VAR_14 & ER_DC_ERROR))

                continue; 



            weight_sum = 0;

            guess      = 0;

            for (VAR_15 = 0; VAR_15 < 4; VAR_15++) {

                int64_t weight  = 256 * 256 * 256 * 16 / dist[VAR_6 + VAR_7*VAR_4][VAR_15];

                guess          += weight*(int64_t)col[VAR_6 + VAR_7*VAR_4][VAR_15];

                weight_sum     += weight;

            }

            guess = (guess + weight_sum / 2) / weight_sum;

            VAR_1[VAR_6 + VAR_7 * VAR_4] = guess;

        }

    }

    av_freep(&col);

    av_freep(&dist);

}

static void FUNC_0(MpegEncContext *VAR_0, int16_t *VAR_1, int VAR_2,
int VAR_3, int VAR_4, int VAR_5)
{ int VAR_6, VAR_7; int16_t  (*col )[4] = av_malloc(VAR_4*VAR_3*sizeof( int16_t)*4); uint32_t (*dist)[4] = av_malloc(VAR_4*VAR_3*sizeof(uint32_t)*4); for(VAR_7=0; VAR_7<VAR_3; VAR_7++){ int VAR_13= 1024; int VAR_13= -1; for(VAR_6=0; VAR_6<VAR_2; VAR_6++){ int VAR_13= (VAR_6>>VAR_5) + (VAR_7>>VAR_5)*VAR_0->mb_stride; int VAR_13= VAR_0->error_status_table[VAR_13]; int VAR_13 = IS_INTRA(VAR_0->current_picture.f.mb_type[VAR_13]); if(VAR_13==0 || !(VAR_13&ER_DC_ERROR)){ VAR_13= VAR_1[VAR_6 + VAR_7*VAR_4]; VAR_13= VAR_6; } col [VAR_6 + VAR_7*VAR_4][1]= VAR_13; dist[VAR_6 + VAR_7*VAR_4][1]= VAR_13 >= 0 ? VAR_6-VAR_13 : 9999; } VAR_13= 1024; VAR_13= -1; for(VAR_6=VAR_2-1; VAR_6>=0; VAR_6--){ int VAR_13= (VAR_6>>VAR_5) + (VAR_7>>VAR_5)*VAR_0->mb_stride; int VAR_13= VAR_0->error_status_table[VAR_13]; int VAR_13 = IS_INTRA(VAR_0->current_picture.f.mb_type[VAR_13]); if(VAR_13==0 || !(VAR_13&ER_DC_ERROR)){ VAR_13= VAR_1[VAR_6 + VAR_7*VAR_4]; VAR_13= VAR_6; } col [VAR_6 + VAR_7*VAR_4][0]= VAR_13; dist[VAR_6 + VAR_7*VAR_4][0]= VAR_13 >= 0 ? VAR_13-VAR_6 : 9999; } } for(VAR_6=0; VAR_6<VAR_2; VAR_6++){ int VAR_13= 1024; int VAR_13= -1; for(VAR_7=0; VAR_7<VAR_3; VAR_7++){ int VAR_13= (VAR_6>>VAR_5) + (VAR_7>>VAR_5)*VAR_0->mb_stride; int VAR_13= VAR_0->error_status_table[VAR_13]; int VAR_13 = IS_INTRA(VAR_0->current_picture.f.mb_type[VAR_13]); if(VAR_13==0 || !(VAR_13&ER_DC_ERROR)){ VAR_13= VAR_1[VAR_6 + VAR_7*VAR_4]; VAR_13= VAR_7; } col [VAR_6 + VAR_7*VAR_4][3]= VAR_13; dist[VAR_6 + VAR_7*VAR_4][3]= VAR_13 >= 0 ? VAR_7-VAR_13 : 9999; } VAR_13= 1024; VAR_13= -1; for(VAR_7=VAR_3-1; VAR_7>=0; VAR_7--){ int VAR_13= (VAR_6>>VAR_5) + (VAR_7>>VAR_5)*VAR_0->mb_stride; int VAR_13= VAR_0->error_status_table[VAR_13]; int VAR_13 = IS_INTRA(VAR_0->current_picture.f.mb_type[VAR_13]); if(VAR_13==0 || !(VAR_13&ER_DC_ERROR)){ VAR_13= VAR_1[VAR_6 + VAR_7*VAR_4]; VAR_13= VAR_7; } col [VAR_6 + VAR_7*VAR_4][2]= VAR_13; dist[VAR_6 + VAR_7*VAR_4][2]= VAR_13 >= 0 ? VAR_13-VAR_7 : 9999; } } for (VAR_7 = 0; VAR_7 < VAR_3; VAR_7++) { for (VAR_6 = 0; VAR_6 < VAR_2; VAR_6++) { int VAR_13, VAR_14, VAR_15; int64_t guess, weight_sum; VAR_13 = (VAR_6 >> VAR_5) + (VAR_7 >> VAR_5) * VAR_0->mb_stride; VAR_14    = VAR_0->error_status_table[VAR_13]; if (IS_INTER(VAR_0->current_picture.f.mb_type[VAR_13]))
continue; if (!(VAR_14 & ER_DC_ERROR))
continue; weight_sum = 0; guess      = 0; for (VAR_15 = 0; VAR_15 < 4; VAR_15++) { int64_t weight  = 256 * 256 * 256 * 16 / dist[VAR_6 + VAR_7*VAR_4][VAR_15]; guess          += weight*(int64_t)col[VAR_6 + VAR_7*VAR_4][VAR_15]; weight_sum     += weight; } guess = (guess + weight_sum / 2) / weight_sum; VAR_1[VAR_6 + VAR_7 * VAR_4] = guess; } } av_freep(&col); av_freep(&dist); }