1

I wrote a pure python TIFF G4 decompress for use with tifffile.py. I know there are ways to add libtiff to a custom PIL, but I never could get that working very well in a mixed virtualenv. I want to manipulate the image in PIL. I am looking for pointers in hooking my decompressor to stock PIL for TiffImagePlugin.py.

Any ideas?

Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
Frustrated
  • 772
  • 1
  • 8
  • 16
  • Have you tried using [Pillow](http://pypi.python.org/pypi/Pillow/) in a virtualenv? It works really well, even with TIFF. – jterrace Aug 08 '12 at 16:31
  • It does, but it still doesn't work with Tiff compressed with group 4. Does pillow allowing hooking in additional decompressors? – Frustrated Aug 08 '12 at 16:36
  • Ah, I see. Have you seen [this question](http://stackoverflow.com/q/7034015/624900)? – jterrace Aug 08 '12 at 16:41
  • Yes. I can uncompress the image, which was their question. I am looking to hook my code into stock PIL to add it as a valid decompressor if possible. – Frustrated Aug 08 '12 at 16:48
  • Have you read [Writing Your Own File Decoder](http://www.pythonware.com/library/pil/handbook/decoder.htm)? – jterrace Aug 08 '12 at 16:50
  • Yes, but it seems to cover a whole new image type, ie image type 'foo'. The decoders appear to be working off the extension of the file name. The TiffImagePlugin would still handle the G4 compressed image and be unable to process it. That is why I starting using tifffile.py. For that, I only needed to add 'ccittfax4' to the TIF_DECOMPESSORS. TiffImagePlugin doesn't seem to allow a clean way of doing this. – Frustrated Aug 08 '12 at 17:01

1 Answers1

0

It appears that TiffImagePlugin does not easily allow me to hook in additional decompressors. Replacing TiffImageFile._decoder with a dictionary of decoders might work, but you would have to examine and test each release of PIL to ensure it hasn't broken. This level of maintenance is just as bad as a custom PIL. I appreciate the design of tifffile.py for using a dictionary of decoders. It made it very easy.

Final solution? I couldn't hook my code into PIL. I had to use PIL.Image.fromarray() to using my decompressed images.

Frustrated
  • 772
  • 1
  • 8
  • 16