static void encode_rgb_frame(FFV1Context *s, uint8_t *src[3], int w, int h, int stride[3])

{

    int x, y, p, i;

    const int ring_size = s->avctx->context_model ? 3 : 2;

    int16_t *sample[4][3];

    int lbd    = s->bits_per_raw_sample <= 8;

    int bits   = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8;

    int offset = 1 << bits;



    s->run_index = 0;



    memset(s->sample_buffer, 0, ring_size * MAX_PLANES *

                                (w + 6) * sizeof(*s->sample_buffer));



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

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

            for (p = 0; p < MAX_PLANES; p++)

                sample[p][i]= s->sample_buffer + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;



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

            int b, g, r, av_uninit(a);

            if (lbd) {

                unsigned v = *((uint32_t*)(src[0] + x*4 + stride[0]*y));

                b =  v        & 0xFF;

                g = (v >>  8) & 0xFF;

                r = (v >> 16) & 0xFF;

                a =  v >> 24;

            } else {

                b = *((uint16_t*)(src[0] + x*2 + stride[0]*y));

                g = *((uint16_t*)(src[1] + x*2 + stride[1]*y));

                r = *((uint16_t*)(src[2] + x*2 + stride[2]*y));

            }



            b -= g;

            r -= g;

            g += (b + r) >> 2;

            b += offset;

            r += offset;



            sample[0][0][x] = g;

            sample[1][0][x] = b;

            sample[2][0][x] = r;

            sample[3][0][x] = a;

        }

        for (p = 0; p < 3 + s->transparency; p++) {

            sample[p][0][-1] = sample[p][1][0  ];

            sample[p][1][ w] = sample[p][1][w-1];

            if (lbd)

                encode_line(s, w, sample[p], (p + 1) / 2, 9);

            else

                encode_line(s, w, sample[p], (p + 1) / 2, bits + 1);

        }

    }

}

static void encode_rgb_frame(FFV1Context *s, uint8_t *src[3], int w, int h, int stride[3])

{

    int x, y, p, i;

    const int ring_size = s->avctx->context_model ? 3 : 2;

    int16_t *sample[4][3];

    int lbd    = s->bits_per_raw_sample <= 8;

    int bits   = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8;

    int offset = 1 << bits;



    s->run_index = 0;



    memset(s->sample_buffer, 0, ring_size * MAX_PLANES *

                                (w + 6) * sizeof(*s->sample_buffer));



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

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

            for (p = 0; p < MAX_PLANES; p++)

                sample[p][i]= s->sample_buffer + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;



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

            int b, g, r, av_uninit(a);

            if (lbd) {

                unsigned v = *((uint32_t*)(src[0] + x*4 + stride[0]*y));

                b =  v        & 0xFF;

                g = (v >>  8) & 0xFF;

                r = (v >> 16) & 0xFF;

                a =  v >> 24;

            } else {

                b = *((uint16_t*)(src[0] + x*2 + stride[0]*y));

                g = *((uint16_t*)(src[1] + x*2 + stride[1]*y));

                r = *((uint16_t*)(src[2] + x*2 + stride[2]*y));

            }



            b -= g;

            r -= g;

            g += (b + r) >> 2;

            b += offset;

            r += offset;



            sample[0][0][x] = g;

            sample[1][0][x] = b;

            sample[2][0][x] = r;

            sample[3][0][x] = a;

        }

        for (p = 0; p < 3 + s->transparency; p++) {

            sample[p][0][-1] = sample[p][1][0  ];

            sample[p][1][ w] = sample[p][1][w-1];

            if (lbd)

                encode_line(s, w, sample[p], (p + 1) / 2, 9);

            else

                encode_line(s, w, sample[p], (p + 1) / 2, bits + 1);

        }

    }

}

static void FUNC_0(FFV1Context *VAR_0, uint8_t *VAR_1[3], int VAR_2, int VAR_3, int VAR_4[3])

{

    int VAR_5, VAR_6, VAR_7, VAR_8;

    const int VAR_9 = VAR_0->avctx->context_model ? 3 : 2;

    int16_t *sample[4][3];

    int VAR_10    = VAR_0->bits_per_raw_sample <= 8;

    int VAR_11   = VAR_0->bits_per_raw_sample > 0 ? VAR_0->bits_per_raw_sample : 8;

    int VAR_12 = 1 << VAR_11;



    VAR_0->run_index = 0;



    memset(VAR_0->sample_buffer, 0, VAR_9 * MAX_PLANES *

                                (VAR_2 + 6) * sizeof(*VAR_0->sample_buffer));



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

        for (VAR_8 = 0; VAR_8 < VAR_9; VAR_8++)

            for (VAR_7 = 0; VAR_7 < MAX_PLANES; VAR_7++)

                sample[VAR_7][VAR_8]= VAR_0->sample_buffer + VAR_7*VAR_9*(VAR_2+6) + ((VAR_3+VAR_8-VAR_6)%VAR_9)*(VAR_2+6) + 3;



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

            int VAR_13, VAR_14, VAR_15, FUNC_1(a);

            if (VAR_10) {

                unsigned VAR_16 = *((uint32_t*)(VAR_1[0] + VAR_5*4 + VAR_4[0]*VAR_6));

                VAR_13 =  VAR_16        & 0xFF;

                VAR_14 = (VAR_16 >>  8) & 0xFF;

                VAR_15 = (VAR_16 >> 16) & 0xFF;

                a =  VAR_16 >> 24;

            } else {

                VAR_13 = *((uint16_t*)(VAR_1[0] + VAR_5*2 + VAR_4[0]*VAR_6));

                VAR_14 = *((uint16_t*)(VAR_1[1] + VAR_5*2 + VAR_4[1]*VAR_6));

                VAR_15 = *((uint16_t*)(VAR_1[2] + VAR_5*2 + VAR_4[2]*VAR_6));

            }



            VAR_13 -= VAR_14;

            VAR_15 -= VAR_14;

            VAR_14 += (VAR_13 + VAR_15) >> 2;

            VAR_13 += VAR_12;

            VAR_15 += VAR_12;



            sample[0][0][VAR_5] = VAR_14;

            sample[1][0][VAR_5] = VAR_13;

            sample[2][0][VAR_5] = VAR_15;

            sample[3][0][VAR_5] = a;

        }

        for (VAR_7 = 0; VAR_7 < 3 + VAR_0->transparency; VAR_7++) {

            sample[VAR_7][0][-1] = sample[VAR_7][1][0  ];

            sample[VAR_7][1][ VAR_2] = sample[VAR_7][1][VAR_2-1];

            if (VAR_10)

                encode_line(VAR_0, VAR_2, sample[VAR_7], (VAR_7 + 1) / 2, 9);

            else

                encode_line(VAR_0, VAR_2, sample[VAR_7], (VAR_7 + 1) / 2, VAR_11 + 1);

        }

    }

}

static void FUNC_0(FFV1Context *VAR_0, uint8_t *VAR_1[3], int VAR_2, int VAR_3, int VAR_4[3])
{ int VAR_5, VAR_6, VAR_7, VAR_8; const int VAR_9 = VAR_0->avctx->context_model ? 3 : 2; int16_t *sample[4][3]; int VAR_10    = VAR_0->bits_per_raw_sample <= 8; int VAR_11   = VAR_0->bits_per_raw_sample > 0 ? VAR_0->bits_per_raw_sample : 8; int VAR_12 = 1 << VAR_11; VAR_0->run_index = 0; memset(VAR_0->sample_buffer, 0, VAR_9 * MAX_PLANES *
(VAR_2 + 6) * sizeof(*VAR_0->sample_buffer)); for (VAR_6 = 0; VAR_6 < VAR_3; VAR_6++) { for (VAR_8 = 0; VAR_8 < VAR_9; VAR_8++) for (VAR_7 = 0; VAR_7 < MAX_PLANES; VAR_7++) sample[VAR_7][VAR_8]= VAR_0->sample_buffer + VAR_7*VAR_9*(VAR_2+6) + ((VAR_3+VAR_8-VAR_6)%VAR_9)*(VAR_2+6) + 3; for (VAR_5 = 0; VAR_5 < VAR_2; VAR_5++) { int VAR_13, VAR_14, VAR_15, FUNC_1(a); if (VAR_10) { unsigned VAR_16 = *((uint32_t*)(VAR_1[0] + VAR_5*4 + VAR_4[0]*VAR_6)); VAR_13 =  VAR_16        & 0xFF; VAR_14 = (VAR_16 >>  8) & 0xFF; VAR_15 = (VAR_16 >> 16) & 0xFF; a =  VAR_16 >> 24; } else { VAR_13 = *((uint16_t*)(VAR_1[0] + VAR_5*2 + VAR_4[0]*VAR_6)); VAR_14 = *((uint16_t*)(VAR_1[1] + VAR_5*2 + VAR_4[1]*VAR_6)); VAR_15 = *((uint16_t*)(VAR_1[2] + VAR_5*2 + VAR_4[2]*VAR_6)); } VAR_13 -= VAR_14; VAR_15 -= VAR_14; VAR_14 += (VAR_13 + VAR_15) >> 2; VAR_13 += VAR_12; VAR_15 += VAR_12; sample[0][0][VAR_5] = VAR_14; sample[1][0][VAR_5] = VAR_13; sample[2][0][VAR_5] = VAR_15; sample[3][0][VAR_5] = a; } for (VAR_7 = 0; VAR_7 < 3 + VAR_0->transparency; VAR_7++) { sample[VAR_7][0][-1] = sample[VAR_7][1][0  ]; sample[VAR_7][1][ VAR_2] = sample[VAR_7][1][VAR_2-1]; if (VAR_10)
encode_line(VAR_0, VAR_2, sample[VAR_7], (VAR_7 + 1) / 2, 9); else
encode_line(VAR_0, VAR_2, sample[VAR_7], (VAR_7 + 1) / 2, VAR_11 + 1); } } }