Merge commit 'e89aa4bf56e5b5c45f569eb12733519789e057da'

* commit 'e89aa4bf56e5b5c45f569eb12733519789e057da':
  lzw: switch to bytestream2

Conflicts:
	libavcodec/lzw.c

See: 44c4170c52
Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2014-01-04 01:43:01 +01:00
commit 508229adb9

View File

@ -28,6 +28,7 @@
*/
#include "avcodec.h"
#include "bytestream.h"
#include "lzw.h"
#include "libavutil/mem.h"
@ -43,7 +44,7 @@ static const uint16_t mask[17] =
};
struct LZWState {
const uint8_t *pbuf, *ebuf;
GetByteContext gb;
int bbits;
unsigned int bbuf;
@ -73,9 +74,9 @@ static int lzw_get_code(struct LZWState * s)
if(s->mode == FF_LZW_GIF) {
while (s->bbits < s->cursize) {
if (!s->bs) {
s->bs = *s->pbuf++;
s->bs = bytestream2_get_byte(&s->gb);
}
s->bbuf |= (*s->pbuf++) << s->bbits;
s->bbuf |= bytestream2_get_byte(&s->gb) << s->bbits;
s->bbits += 8;
s->bs--;
}
@ -83,7 +84,7 @@ static int lzw_get_code(struct LZWState * s)
s->bbuf >>= s->cursize;
} else { // TIFF
while (s->bbits < s->cursize) {
s->bbuf = (s->bbuf << 8) | (*s->pbuf++);
s->bbuf = (s->bbuf << 8) | bytestream2_get_byte(&s->gb);
s->bbits += 8;
}
c = s->bbuf >> (s->bbits - s->cursize);
@ -97,17 +98,12 @@ void ff_lzw_decode_tail(LZWState *p)
struct LZWState *s = (struct LZWState *)p;
if(s->mode == FF_LZW_GIF) {
while (s->bs > 0) {
if (s->bs >= s->ebuf - s->pbuf) {
s->pbuf = s->ebuf;
break;
} else {
s->pbuf += s->bs;
s->bs = *s->pbuf++;
}
while (s->bs > 0 && bytestream2_get_bytes_left(&s->gb)) {
bytestream2_skip(&s->gb, s->bs);
s->bs = bytestream2_get_byte(&s->gb);
}
}else
s->pbuf= s->ebuf;
bytestream2_skip(&s->gb, bytestream2_get_bytes_left(&s->gb));
}
av_cold void ff_lzw_decode_open(LZWState **p)
@ -135,8 +131,7 @@ int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size,
if(csize < 1 || csize >= LZW_MAXBITS)
return -1;
/* read buffer */
s->pbuf = buf;
s->ebuf = s->pbuf + buf_size;
bytestream2_init(&s->gb, buf, buf_size);
s->bbuf = 0;
s->bbits = 0;
s->bs = 0;
@ -186,10 +181,6 @@ int ff_lzw_decode(LZWState *p, uint8_t *buf, int len){
if ((--l) == 0)
goto the_end;
}
if (s->ebuf < s->pbuf) {
av_log(NULL, AV_LOG_ERROR, "lzw overread\n");
goto the_end;
}
c = lzw_get_code(s);
if (c == s->end_code) {
break;