[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pdf-devel] Bug in LZW filter?
From: |
Georg Gottleuber |
Subject: |
Re: [pdf-devel] Bug in LZW filter? |
Date: |
Thu, 01 Dec 2011 14:42:29 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20111101 Thunderbird/7.0.1 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I ended up with this encoder structure:
/**************** code fragment ***************************/
while (!pdf_buffer_eob_p (in) && !pdf_buffer_full_p (out))
{
/* accumulate input data */
st->string.suffix = in->data [in->rp++];
if (!lzw_dict_find (&st->dict, &st->string))
{
/* emit output code of longest input sequence in dict */
lzw_buffer_put_code (&st->buffer, st->string.prefix);
/* is current bitsize enough? */
if (st->dict.size - 1 == st->buffer.maxval - st->early_change)
{
if (!lzw_buffer_inc_bitsize (&st->buffer))
{
lzw_buffer_put_code (&st->buffer, LZW_RESET_CODE);
lzw_buffer_set_bitsize (&st->buffer, LZW_MIN_BITSIZE);
lzw_dict_reset (&st->dict);
dict_reset = PDF_TRUE;
}
}
/* create new dict entry */
if(!dict_reset)
lzw_dict_create_entry (&st->dict, &st->string);
else
dict_reset = PDF_FALSE;
st->string.prefix = st->string.suffix
}
}
/**************** code fragment ***************************/
Bitsize increase should happen as late as possible (as mentioned in
en.wikipedia.org). This is why it is tested right before creating a
new table entry.
Unit test results are positive for this code (see attached patch).
If you agree with this encoder version I will refactor the decoder in
the same way.
Regards,
Georg
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk7XhEUACgkQ5sLITM1qIaINcACePiqwSZ1iodSIYmuCJBtLDaAK
bsMAoIhZHj6I+IItrmCugFfj/ksBWUcy
=HQFB
-----END PGP SIGNATURE-----
lzw_enc_refactor.patch
Description: Text Data
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [pdf-devel] Bug in LZW filter?,
Georg Gottleuber <=