mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 09:56:17 +03:00
Fix tiled raw tiff read and add tests
This commit is contained in:
parent
f0436a4ddc
commit
1f63abdba8
BIN
Tests/images/tiff_strip_cmyk_jpeg.tif
Normal file
BIN
Tests/images/tiff_strip_cmyk_jpeg.tif
Normal file
Binary file not shown.
BIN
Tests/images/tiff_strip_raw.tif
Normal file
BIN
Tests/images/tiff_strip_raw.tif
Normal file
Binary file not shown.
BIN
Tests/images/tiff_strip_ycbcr_jpeg_1x1_sampling.tif
Normal file
BIN
Tests/images/tiff_strip_ycbcr_jpeg_1x1_sampling.tif
Normal file
Binary file not shown.
BIN
Tests/images/tiff_strip_ycbcr_jpeg_2x2_sampling.tif
Normal file
BIN
Tests/images/tiff_strip_ycbcr_jpeg_2x2_sampling.tif
Normal file
Binary file not shown.
BIN
Tests/images/tiff_tiled_cmyk_jpeg.tif
Normal file
BIN
Tests/images/tiff_tiled_cmyk_jpeg.tif
Normal file
Binary file not shown.
BIN
Tests/images/tiff_tiled_raw.tif
Normal file
BIN
Tests/images/tiff_tiled_raw.tif
Normal file
Binary file not shown.
BIN
Tests/images/tiff_tiled_ycbcr_jpeg_1x1_sampling.tif
Normal file
BIN
Tests/images/tiff_tiled_ycbcr_jpeg_1x1_sampling.tif
Normal file
Binary file not shown.
BIN
Tests/images/tiff_tiled_ycbcr_jpeg_2x2_sampling.tif
Normal file
BIN
Tests/images/tiff_tiled_ycbcr_jpeg_2x2_sampling.tif
Normal file
Binary file not shown.
|
@ -416,6 +416,54 @@ class TestFileTiff(PillowTestCase):
|
||||||
|
|
||||||
self.assert_image_equal(im, reloaded)
|
self.assert_image_equal(im, reloaded)
|
||||||
|
|
||||||
|
def test_strip_raw(self):
|
||||||
|
infile = "Tests/images/tiff_strip_raw.tif"
|
||||||
|
im = Image.open(infile)
|
||||||
|
|
||||||
|
self.assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png")
|
||||||
|
|
||||||
|
def test_strip_cmyk_jpeg(self):
|
||||||
|
infile = "Tests/images/tiff_strip_cmyk_jpeg.tif"
|
||||||
|
im = Image.open(infile)
|
||||||
|
|
||||||
|
self.assert_image_similar_tofile(im, "Tests/images/pil_sample_cmyk.jpg", 3, mode='CMYK')
|
||||||
|
|
||||||
|
def test_strip_ycbcr_jpeg_2x2_sampling(self):
|
||||||
|
infile = "Tests/images/tiff_strip_ycbcr_jpeg_2x2_sampling.tif"
|
||||||
|
im = Image.open(infile)
|
||||||
|
|
||||||
|
self.assert_image_similar_tofile(im, "Tests/images/flower.jpg", 2)
|
||||||
|
|
||||||
|
def test_strip_ycbcr_jpeg_1x1_sampling(self):
|
||||||
|
infile = "Tests/images/tiff_strip_ycbcr_jpeg_1x1_sampling.tif"
|
||||||
|
im = Image.open(infile)
|
||||||
|
|
||||||
|
self.assert_image_similar_tofile(im, "Tests/images/flower.jpg", 5)
|
||||||
|
|
||||||
|
def test_tiled_raw(self):
|
||||||
|
infile = "Tests/images/tiff_tiled_raw.tif"
|
||||||
|
im = Image.open(infile)
|
||||||
|
|
||||||
|
self.assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png")
|
||||||
|
|
||||||
|
def test_tiled_cmyk_jpeg(self):
|
||||||
|
infile = "Tests/images/tiff_tiled_cmyk_jpeg.tif"
|
||||||
|
im = Image.open(infile)
|
||||||
|
|
||||||
|
self.assert_image_similar_tofile(im, "Tests/images/pil_sample_cmyk.jpg", 3.5, mode='CMYK')
|
||||||
|
|
||||||
|
def test_tiled_ycbcr_jpeg_1x1_sampling(self):
|
||||||
|
infile = "Tests/images/tiff_tiled_ycbcr_jpeg_1x1_sampling.tif"
|
||||||
|
im = Image.open(infile)
|
||||||
|
|
||||||
|
self.assert_image_similar_tofile(im, "Tests/images/flower.jpg", 5)
|
||||||
|
|
||||||
|
def test_tiled_ycbcr_jpeg_2x2_sampling(self):
|
||||||
|
infile = "Tests/images/tiff_tiled_ycbcr_jpeg_2x2_sampling.tif"
|
||||||
|
im = Image.open(infile)
|
||||||
|
|
||||||
|
self.assert_image_similar_tofile(im, "Tests/images/flower.jpg", 1)
|
||||||
|
|
||||||
def test_tiff_save_all(self):
|
def test_tiff_save_all(self):
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
|
|
|
@ -1053,15 +1053,16 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
"Return the current frame number"
|
"Return the current frame number"
|
||||||
return self.__frame
|
return self.__frame
|
||||||
|
|
||||||
def _decoder(self, rawmode, layer, tile=None):
|
def _decoder(self, rawmode, layer, stride):
|
||||||
"Setup decoder contexts"
|
"Setup decoder contexts"
|
||||||
|
|
||||||
args = None
|
args = None
|
||||||
if rawmode == "RGB" and self._planar_configuration == 2:
|
if rawmode == "RGB" and self._planar_configuration == 2:
|
||||||
rawmode = rawmode[layer]
|
rawmode = rawmode[layer]
|
||||||
|
stride /= 3
|
||||||
compression = self._compression
|
compression = self._compression
|
||||||
if compression == "raw":
|
if compression == "raw":
|
||||||
args = (rawmode, 0, 1)
|
args = (rawmode, int(stride), 1)
|
||||||
if compression == "jpeg":
|
if compression == "jpeg":
|
||||||
args = ("RGB", "")
|
args = ("RGB", "")
|
||||||
elif compression == "packbits":
|
elif compression == "packbits":
|
||||||
|
@ -1261,7 +1262,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
# build tile descriptors
|
# build tile descriptors
|
||||||
x = y = layer = 0
|
x = y = layer = 0
|
||||||
self.tile = []
|
self.tile = []
|
||||||
self.use_load_libtiff = self._compression != 'raw'
|
self.use_load_libtiff = READ_LIBTIFF or self._compression != 'raw'
|
||||||
if self.use_load_libtiff:
|
if self.use_load_libtiff:
|
||||||
# Decoder expects entire file as one tile.
|
# Decoder expects entire file as one tile.
|
||||||
# There's a buffer size limit in load (64k)
|
# There's a buffer size limit in load (64k)
|
||||||
|
@ -1318,13 +1319,16 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
w = self.tag_v2.get(322)
|
w = self.tag_v2.get(322)
|
||||||
h = self.tag_v2.get(323)
|
h = self.tag_v2.get(323)
|
||||||
|
|
||||||
a = None
|
|
||||||
for offset in offsets:
|
for offset in offsets:
|
||||||
if not a:
|
if x + w > xsize:
|
||||||
a = self._decoder(rawmode, layer)
|
stride = w * sum(bps_tuple) / 8 # bytes per line
|
||||||
|
else:
|
||||||
|
stride = 0
|
||||||
|
|
||||||
|
a = self._decoder(rawmode, layer, stride)
|
||||||
self.tile.append(
|
self.tile.append(
|
||||||
(self._compression,
|
(self._compression,
|
||||||
(min(x, xsize), min(y, ysize), min(x+w, xsize), min(y+h, ysize)),
|
(x, y, min(x+w, xsize), min(y+h, ysize)),
|
||||||
offset, a))
|
offset, a))
|
||||||
x = x + w
|
x = x + w
|
||||||
if x >= self.size[0]:
|
if x >= self.size[0]:
|
||||||
|
@ -1332,7 +1336,6 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
if y >= self.size[1]:
|
if y >= self.size[1]:
|
||||||
x = y = 0
|
x = y = 0
|
||||||
layer += 1
|
layer += 1
|
||||||
a = None
|
|
||||||
self.tile_prefix = self.tag_v2.get(JPEGTABLES, b"")
|
self.tile_prefix = self.tag_v2.get(JPEGTABLES, b"")
|
||||||
else:
|
else:
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user