Mercurial > libavcodec.hg
comparison rle.c @ 4771:7cd3ffe4897f libavcodec
Changed the rle encoder a little and made it more universal.
Not only the repeated byte is calculated as (count ^ xor) + add
but also the raw encoding lenth byte is calculated as that too
patch by Xiaohui Sun sunxiaohui dsp ac cn
author | michael |
---|---|
date | Tue, 03 Apr 2007 06:40:21 +0000 |
parents | a6d1c26e8b6f |
children | 3cd67a410b68 |
comparison
equal
deleted
inserted
replaced
4770:a6d1c26e8b6f | 4771:7cd3ffe4897f |
---|---|
53 } | 53 } |
54 | 54 |
55 return count; | 55 return count; |
56 } | 56 } |
57 | 57 |
58 int ff_rle_encode(uint8_t *outbuf, int out_size, const uint8_t *ptr , int bpp, int w, int8_t add, uint8_t xor) | 58 int ff_rle_encode(uint8_t *outbuf, int out_size, const uint8_t *ptr , int bpp, int w, |
59 int8_t add_rep, uint8_t xor_rep,int8_t add_raw,uint8_t xor_raw) | |
59 { | 60 { |
60 int count, x; | 61 int count, x; |
61 uint8_t *out = outbuf; | 62 uint8_t *out = outbuf; |
62 | 63 |
63 for(x = 0; x < w; x += count) { | 64 for(x = 0; x < w; x += count) { |
64 /* see if we can encode the next set of pixels with RLE */ | 65 /* see if we can encode the next set of pixels with RLE */ |
65 if((count = count_pixels(ptr, w-x, bpp, 1)) > 1) { | 66 if((count = count_pixels(ptr, w-x, bpp, 1)) > 1) { |
66 if(out + bpp + 1 > outbuf + out_size) return -1; | 67 if(out + bpp + 1 > outbuf + out_size) return -1; |
67 *out++ = (count ^ xor) + add; | 68 *out++ = (count ^ xor_rep) + add_rep; |
68 memcpy(out, ptr, bpp); | 69 memcpy(out, ptr, bpp); |
69 out += bpp; | 70 out += bpp; |
70 } else { | 71 } else { |
71 /* fall back on uncompressed */ | 72 /* fall back on uncompressed */ |
72 count = count_pixels(ptr, w-x, bpp, 0); | 73 count = count_pixels(ptr, w-x, bpp, 0); |
73 *out++ = count - 1; | 74 *out++ = (count ^ xor_raw) + add_raw; |
74 | 75 |
75 if(out + bpp*count > outbuf + out_size) return -1; | 76 if(out + bpp*count > outbuf + out_size) return -1; |
76 memcpy(out, ptr, bpp * count); | 77 memcpy(out, ptr, bpp * count); |
77 out += bpp * count; | 78 out += bpp * count; |
78 } | 79 } |