diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index 2c6e3dd9b..220b80026 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -118,8 +118,13 @@ COMPRESSION_INFO = { 5: "tiff_lzw", 6: "tiff_jpeg", # obsolete 7: "jpeg", + 8: "tiff_adobe_deflate", 32771: "tiff_raw_16", # 16-bit padding - 32773: "packbits" + 32773: "packbits", + 32809: "tiff_thunderscan", + 32946: "tiff_deflate", + 34676: "tiff_sgilog", + 34677: "tiff_sgilog24", } COMPRESSION_INFO_REV = dict([(v,k) for (k,v) in COMPRESSION_INFO.items()]) @@ -746,8 +751,11 @@ class TiffImageFile(ImageFile.ImageFile): offsets = self.tag[STRIPOFFSETS] h = getscalar(ROWSPERSTRIP, ysize) w = self.size[0] - if self._compression in ["tiff_ccitt", "group3", - "group4", "tiff_raw_16"]: + if self._compression in ["tiff_ccitt", "group3", "group4", + "tiff_jpeg", "tiff_adobe_deflate", + "tiff_thunderscan", "tiff_deflate", + "tiff_sgilog", "tiff_sgilog24", + "tiff_raw_16"]: ## if Image.DEBUG: ## print "Activating g4 compression for whole file" @@ -878,8 +886,11 @@ def _save(im, fp, filename): ifd = ImageFileDirectory(prefix) compression = im.info.get('compression','raw') - libtiff = compression in ["tiff_ccitt", "group3", - "group4", "tiff_raw_16"] + libtiff = compression in ["tiff_ccitt", "group3", "group4", + "tiff_jpeg", "tiff_adobe_deflate", + "tiff_thunderscan", "tiff_deflate", + "tiff_sgilog", "tiff_sgilog24", + "tiff_raw_16"] # -- multi-page -- skip TIFF header on subsequent pages if not libtiff and fp.tell() == 0: diff --git a/Tests/images/tiff_adobe_deflate.tif b/Tests/images/tiff_adobe_deflate.tif new file mode 100644 index 000000000..7c0d9c53d Binary files /dev/null and b/Tests/images/tiff_adobe_deflate.tif differ diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index ddca24876..095226f84 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -71,3 +71,12 @@ def test_xyres_tiff(): im.tag.tags[Y_RESOLUTION] = (72,) im._setup() assert_equal(im.info['dpi'], (72., 72.)) + +def test_adobe_deflate_tiff(): + file = "Tests/images/tiff_adobe_deflate.tif" + im = Image.open(file) + + assert_equal(im.mode, "RGB") + assert_equal(im.size, (278, 374)) + assert_equal(im.tile[0][:3], ('tiff_adobe_deflate', (0, 0, 278, 374), 0)) + assert_no_exception(lambda: im.load()) diff --git a/_imaging.c b/_imaging.c index 8e30e5902..9f480304d 100644 --- a/_imaging.c +++ b/_imaging.c @@ -3313,11 +3313,23 @@ static PyMethodDef functions[] = { {"tiff_ccitt_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1}, {"group3_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1}, {"group4_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1}, + {"tiff_jpeg_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1}, + {"tiff_adobe_deflate_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1}, + {"tiff_thunderscan_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1}, + {"tiff_deflate_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1}, + {"tiff_sgilog_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1}, + {"tiff_sgilog24_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1}, {"tiff_raw_16_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1}, {"tiff_ccitt_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1}, {"group3_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1}, {"group4_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1}, + {"tiff_jpeg_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1}, + {"tiff_adobe_deflate_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1}, + {"tiff_thunderscan_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1}, + {"tiff_deflate_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1}, + {"tiff_sgilog_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1}, + {"tiff_sgilog24_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1}, {"tiff_raw_16_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1}, #endif {"msp_decoder", (PyCFunction)PyImaging_MspDecoderNew, 1}, diff --git a/decode.c b/decode.c index 49aad9c07..4bdfbeef2 100644 --- a/decode.c +++ b/decode.c @@ -449,6 +449,24 @@ PyImaging_LibTiffDecoderNew(PyObject* self, PyObject* args) } else if (strcasecmp(compname, "group4") == 0) { compression = COMPRESSION_CCITTFAX4; + } else if (strcasecmp(compname, "tiff_jpeg") == 0) { + compression = COMPRESSION_OJPEG; + + } else if (strcasecmp(compname, "tiff_adobe_deflate") == 0) { + compression = COMPRESSION_ADOBE_DEFLATE; + + } else if (strcasecmp(compname, "tiff_thunderscan") == 0) { + compression = COMPRESSION_THUNDERSCAN; + + } else if (strcasecmp(compname, "tiff_deflate") == 0) { + compression = COMPRESSION_DEFLATE; + + } else if (strcasecmp(compname, "tiff_sgilog") == 0) { + compression = COMPRESSION_SGILOG; + + } else if (strcasecmp(compname, "tiff_sgilog24") == 0) { + compression = COMPRESSION_SGILOG24; + } else if (strcasecmp(compname, "tiff_raw_16") == 0) { compression = COMPRESSION_CCITTRLEW; diff --git a/encode.c b/encode.c index 0044709c0..d264ad914 100644 --- a/encode.c +++ b/encode.c @@ -719,6 +719,24 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args) } else if (strcasecmp(compname, "group4") == 0) { compression = COMPRESSION_CCITTFAX4; + } else if (strcasecmp(compname, "tiff_jpeg") == 0) { + compression = COMPRESSION_OJPEG; + + } else if (strcasecmp(compname, "tiff_adobe_deflate") == 0) { + compression = COMPRESSION_ADOBE_DEFLATE; + + } else if (strcasecmp(compname, "tiff_thunderscan") == 0) { + compression = COMPRESSION_THUNDERSCAN; + + } else if (strcasecmp(compname, "tiff_deflate") == 0) { + compression = COMPRESSION_DEFLATE; + + } else if (strcasecmp(compname, "tiff_sgilog") == 0) { + compression = COMPRESSION_SGILOG; + + } else if (strcasecmp(compname, "tiff_sgilog24") == 0) { + compression = COMPRESSION_SGILOG24; + } else if (strcasecmp(compname, "tiff_raw_16") == 0) { compression = COMPRESSION_CCITTRLEW; diff --git a/libImaging/TiffDecode.c b/libImaging/TiffDecode.c index 8acea0317..d535a5033 100644 --- a/libImaging/TiffDecode.c +++ b/libImaging/TiffDecode.c @@ -197,6 +197,10 @@ int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int clientstate->flrealloc = 0; dump_state(clientstate); + + TIFFSetWarningHandler(NULL); + TIFFSetWarningHandlerExt(NULL); + if (clientstate->fp) { TRACE(("Opening using fd: %d\n",clientstate->fp)); lseek(clientstate->fp,0,SEEK_SET); // Sometimes, I get it set to the end.