/* RLE compress the image, with maximum size of out_size  */
static int targa_encode_rle(uint8_t *outbuf, int out_size, AVFrame *pic, int bpp, int w, int h)
/* RLE compress the image, with maximum size of out_size  */
static int targa_encode_rle(uint8_t *outbuf, int out_size, AVFrame *pic, int bpp, int w, int h)
{
    int y,ret;
    uint8_t *out;
    out = outbuf;
    for(y = 0; y < h; y ++) {
        ret = ff_rle_encode(out, out_size, pic->data[0] + pic->linesize[0] * y, bpp, w, 0x7f, 0, -1, 0);
        if(ret == -1){
            return -1;
        }
        out+= ret;
        out_size -= ret;
    }
    return out - outbuf;
}