mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Merge pull request #268 from megabuz/master
Add several TIFF decoders and encoders
This commit is contained in:
commit
fd98b0cceb
|
@ -118,8 +118,13 @@ COMPRESSION_INFO = {
|
||||||
5: "tiff_lzw",
|
5: "tiff_lzw",
|
||||||
6: "tiff_jpeg", # obsolete
|
6: "tiff_jpeg", # obsolete
|
||||||
7: "jpeg",
|
7: "jpeg",
|
||||||
|
8: "tiff_adobe_deflate",
|
||||||
32771: "tiff_raw_16", # 16-bit padding
|
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()])
|
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]
|
offsets = self.tag[STRIPOFFSETS]
|
||||||
h = getscalar(ROWSPERSTRIP, ysize)
|
h = getscalar(ROWSPERSTRIP, ysize)
|
||||||
w = self.size[0]
|
w = self.size[0]
|
||||||
if self._compression in ["tiff_ccitt", "group3",
|
if self._compression in ["tiff_ccitt", "group3", "group4",
|
||||||
"group4", "tiff_raw_16"]:
|
"tiff_jpeg", "tiff_adobe_deflate",
|
||||||
|
"tiff_thunderscan", "tiff_deflate",
|
||||||
|
"tiff_sgilog", "tiff_sgilog24",
|
||||||
|
"tiff_raw_16"]:
|
||||||
## if Image.DEBUG:
|
## if Image.DEBUG:
|
||||||
## print "Activating g4 compression for whole file"
|
## print "Activating g4 compression for whole file"
|
||||||
|
|
||||||
|
@ -878,8 +886,11 @@ def _save(im, fp, filename):
|
||||||
ifd = ImageFileDirectory(prefix)
|
ifd = ImageFileDirectory(prefix)
|
||||||
|
|
||||||
compression = im.info.get('compression','raw')
|
compression = im.info.get('compression','raw')
|
||||||
libtiff = compression in ["tiff_ccitt", "group3",
|
libtiff = compression in ["tiff_ccitt", "group3", "group4",
|
||||||
"group4", "tiff_raw_16"]
|
"tiff_jpeg", "tiff_adobe_deflate",
|
||||||
|
"tiff_thunderscan", "tiff_deflate",
|
||||||
|
"tiff_sgilog", "tiff_sgilog24",
|
||||||
|
"tiff_raw_16"]
|
||||||
|
|
||||||
# -- multi-page -- skip TIFF header on subsequent pages
|
# -- multi-page -- skip TIFF header on subsequent pages
|
||||||
if not libtiff and fp.tell() == 0:
|
if not libtiff and fp.tell() == 0:
|
||||||
|
|
BIN
Tests/images/tiff_adobe_deflate.tif
Normal file
BIN
Tests/images/tiff_adobe_deflate.tif
Normal file
Binary file not shown.
|
@ -71,3 +71,12 @@ def test_xyres_tiff():
|
||||||
im.tag.tags[Y_RESOLUTION] = (72,)
|
im.tag.tags[Y_RESOLUTION] = (72,)
|
||||||
im._setup()
|
im._setup()
|
||||||
assert_equal(im.info['dpi'], (72., 72.))
|
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())
|
||||||
|
|
12
_imaging.c
12
_imaging.c
|
@ -3313,11 +3313,23 @@ static PyMethodDef functions[] = {
|
||||||
{"tiff_ccitt_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1},
|
{"tiff_ccitt_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1},
|
||||||
{"group3_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1},
|
{"group3_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1},
|
||||||
{"group4_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_raw_16_decoder", (PyCFunction)PyImaging_LibTiffDecoderNew, 1},
|
||||||
|
|
||||||
{"tiff_ccitt_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1},
|
{"tiff_ccitt_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1},
|
||||||
{"group3_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1},
|
{"group3_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1},
|
||||||
{"group4_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},
|
{"tiff_raw_16_encoder", (PyCFunction)PyImaging_LibTiffEncoderNew, 1},
|
||||||
#endif
|
#endif
|
||||||
{"msp_decoder", (PyCFunction)PyImaging_MspDecoderNew, 1},
|
{"msp_decoder", (PyCFunction)PyImaging_MspDecoderNew, 1},
|
||||||
|
|
18
decode.c
18
decode.c
|
@ -449,6 +449,24 @@ PyImaging_LibTiffDecoderNew(PyObject* self, PyObject* args)
|
||||||
} else if (strcasecmp(compname, "group4") == 0) {
|
} else if (strcasecmp(compname, "group4") == 0) {
|
||||||
compression = COMPRESSION_CCITTFAX4;
|
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) {
|
} else if (strcasecmp(compname, "tiff_raw_16") == 0) {
|
||||||
compression = COMPRESSION_CCITTRLEW;
|
compression = COMPRESSION_CCITTRLEW;
|
||||||
|
|
||||||
|
|
18
encode.c
18
encode.c
|
@ -719,6 +719,24 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
|
||||||
} else if (strcasecmp(compname, "group4") == 0) {
|
} else if (strcasecmp(compname, "group4") == 0) {
|
||||||
compression = COMPRESSION_CCITTFAX4;
|
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) {
|
} else if (strcasecmp(compname, "tiff_raw_16") == 0) {
|
||||||
compression = COMPRESSION_CCITTRLEW;
|
compression = COMPRESSION_CCITTRLEW;
|
||||||
|
|
||||||
|
|
|
@ -197,6 +197,10 @@ int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, int
|
||||||
clientstate->flrealloc = 0;
|
clientstate->flrealloc = 0;
|
||||||
|
|
||||||
dump_state(clientstate);
|
dump_state(clientstate);
|
||||||
|
|
||||||
|
TIFFSetWarningHandler(NULL);
|
||||||
|
TIFFSetWarningHandlerExt(NULL);
|
||||||
|
|
||||||
if (clientstate->fp) {
|
if (clientstate->fp) {
|
||||||
TRACE(("Opening using fd: %d\n",clientstate->fp));
|
TRACE(("Opening using fd: %d\n",clientstate->fp));
|
||||||
lseek(clientstate->fp,0,SEEK_SET); // Sometimes, I get it set to the end.
|
lseek(clientstate->fp,0,SEEK_SET); // Sometimes, I get it set to the end.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user