static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah,

                             int Al, const uint8_t *mb_bitmask,

                             const AVFrame *reference)

{

    int i, mb_x, mb_y;

    uint8_t *data[MAX_COMPONENTS];

    const uint8_t *reference_data[MAX_COMPONENTS];

    int linesize[MAX_COMPONENTS];

    GetBitContext mb_bitmask_gb;

    int bytes_per_pixel = 1 + (s->bits > 8);



    if (mb_bitmask)

        init_get_bits(&mb_bitmask_gb, mb_bitmask, s->mb_width * s->mb_height);



    s->restart_count = 0;



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

        int c   = s->comp_index[i];

        data[c] = s->picture_ptr->data[c];

        reference_data[c] = reference ? reference->data[c] : NULL;

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

        s->coefs_finished[c] |= 1;

    }



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

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

            const int copy_mb = mb_bitmask && !get_bits1(&mb_bitmask_gb);



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

                s->restart_count = s->restart_interval;



            if (get_bits_left(&s->gb) < 0) {

                av_log(s->avctx, AV_LOG_ERROR, "overread %d\n",

                       -get_bits_left(&s->gb));

                return AVERROR_INVALIDDATA;

            }

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

                uint8_t *ptr;

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

                int block_offset;

                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++) {

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

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



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

                        block_offset += linesize[c] >> 1;

                    ptr = data[c] + block_offset;

                    if (!s->progressive) {

                        if (copy_mb)

                            mjpeg_copy_block(s, ptr, reference_data[c] + block_offset,

                                             linesize[c], s->avctx->lowres);



                        else {

                            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_sindex[i]]) < 0) {

                                av_log(s->avctx, AV_LOG_ERROR,

                                       "error y=%d x=%d\n", mb_y, mb_x);

                                return AVERROR_INVALIDDATA;

                            }

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

                            if (s->bits & 7)

                                shift_output(s, ptr, linesize[c]);

                        }

                    } else {

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

                                         (h * mb_x + x);

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

                        if (Ah)

                            block[0] += get_bits1(&s->gb) *

                                        s->quant_matrixes[s->quant_sindex[i]][0] << Al;

                        else if (decode_dc_progressive(s, block, i, s->dc_index[i],

                                                       s->quant_matrixes[s->quant_sindex[i]],

                                                       Al) < 0) {

                            av_log(s->avctx, AV_LOG_ERROR,

                                   "error y=%d x=%d\n", mb_y, mb_x);

                            return AVERROR_INVALIDDATA;

                        }

                    }

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

                    av_dlog(s->avctx, "%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++;

                    }

                }

            }



            handle_rstn(s, nb_components);

        }

    }

    return 0;

}

static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah,

                             int Al, const uint8_t *mb_bitmask,

                             const AVFrame *reference)

{

    int i, mb_x, mb_y;

    uint8_t *data[MAX_COMPONENTS];

    const uint8_t *reference_data[MAX_COMPONENTS];

    int linesize[MAX_COMPONENTS];

    GetBitContext mb_bitmask_gb;

    int bytes_per_pixel = 1 + (s->bits > 8);



    if (mb_bitmask)

        init_get_bits(&mb_bitmask_gb, mb_bitmask, s->mb_width * s->mb_height);



    s->restart_count = 0;



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

        int c   = s->comp_index[i];

        data[c] = s->picture_ptr->data[c];

        reference_data[c] = reference ? reference->data[c] : NULL;

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

        s->coefs_finished[c] |= 1;

    }



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

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

            const int copy_mb = mb_bitmask && !get_bits1(&mb_bitmask_gb);



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

                s->restart_count = s->restart_interval;



            if (get_bits_left(&s->gb) < 0) {

                av_log(s->avctx, AV_LOG_ERROR, "overread %d\n",

                       -get_bits_left(&s->gb));

                return AVERROR_INVALIDDATA;

            }

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

                uint8_t *ptr;

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

                int block_offset;

                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++) {

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

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



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

                        block_offset += linesize[c] >> 1;

                    ptr = data[c] + block_offset;

                    if (!s->progressive) {

                        if (copy_mb)

                            mjpeg_copy_block(s, ptr, reference_data[c] + block_offset,

                                             linesize[c], s->avctx->lowres);



                        else {

                            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_sindex[i]]) < 0) {

                                av_log(s->avctx, AV_LOG_ERROR,

                                       "error y=%d x=%d\n", mb_y, mb_x);

                                return AVERROR_INVALIDDATA;

                            }

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

                            if (s->bits & 7)

                                shift_output(s, ptr, linesize[c]);

                        }

                    } else {

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

                                         (h * mb_x + x);

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

                        if (Ah)

                            block[0] += get_bits1(&s->gb) *

                                        s->quant_matrixes[s->quant_sindex[i]][0] << Al;

                        else if (decode_dc_progressive(s, block, i, s->dc_index[i],

                                                       s->quant_matrixes[s->quant_sindex[i]],

                                                       Al) < 0) {

                            av_log(s->avctx, AV_LOG_ERROR,

                                   "error y=%d x=%d\n", mb_y, mb_x);

                            return AVERROR_INVALIDDATA;

                        }

                    }

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

                    av_dlog(s->avctx, "%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++;

                    }

                }

            }



            handle_rstn(s, nb_components);

        }

    }

    return 0;

}

    if (mb_bitmask)
static int FUNC_0(MJpegDecodeContext *VAR_0, int VAR_1, int VAR_2,

                             int VAR_3, const uint8_t *VAR_4,

                             const AVFrame *VAR_5)

{

    int VAR_6, VAR_7, VAR_8;

    uint8_t *data[MAX_COMPONENTS];

    const uint8_t *VAR_9[MAX_COMPONENTS];

    int VAR_10[MAX_COMPONENTS];

    GetBitContext mb_bitmask_gb;

    int VAR_11 = 1 + (VAR_0->bits > 8);



    if (VAR_4)

        init_get_bits(&mb_bitmask_gb, VAR_4, VAR_0->mb_width * VAR_0->mb_height);



    VAR_0->restart_count = 0;



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

        int VAR_12   = VAR_0->comp_index[VAR_6];

        data[VAR_12] = VAR_0->picture_ptr->data[VAR_12];

        VAR_9[VAR_12] = VAR_5 ? VAR_5->data[VAR_12] : NULL;

        VAR_10[VAR_12] = VAR_0->VAR_10[VAR_12];

        VAR_0->coefs_finished[VAR_12] |= 1;

    }



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

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

            const int copy_mb = VAR_4 && !get_bits1(&mb_bitmask_gb);



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

                VAR_0->restart_count = VAR_0->restart_interval;



            if (get_bits_left(&VAR_0->gb) < 0) {

                av_log(VAR_0->avctx, AV_LOG_ERROR, "overread %d\n",

                       -get_bits_left(&VAR_0->gb));

                return AVERROR_INVALIDDATA;

            }

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

                uint8_t *ptr;

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

                int block_offset;

                n = VAR_0->nb_blocks[VAR_6];

                VAR_12 = VAR_0->comp_index[VAR_6];

                h = VAR_0->h_scount[VAR_6];

                v = VAR_0->v_scount[VAR_6];

                x = 0;

                y = 0;

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

                    block_offset = (((VAR_10[VAR_12] * (v * VAR_8 + y) * 8) +

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



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

                        block_offset += VAR_10[VAR_12] >> 1;

                    ptr = data[VAR_12] + block_offset;

                    if (!VAR_0->progressive) {

                        if (copy_mb)

                            mjpeg_copy_block(VAR_0, ptr, VAR_9[VAR_12] + block_offset,

                                             VAR_10[VAR_12], VAR_0->avctx->lowres);



                        else {

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

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

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

                                             VAR_0->quant_matrixes[VAR_0->quant_sindex[VAR_6]]) < 0) {

                                av_log(VAR_0->avctx, AV_LOG_ERROR,

                                       "error y=%d x=%d\n", VAR_8, VAR_7);

                                return AVERROR_INVALIDDATA;

                            }

                            VAR_0->dsp.idct_put(ptr, VAR_10[VAR_12], VAR_0->block);

                            if (VAR_0->bits & 7)

                                shift_output(VAR_0, ptr, VAR_10[VAR_12]);

                        }

                    } else {

                        int block_idx  = VAR_0->block_stride[VAR_12] * (v * VAR_8 + y) +

                                         (h * VAR_7 + x);

                        int16_t *block = VAR_0->blocks[VAR_12][block_idx];

                        if (VAR_2)

                            block[0] += get_bits1(&VAR_0->gb) *

                                        VAR_0->quant_matrixes[VAR_0->quant_sindex[VAR_6]][0] << VAR_3;

                        else if (decode_dc_progressive(VAR_0, block, VAR_6, VAR_0->dc_index[VAR_6],

                                                       VAR_0->quant_matrixes[VAR_0->quant_sindex[VAR_6]],

                                                       VAR_3) < 0) {

                            av_log(VAR_0->avctx, AV_LOG_ERROR,

                                   "error y=%d x=%d\n", VAR_8, VAR_7);

                            return AVERROR_INVALIDDATA;

                        }

                    }

                    av_dlog(VAR_0->avctx, "mb: %d %d processed\n", VAR_8, VAR_7);

                    av_dlog(VAR_0->avctx, "%d %d %d %d %d %d %d %d \n",

                            VAR_7, VAR_8, x, y, VAR_12, VAR_0->bottom_field,

                            (v * VAR_8 + y) * 8, (h * VAR_7 + x) * 8);

                    if (++x == h) {

                        x = 0;

                        y++;

                    }

                }

            }



            handle_rstn(VAR_0, VAR_1);

        }

    }

    return 0;

}

static int FUNC_0(MJpegDecodeContext *VAR_0, int VAR_1, int VAR_2,
int VAR_3, const uint8_t *VAR_4,
const AVFrame *VAR_5)
{ int VAR_6, VAR_7, VAR_8; uint8_t *data[MAX_COMPONENTS]; const uint8_t *VAR_9[MAX_COMPONENTS]; int VAR_10[MAX_COMPONENTS]; GetBitContext mb_bitmask_gb; int VAR_11 = 1 + (VAR_0->bits > 8); if (VAR_4)
init_get_bits(&mb_bitmask_gb, VAR_4, VAR_0->mb_width * VAR_0->mb_height); VAR_0->restart_count = 0; for (VAR_6 = 0; VAR_6 < VAR_1; VAR_6++) { int VAR_12   = VAR_0->comp_index[VAR_6]; data[VAR_12] = VAR_0->picture_ptr->data[VAR_12]; VAR_9[VAR_12] = VAR_5 ? VAR_5->data[VAR_12] : NULL; VAR_10[VAR_12] = VAR_0->VAR_10[VAR_12]; VAR_0->coefs_finished[VAR_12] |= 1; } for (VAR_8 = 0; VAR_8 < VAR_0->mb_height; VAR_8++) { for (VAR_7 = 0; VAR_7 < VAR_0->mb_width; VAR_7++) { const int copy_mb = VAR_4 && !get_bits1(&mb_bitmask_gb); if (VAR_0->restart_interval && !VAR_0->restart_count)
VAR_0->restart_count = VAR_0->restart_interval; if (get_bits_left(&VAR_0->gb) < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "overread %d\n",
-get_bits_left(&VAR_0->gb)); return AVERROR_INVALIDDATA; } for (VAR_6 = 0; VAR_6 < VAR_1; VAR_6++) { uint8_t *ptr; int n, h, v, x, y, VAR_12, j; int block_offset; n = VAR_0->nb_blocks[VAR_6]; VAR_12 = VAR_0->comp_index[VAR_6]; h = VAR_0->h_scount[VAR_6]; v = VAR_0->v_scount[VAR_6]; x = 0; y = 0; for (j = 0; j < n; j++) { block_offset = (((VAR_10[VAR_12] * (v * VAR_8 + y) * 8) +
(h * VAR_7 + x) * 8 * VAR_11) >> VAR_0->avctx->lowres); if (VAR_0->interlaced && VAR_0->bottom_field)
block_offset += VAR_10[VAR_12] >> 1; ptr = data[VAR_12] + block_offset; if (!VAR_0->progressive) { if (copy_mb)
mjpeg_copy_block(VAR_0, ptr, VAR_9[VAR_12] + block_offset,
VAR_10[VAR_12], VAR_0->avctx->lowres); else { VAR_0->dsp.clear_block(VAR_0->block); if (decode_block(VAR_0, VAR_0->block, VAR_6,
VAR_0->dc_index[VAR_6], VAR_0->ac_index[VAR_6],
VAR_0->quant_matrixes[VAR_0->quant_sindex[VAR_6]]) < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"error y=%d x=%d\n", VAR_8, VAR_7); return AVERROR_INVALIDDATA; } VAR_0->dsp.idct_put(ptr, VAR_10[VAR_12], VAR_0->block); if (VAR_0->bits & 7)
shift_output(VAR_0, ptr, VAR_10[VAR_12]); } } else { int block_idx  = VAR_0->block_stride[VAR_12] * (v * VAR_8 + y) +
(h * VAR_7 + x); int16_t *block = VAR_0->blocks[VAR_12][block_idx]; if (VAR_2)
block[0] += get_bits1(&VAR_0->gb) *
VAR_0->quant_matrixes[VAR_0->quant_sindex[VAR_6]][0] << VAR_3; else if (decode_dc_progressive(VAR_0, block, VAR_6, VAR_0->dc_index[VAR_6],
VAR_0->quant_matrixes[VAR_0->quant_sindex[VAR_6]],
VAR_3) < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"error y=%d x=%d\n", VAR_8, VAR_7); return AVERROR_INVALIDDATA; } } av_dlog(VAR_0->avctx, "mb: %d %d processed\n", VAR_8, VAR_7); av_dlog(VAR_0->avctx, "%d %d %d %d %d %d %d %d \n",
VAR_7, VAR_8, x, y, VAR_12, VAR_0->bottom_field,
(v * VAR_8 + y) * 8, (h * VAR_7 + x) * 8); if (++x == h) { x = 0; y++; } } } handle_rstn(VAR_0, VAR_1); } } return 0; }