AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

1994.03.14 00:46 "MPW libtiff and LZW", by Dwight Kelly
1994.03.14 09:41 "Re: MPW libtiff and LZW", by Niles Ritter

1994.03.14 09:41 "Re: MPW libtiff and LZW", by Niles Ritter

Has anyone got LZW & CCITT compression to compile using Apple's MPW C compiler? It fails since the compression code needs tables larger than 32KB.

I'm pretty sure that Sam has this already, but here's a set of diffs that will patch tif_lzw.c to dynamically allocate the tables and free them up later. This patch is for the latest (v3.3beta002.src.tar.Z) version on sgi.com:

136c136
<       code_t  dec_codetab[CSIZE];
---
>       code_t  *dec_codetab;           /* [CSIZE] -dynamically allocated */
156c156
<       hash_t  enc_hashtab[HSIZE];
---
>       hash_t  *enc_hashtab;           /* [HSIZE] -- dynamically allocate */
340a341,350
>               
>               /* instead of creating a huge struct,
>                * we dynamically allocate this array.
>                */
>               sp->dec_codetab = (code_t*)_TIFFmalloc(sizeof(code_t) * CSIZE); 
>               if (sp->dec_codetab == NULL) {
>                       TIFFError("LZWPreDecode",
>                           "No space for LZW Code Table");
>                       return (0);
>               }
897a908,916
>               /* instead of creating a huge struct,
>                * we dynamically allocate this array.
>                */
>               sp->enc_hashtab = (hash_t*)_TIFFmalloc( sizeof(hash_t) * HSIZE);
>               if (sp->enc_hashtab == NULL) {
>                       TIFFError("LZWPreEncode",
>                           "No space for LZW Hash Table");
>                       return (0);
>               }
1190a1210,1220
>           /* 
>            * free up dynamically allocated memory. 
>            * This should actually be a method pointer,
>            * but it suffices here to test the file
>            * mode to figure out which structure is
>            * stored in the tif_data member.
>            */
>        if (tif->tif_mode == O_RDONLY)
>               _TIFFfree(((LZWDecodeState*)tif->tif_data)->dec_codetab);
>        else
>               _TIFFfree(((LZWEncodeState*)tif->tif_data)->enc_hashtab);                           

I tried once to fix up CCITT as well, but that's a bit more formidable problem, and of limited usefulness to us since it doesn't handle anything more than one-bit pixels.

  --Niles.