avutil/lzo: K&R formatting cosmetics

This commit is contained in:
Diego Biurrun 2012-10-18 19:15:43 +02:00
parent c9ef43215c
commit c08536979b
2 changed files with 58 additions and 48 deletions

View File

@ -29,6 +29,7 @@
#define OUTBUF_PADDED 1
/// Define if we may read up to 8 bytes beyond the input buffer.
#define INBUF_PADDED 1
typedef struct LZOContext {
const uint8_t *in, *in_end;
uint8_t *out_start, *out, *out_end;
@ -39,7 +40,8 @@ typedef struct LZOContext {
* @brief Reads one byte from the input buffer, avoiding an overrun.
* @return byte read
*/
static inline int get_byte(LZOContext *c) {
static inline int get_byte(LZOContext *c)
{
if (c->in < c->in_end)
return *c->in++;
c->error |= AV_LZO_INPUT_DEPLETED;
@ -58,10 +60,12 @@ static inline int get_byte(LZOContext *c) {
* @param mask bits used from x
* @return decoded length value
*/
static inline int get_len(LZOContext *c, int x, int mask) {
static inline int get_len(LZOContext *c, int x, int mask)
{
int cnt = x & mask;
if (!cnt) {
while (!(x = get_byte(c))) cnt += 255;
while (!(x = get_byte(c)))
cnt += 255;
cnt += mask + x;
}
return cnt;
@ -84,15 +88,16 @@ static inline int get_len(LZOContext *c, int x, int mask) {
* @brief Copies bytes from input to output buffer with checking.
* @param cnt number of bytes to copy, must be >= 0
*/
static inline void copy(LZOContext *c, int cnt) {
static inline void copy(LZOContext *c, int cnt)
{
register const uint8_t *src = c->in;
register uint8_t *dst = c->out;
register uint8_t *dst = c->out;
if (cnt > c->in_end - src) {
cnt = FFMAX(c->in_end - src, 0);
cnt = FFMAX(c->in_end - src, 0);
c->error |= AV_LZO_INPUT_DEPLETED;
}
if (cnt > c->out_end - dst) {
cnt = FFMAX(c->out_end - dst, 0);
cnt = FFMAX(c->out_end - dst, 0);
c->error |= AV_LZO_OUTPUT_FULL;
}
#if defined(INBUF_PADDED) && defined(OUTBUF_PADDED)
@ -102,8 +107,8 @@ static inline void copy(LZOContext *c, int cnt) {
cnt -= 4;
if (cnt > 0)
#endif
memcpy(dst, src, cnt);
c->in = src + cnt;
memcpy(dst, src, cnt);
c->in = src + cnt;
c->out = dst + cnt;
}
@ -117,22 +122,24 @@ static inline void memcpy_backptr(uint8_t *dst, int back, int cnt);
* cnt > back is valid, this will copy the bytes we just copied,
* thus creating a repeating pattern with a period length of back.
*/
static inline void copy_backptr(LZOContext *c, int back, int cnt) {
static inline void copy_backptr(LZOContext *c, int back, int cnt)
{
register const uint8_t *src = &c->out[-back];
register uint8_t *dst = c->out;
register uint8_t *dst = c->out;
if (src < c->out_start || src > dst) {
c->error |= AV_LZO_INVALID_BACKPTR;
return;
}
if (cnt > c->out_end - dst) {
cnt = FFMAX(c->out_end - dst, 0);
cnt = FFMAX(c->out_end - dst, 0);
c->error |= AV_LZO_OUTPUT_FULL;
}
memcpy_backptr(dst, back, cnt);
c->out = dst + cnt;
}
static inline void memcpy_backptr(uint8_t *dst, int back, int cnt) {
static inline void memcpy_backptr(uint8_t *dst, int back, int cnt)
{
const uint8_t *src = &dst[-back];
if (back == 1) {
memset(dst, *src, cnt);
@ -157,8 +164,8 @@ static inline void memcpy_backptr(uint8_t *dst, int back, int cnt) {
int blocklen = back;
while (cnt > blocklen) {
memcpy(dst, src, blocklen);
dst += blocklen;
cnt -= blocklen;
dst += blocklen;
cnt -= blocklen;
blocklen <<= 1;
}
memcpy(dst, src, cnt);
@ -166,12 +173,14 @@ static inline void memcpy_backptr(uint8_t *dst, int back, int cnt) {
}
}
void av_memcpy_backptr(uint8_t *dst, int back, int cnt) {
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
{
memcpy_backptr(dst, back, cnt);
}
int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
int state= 0;
int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen)
{
int state = 0;
int x;
LZOContext c;
if (!*outlen || !*inlen) {
@ -182,16 +191,17 @@ int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
res |= AV_LZO_INPUT_DEPLETED;
return res;
}
c.in = in;
c.in_end = (const uint8_t *)in + *inlen;
c.out = c.out_start = out;
c.out_end = (uint8_t *)out + * outlen;
c.error = 0;
x = GETB(c);
c.in = in;
c.in_end = (const uint8_t *)in + *inlen;
c.out = c.out_start = out;
c.out_end = (uint8_t *)out + *outlen;
c.error = 0;
x = GETB(c);
if (x > 17) {
copy(&c, x - 17);
x = GETB(c);
if (x < 16) c.error |= AV_LZO_ERROR;
if (x < 16)
c.error |= AV_LZO_ERROR;
}
if (c.in > c.in_end)
c.error |= AV_LZO_INPUT_DEPLETED;
@ -199,16 +209,16 @@ int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
int cnt, back;
if (x > 15) {
if (x > 63) {
cnt = (x >> 5) - 1;
cnt = (x >> 5) - 1;
back = (GETB(c) << 3) + ((x >> 2) & 7) + 1;
} else if (x > 31) {
cnt = get_len(&c, x, 31);
x = GETB(c);
cnt = get_len(&c, x, 31);
x = GETB(c);
back = (GETB(c) << 6) + (x >> 2) + 1;
} else {
cnt = get_len(&c, x, 7);
back = (1 << 14) + ((x & 8) << 11);
x = GETB(c);
cnt = get_len(&c, x, 7);
back = (1 << 14) + ((x & 8) << 11);
x = GETB(c);
back += (GETB(c) << 6) + (x >> 2);
if (back == (1 << 14)) {
if (cnt != 1)
@ -216,21 +226,21 @@ int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) {
break;
}
}
} else if(!state){
cnt = get_len(&c, x, 15);
copy(&c, cnt + 3);
x = GETB(c);
if (x > 15)
continue;
cnt = 1;
back = (1 << 11) + (GETB(c) << 2) + (x >> 2) + 1;
} else if (!state) {
cnt = get_len(&c, x, 15);
copy(&c, cnt + 3);
x = GETB(c);
if (x > 15)
continue;
cnt = 1;
back = (1 << 11) + (GETB(c) << 2) + (x >> 2) + 1;
} else {
cnt = 0;
back = (GETB(c) << 2) + (x >> 2) + 1;
cnt = 0;
back = (GETB(c) << 2) + (x >> 2) + 1;
}
copy_backptr(&c, back, cnt + 2);
state=
cnt = x & 3;
state =
cnt = x & 3;
copy(&c, cnt);
x = GETB(c);
}

View File

@ -32,18 +32,18 @@
#include <stdint.h>
/** @name Error flags returned by av_lzo1x_decode
* @{ */
* @{ */
/// end of the input buffer reached before decoding finished
#define AV_LZO_INPUT_DEPLETED 1
#define AV_LZO_INPUT_DEPLETED 1
/// decoded data did not fit into output buffer
#define AV_LZO_OUTPUT_FULL 2
#define AV_LZO_OUTPUT_FULL 2
/// a reference to previously decoded data was wrong
#define AV_LZO_INVALID_BACKPTR 4
/// a non-specific error in the compressed bitstream
#define AV_LZO_ERROR 8
#define AV_LZO_ERROR 8
/** @} */
#define AV_LZO_INPUT_PADDING 8
#define AV_LZO_INPUT_PADDING 8
#define AV_LZO_OUTPUT_PADDING 12
/**