static int ljpeg_encode_yuv(AVCodecContext *avctx, PutBitContext *pb,

                            const AVFrame *frame)

{

    const int predictor = avctx->prediction_method + 1;

    LJpegEncContext *s  = avctx->priv_data;

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

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

    int mb_x, mb_y;



    for (mb_y = 0; mb_y < mb_height; mb_y++) {

        if (pb->buf_end - pb->buf - (put_bits_count(pb) >> 3) <

            mb_width * 4 * 3 * s->hsample[0] * s->vsample[0]) {

            av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");

            return -1;

        }



        for (mb_x = 0; mb_x < mb_width; mb_x++)

            ljpeg_encode_yuv_mb(s, pb, frame, predictor, mb_x, mb_y);

    }



    return 0;

}

static int ljpeg_encode_yuv(AVCodecContext *avctx, PutBitContext *pb,

                            const AVFrame *frame)

{

    const int predictor = avctx->prediction_method + 1;

    LJpegEncContext *s  = avctx->priv_data;

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

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

    int mb_x, mb_y;



    for (mb_y = 0; mb_y < mb_height; mb_y++) {

        if (pb->buf_end - pb->buf - (put_bits_count(pb) >> 3) <

            mb_width * 4 * 3 * s->hsample[0] * s->vsample[0]) {

            av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");

            return -1;

        }



        for (mb_x = 0; mb_x < mb_width; mb_x++)

            ljpeg_encode_yuv_mb(s, pb, frame, predictor, mb_x, mb_y);

    }



    return 0;

}

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

                            const AVFrame *VAR_2)

{

    const int VAR_3 = VAR_0->prediction_method + 1;

    LJpegEncContext *s  = VAR_0->priv_data;

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

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

    int VAR_6, VAR_7;



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

        if (VAR_1->buf_end - VAR_1->buf - (put_bits_count(VAR_1) >> 3) <

            VAR_4 * 4 * 3 * s->hsample[0] * s->vsample[0]) {

            av_log(VAR_0, AV_LOG_ERROR, "encoded VAR_2 too large\n");

            return -1;

        }



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

            ljpeg_encode_yuv_mb(s, VAR_1, VAR_2, VAR_3, VAR_6, VAR_7);

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, PutBitContext *VAR_1,
const AVFrame *VAR_2)
{ const int VAR_3 = VAR_0->prediction_method + 1; LJpegEncContext *s  = VAR_0->priv_data; const int VAR_4  = (VAR_0->width  + s->hsample[0] - 1) / s->hsample[0]; const int VAR_5 = (VAR_0->height + s->vsample[0] - 1) / s->vsample[0]; int VAR_6, VAR_7; for (VAR_7 = 0; VAR_7 < VAR_5; VAR_7++) { if (VAR_1->buf_end - VAR_1->buf - (put_bits_count(VAR_1) >> 3) <
VAR_4 * 4 * 3 * s->hsample[0] * s->vsample[0]) { av_log(VAR_0, AV_LOG_ERROR, "encoded VAR_2 too large\n"); return -1; } for (VAR_6 = 0; VAR_6 < VAR_4; VAR_6++) ljpeg_encode_yuv_mb(s, VAR_1, VAR_2, VAR_3, VAR_6, VAR_7); } return 0; }