AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

1999.05.20 09:01 "Fix for decompression bug (sizes >= 65536)", by François Dagand

Hello again,

I just received a mail from Frank D. Cringle, the guy who wrote viewfax, a software for displaying TIFF files on X-Windows. The decompression algorithm for this software was used in libtiff, according to the comments. This soft also had a problem for tiffs wider than 65536 pixels. Frank gave me a correction for this bug in viewfax, and I was able to port the correction to libtiff. Don't ask me how it works, though.

If you want to go over that limit of 65536, modify files tif_fax3.h and tif_fax3.c (lines number from v3.4 beta). ">" is the modified code, "<" is the original:

tif_fax3.h:

46c46
<  * fillruns(unsigned char* buf, uint16* runs, uint16* erun, uint32
lastx)
>  * fillruns(unsigned char* buf, uint32* runs, uint32* erun, uint32
lastx)
55c55
< typedef void (*TIFFFaxFillFunc)(unsigned char*, uint16*, uint16*,
uint32);
> typedef void (*TIFFFaxFillFunc)(unsigned char*, uint32*, uint32*,
uint32);
63c63
< extern void _TIFFFax3fillruns(unsigned char*, uint16*, uint16*,
uint32);
> extern void _TIFFFax3fillruns(unsigned char*, uint32*, uint32*,
uint32);
87c87
<  uint16 Param;  /* unsigned 16-bit run length in bits */
>  uint32 Param;  /* unsigned 32-bit run length in bits */

tif_fax3.c:

81,83c81,83
<  uint16* runs;      /* b&w runs for current/previous row */
<  uint16* refruns;  /* runs for reference line */
<  uint16* curruns; /* runs for current line */
>  uint32* runs;      /* b&w runs for current/previous row */
>  uint32* refruns;  /* runs for reference line */
>  uint32* curruns; /* runs for current line */
120,121c120,121
<     uint16* pa;    /* place to stuff next run */ \
<     uint16* thisrun;   /* current row's run array */ \
>     uint32* pa;    /* place to stuff next run */ \
>     uint32* thisrun;   /* current row's run array */ \
128c128
<     uint16* pb    /* next run in reference line */\
>     uint32* pb    /* next run in reference line */\
298c298
<   SWAP(uint16*, sp->curruns, sp->refruns);
>   SWAP(uint32*, sp->curruns, sp->refruns);
361c361
< _TIFFFax3fillruns(u_char* buf, uint16* runs, uint16* erun, uint32
lastx)
> _TIFFFax3fillruns(u_char* buf, uint32* runs, uint32* erun, uint32
lastx)
502c502
<   dsp->runs = (uint16*) _TIFFmalloc(nruns*sizeof (uint16));
>   dsp->runs = (uint32*) _TIFFmalloc(nruns*sizeof (uint32));
1378c1378
<   SWAP(uint16*, sp->curruns, sp->refruns);
>   SWAP(uint32*, sp->curruns, sp->refruns);

--- end ---