static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,

                                 int *got_frame, AVPacket *avpkt)

{

    Jpeg2000DecoderContext *s = avctx->priv_data;

    ThreadFrame frame = { .f = data };

    AVFrame *picture = data;

    int tileno, ret;



    s->avctx     = avctx;

    s->buf       = s->buf_start = avpkt->data;

    s->buf_end   = s->buf_start + avpkt->size;

    s->curtileno = 0; // TODO: only one tile in DCI JP2K. to implement for more tiles



    // reduction factor, i.e number of resolution levels to skip

    s->reduction_factor = s->lowres;



    if (s->buf_end - s->buf < 2)

        return AVERROR_INVALIDDATA;



    // check if the image is in jp2 format

    if ((AV_RB32(s->buf) == 12) &&

        (AV_RB32(s->buf + 4) == JP2_SIG_TYPE) &&

        (AV_RB32(s->buf + 8) == JP2_SIG_VALUE)) {

        if (!jp2_find_codestream(s)) {

            av_log(avctx, AV_LOG_ERROR,

                   "Could not find Jpeg2000 codestream atom.\n");

            return AVERROR_INVALIDDATA;

        }

    }



    if (bytestream_get_be16(&s->buf) != JPEG2000_SOC) {

        av_log(avctx, AV_LOG_ERROR, "SOC marker not present\n");

        return AVERROR_INVALIDDATA;

    }

    if (ret = jpeg2000_read_main_headers(s))

        goto end;



    /* get picture buffer */

    if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0) {

        av_log(avctx, AV_LOG_ERROR, "ff_thread_get_buffer() failed.\n");

        goto end;

    }

    picture->pict_type = AV_PICTURE_TYPE_I;

    picture->key_frame = 1;



    if (ret = jpeg2000_read_bitstream_packets(s))

        goto end;

    for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++)

        if (ret = jpeg2000_decode_tile(s, s->tile + tileno, picture))

            goto end;



    *got_frame = 1;



end:

    jpeg2000_dec_cleanup(s);

    return ret ? ret : s->buf - s->buf_start;

}

static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,

                                 int *got_frame, AVPacket *avpkt)

{

    Jpeg2000DecoderContext *s = avctx->priv_data;

    ThreadFrame frame = { .f = data };

    AVFrame *picture = data;

    int tileno, ret;



    s->avctx     = avctx;

    s->buf       = s->buf_start = avpkt->data;

    s->buf_end   = s->buf_start + avpkt->size;

    s->curtileno = 0; 



    

    s->reduction_factor = s->lowres;



    if (s->buf_end - s->buf < 2)

        return AVERROR_INVALIDDATA;



    

    if ((AV_RB32(s->buf) == 12) &&

        (AV_RB32(s->buf + 4) == JP2_SIG_TYPE) &&

        (AV_RB32(s->buf + 8) == JP2_SIG_VALUE)) {

        if (!jp2_find_codestream(s)) {

            av_log(avctx, AV_LOG_ERROR,

                   "Could not find Jpeg2000 codestream atom.\n");

            return AVERROR_INVALIDDATA;

        }

    }



    if (bytestream_get_be16(&s->buf) != JPEG2000_SOC) {

        av_log(avctx, AV_LOG_ERROR, "SOC marker not present\n");

        return AVERROR_INVALIDDATA;

    }

    if (ret = jpeg2000_read_main_headers(s))

        goto end;



    

    if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0) {

        av_log(avctx, AV_LOG_ERROR, "ff_thread_get_buffer() failed.\n");

        goto end;

    }

    picture->pict_type = AV_PICTURE_TYPE_I;

    picture->key_frame = 1;



    if (ret = jpeg2000_read_bitstream_packets(s))

        goto end;

    for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++)

        if (ret = jpeg2000_decode_tile(s, s->tile + tileno, picture))

            goto end;



    *got_frame = 1;



end:

    jpeg2000_dec_cleanup(s);

    return ret ? ret : s->buf - s->buf_start;

}

        return AVERROR_INVALIDDATA;     if (s->buf_end - s->buf < 2)     s->buf       = s->buf_start = avpkt->data;     s->buf_end   = s->buf_start + avpkt->size;     if (s->buf_end - s->buf < 2)     if ((AV_RB32(s->buf) == 12) &&         (AV_RB32(s->buf + 4) == JP2_SIG_TYPE) &&         (AV_RB32(s->buf + 8) == JP2_SIG_VALUE)) {     if (bytestream_get_be16(&s->buf) != JPEG2000_SOC) {     return ret ? ret : s->buf - s->buf_start;
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,

                                 int *VAR_2, AVPacket *VAR_3)

{

    Jpeg2000DecoderContext *s = VAR_0->priv_data;

    ThreadFrame frame = { .f = VAR_1 };

    AVFrame *picture = VAR_1;

    int VAR_4, VAR_5;



    s->VAR_0     = VAR_0;

    s->buf       = s->buf_start = VAR_3->VAR_1;

    s->buf_end   = s->buf_start + VAR_3->size;

    s->curtileno = 0; 



    

    s->reduction_factor = s->lowres;



    if (s->buf_end - s->buf < 2)

        return AVERROR_INVALIDDATA;



    

    if ((AV_RB32(s->buf) == 12) &&

        (AV_RB32(s->buf + 4) == JP2_SIG_TYPE) &&

        (AV_RB32(s->buf + 8) == JP2_SIG_VALUE)) {

        if (!jp2_find_codestream(s)) {

            av_log(VAR_0, AV_LOG_ERROR,

                   "Could not find Jpeg2000 codestream atom.\n");

            return AVERROR_INVALIDDATA;

        }

    }



    if (bytestream_get_be16(&s->buf) != JPEG2000_SOC) {

        av_log(VAR_0, AV_LOG_ERROR, "SOC marker not present\n");

        return AVERROR_INVALIDDATA;

    }

    if (VAR_5 = jpeg2000_read_main_headers(s))

        goto end;



    

    if ((VAR_5 = ff_thread_get_buffer(VAR_0, &frame, 0)) < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "ff_thread_get_buffer() failed.\n");

        goto end;

    }

    picture->pict_type = AV_PICTURE_TYPE_I;

    picture->key_frame = 1;



    if (VAR_5 = jpeg2000_read_bitstream_packets(s))

        goto end;

    for (VAR_4 = 0; VAR_4 < s->numXtiles * s->numYtiles; VAR_4++)

        if (VAR_5 = jpeg2000_decode_tile(s, s->tile + VAR_4, picture))

            goto end;



    *VAR_2 = 1;



end:

    jpeg2000_dec_cleanup(s);

    return VAR_5 ? VAR_5 : s->buf - s->buf_start;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,
int *VAR_2, AVPacket *VAR_3)
{ Jpeg2000DecoderContext *s = VAR_0->priv_data; ThreadFrame frame = { .f = VAR_1 }; AVFrame *picture = VAR_1; int VAR_4, VAR_5; s->VAR_0     = VAR_0; s->buf       = s->buf_start = VAR_3->VAR_1; s->buf_end   = s->buf_start + VAR_3->size; s->curtileno = 0; s->reduction_factor = s->lowres; if (s->buf_end - s->buf < 2)
return AVERROR_INVALIDDATA; if ((AV_RB32(s->buf) == 12) &&
(AV_RB32(s->buf + 4) == JP2_SIG_TYPE) &&
(AV_RB32(s->buf + 8) == JP2_SIG_VALUE)) { if (!jp2_find_codestream(s)) { av_log(VAR_0, AV_LOG_ERROR,
"Could not find Jpeg2000 codestream atom.\n"); return AVERROR_INVALIDDATA; } } if (bytestream_get_be16(&s->buf) != JPEG2000_SOC) { av_log(VAR_0, AV_LOG_ERROR, "SOC marker not present\n"); return AVERROR_INVALIDDATA; } if (VAR_5 = jpeg2000_read_main_headers(s))
goto end; if ((VAR_5 = ff_thread_get_buffer(VAR_0, &frame, 0)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "ff_thread_get_buffer() failed.\n"); goto end; } picture->pict_type = AV_PICTURE_TYPE_I; picture->key_frame = 1; if (VAR_5 = jpeg2000_read_bitstream_packets(s))
goto end; for (VAR_4 = 0; VAR_4 < s->numXtiles * s->numYtiles; VAR_4++) if (VAR_5 = jpeg2000_decode_tile(s, s->tile + VAR_4, picture))
goto end; *VAR_2 = 1; end:
jpeg2000_dec_cleanup(s); return VAR_5 ? VAR_5 : s->buf - s->buf_start; }