2001.09.24 20:17 "libtiff 3.5.7 beta", by Frank Warmerdam

2001.09.24 23:51 "Re: libtiff 3.5.7 beta", by Peter Montgomery

Frank,

Back in April of 2000, I discovered a bug in the way VC++ 5.0 handled the LZW code when compiling with optimizations turned on. I finally discovered where the problem was and suggested a solution. A list member named Jan Nijtmans came up with a more elegant solution that didn't affect the speed of the code, but compiled perfectly under VC++. Could you please integrate this into the current code base prior to releasing the latest version of the code? The problem is in tif_lzw.c, in a function called "LZWSetupDecode( )". Here's the affected area...

#define VCC_FIX
#ifdef VCC_FIX
   code = 255;
   do {
      sp->dec_codetab[code].value = code;
      sp->dec_codetab[code].firstchar = code;
      sp->dec_codetab[code].length = 1;
      sp->dec_codetab[code].next = NULL;
   } while (code--);
#else
  for (code = 255; code >= 0; code--) {
   sp->dec_codetab[code].value = code;
   sp->dec_codetab[code].firstchar = code;
   sp->dec_codetab[code].length = 1;
   sp->dec_codetab[code].next = NULL;
  }
#endif VCC_FIX

If you define VCC_FIX, then the code works perfectly when compiling with optimizations. If you don't, then you get horribly nasty results with RGBA images (I don't remember if it also affected RGB images). It's a small change, but it would prevent me (and I assume others) from having to manually fix the problem with each new release of the code.

Thanks,
PeterM