static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, int Al){

    int i, mb_x, mb_y;

    uint8_t* data[MAX_COMPONENTS];

    int linesize[MAX_COMPONENTS];



    for(i=0; i < nb_components; i++) {

        int c = s->comp_index[i];

        data[c] = s->picture.data[c];

        linesize[c]=s->linesize[c];

        s->coefs_finished[c] |= 1;

        if(s->flipped) {

            //picture should be flipped upside-down for this codec

            assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE));

            data[c] += (linesize[c] * (s->v_scount[i] * (8 * s->mb_height -((s->height/s->v_max)&7)) - 1 ));

            linesize[c] *= -1;

        }

    }



    for(mb_y = 0; mb_y < s->mb_height; mb_y++) {

        for(mb_x = 0; mb_x < s->mb_width; mb_x++) {

            if (s->restart_interval && !s->restart_count)

                s->restart_count = s->restart_interval;



            for(i=0;i<nb_components;i++) {

                uint8_t *ptr;

                int n, h, v, x, y, c, j;

                n = s->nb_blocks[i];

                c = s->comp_index[i];

                h = s->h_scount[i];

                v = s->v_scount[i];

                x = 0;

                y = 0;

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

                    ptr = data[c] +

                        (((linesize[c] * (v * mb_y + y) * 8) +

                        (h * mb_x + x) * 8) >> s->avctx->lowres);

                    if(s->interlaced && s->bottom_field)

                        ptr += linesize[c] >> 1;

                    if(!s->progressive) {

                        s->dsp.clear_block(s->block);

                        if(decode_block(s, s->block, i,

                                     s->dc_index[i], s->ac_index[i],

                                     s->quant_matrixes[ s->quant_index[c] ]) < 0) {

                            av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x);

                            return -1;

                        }

                        s->dsp.idct_put(ptr, linesize[c], s->block);

                    } else {

                        int block_idx = s->block_stride[c] * (v * mb_y + y) + (h * mb_x + x);

                        DCTELEM *block = s->blocks[c][block_idx];

                        if(Ah)

                            block[0] += get_bits1(&s->gb) * s->quant_matrixes[ s->quant_index[c] ][0] << Al;

                        else if(decode_dc_progressive(s, block, i, s->dc_index[i], s->quant_matrixes[ s->quant_index[c] ], Al) < 0) {

                            av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x);

                            return -1;

                        }

                    }

//                    av_log(s->avctx, AV_LOG_DEBUG, "mb: %d %d processed\n", mb_y, mb_x);

//av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d \n", mb_x, mb_y, x, y, c, s->bottom_field, (v * mb_y + y) * 8, (h * mb_x + x) * 8);

                    if (++x == h) {

                        x = 0;

                        y++;

                    }

                }

            }



            if (s->restart_interval && !--s->restart_count) {

                align_get_bits(&s->gb);

                skip_bits(&s->gb, 16); /* skip RSTn */

                for (i=0; i<nb_components; i++) /* reset dc */

                    s->last_dc[i] = 1024;

            }

        }

    }

    return 0;

}

static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, int Al){

    int i, mb_x, mb_y;

    uint8_t* data[MAX_COMPONENTS];

    int linesize[MAX_COMPONENTS];



    for(i=0; i < nb_components; i++) {

        int c = s->comp_index[i];

        data[c] = s->picture.data[c];

        linesize[c]=s->linesize[c];

        s->coefs_finished[c] |= 1;

        if(s->flipped) {

            

            assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE));

            data[c] += (linesize[c] * (s->v_scount[i] * (8 * s->mb_height -((s->height/s->v_max)&7)) - 1 ));

            linesize[c] *= -1;

        }

    }



    for(mb_y = 0; mb_y < s->mb_height; mb_y++) {

        for(mb_x = 0; mb_x < s->mb_width; mb_x++) {

            if (s->restart_interval && !s->restart_count)

                s->restart_count = s->restart_interval;



            for(i=0;i<nb_components;i++) {

                uint8_t *ptr;

                int n, h, v, x, y, c, j;

                n = s->nb_blocks[i];

                c = s->comp_index[i];

                h = s->h_scount[i];

                v = s->v_scount[i];

                x = 0;

                y = 0;

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

                    ptr = data[c] +

                        (((linesize[c] * (v * mb_y + y) * 8) +

                        (h * mb_x + x) * 8) >> s->avctx->lowres);

                    if(s->interlaced && s->bottom_field)

                        ptr += linesize[c] >> 1;

                    if(!s->progressive) {

                        s->dsp.clear_block(s->block);

                        if(decode_block(s, s->block, i,

                                     s->dc_index[i], s->ac_index[i],

                                     s->quant_matrixes[ s->quant_index[c] ]) < 0) {

                            av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x);

                            return -1;

                        }

                        s->dsp.idct_put(ptr, linesize[c], s->block);

                    } else {

                        int block_idx = s->block_stride[c] * (v * mb_y + y) + (h * mb_x + x);

                        DCTELEM *block = s->blocks[c][block_idx];

                        if(Ah)

                            block[0] += get_bits1(&s->gb) * s->quant_matrixes[ s->quant_index[c] ][0] << Al;

                        else if(decode_dc_progressive(s, block, i, s->dc_index[i], s->quant_matrixes[ s->quant_index[c] ], Al) < 0) {

                            av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x);

                            return -1;

                        }

                    }





                    if (++x == h) {

                        x = 0;

                        y++;

                    }

                }

            }



            if (s->restart_interval && !--s->restart_count) {

                align_get_bits(&s->gb);

                skip_bits(&s->gb, 16); 

                for (i=0; i<nb_components; i++) 

                    s->last_dc[i] = 1024;

            }

        }

    }

    return 0;

}

            assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE));
static int FUNC_0(MJpegDecodeContext *VAR_0, int VAR_1, int VAR_2, int VAR_3){

    int VAR_4, VAR_5, VAR_6;

    uint8_t* data[MAX_COMPONENTS];

    int VAR_7[MAX_COMPONENTS];



    for(VAR_4=0; VAR_4 < VAR_1; VAR_4++) {

        int VAR_8 = VAR_0->comp_index[VAR_4];

        data[VAR_8] = VAR_0->picture.data[VAR_8];

        VAR_7[VAR_8]=VAR_0->VAR_7[VAR_8];

        VAR_0->coefs_finished[VAR_8] |= 1;

        if(VAR_0->flipped) {

            

            assert(!(VAR_0->avctx->flags & CODEC_FLAG_EMU_EDGE));

            data[VAR_8] += (VAR_7[VAR_8] * (VAR_0->v_scount[VAR_4] * (8 * VAR_0->mb_height -((VAR_0->height/VAR_0->v_max)&7)) - 1 ));

            VAR_7[VAR_8] *= -1;

        }

    }



    for(VAR_6 = 0; VAR_6 < VAR_0->mb_height; VAR_6++) {

        for(VAR_5 = 0; VAR_5 < VAR_0->mb_width; VAR_5++) {

            if (VAR_0->restart_interval && !VAR_0->restart_count)

                VAR_0->restart_count = VAR_0->restart_interval;



            for(VAR_4=0;VAR_4<VAR_1;VAR_4++) {

                uint8_t *ptr;

                int n, h, v, x, y, VAR_8, j;

                n = VAR_0->nb_blocks[VAR_4];

                VAR_8 = VAR_0->comp_index[VAR_4];

                h = VAR_0->h_scount[VAR_4];

                v = VAR_0->v_scount[VAR_4];

                x = 0;

                y = 0;

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

                    ptr = data[VAR_8] +

                        (((VAR_7[VAR_8] * (v * VAR_6 + y) * 8) +

                        (h * VAR_5 + x) * 8) >> VAR_0->avctx->lowres);

                    if(VAR_0->interlaced && VAR_0->bottom_field)

                        ptr += VAR_7[VAR_8] >> 1;

                    if(!VAR_0->progressive) {

                        VAR_0->dsp.clear_block(VAR_0->block);

                        if(decode_block(VAR_0, VAR_0->block, VAR_4,

                                     VAR_0->dc_index[VAR_4], VAR_0->ac_index[VAR_4],

                                     VAR_0->quant_matrixes[ VAR_0->quant_index[VAR_8] ]) < 0) {

                            av_log(VAR_0->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", VAR_6, VAR_5);

                            return -1;

                        }

                        VAR_0->dsp.idct_put(ptr, VAR_7[VAR_8], VAR_0->block);

                    } else {

                        int block_idx = VAR_0->block_stride[VAR_8] * (v * VAR_6 + y) + (h * VAR_5 + x);

                        DCTELEM *block = VAR_0->blocks[VAR_8][block_idx];

                        if(VAR_2)

                            block[0] += get_bits1(&VAR_0->gb) * VAR_0->quant_matrixes[ VAR_0->quant_index[VAR_8] ][0] << VAR_3;

                        else if(decode_dc_progressive(VAR_0, block, VAR_4, VAR_0->dc_index[VAR_4], VAR_0->quant_matrixes[ VAR_0->quant_index[VAR_8] ], VAR_3) < 0) {

                            av_log(VAR_0->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", VAR_6, VAR_5);

                            return -1;

                        }

                    }





                    if (++x == h) {

                        x = 0;

                        y++;

                    }

                }

            }



            if (VAR_0->restart_interval && !--VAR_0->restart_count) {

                align_get_bits(&VAR_0->gb);

                skip_bits(&VAR_0->gb, 16); 

                for (VAR_4=0; VAR_4<VAR_1; VAR_4++) 

                    VAR_0->last_dc[VAR_4] = 1024;

            }

        }

    }

    return 0;

}

static int FUNC_0(MJpegDecodeContext *VAR_0, int VAR_1, int VAR_2, int VAR_3){ int VAR_4, VAR_5, VAR_6; uint8_t* data[MAX_COMPONENTS]; int VAR_7[MAX_COMPONENTS]; for(VAR_4=0; VAR_4 < VAR_1; VAR_4++) { int VAR_8 = VAR_0->comp_index[VAR_4]; data[VAR_8] = VAR_0->picture.data[VAR_8]; VAR_7[VAR_8]=VAR_0->VAR_7[VAR_8]; VAR_0->coefs_finished[VAR_8] |= 1; if(VAR_0->flipped) { assert(!(VAR_0->avctx->flags & CODEC_FLAG_EMU_EDGE)); data[VAR_8] += (VAR_7[VAR_8] * (VAR_0->v_scount[VAR_4] * (8 * VAR_0->mb_height -((VAR_0->height/VAR_0->v_max)&7)) - 1 )); VAR_7[VAR_8] *= -1; } } for(VAR_6 = 0; VAR_6 < VAR_0->mb_height; VAR_6++) { for(VAR_5 = 0; VAR_5 < VAR_0->mb_width; VAR_5++) { if (VAR_0->restart_interval && !VAR_0->restart_count)
VAR_0->restart_count = VAR_0->restart_interval; for(VAR_4=0;VAR_4<VAR_1;VAR_4++) { uint8_t *ptr; int n, h, v, x, y, VAR_8, j; n = VAR_0->nb_blocks[VAR_4]; VAR_8 = VAR_0->comp_index[VAR_4]; h = VAR_0->h_scount[VAR_4]; v = VAR_0->v_scount[VAR_4]; x = 0; y = 0; for(j=0;j<n;j++) { ptr = data[VAR_8] +
(((VAR_7[VAR_8] * (v * VAR_6 + y) * 8) +
(h * VAR_5 + x) * 8) >> VAR_0->avctx->lowres); if(VAR_0->interlaced && VAR_0->bottom_field)
ptr += VAR_7[VAR_8] >> 1; if(!VAR_0->progressive) { VAR_0->dsp.clear_block(VAR_0->block); if(decode_block(VAR_0, VAR_0->block, VAR_4,
VAR_0->dc_index[VAR_4], VAR_0->ac_index[VAR_4],
VAR_0->quant_matrixes[ VAR_0->quant_index[VAR_8] ]) < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", VAR_6, VAR_5); return -1; } VAR_0->dsp.idct_put(ptr, VAR_7[VAR_8], VAR_0->block); } else { int block_idx = VAR_0->block_stride[VAR_8] * (v * VAR_6 + y) + (h * VAR_5 + x); DCTELEM *block = VAR_0->blocks[VAR_8][block_idx]; if(VAR_2)
block[0] += get_bits1(&VAR_0->gb) * VAR_0->quant_matrixes[ VAR_0->quant_index[VAR_8] ][0] << VAR_3; else if(decode_dc_progressive(VAR_0, block, VAR_4, VAR_0->dc_index[VAR_4], VAR_0->quant_matrixes[ VAR_0->quant_index[VAR_8] ], VAR_3) < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", VAR_6, VAR_5); return -1; } } if (++x == h) { x = 0; y++; } } } if (VAR_0->restart_interval && !--VAR_0->restart_count) { align_get_bits(&VAR_0->gb); skip_bits(&VAR_0->gb, 16); for (VAR_4=0; VAR_4<VAR_1; VAR_4++) VAR_0->last_dc[VAR_4] = 1024; } } } return 0; }