int ff_rle_encode(uint8_t *outbuf, int out_size, const uint8_t *ptr , int bpp, int w,

                  int add_rep, int xor_rep, int add_raw, int xor_raw)

{

    int count, x;

    uint8_t *out = outbuf;



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

        /* see if we can encode the next set of pixels with RLE */

        if((count = count_pixels(ptr, w-x, bpp, 1)) > 1) {

            if(out + bpp + 1 > outbuf + out_size) return -1;

            *out++ = (count ^ xor_rep) + add_rep;

            memcpy(out, ptr, bpp);

            out += bpp;

        } else {

            /* fall back on uncompressed */

            count = count_pixels(ptr, w-x, bpp, 0);

            *out++ = (count ^ xor_raw) + add_raw;



            if(out + bpp*count > outbuf + out_size) return -1;

            memcpy(out, ptr, bpp * count);

            out += bpp * count;

        }



        ptr += count * bpp;

    }



    return out - outbuf;

}

int ff_rle_encode(uint8_t *outbuf, int out_size, const uint8_t *ptr , int bpp, int w,

                  int add_rep, int xor_rep, int add_raw, int xor_raw)

{

    int count, x;

    uint8_t *out = outbuf;



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

        

        if((count = count_pixels(ptr, w-x, bpp, 1)) > 1) {

            if(out + bpp + 1 > outbuf + out_size) return -1;

            *out++ = (count ^ xor_rep) + add_rep;

            memcpy(out, ptr, bpp);

            out += bpp;

        } else {

            

            count = count_pixels(ptr, w-x, bpp, 0);

            *out++ = (count ^ xor_raw) + add_raw;



            if(out + bpp*count > outbuf + out_size) return -1;

            memcpy(out, ptr, bpp * count);

            out += bpp * count;

        }



        ptr += count * bpp;

    }



    return out - outbuf;

}

int FUNC_0(uint8_t *VAR_0, int VAR_1, const uint8_t *VAR_2 , int VAR_3, int VAR_4,

                  int VAR_5, int VAR_6, int VAR_7, int VAR_8)

{

    int VAR_9, VAR_10;

    uint8_t *out = VAR_0;



    for(VAR_10 = 0; VAR_10 < VAR_4; VAR_10 += VAR_9) {

        

        if((VAR_9 = count_pixels(VAR_2, VAR_4-VAR_10, VAR_3, 1)) > 1) {

            if(out + VAR_3 + 1 > VAR_0 + VAR_1) return -1;

            *out++ = (VAR_9 ^ VAR_6) + VAR_5;

            memcpy(out, VAR_2, VAR_3);

            out += VAR_3;

        } else {

            

            VAR_9 = count_pixels(VAR_2, VAR_4-VAR_10, VAR_3, 0);

            *out++ = (VAR_9 ^ VAR_8) + VAR_7;



            if(out + VAR_3*VAR_9 > VAR_0 + VAR_1) return -1;

            memcpy(out, VAR_2, VAR_3 * VAR_9);

            out += VAR_3 * VAR_9;

        }



        VAR_2 += VAR_9 * VAR_3;

    }



    return out - VAR_0;

}

int FUNC_0(uint8_t *VAR_0, int VAR_1, const uint8_t *VAR_2 , int VAR_3, int VAR_4,
int VAR_5, int VAR_6, int VAR_7, int VAR_8)
{ int VAR_9, VAR_10; uint8_t *out = VAR_0; for(VAR_10 = 0; VAR_10 < VAR_4; VAR_10 += VAR_9) { if((VAR_9 = count_pixels(VAR_2, VAR_4-VAR_10, VAR_3, 1)) > 1) { if(out + VAR_3 + 1 > VAR_0 + VAR_1) return -1; *out++ = (VAR_9 ^ VAR_6) + VAR_5; memcpy(out, VAR_2, VAR_3); out += VAR_3; } else { VAR_9 = count_pixels(VAR_2, VAR_4-VAR_10, VAR_3, 0); *out++ = (VAR_9 ^ VAR_8) + VAR_7; if(out + VAR_3*VAR_9 > VAR_0 + VAR_1) return -1; memcpy(out, VAR_2, VAR_3 * VAR_9); out += VAR_3 * VAR_9; } VAR_2 += VAR_9 * VAR_3; } return out - VAR_0; }