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

                            const AVFrame *frame)

{

    LJpegEncContext *s    = avctx->priv_data;

    const int width       = frame->width;

    const int height      = frame->height;

    const int linesize    = frame->linesize[0];

    uint16_t (*buffer)[4] = s->scratch;

    const int predictor   = avctx->prediction_method+1;

    int left[3], top[3], topleft[3];

    int x, y, i;



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

        buffer[0][i] = 1 << (9 - 1);



    for (y = 0; y < height; y++) {

        const int modified_predictor = y ? predictor : 1;

        uint8_t *ptr = frame->data[0] + (linesize * y);



        if (pb->buf_end - pb->buf - (put_bits_count(pb) >> 3) < width * 3 * 3) {

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

            return -1;

        }



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

            top[i]= left[i]= topleft[i]= buffer[0][i];



        for (x = 0; x < width; x++) {

            buffer[x][1] =  ptr[3 * x + 0] -     ptr[3 * x + 1] + 0x100;

            buffer[x][2] =  ptr[3 * x + 2] -     ptr[3 * x + 1] + 0x100;

            buffer[x][0] = (ptr[3 * x + 0] + 2 * ptr[3 * x + 1] + ptr[3 * x + 2]) >> 2;



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

                int pred, diff;



                PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);



                topleft[i] = top[i];

                top[i]     = buffer[x+1][i];



                left[i]    = buffer[x][i];



                diff       = ((left[i] - pred + 0x100) & 0x1FF) - 0x100;



                if (i == 0)

                    ff_mjpeg_encode_dc(pb, diff, s->huff_size_dc_luminance, s->huff_code_dc_luminance); //FIXME ugly

                else

                    ff_mjpeg_encode_dc(pb, diff, s->huff_size_dc_chrominance, s->huff_code_dc_chrominance);

            }

        }

    }



    return 0;

}

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

                            const AVFrame *frame)

{

    LJpegEncContext *s    = avctx->priv_data;

    const int width       = frame->width;

    const int height      = frame->height;

    const int linesize    = frame->linesize[0];

    uint16_t (*buffer)[4] = s->scratch;

    const int predictor   = avctx->prediction_method+1;

    int left[3], top[3], topleft[3];

    int x, y, i;



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

        buffer[0][i] = 1 << (9 - 1);



    for (y = 0; y < height; y++) {

        const int modified_predictor = y ? predictor : 1;

        uint8_t *ptr = frame->data[0] + (linesize * y);



        if (pb->buf_end - pb->buf - (put_bits_count(pb) >> 3) < width * 3 * 3) {

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

            return -1;

        }



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

            top[i]= left[i]= topleft[i]= buffer[0][i];



        for (x = 0; x < width; x++) {

            buffer[x][1] =  ptr[3 * x + 0] -     ptr[3 * x + 1] + 0x100;

            buffer[x][2] =  ptr[3 * x + 2] -     ptr[3 * x + 1] + 0x100;

            buffer[x][0] = (ptr[3 * x + 0] + 2 * ptr[3 * x + 1] + ptr[3 * x + 2]) >> 2;



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

                int pred, diff;



                PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);



                topleft[i] = top[i];

                top[i]     = buffer[x+1][i];



                left[i]    = buffer[x][i];



                diff       = ((left[i] - pred + 0x100) & 0x1FF) - 0x100;



                if (i == 0)

                    ff_mjpeg_encode_dc(pb, diff, s->huff_size_dc_luminance, s->huff_code_dc_luminance); 

                else

                    ff_mjpeg_encode_dc(pb, diff, s->huff_size_dc_chrominance, s->huff_code_dc_chrominance);

            }

        }

    }



    return 0;

}

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

                            const AVFrame *VAR_2)

{

    LJpegEncContext *s    = VAR_0->priv_data;

    const int VAR_3       = VAR_2->VAR_3;

    const int VAR_4      = VAR_2->VAR_4;

    const int VAR_5    = VAR_2->VAR_5[0];

    uint16_t (*buffer)[4] = s->scratch;

    const int VAR_6   = VAR_0->prediction_method+1;

    int VAR_7[3], VAR_8[3], VAR_9[3];

    int VAR_10, VAR_11, VAR_12;



    for (VAR_12 = 0; VAR_12 < 3; VAR_12++)

        buffer[0][VAR_12] = 1 << (9 - 1);



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

        const int VAR_13 = VAR_11 ? VAR_6 : 1;

        uint8_t *ptr = VAR_2->data[0] + (VAR_5 * VAR_11);



        if (VAR_1->buf_end - VAR_1->buf - (put_bits_count(VAR_1) >> 3) < VAR_3 * 3 * 3) {

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

            return -1;

        }



        for (VAR_12 = 0; VAR_12 < 3; VAR_12++)

            VAR_8[VAR_12]= VAR_7[VAR_12]= VAR_9[VAR_12]= buffer[0][VAR_12];



        for (VAR_10 = 0; VAR_10 < VAR_3; VAR_10++) {

            buffer[VAR_10][1] =  ptr[3 * VAR_10 + 0] -     ptr[3 * VAR_10 + 1] + 0x100;

            buffer[VAR_10][2] =  ptr[3 * VAR_10 + 2] -     ptr[3 * VAR_10 + 1] + 0x100;

            buffer[VAR_10][0] = (ptr[3 * VAR_10 + 0] + 2 * ptr[3 * VAR_10 + 1] + ptr[3 * VAR_10 + 2]) >> 2;



            for (VAR_12 = 0; VAR_12 < 3; VAR_12++) {

                int VAR_14, VAR_15;



                PREDICT(VAR_14, VAR_9[VAR_12], VAR_8[VAR_12], VAR_7[VAR_12], VAR_13);



                VAR_9[VAR_12] = VAR_8[VAR_12];

                VAR_8[VAR_12]     = buffer[VAR_10+1][VAR_12];



                VAR_7[VAR_12]    = buffer[VAR_10][VAR_12];



                VAR_15       = ((VAR_7[VAR_12] - VAR_14 + 0x100) & 0x1FF) - 0x100;



                if (VAR_12 == 0)

                    ff_mjpeg_encode_dc(VAR_1, VAR_15, s->huff_size_dc_luminance, s->huff_code_dc_luminance); 

                else

                    ff_mjpeg_encode_dc(VAR_1, VAR_15, s->huff_size_dc_chrominance, s->huff_code_dc_chrominance);

            }

        }

    }



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, PutBitContext *VAR_1,
const AVFrame *VAR_2)
{ LJpegEncContext *s    = VAR_0->priv_data; const int VAR_3       = VAR_2->VAR_3; const int VAR_4      = VAR_2->VAR_4; const int VAR_5    = VAR_2->VAR_5[0]; uint16_t (*buffer)[4] = s->scratch; const int VAR_6   = VAR_0->prediction_method+1; int VAR_7[3], VAR_8[3], VAR_9[3]; int VAR_10, VAR_11, VAR_12; for (VAR_12 = 0; VAR_12 < 3; VAR_12++) buffer[0][VAR_12] = 1 << (9 - 1); for (VAR_11 = 0; VAR_11 < VAR_4; VAR_11++) { const int VAR_13 = VAR_11 ? VAR_6 : 1; uint8_t *ptr = VAR_2->data[0] + (VAR_5 * VAR_11); if (VAR_1->buf_end - VAR_1->buf - (put_bits_count(VAR_1) >> 3) < VAR_3 * 3 * 3) { av_log(VAR_0, AV_LOG_ERROR, "encoded VAR_2 too large\n"); return -1; } for (VAR_12 = 0; VAR_12 < 3; VAR_12++) VAR_8[VAR_12]= VAR_7[VAR_12]= VAR_9[VAR_12]= buffer[0][VAR_12]; for (VAR_10 = 0; VAR_10 < VAR_3; VAR_10++) { buffer[VAR_10][1] =  ptr[3 * VAR_10 + 0] -     ptr[3 * VAR_10 + 1] + 0x100; buffer[VAR_10][2] =  ptr[3 * VAR_10 + 2] -     ptr[3 * VAR_10 + 1] + 0x100; buffer[VAR_10][0] = (ptr[3 * VAR_10 + 0] + 2 * ptr[3 * VAR_10 + 1] + ptr[3 * VAR_10 + 2]) >> 2; for (VAR_12 = 0; VAR_12 < 3; VAR_12++) { int VAR_14, VAR_15; PREDICT(VAR_14, VAR_9[VAR_12], VAR_8[VAR_12], VAR_7[VAR_12], VAR_13); VAR_9[VAR_12] = VAR_8[VAR_12]; VAR_8[VAR_12]     = buffer[VAR_10+1][VAR_12]; VAR_7[VAR_12]    = buffer[VAR_10][VAR_12]; VAR_15       = ((VAR_7[VAR_12] - VAR_14 + 0x100) & 0x1FF) - 0x100; if (VAR_12 == 0)
ff_mjpeg_encode_dc(VAR_1, VAR_15, s->huff_size_dc_luminance, s->huff_code_dc_luminance); else
ff_mjpeg_encode_dc(VAR_1, VAR_15, s->huff_size_dc_chrominance, s->huff_code_dc_chrominance); } } } return 0; }