[Ffmpeg-devel] lzw compression in tiff encoder (qualification task for GSoC)

Bartlomiej Wolowiec b.wolowiec
Sat Apr 7 14:33:00 CEST 2007


Hi,
On Saturday 07 April 2007 01:50, Michael Niedermayer wrote:
> > +/**
> > + * Init LZW encoder (allocate memory)
> > + * @param s LZW state
> > + */
> > +void ff_lzw_encode_open(LZWEncodeState ** s){
> > +    *s = av_malloc(sizeof(LZWEncodeState));
> > +    (*s)->tab = av_malloc(LZW_HASH_SIZE * sizeof(Code));
> > +}
>
> why _init and _open ? it seems one would be enough

I've changed functions _open/_close to _alloc/_free. I use _alloc/_init 
functions, because allocated memory can be used many times (e.g. in TIFF 
encoder can compress every strip separately).

> also why use malloc for tab instead of a
> Code tab[LZW_HASH_SIZE]
> in the struct?
>
> and it would be easier to
> return s;
> instead of using an pointer to pointer ...

ok

> > +
> > +/**
> > + * LZW main compress function
> > + * @param s LZW state
> > + * @param inbuf Input buffer
> > + * @param insize Size of input buffer
> > + * @return Number of bytes written or -1 on error
> > + */
> > +int ff_lzw_encode(LZWEncodeState * s, const uint8_t * inbuf, int insize)
> > +{
> > +    int i;
> > +    int ret;
> > +    int code_prefix = s->last_code;
> > +
> > +    if (code_prefix == LZW_PREFIX_EMPTY)
> > +        clearTable(s);
> > +
> > +    for (i = 0; i < insize; i++) {
> > +        uint8_t c = *inbuf++;
> > +        int code = findCode(s, c, code_prefix);
> > +        if (s->tab[code].hash_prefix != LZW_PREFIX_FREE) {
> > +            code_prefix = s->tab[code].code;
> > +        } else {
> > +            writeCode(s, code_prefix);
> > +            addCode(s, c, code_prefix, code);
> > +            code_prefix = s->tab[hash(0, c)].code;
> > +        }
> > +        if (s->tabsize >= s->maxcode - 1) {
> > +            clearTable(s);
> > +        }
> > +    }
> > +    s->last_code = code_prefix;
> > +
> > +    return writtenBytes(s);
> > +}
>
> it seems there is no check for the output buffer (put_bits() does not check
> this automically)
> a simple check like 1.5 x insize > outsize then fail at the
> top of ff_lzw_encode() should do
>
> [...]

done

Best Regards,
Bartek
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lzw.patch
Type: text/x-diff
Size: 8534 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070407/32bd054a/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tifflzw.patch
Type: text/x-diff
Size: 3147 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070407/32bd054a/attachment-0001.patch>



More information about the ffmpeg-devel mailing list