[Image-SIG] PIL is corrupting/inverting TIFF images

Fredrik Lundh fredrik@pythonware.com
Tue, 16 Oct 2001 09:32:56 +0200

Larry Bates wrote:
> As you can see the output from the im.save has changed
> the Photometric Interpretation to min-is-black (inverted??).
> The thing I don't understand is that if I open this file in a
> viewing program (Windows Imaging) it doesn't show up
> as inverted is shows up just fine (which is why this
> problem hasn't been discovered yet).  It is only when I
> compress the file that it becomes inverted.  If I use TIFFCP
> to compress test.tif directly (without going through PIL
> Image module), it works just fine.  PIL Image module is
> doing something to the image.

PIL is storing the image in a given format, and is setting
the photometric interpretation tag accordingly.  a TIFF
reader should use this tag to figure out if/how to display
the image.

if there's a bug somewhere, it looks like it's in tiffcp.  both
PIL and Windows Imaging does the right thing.

you might be able to work around this in TiffImagePlugin.py;
look for the SAVE_INFO dictionary:

    # mode => rawmode, photometrics, sampleformat, bitspersample, extra
    "1": ("1", 1, 1, (1,), None),
    "L": ("L", 1, 1, (8,), None),

and change the "1" line to look like this (untested):

    "1": ("1;I", 0, 1, (1,), None),