static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,

                              const AVFrame *pict, int *got_packet)

{

    LJpegEncContext *s = avctx->priv_data;

    PutBitContext pb;

    const int width  = avctx->width;

    const int height = avctx->height;

    const int mb_width  = (width  + s->hsample[0] - 1) / s->hsample[0];

    const int mb_height = (height + s->vsample[0] - 1) / s->vsample[0];

    int max_pkt_size = AV_INPUT_BUFFER_MIN_SIZE;

    int ret, header_bits;



    if (avctx->pix_fmt == AV_PIX_FMT_BGR24)

        max_pkt_size += width * height * 3 * 3;

    else {

        max_pkt_size += mb_width * mb_height * 3 * 4

                        * s->hsample[0] * s->vsample[0];

    }

    if ((ret = ff_alloc_packet(pkt, max_pkt_size)) < 0) {

        av_log(avctx, AV_LOG_ERROR, "Error getting output packet of size %d.\n", max_pkt_size);

        return ret;

    }



    init_put_bits(&pb, pkt->data, pkt->size);



    ff_mjpeg_encode_picture_header(avctx, &pb, &s->scantable,

                                   s->matrix);



    header_bits = put_bits_count(&pb);



    if (avctx->pix_fmt == AV_PIX_FMT_BGR24)

        ret = ljpeg_encode_bgr(avctx, &pb, pict);

    else

        ret = ljpeg_encode_yuv(avctx, &pb, pict);

    if (ret < 0)

        return ret;



    emms_c();



    ff_mjpeg_encode_picture_trailer(&pb, header_bits);



    flush_put_bits(&pb);

    pkt->size   = put_bits_ptr(&pb) - pb.buf;

    pkt->flags |= AV_PKT_FLAG_KEY;

    *got_packet = 1;



    return 0;

}

static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,

                              const AVFrame *pict, int *got_packet)

{

    LJpegEncContext *s = avctx->priv_data;

    PutBitContext pb;

    const int width  = avctx->width;

    const int height = avctx->height;

    const int mb_width  = (width  + s->hsample[0] - 1) / s->hsample[0];

    const int mb_height = (height + s->vsample[0] - 1) / s->vsample[0];

    int max_pkt_size = AV_INPUT_BUFFER_MIN_SIZE;

    int ret, header_bits;



    if (avctx->pix_fmt == AV_PIX_FMT_BGR24)

        max_pkt_size += width * height * 3 * 3;

    else {

        max_pkt_size += mb_width * mb_height * 3 * 4

                        * s->hsample[0] * s->vsample[0];

    }

    if ((ret = ff_alloc_packet(pkt, max_pkt_size)) < 0) {

        av_log(avctx, AV_LOG_ERROR, "Error getting output packet of size %d.\n", max_pkt_size);

        return ret;

    }



    init_put_bits(&pb, pkt->data, pkt->size);



    ff_mjpeg_encode_picture_header(avctx, &pb, &s->scantable,

                                   s->matrix);



    header_bits = put_bits_count(&pb);



    if (avctx->pix_fmt == AV_PIX_FMT_BGR24)

        ret = ljpeg_encode_bgr(avctx, &pb, pict);

    else

        ret = ljpeg_encode_yuv(avctx, &pb, pict);

    if (ret < 0)

        return ret;



    emms_c();



    ff_mjpeg_encode_picture_trailer(&pb, header_bits);



    flush_put_bits(&pb);

    pkt->size   = put_bits_ptr(&pb) - pb.buf;

    pkt->flags |= AV_PKT_FLAG_KEY;

    *got_packet = 1;



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,

                              const AVFrame *VAR_2, int *VAR_3)

{

    LJpegEncContext *s = VAR_0->priv_data;

    PutBitContext pb;

    const int VAR_4  = VAR_0->VAR_4;

    const int VAR_5 = VAR_0->VAR_5;

    const int VAR_6  = (VAR_4  + s->hsample[0] - 1) / s->hsample[0];

    const int VAR_7 = (VAR_5 + s->vsample[0] - 1) / s->vsample[0];

    int VAR_8 = AV_INPUT_BUFFER_MIN_SIZE;

    int VAR_9, VAR_10;



    if (VAR_0->pix_fmt == AV_PIX_FMT_BGR24)

        VAR_8 += VAR_4 * VAR_5 * 3 * 3;

    else {

        VAR_8 += VAR_6 * VAR_7 * 3 * 4

                        * s->hsample[0] * s->vsample[0];

    }

    if ((VAR_9 = ff_alloc_packet(VAR_1, VAR_8)) < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Error getting output packet of size %d.\n", VAR_8);

        return VAR_9;

    }



    init_put_bits(&pb, VAR_1->data, VAR_1->size);



    ff_mjpeg_encode_picture_header(VAR_0, &pb, &s->scantable,

                                   s->matrix);



    VAR_10 = put_bits_count(&pb);



    if (VAR_0->pix_fmt == AV_PIX_FMT_BGR24)

        VAR_9 = ljpeg_encode_bgr(VAR_0, &pb, VAR_2);

    else

        VAR_9 = ljpeg_encode_yuv(VAR_0, &pb, VAR_2);

    if (VAR_9 < 0)

        return VAR_9;



    emms_c();



    ff_mjpeg_encode_picture_trailer(&pb, VAR_10);



    flush_put_bits(&pb);

    VAR_1->size   = put_bits_ptr(&pb) - pb.buf;

    VAR_1->flags |= AV_PKT_FLAG_KEY;

    *VAR_3 = 1;



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
const AVFrame *VAR_2, int *VAR_3)
{ LJpegEncContext *s = VAR_0->priv_data; PutBitContext pb; const int VAR_4  = VAR_0->VAR_4; const int VAR_5 = VAR_0->VAR_5; const int VAR_6  = (VAR_4  + s->hsample[0] - 1) / s->hsample[0]; const int VAR_7 = (VAR_5 + s->vsample[0] - 1) / s->vsample[0]; int VAR_8 = AV_INPUT_BUFFER_MIN_SIZE; int VAR_9, VAR_10; if (VAR_0->pix_fmt == AV_PIX_FMT_BGR24)
VAR_8 += VAR_4 * VAR_5 * 3 * 3; else { VAR_8 += VAR_6 * VAR_7 * 3 * 4
* s->hsample[0] * s->vsample[0]; } if ((VAR_9 = ff_alloc_packet(VAR_1, VAR_8)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "Error getting output packet of size %d.\n", VAR_8); return VAR_9; } init_put_bits(&pb, VAR_1->data, VAR_1->size); ff_mjpeg_encode_picture_header(VAR_0, &pb, &s->scantable,
s->matrix); VAR_10 = put_bits_count(&pb); if (VAR_0->pix_fmt == AV_PIX_FMT_BGR24)
VAR_9 = ljpeg_encode_bgr(VAR_0, &pb, VAR_2); else
VAR_9 = ljpeg_encode_yuv(VAR_0, &pb, VAR_2); if (VAR_9 < 0)
return VAR_9; emms_c(); ff_mjpeg_encode_picture_trailer(&pb, VAR_10); flush_put_bits(&pb); VAR_1->size   = put_bits_ptr(&pb) - pb.buf; VAR_1->flags |= AV_PKT_FLAG_KEY; *VAR_3 = 1; return 0; }