};
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);
}
* @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;
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;
}
}
c = lzw_get_code(s);
if (c == s->end_code) {
- s->end_code = -1;
break;
} else if (c == s->clear_code) {
s->cursize = s->codesize + 1;
fc= oc= -1;
} else {
code = c;
- if (code >= s->slot) {
+ if (code == s->slot && fc>=0) {
*sp++ = fc;
code = oc;
- }
+ }else if(code >= s->slot)
+ break;
while (code >= s->newcodes) {
*sp++ = s->suffix[code];
code = s->prefix[code];
}
}
}
+ s->end_code = -1;
the_end:
s->sp = sp;
s->oc = oc;