Login  Register

LZW compressed tiffs

Posted by Jon Harman on Sep 13, 2005; 9:16pm
URL: http://imagej.273.s1.nabble.com/LZW-compressed-tiffs-tp3704864.html

Hi

In looking for lossless compression for my large image files, I started
using LZW tiffs. (are there better formats?) I found that different
programs produce very different output files using this and sometimes
ImageJ would fail to read the output.  For instance paintshop pro
sometimes produces a file that can't be read.  Photoshop seems much
better.  Irfanview  produces files that sometimes can't be read, and
additionally aren't much compressed.  So this format seems to be a can
of worms.

At any rate the other programs did not have the problem that ImageJ did
in opening the files, they all could read the files wrote by the others,
unlike ImageJ.  I looked into this and found that making the following
modification to readCompressesChunkyRGB in ImageReader.java fixed the
problem.  Just add a test that j is < nPixels before writing to pixels:

                if(j < nPixels){
                    if (bgr)
                        pixels[j] = 0xff000000 | (blue<<16) | (green<<8)
| red;
                    else
                        pixels[j] = 0xff000000 | (red<<16) | (green<<8)
| blue;
                }

I have no clue as to why j is getting too big, but adding the test seems
to work just fine.

Jon