int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask,

                        const AVFrame *reference)

{

    int len, nb_components, i, h, v, predictor, point_transform;

    int index, id, ret;

    const int block_size = s->lossless ? 1 : 8;

    int ilv, prev_shift;



    if (!s->got_picture) {

        av_log(s->avctx, AV_LOG_WARNING,

                "Can not process SOS before SOF, skipping\n");

        return -1;

    }



    av_assert0(s->picture_ptr->data[0]);

    /* XXX: verify len field validity */

    len = get_bits(&s->gb, 16);

    nb_components = get_bits(&s->gb, 8);

    if (nb_components == 0 || nb_components > MAX_COMPONENTS) {

        av_log(s->avctx, AV_LOG_ERROR,

               "decode_sos: nb_components (%d) unsupported\n", nb_components);

        return AVERROR_PATCHWELCOME;

    }

    if (len != 6 + 2 * nb_components) {

        av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len);

        return AVERROR_INVALIDDATA;

    }

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

        id = get_bits(&s->gb, 8) - 1;

        av_log(s->avctx, AV_LOG_DEBUG, "component: %d\n", id);

        /* find component index */

        for (index = 0; index < s->nb_components; index++)

            if (id == s->component_id[index])

                break;

        if (index == s->nb_components) {

            av_log(s->avctx, AV_LOG_ERROR,

                   "decode_sos: index(%d) out of components\n", index);

            return AVERROR_INVALIDDATA;

        }

        /* Metasoft MJPEG codec has Cb and Cr swapped */

        if (s->avctx->codec_tag == MKTAG('M', 'T', 'S', 'J')

            && nb_components == 3 && s->nb_components == 3 && i)

            index = 3 - i;



        if(nb_components == 3 && s->nb_components == 3 && s->avctx->pix_fmt == AV_PIX_FMT_GBR24P)

            index = (i+2)%3;

        if(nb_components == 1 && s->nb_components == 3 && s->avctx->pix_fmt == AV_PIX_FMT_GBR24P)

            index = (index+2)%3;



        s->comp_index[i] = index;



        s->nb_blocks[i] = s->h_count[index] * s->v_count[index];

        s->h_scount[i]  = s->h_count[index];

        s->v_scount[i]  = s->v_count[index];



        s->dc_index[i] = get_bits(&s->gb, 4);

        s->ac_index[i] = get_bits(&s->gb, 4);



        if (s->dc_index[i] <  0 || s->ac_index[i] < 0 ||

            s->dc_index[i] >= 4 || s->ac_index[i] >= 4)

            goto out_of_range;

        if (!s->vlcs[0][s->dc_index[i]].table || !(s->progressive ? s->vlcs[2][s->ac_index[0]].table : s->vlcs[1][s->ac_index[i]].table))

            goto out_of_range;

    }



    predictor = get_bits(&s->gb, 8);       /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */

    ilv = get_bits(&s->gb, 8);             /* JPEG Se / JPEG-LS ILV */

    if(s->avctx->codec_tag != AV_RL32("CJPG")){

        prev_shift      = get_bits(&s->gb, 4); /* Ah */

        point_transform = get_bits(&s->gb, 4); /* Al */

    }else

        prev_shift = point_transform = 0;



    if (nb_components > 1) {

        /* interleaved stream */

        s->mb_width  = (s->width  + s->h_max * block_size - 1) / (s->h_max * block_size);

        s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size);

    } else if (!s->ls) { /* skip this for JPEG-LS */

        h = s->h_max / s->h_scount[0];

        v = s->v_max / s->v_scount[0];

        s->mb_width     = (s->width  + h * block_size - 1) / (h * block_size);

        s->mb_height    = (s->height + v * block_size - 1) / (v * block_size);

        s->nb_blocks[0] = 1;

        s->h_scount[0]  = 1;

        s->v_scount[0]  = 1;

    }



    if (s->avctx->debug & FF_DEBUG_PICT_INFO)

        av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d skip:%d %s comp:%d\n",

               s->lossless ? "lossless" : "sequential DCT", s->rgb ? "RGB" : "",

               predictor, point_transform, ilv, s->bits, s->mjpb_skiptosod,

               s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""), nb_components);





    /* mjpeg-b can have padding bytes between sos and image data, skip them */

    for (i = s->mjpb_skiptosod; i > 0; i--)

        skip_bits(&s->gb, 8);



next_field:

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

        s->last_dc[i] = 1024;



    if (s->lossless) {

        av_assert0(s->picture_ptr == &s->picture);

        if (CONFIG_JPEGLS_DECODER && s->ls) {

//            for () {

//            reset_ls_coding_parameters(s, 0);



            if ((ret = ff_jpegls_decode_picture(s, predictor,

                                                point_transform, ilv)) < 0)

                return ret;

        } else {

            if (s->rgb) {

                if ((ret = ljpeg_decode_rgb_scan(s, nb_components, predictor, point_transform)) < 0)

                    return ret;

            } else {

                if ((ret = ljpeg_decode_yuv_scan(s, predictor,

                                                 point_transform,

                                                 nb_components)) < 0)

                    return ret;

            }

        }

    } else {

        if (s->progressive && predictor) {

            av_assert0(s->picture_ptr == &s->picture);

            if ((ret = mjpeg_decode_scan_progressive_ac(s, predictor,

                                                        ilv, prev_shift,

                                                        point_transform)) < 0)

                return ret;

        } else {

            if ((ret = mjpeg_decode_scan(s, nb_components,

                                         prev_shift, point_transform,

                                         mb_bitmask, reference)) < 0)

                return ret;

        }

    }



    if (s->interlaced &&

        get_bits_left(&s->gb) > 32 &&

        show_bits(&s->gb, 8) == 0xFF) {

        GetBitContext bak = s->gb;

        align_get_bits(&bak);

        if (show_bits(&bak, 16) == 0xFFD1) {

            av_log(s->avctx, AV_LOG_DEBUG, "AVRn interlaced picture marker found\n");

            s->gb = bak;

            skip_bits(&s->gb, 16);

            s->bottom_field ^= 1;



            goto next_field;

        }

    }



    emms_c();

    return 0;

 out_of_range:

    av_log(s->avctx, AV_LOG_ERROR, "decode_sos: ac/dc index out of range\n");

    return AVERROR_INVALIDDATA;

}

int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask,

                        const AVFrame *reference)

{

    int len, nb_components, i, h, v, predictor, point_transform;

    int index, id, ret;

    const int block_size = s->lossless ? 1 : 8;

    int ilv, prev_shift;



    if (!s->got_picture) {

        av_log(s->avctx, AV_LOG_WARNING,

                "Can not process SOS before SOF, skipping\n");

        return -1;

    }



    av_assert0(s->picture_ptr->data[0]);

    

    len = get_bits(&s->gb, 16);

    nb_components = get_bits(&s->gb, 8);

    if (nb_components == 0 || nb_components > MAX_COMPONENTS) {

        av_log(s->avctx, AV_LOG_ERROR,

               "decode_sos: nb_components (%d) unsupported\n", nb_components);

        return AVERROR_PATCHWELCOME;

    }

    if (len != 6 + 2 * nb_components) {

        av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len);

        return AVERROR_INVALIDDATA;

    }

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

        id = get_bits(&s->gb, 8) - 1;

        av_log(s->avctx, AV_LOG_DEBUG, "component: %d\n", id);

        

        for (index = 0; index < s->nb_components; index++)

            if (id == s->component_id[index])

                break;

        if (index == s->nb_components) {

            av_log(s->avctx, AV_LOG_ERROR,

                   "decode_sos: index(%d) out of components\n", index);

            return AVERROR_INVALIDDATA;

        }

        

        if (s->avctx->codec_tag == MKTAG('M', 'T', 'S', 'J')

            && nb_components == 3 && s->nb_components == 3 && i)

            index = 3 - i;



        if(nb_components == 3 && s->nb_components == 3 && s->avctx->pix_fmt == AV_PIX_FMT_GBR24P)

            index = (i+2)%3;

        if(nb_components == 1 && s->nb_components == 3 && s->avctx->pix_fmt == AV_PIX_FMT_GBR24P)

            index = (index+2)%3;



        s->comp_index[i] = index;



        s->nb_blocks[i] = s->h_count[index] * s->v_count[index];

        s->h_scount[i]  = s->h_count[index];

        s->v_scount[i]  = s->v_count[index];



        s->dc_index[i] = get_bits(&s->gb, 4);

        s->ac_index[i] = get_bits(&s->gb, 4);



        if (s->dc_index[i] <  0 || s->ac_index[i] < 0 ||

            s->dc_index[i] >= 4 || s->ac_index[i] >= 4)

            goto out_of_range;

        if (!s->vlcs[0][s->dc_index[i]].table || !(s->progressive ? s->vlcs[2][s->ac_index[0]].table : s->vlcs[1][s->ac_index[i]].table))

            goto out_of_range;

    }



    predictor = get_bits(&s->gb, 8);       

    ilv = get_bits(&s->gb, 8);             

    if(s->avctx->codec_tag != AV_RL32("CJPG")){

        prev_shift      = get_bits(&s->gb, 4); 

        point_transform = get_bits(&s->gb, 4); 

    }else

        prev_shift = point_transform = 0;



    if (nb_components > 1) {

        

        s->mb_width  = (s->width  + s->h_max * block_size - 1) / (s->h_max * block_size);

        s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size);

    } else if (!s->ls) { 

        h = s->h_max / s->h_scount[0];

        v = s->v_max / s->v_scount[0];

        s->mb_width     = (s->width  + h * block_size - 1) / (h * block_size);

        s->mb_height    = (s->height + v * block_size - 1) / (v * block_size);

        s->nb_blocks[0] = 1;

        s->h_scount[0]  = 1;

        s->v_scount[0]  = 1;

    }



    if (s->avctx->debug & FF_DEBUG_PICT_INFO)

        av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d skip:%d %s comp:%d\n",

               s->lossless ? "lossless" : "sequential DCT", s->rgb ? "RGB" : "",

               predictor, point_transform, ilv, s->bits, s->mjpb_skiptosod,

               s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""), nb_components);





    

    for (i = s->mjpb_skiptosod; i > 0; i--)

        skip_bits(&s->gb, 8);



next_field:

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

        s->last_dc[i] = 1024;



    if (s->lossless) {

        av_assert0(s->picture_ptr == &s->picture);

        if (CONFIG_JPEGLS_DECODER && s->ls) {







            if ((ret = ff_jpegls_decode_picture(s, predictor,

                                                point_transform, ilv)) < 0)

                return ret;

        } else {

            if (s->rgb) {

                if ((ret = ljpeg_decode_rgb_scan(s, nb_components, predictor, point_transform)) < 0)

                    return ret;

            } else {

                if ((ret = ljpeg_decode_yuv_scan(s, predictor,

                                                 point_transform,

                                                 nb_components)) < 0)

                    return ret;

            }

        }

    } else {

        if (s->progressive && predictor) {

            av_assert0(s->picture_ptr == &s->picture);

            if ((ret = mjpeg_decode_scan_progressive_ac(s, predictor,

                                                        ilv, prev_shift,

                                                        point_transform)) < 0)

                return ret;

        } else {

            if ((ret = mjpeg_decode_scan(s, nb_components,

                                         prev_shift, point_transform,

                                         mb_bitmask, reference)) < 0)

                return ret;

        }

    }



    if (s->interlaced &&

        get_bits_left(&s->gb) > 32 &&

        show_bits(&s->gb, 8) == 0xFF) {

        GetBitContext bak = s->gb;

        align_get_bits(&bak);

        if (show_bits(&bak, 16) == 0xFFD1) {

            av_log(s->avctx, AV_LOG_DEBUG, "AVRn interlaced picture marker found\n");

            s->gb = bak;

            skip_bits(&s->gb, 16);

            s->bottom_field ^= 1;



            goto next_field;

        }

    }



    emms_c();

    return 0;

 out_of_range:

    av_log(s->avctx, AV_LOG_ERROR, "decode_sos: ac/dc index out of range\n");

    return AVERROR_INVALIDDATA;

}

int FUNC_0(MJpegDecodeContext *VAR_0, const uint8_t *VAR_1,

                        const AVFrame *VAR_2)

{

    int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9;

    int VAR_10, VAR_11, VAR_12;

    const int VAR_13 = VAR_0->lossless ? 1 : 8;

    int VAR_14, VAR_15;



    if (!VAR_0->got_picture) {

        av_log(VAR_0->avctx, AV_LOG_WARNING,

                "Can not process SOS before SOF, skipping\n");

        return -1;

    }



    av_assert0(VAR_0->picture_ptr->data[0]);

    

    VAR_3 = get_bits(&VAR_0->gb, 16);

    VAR_4 = get_bits(&VAR_0->gb, 8);

    if (VAR_4 == 0 || VAR_4 > MAX_COMPONENTS) {

        av_log(VAR_0->avctx, AV_LOG_ERROR,

               "decode_sos: VAR_4 (%d) unsupported\n", VAR_4);

        return AVERROR_PATCHWELCOME;

    }

    if (VAR_3 != 6 + 2 * VAR_4) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "decode_sos: invalid VAR_3 (%d)\n", VAR_3);

        return AVERROR_INVALIDDATA;

    }

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

        VAR_11 = get_bits(&VAR_0->gb, 8) - 1;

        av_log(VAR_0->avctx, AV_LOG_DEBUG, "component: %d\n", VAR_11);

        

        for (VAR_10 = 0; VAR_10 < VAR_0->VAR_4; VAR_10++)

            if (VAR_11 == VAR_0->component_id[VAR_10])

                break;

        if (VAR_10 == VAR_0->VAR_4) {

            av_log(VAR_0->avctx, AV_LOG_ERROR,

                   "decode_sos: VAR_10(%d) out of components\n", VAR_10);

            return AVERROR_INVALIDDATA;

        }

        

        if (VAR_0->avctx->codec_tag == MKTAG('M', 'T', 'S', 'J')

            && VAR_4 == 3 && VAR_0->VAR_4 == 3 && VAR_5)

            VAR_10 = 3 - VAR_5;



        if(VAR_4 == 3 && VAR_0->VAR_4 == 3 && VAR_0->avctx->pix_fmt == AV_PIX_FMT_GBR24P)

            VAR_10 = (VAR_5+2)%3;

        if(VAR_4 == 1 && VAR_0->VAR_4 == 3 && VAR_0->avctx->pix_fmt == AV_PIX_FMT_GBR24P)

            VAR_10 = (VAR_10+2)%3;



        VAR_0->comp_index[VAR_5] = VAR_10;



        VAR_0->nb_blocks[VAR_5] = VAR_0->h_count[VAR_10] * VAR_0->v_count[VAR_10];

        VAR_0->h_scount[VAR_5]  = VAR_0->h_count[VAR_10];

        VAR_0->v_scount[VAR_5]  = VAR_0->v_count[VAR_10];



        VAR_0->dc_index[VAR_5] = get_bits(&VAR_0->gb, 4);

        VAR_0->ac_index[VAR_5] = get_bits(&VAR_0->gb, 4);



        if (VAR_0->dc_index[VAR_5] <  0 || VAR_0->ac_index[VAR_5] < 0 ||

            VAR_0->dc_index[VAR_5] >= 4 || VAR_0->ac_index[VAR_5] >= 4)

            goto out_of_range;

        if (!VAR_0->vlcs[0][VAR_0->dc_index[VAR_5]].table || !(VAR_0->progressive ? VAR_0->vlcs[2][VAR_0->ac_index[0]].table : VAR_0->vlcs[1][VAR_0->ac_index[VAR_5]].table))

            goto out_of_range;

    }



    VAR_8 = get_bits(&VAR_0->gb, 8);       

    VAR_14 = get_bits(&VAR_0->gb, 8);             

    if(VAR_0->avctx->codec_tag != AV_RL32("CJPG")){

        VAR_15      = get_bits(&VAR_0->gb, 4); 

        VAR_9 = get_bits(&VAR_0->gb, 4); 

    }else

        VAR_15 = VAR_9 = 0;



    if (VAR_4 > 1) {

        

        VAR_0->mb_width  = (VAR_0->width  + VAR_0->h_max * VAR_13 - 1) / (VAR_0->h_max * VAR_13);

        VAR_0->mb_height = (VAR_0->height + VAR_0->v_max * VAR_13 - 1) / (VAR_0->v_max * VAR_13);

    } else if (!VAR_0->ls) { 

        VAR_6 = VAR_0->h_max / VAR_0->h_scount[0];

        VAR_7 = VAR_0->v_max / VAR_0->v_scount[0];

        VAR_0->mb_width     = (VAR_0->width  + VAR_6 * VAR_13 - 1) / (VAR_6 * VAR_13);

        VAR_0->mb_height    = (VAR_0->height + VAR_7 * VAR_13 - 1) / (VAR_7 * VAR_13);

        VAR_0->nb_blocks[0] = 1;

        VAR_0->h_scount[0]  = 1;

        VAR_0->v_scount[0]  = 1;

    }



    if (VAR_0->avctx->debug & FF_DEBUG_PICT_INFO)

        av_log(VAR_0->avctx, AV_LOG_DEBUG, "%VAR_0 %VAR_0 p:%d >>:%d VAR_14:%d bits:%d skip:%d %VAR_0 comp:%d\n",

               VAR_0->lossless ? "lossless" : "sequential DCT", VAR_0->rgb ? "RGB" : "",

               VAR_8, VAR_9, VAR_14, VAR_0->bits, VAR_0->mjpb_skiptosod,

               VAR_0->pegasus_rct ? "PRCT" : (VAR_0->rct ? "RCT" : ""), VAR_4);





    

    for (VAR_5 = VAR_0->mjpb_skiptosod; VAR_5 > 0; VAR_5--)

        skip_bits(&VAR_0->gb, 8);



next_field:

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

        VAR_0->last_dc[VAR_5] = 1024;



    if (VAR_0->lossless) {

        av_assert0(VAR_0->picture_ptr == &VAR_0->picture);

        if (CONFIG_JPEGLS_DECODER && VAR_0->ls) {







            if ((VAR_12 = ff_jpegls_decode_picture(VAR_0, VAR_8,

                                                VAR_9, VAR_14)) < 0)

                return VAR_12;

        } else {

            if (VAR_0->rgb) {

                if ((VAR_12 = ljpeg_decode_rgb_scan(VAR_0, VAR_4, VAR_8, VAR_9)) < 0)

                    return VAR_12;

            } else {

                if ((VAR_12 = ljpeg_decode_yuv_scan(VAR_0, VAR_8,

                                                 VAR_9,

                                                 VAR_4)) < 0)

                    return VAR_12;

            }

        }

    } else {

        if (VAR_0->progressive && VAR_8) {

            av_assert0(VAR_0->picture_ptr == &VAR_0->picture);

            if ((VAR_12 = mjpeg_decode_scan_progressive_ac(VAR_0, VAR_8,

                                                        VAR_14, VAR_15,

                                                        VAR_9)) < 0)

                return VAR_12;

        } else {

            if ((VAR_12 = mjpeg_decode_scan(VAR_0, VAR_4,

                                         VAR_15, VAR_9,

                                         VAR_1, VAR_2)) < 0)

                return VAR_12;

        }

    }



    if (VAR_0->interlaced &&

        get_bits_left(&VAR_0->gb) > 32 &&

        show_bits(&VAR_0->gb, 8) == 0xFF) {

        GetBitContext bak = VAR_0->gb;

        align_get_bits(&bak);

        if (show_bits(&bak, 16) == 0xFFD1) {

            av_log(VAR_0->avctx, AV_LOG_DEBUG, "AVRn interlaced picture marker found\n");

            VAR_0->gb = bak;

            skip_bits(&VAR_0->gb, 16);

            VAR_0->bottom_field ^= 1;



            goto next_field;

        }

    }



    emms_c();

    return 0;

 out_of_range:

    av_log(VAR_0->avctx, AV_LOG_ERROR, "decode_sos: ac/dc VAR_10 out of range\n");

    return AVERROR_INVALIDDATA;

}

int FUNC_0(MJpegDecodeContext *VAR_0, const uint8_t *VAR_1,
const AVFrame *VAR_2)
{ int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9; int VAR_10, VAR_11, VAR_12; const int VAR_13 = VAR_0->lossless ? 1 : 8; int VAR_14, VAR_15; if (!VAR_0->got_picture) { av_log(VAR_0->avctx, AV_LOG_WARNING,
"Can not process SOS before SOF, skipping\n"); return -1; } av_assert0(VAR_0->picture_ptr->data[0]); VAR_3 = get_bits(&VAR_0->gb, 16); VAR_4 = get_bits(&VAR_0->gb, 8); if (VAR_4 == 0 || VAR_4 > MAX_COMPONENTS) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"decode_sos: VAR_4 (%d) unsupported\n", VAR_4); return AVERROR_PATCHWELCOME; } if (VAR_3 != 6 + 2 * VAR_4) { av_log(VAR_0->avctx, AV_LOG_ERROR, "decode_sos: invalid VAR_3 (%d)\n", VAR_3); return AVERROR_INVALIDDATA; } for (VAR_5 = 0; VAR_5 < VAR_4; VAR_5++) { VAR_11 = get_bits(&VAR_0->gb, 8) - 1; av_log(VAR_0->avctx, AV_LOG_DEBUG, "component: %d\n", VAR_11); for (VAR_10 = 0; VAR_10 < VAR_0->VAR_4; VAR_10++) if (VAR_11 == VAR_0->component_id[VAR_10])
break; if (VAR_10 == VAR_0->VAR_4) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"decode_sos: VAR_10(%d) out of components\n", VAR_10); return AVERROR_INVALIDDATA; } if (VAR_0->avctx->codec_tag == MKTAG('M', 'T', 'S', 'J')
&& VAR_4 == 3 && VAR_0->VAR_4 == 3 && VAR_5)
VAR_10 = 3 - VAR_5; if(VAR_4 == 3 && VAR_0->VAR_4 == 3 && VAR_0->avctx->pix_fmt == AV_PIX_FMT_GBR24P)
VAR_10 = (VAR_5+2)%3; if(VAR_4 == 1 && VAR_0->VAR_4 == 3 && VAR_0->avctx->pix_fmt == AV_PIX_FMT_GBR24P)
VAR_10 = (VAR_10+2)%3; VAR_0->comp_index[VAR_5] = VAR_10; VAR_0->nb_blocks[VAR_5] = VAR_0->h_count[VAR_10] * VAR_0->v_count[VAR_10]; VAR_0->h_scount[VAR_5]  = VAR_0->h_count[VAR_10]; VAR_0->v_scount[VAR_5]  = VAR_0->v_count[VAR_10]; VAR_0->dc_index[VAR_5] = get_bits(&VAR_0->gb, 4); VAR_0->ac_index[VAR_5] = get_bits(&VAR_0->gb, 4); if (VAR_0->dc_index[VAR_5] <  0 || VAR_0->ac_index[VAR_5] < 0 ||
VAR_0->dc_index[VAR_5] >= 4 || VAR_0->ac_index[VAR_5] >= 4)
goto out_of_range; if (!VAR_0->vlcs[0][VAR_0->dc_index[VAR_5]].table || !(VAR_0->progressive ? VAR_0->vlcs[2][VAR_0->ac_index[0]].table : VAR_0->vlcs[1][VAR_0->ac_index[VAR_5]].table))
goto out_of_range; } VAR_8 = get_bits(&VAR_0->gb, 8); VAR_14 = get_bits(&VAR_0->gb, 8); if(VAR_0->avctx->codec_tag != AV_RL32("CJPG")){ VAR_15      = get_bits(&VAR_0->gb, 4); VAR_9 = get_bits(&VAR_0->gb, 4); }else VAR_15 = VAR_9 = 0; if (VAR_4 > 1) { VAR_0->mb_width  = (VAR_0->width  + VAR_0->h_max * VAR_13 - 1) / (VAR_0->h_max * VAR_13); VAR_0->mb_height = (VAR_0->height + VAR_0->v_max * VAR_13 - 1) / (VAR_0->v_max * VAR_13); } else if (!VAR_0->ls) { VAR_6 = VAR_0->h_max / VAR_0->h_scount[0]; VAR_7 = VAR_0->v_max / VAR_0->v_scount[0]; VAR_0->mb_width     = (VAR_0->width  + VAR_6 * VAR_13 - 1) / (VAR_6 * VAR_13); VAR_0->mb_height    = (VAR_0->height + VAR_7 * VAR_13 - 1) / (VAR_7 * VAR_13); VAR_0->nb_blocks[0] = 1; VAR_0->h_scount[0]  = 1; VAR_0->v_scount[0]  = 1; } if (VAR_0->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(VAR_0->avctx, AV_LOG_DEBUG, "%VAR_0 %VAR_0 p:%d >>:%d VAR_14:%d bits:%d skip:%d %VAR_0 comp:%d\n",
VAR_0->lossless ? "lossless" : "sequential DCT", VAR_0->rgb ? "RGB" : "",
VAR_8, VAR_9, VAR_14, VAR_0->bits, VAR_0->mjpb_skiptosod,
VAR_0->pegasus_rct ? "PRCT" : (VAR_0->rct ? "RCT" : ""), VAR_4); for (VAR_5 = VAR_0->mjpb_skiptosod; VAR_5 > 0; VAR_5--) skip_bits(&VAR_0->gb, 8); next_field:
for (VAR_5 = 0; VAR_5 < VAR_4; VAR_5++) VAR_0->last_dc[VAR_5] = 1024; if (VAR_0->lossless) { av_assert0(VAR_0->picture_ptr == &VAR_0->picture); if (CONFIG_JPEGLS_DECODER && VAR_0->ls) { if ((VAR_12 = ff_jpegls_decode_picture(VAR_0, VAR_8,
VAR_9, VAR_14)) < 0)
return VAR_12; } else { if (VAR_0->rgb) { if ((VAR_12 = ljpeg_decode_rgb_scan(VAR_0, VAR_4, VAR_8, VAR_9)) < 0)
return VAR_12; } else { if ((VAR_12 = ljpeg_decode_yuv_scan(VAR_0, VAR_8,
VAR_9,
VAR_4)) < 0)
return VAR_12; } } } else { if (VAR_0->progressive && VAR_8) { av_assert0(VAR_0->picture_ptr == &VAR_0->picture); if ((VAR_12 = mjpeg_decode_scan_progressive_ac(VAR_0, VAR_8,
VAR_14, VAR_15,
VAR_9)) < 0)
return VAR_12; } else { if ((VAR_12 = mjpeg_decode_scan(VAR_0, VAR_4,
VAR_15, VAR_9,
VAR_1, VAR_2)) < 0)
return VAR_12; } } if (VAR_0->interlaced &&
get_bits_left(&VAR_0->gb) > 32 &&
show_bits(&VAR_0->gb, 8) == 0xFF) { GetBitContext bak = VAR_0->gb; align_get_bits(&bak); if (show_bits(&bak, 16) == 0xFFD1) { av_log(VAR_0->avctx, AV_LOG_DEBUG, "AVRn interlaced picture marker found\n"); VAR_0->gb = bak; skip_bits(&VAR_0->gb, 16); VAR_0->bottom_field ^= 1; goto next_field; } } emms_c(); return 0; out_of_range:
av_log(VAR_0->avctx, AV_LOG_ERROR, "decode_sos: ac/dc VAR_10 out of range\n"); return AVERROR_INVALIDDATA; }