comparison lzo.c @ 643:db8f45986cff libavutil

Add av_ prefix to LZO stuff and thus make it officially part of the public API. Keep lzo1x_decode until the next major version bump for binary compatibility.
author reimar
date Mon, 02 Feb 2009 20:16:00 +0000
parents c04808220c83
children 8bcaa41403bd
comparison
equal deleted inserted replaced
642:70bdd5501662 643:db8f45986cff
39 * \return byte read 39 * \return byte read
40 */ 40 */
41 static inline int get_byte(LZOContext *c) { 41 static inline int get_byte(LZOContext *c) {
42 if (c->in < c->in_end) 42 if (c->in < c->in_end)
43 return *c->in++; 43 return *c->in++;
44 c->error |= LZO_INPUT_DEPLETED; 44 c->error |= AV_LZO_INPUT_DEPLETED;
45 return 1; 45 return 1;
46 } 46 }
47 47
48 #ifdef INBUF_PADDED 48 #ifdef INBUF_PADDED
49 #define GETB(c) (*(c).in++) 49 #define GETB(c) (*(c).in++)
86 static inline void copy(LZOContext *c, int cnt) { 86 static inline void copy(LZOContext *c, int cnt) {
87 register const uint8_t *src = c->in; 87 register const uint8_t *src = c->in;
88 register uint8_t *dst = c->out; 88 register uint8_t *dst = c->out;
89 if (cnt > c->in_end - src) { 89 if (cnt > c->in_end - src) {
90 cnt = FFMAX(c->in_end - src, 0); 90 cnt = FFMAX(c->in_end - src, 0);
91 c->error |= LZO_INPUT_DEPLETED; 91 c->error |= AV_LZO_INPUT_DEPLETED;
92 } 92 }
93 if (cnt > c->out_end - dst) { 93 if (cnt > c->out_end - dst) {
94 cnt = FFMAX(c->out_end - dst, 0); 94 cnt = FFMAX(c->out_end - dst, 0);
95 c->error |= LZO_OUTPUT_FULL; 95 c->error |= AV_LZO_OUTPUT_FULL;
96 } 96 }
97 #if defined(INBUF_PADDED) && defined(OUTBUF_PADDED) 97 #if defined(INBUF_PADDED) && defined(OUTBUF_PADDED)
98 COPY4(dst, src); 98 COPY4(dst, src);
99 src += 4; 99 src += 4;
100 dst += 4; 100 dst += 4;
118 */ 118 */
119 static inline void copy_backptr(LZOContext *c, int back, int cnt) { 119 static inline void copy_backptr(LZOContext *c, int back, int cnt) {
120 register const uint8_t *src = &c->out[-back]; 120 register const uint8_t *src = &c->out[-back];
121 register uint8_t *dst = c->out; 121 register uint8_t *dst = c->out;
122 if (src < c->out_start || src > dst) { 122 if (src < c->out_start || src > dst) {
123 c->error |= LZO_INVALID_BACKPTR; 123 c->error |= AV_LZO_INVALID_BACKPTR;
124 return; 124 return;
125 } 125 }
126 if (cnt > c->out_end - dst) { 126 if (cnt > c->out_end - dst) {
127 cnt = FFMAX(c->out_end - dst, 0); 127 cnt = FFMAX(c->out_end - dst, 0);
128 c->error |= LZO_OUTPUT_FULL; 128 c->error |= AV_LZO_OUTPUT_FULL;
129 } 129 }
130 memcpy_backptr(dst, back, cnt); 130 memcpy_backptr(dst, back, cnt);
131 c->out = dst + cnt; 131 c->out = dst + cnt;
132 } 132 }
133 133
185 * \param in input buffer 185 * \param in input buffer
186 * \param inlen size of input buffer, number of bytes left are returned here 186 * \param inlen size of input buffer, number of bytes left are returned here
187 * \return 0 on success, otherwise error flags, see lzo.h 187 * \return 0 on success, otherwise error flags, see lzo.h
188 * 188 *
189 * Make sure all buffers are appropriately padded, in must provide 189 * Make sure all buffers are appropriately padded, in must provide
190 * LZO_INPUT_PADDING, out must provide LZO_OUTPUT_PADDING additional bytes. 190 * AV_LZO_INPUT_PADDING, out must provide AV_LZO_OUTPUT_PADDING additional bytes.
191 */ 191 */
192 int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) { 192 int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
193 int state= 0; 193 int state= 0;
194 int x; 194 int x;
195 LZOContext c; 195 LZOContext c;
196 c.in = in; 196 c.in = in;
197 c.in_end = (const uint8_t *)in + *inlen; 197 c.in_end = (const uint8_t *)in + *inlen;
200 c.error = 0; 200 c.error = 0;
201 x = GETB(c); 201 x = GETB(c);
202 if (x > 17) { 202 if (x > 17) {
203 copy(&c, x - 17); 203 copy(&c, x - 17);
204 x = GETB(c); 204 x = GETB(c);
205 if (x < 16) c.error |= LZO_ERROR; 205 if (x < 16) c.error |= AV_LZO_ERROR;
206 } 206 }
207 if (c.in > c.in_end) 207 if (c.in > c.in_end)
208 c.error |= LZO_INPUT_DEPLETED; 208 c.error |= AV_LZO_INPUT_DEPLETED;
209 while (!c.error) { 209 while (!c.error) {
210 int cnt, back; 210 int cnt, back;
211 if (x > 15) { 211 if (x > 15) {
212 if (x > 63) { 212 if (x > 63) {
213 cnt = (x >> 5) - 1; 213 cnt = (x >> 5) - 1;
221 back = (1 << 14) + ((x & 8) << 11); 221 back = (1 << 14) + ((x & 8) << 11);
222 x = GETB(c); 222 x = GETB(c);
223 back += (GETB(c) << 6) + (x >> 2); 223 back += (GETB(c) << 6) + (x >> 2);
224 if (back == (1 << 14)) { 224 if (back == (1 << 14)) {
225 if (cnt != 1) 225 if (cnt != 1)
226 c.error |= LZO_ERROR; 226 c.error |= AV_LZO_ERROR;
227 break; 227 break;
228 } 228 }
229 } 229 }
230 } else if(!state){ 230 } else if(!state){
231 cnt = get_len(&c, x, 15); 231 cnt = get_len(&c, x, 15);
249 if (c.in > c.in_end) 249 if (c.in > c.in_end)
250 *inlen = 0; 250 *inlen = 0;
251 *outlen = c.out_end - c.out; 251 *outlen = c.out_end - c.out;
252 return c.error; 252 return c.error;
253 } 253 }
254
255 #if LIBAVUTIL_VERSION_MAJOR < 50
256 int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
257 return av_lzo1x_decode(out, outlen, in, inlen);
258 }
259 #endif
254 260
255 #ifdef TEST 261 #ifdef TEST
256 #include <stdio.h> 262 #include <stdio.h>
257 #include <lzo/lzo1x.h> 263 #include <lzo/lzo1x.h>
258 #include "log.h" 264 #include "log.h"
275 #ifdef LIBLZO 281 #ifdef LIBLZO
276 if (lzo1x_decompress_safe(comp, inlen, decomp, &outlen, NULL)) 282 if (lzo1x_decompress_safe(comp, inlen, decomp, &outlen, NULL))
277 #elif defined(LIBLZO_UNSAFE) 283 #elif defined(LIBLZO_UNSAFE)
278 if (lzo1x_decompress(comp, inlen, decomp, &outlen, NULL)) 284 if (lzo1x_decompress(comp, inlen, decomp, &outlen, NULL))
279 #else 285 #else
280 if (lzo1x_decode(decomp, &outlen, comp, &inlen)) 286 if (av_lzo1x_decode(decomp, &outlen, comp, &inlen))
281 #endif 287 #endif
282 av_log(NULL, AV_LOG_ERROR, "decompression error\n"); 288 av_log(NULL, AV_LOG_ERROR, "decompression error\n");
283 STOP_TIMER("lzod") 289 STOP_TIMER("lzod")
284 } 290 }
285 if (memcmp(orig, decomp, s)) 291 if (memcmp(orig, decomp, s))