/*
* LZW decoder
- * Copyright (c) 2003 Fabrice Bellard.
- * Copyright (c) 2006 Konstantin Shishkov.
+ * 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
*/
/**
- * @file lzw.c
+ * @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"
};
struct LZWState {
- uint8_t *pbuf, *ebuf;
+ const uint8_t *pbuf, *ebuf;
int bbits;
unsigned int bbuf;
s->bbits += 8;
s->bs--;
}
- c = s->bbuf & s->curmask;
+ c = s->bbuf;
s->bbuf >>= s->cursize;
} else { // TIFF
while (s->bbits < s->cursize) {
s->bbuf = (s->bbuf << 8) | (*s->pbuf++);
s->bbits += 8;
}
- c = (s->bbuf >> (s->bbits - s->cursize)) & s->curmask;
+ c = s->bbuf >> (s->bbits - s->cursize);
}
s->bbits -= s->cursize;
- return c;
+ return c & s->curmask;
}
-uint8_t* ff_lzw_cur_ptr(LZWState *p)
+const uint8_t* ff_lzw_cur_ptr(LZWState *p)
{
return ((struct LZWState*)p)->pbuf;
}
s->pbuf= s->ebuf;
}
-void ff_lzw_decode_open(LZWState **p)
+av_cold void ff_lzw_decode_open(LZWState **p)
{
*p = av_mallocz(sizeof(struct LZWState));
}
-void ff_lzw_decode_close(LZWState **p)
+av_cold void ff_lzw_decode_close(LZWState **p)
{
av_freep(p);
}
/**
* Initialize LZW decoder
- * @param s LZW context
+ * @param p LZW context
* @param csize initial code size in bits
* @param buf input data
* @param buf_size input data size
* @param mode decoder working mode - either GIF or TIFF
*/
-int ff_lzw_decode_init(LZWState *p, int csize, uint8_t *buf, int buf_size, int mode)
+int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
{
struct LZWState *s = (struct LZWState *)p;
- if(csize < 1 || csize > LZW_MAXBITS)
+ if(csize < 1 || csize >= LZW_MAXBITS)
return -1;
/* read buffer */
s->pbuf = buf;
s->sp = s->stack;
s->mode = mode;
- switch(s->mode){
- case FF_LZW_GIF:
- s->extra_slot= 0;
- break;
- case FF_LZW_TIFF:
- s->extra_slot= 1;
- break;
- default:
- return -1;
- }
+ s->extra_slot = s->mode == FF_LZW_TIFF;
return 0;
}
* NOTE: the algorithm here is inspired from the LZW GIF decoder
* written by Steven A. Bennett in 1987.
*
- * @param s LZW context
+ * @param p LZW context
* @param buf output buffer
* @param len number of bytes to decode
* @return number of bytes decoded