static int encode_frame(AVCodecContext *avctx,

                        uint8_t *buf, int buf_size,

                        void *data)

{

    int tileno, ret;

    J2kEncoderContext *s = avctx->priv_data;



    // init:

    s->buf = s->buf_start = buf;

    s->buf_end = buf + buf_size;



    s->picture = data;



    s->lambda = s->picture->quality * LAMBDA_SCALE;



    copy_frame(s);

    reinit(s);



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

        return -1;

    bytestream_put_be16(&s->buf, J2K_SOC);

    if (ret = put_siz(s))

        return ret;

    if (ret = put_cod(s))

        return ret;

    if (ret = put_qcd(s, 0))

        return ret;



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

        uint8_t *psotptr;

        if ((psotptr = put_sot(s, tileno)) < 0)

            return psotptr;

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

            return -1;

        bytestream_put_be16(&s->buf, J2K_SOD);

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

            return ret;

        bytestream_put_be32(&psotptr, s->buf - psotptr + 6);

    }

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

        return -1;

    bytestream_put_be16(&s->buf, J2K_EOC);



    av_log(s->avctx, AV_LOG_DEBUG, "end\n");

    return s->buf - s->buf_start;

}

static int encode_frame(AVCodecContext *avctx,

                        uint8_t *buf, int buf_size,

                        void *data)

{

    int tileno, ret;

    J2kEncoderContext *s = avctx->priv_data;



    

    s->buf = s->buf_start = buf;

    s->buf_end = buf + buf_size;



    s->picture = data;



    s->lambda = s->picture->quality * LAMBDA_SCALE;



    copy_frame(s);

    reinit(s);



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

        return -1;

    bytestream_put_be16(&s->buf, J2K_SOC);

    if (ret = put_siz(s))

        return ret;

    if (ret = put_cod(s))

        return ret;

    if (ret = put_qcd(s, 0))

        return ret;



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

        uint8_t *psotptr;

        if ((psotptr = put_sot(s, tileno)) < 0)

            return psotptr;

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

            return -1;

        bytestream_put_be16(&s->buf, J2K_SOD);

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

            return ret;

        bytestream_put_be32(&psotptr, s->buf - psotptr + 6);

    }

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

        return -1;

    bytestream_put_be16(&s->buf, J2K_EOC);



    av_log(s->avctx, AV_LOG_DEBUG, "end\n");

    return s->buf - s->buf_start;

}

    s->picture = data;     s->lambda = s->picture->quality * LAMBDA_SCALE;
static int FUNC_0(AVCodecContext *VAR_0,

                        uint8_t *VAR_1, int VAR_2,

                        void *VAR_3)

{

    int VAR_4, VAR_5;

    J2kEncoderContext *s = VAR_0->priv_data;



    

    s->VAR_1 = s->buf_start = VAR_1;

    s->buf_end = VAR_1 + VAR_2;



    s->picture = VAR_3;



    s->lambda = s->picture->quality * LAMBDA_SCALE;



    copy_frame(s);

    reinit(s);



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

        return -1;

    bytestream_put_be16(&s->VAR_1, J2K_SOC);

    if (VAR_5 = put_siz(s))

        return VAR_5;

    if (VAR_5 = put_cod(s))

        return VAR_5;

    if (VAR_5 = put_qcd(s, 0))

        return VAR_5;



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

        uint8_t *psotptr;

        if ((psotptr = put_sot(s, VAR_4)) < 0)

            return psotptr;

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

            return -1;

        bytestream_put_be16(&s->VAR_1, J2K_SOD);

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

            return VAR_5;

        bytestream_put_be32(&psotptr, s->VAR_1 - psotptr + 6);

    }

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

        return -1;

    bytestream_put_be16(&s->VAR_1, J2K_EOC);



    av_log(s->VAR_0, AV_LOG_DEBUG, "end\n");

    return s->VAR_1 - s->buf_start;

}

static int FUNC_0(AVCodecContext *VAR_0,
uint8_t *VAR_1, int VAR_2,
void *VAR_3)
{ int VAR_4, VAR_5; J2kEncoderContext *s = VAR_0->priv_data; s->VAR_1 = s->buf_start = VAR_1; s->buf_end = VAR_1 + VAR_2; s->picture = VAR_3; s->lambda = s->picture->quality * LAMBDA_SCALE; copy_frame(s); reinit(s); if (s->buf_end - s->VAR_1 < 2)
return -1; bytestream_put_be16(&s->VAR_1, J2K_SOC); if (VAR_5 = put_siz(s))
return VAR_5; if (VAR_5 = put_cod(s))
return VAR_5; if (VAR_5 = put_qcd(s, 0))
return VAR_5; for (VAR_4 = 0; VAR_4 < s->numXtiles * s->numYtiles; VAR_4++){ uint8_t *psotptr; if ((psotptr = put_sot(s, VAR_4)) < 0)
return psotptr; if (s->buf_end - s->VAR_1 < 2)
return -1; bytestream_put_be16(&s->VAR_1, J2K_SOD); if (VAR_5 = encode_tile(s, s->tile + VAR_4, VAR_4))
return VAR_5; bytestream_put_be32(&psotptr, s->VAR_1 - psotptr + 6); } if (s->buf_end - s->VAR_1 < 2)
return -1; bytestream_put_be16(&s->VAR_1, J2K_EOC); av_log(s->VAR_0, AV_LOG_DEBUG, "end\n"); return s->VAR_1 - s->buf_start; }