X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Flzw.c;h=fae5687ab7af48a524061bad74c46427fc71d393;hb=51d8725a6e4c7f989d6f0f38b59cb54a2d72846c;hp=aa886910bea86f087974babbbbf4d5b105f6af18;hpb=9a58234feaae8b387b7a7e41b643ec619534d26a;p=ffmpeg diff --git a/libavcodec/lzw.c b/libavcodec/lzw.c index aa886910bea..fae5687ab7a 100644 --- a/libavcodec/lzw.c +++ b/libavcodec/lzw.c @@ -3,20 +3,20 @@ * Copyright (c) 2003 Fabrice Bellard * Copyright (c) 2006 Konstantin Shishkov * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -24,11 +24,13 @@ * @file * @brief LZW decoding routines * @author Fabrice Bellard - * Modified for use in TIFF by Konstantin Shishkov + * @author modified for use in TIFF by Konstantin Shishkov */ #include "avcodec.h" +#include "bytestream.h" #include "lzw.h" +#include "libavutil/mem.h" #define LZW_MAXBITS 12 #define LZW_SIZTABLE (1<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--; } @@ -82,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); @@ -91,9 +93,10 @@ static int lzw_get_code(struct LZWState * s) return c & s->curmask; } -const uint8_t* ff_lzw_cur_ptr(LZWState *p) +int ff_lzw_size_read(LZWState *p) { - return ((struct LZWState*)p)->pbuf; + struct LZWState *s = p; + return bytestream2_tell(&s->gb); } void ff_lzw_decode_tail(LZWState *p) @@ -101,12 +104,12 @@ void ff_lzw_decode_tail(LZWState *p) struct LZWState *s = (struct LZWState *)p; if(s->mode == FF_LZW_GIF) { - while(s->pbuf < s->ebuf && s->bs>0){ - 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) @@ -134,8 +137,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;