int ff_rle_encode(uint8_t *outbuf, int out_size, const uint8_t *ptr , int bpp, int w, int8_t add, uint8_t xor)

{

    int count, x;

    uint8_t *out;



    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) + add;

                memcpy(out, ptr, bpp);

                out += bpp;

            } else {

                /* fall back on uncompressed */

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

                *out++ = count - 1;



                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, int8_t add, uint8_t xor)

{

    int count, x;

    uint8_t *out;



    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) + add;

                memcpy(out, ptr, bpp);

                out += bpp;

            } else {

                

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

                *out++ = count - 1;



                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, int8_t VAR_5, uint8_t VAR_6)

{

    int VAR_7, VAR_8;

    uint8_t *out;



    out = VAR_0;





        for(VAR_8 = 0; VAR_8 < VAR_4; VAR_8 += VAR_7) {

            

            if((VAR_7 = count_pixels(VAR_2, VAR_4-VAR_8, VAR_3, 1)) > 1) {

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

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

                memcpy(out, VAR_2, VAR_3);

                out += VAR_3;

            } else {

                

                VAR_7 = count_pixels(VAR_2, VAR_4-VAR_8, VAR_3, 0);

                *out++ = VAR_7 - 1;



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

                memcpy(out, VAR_2, VAR_3 * VAR_7);

                out += VAR_3 * VAR_7;

        }



        VAR_2 += VAR_7 * 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, int8_t VAR_5, uint8_t VAR_6)
{ int VAR_7, VAR_8; uint8_t *out; out = VAR_0; for(VAR_8 = 0; VAR_8 < VAR_4; VAR_8 += VAR_7) { if((VAR_7 = count_pixels(VAR_2, VAR_4-VAR_8, VAR_3, 1)) > 1) { if(out + VAR_3 + 1 > VAR_0 + VAR_1) return -1; *out++ = (VAR_7 ^ VAR_6) + VAR_5; memcpy(out, VAR_2, VAR_3); out += VAR_3; } else { VAR_7 = count_pixels(VAR_2, VAR_4-VAR_8, VAR_3, 0); *out++ = VAR_7 - 1; if(out + VAR_3*VAR_7 > VAR_0 + VAR_1) return -1; memcpy(out, VAR_2, VAR_3 * VAR_7); out += VAR_3 * VAR_7; } VAR_2 += VAR_7 * VAR_3; } return out - VAR_0; }