aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-01-04 01:43:01 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-01-04 02:00:07 +0100
commit508229adb930c03ee0539faada5ff0b14fb570d6 (patch)
tree82ea9560055edf741f8bf5f87395d33553a86619
parent4a055f91bec2f746517ec7757e2b2a3bbdb90027 (diff)
parente89aa4bf56e5b5c45f569eb12733519789e057da (diff)
downloadffmpeg-508229adb930c03ee0539faada5ff0b14fb570d6.tar.gz
Merge commit 'e89aa4bf56e5b5c45f569eb12733519789e057da'
* commit 'e89aa4bf56e5b5c45f569eb12733519789e057da': lzw: switch to bytestream2 Conflicts: libavcodec/lzw.c See: 44c4170c52c10e3da3a7ea8e3435ef37c4edc2cc Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/lzw.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/libavcodec/lzw.c b/libavcodec/lzw.c
index 43e3e055c2..6832c122a2 100644
--- a/libavcodec/lzw.c
+++ b/libavcodec/lzw.c
@@ -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;