mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 09:26:16 +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)
|
||||
|
||||
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):
|
||||
import io
|
||||
import os
|
||||
|
|
|
@ -1053,15 +1053,16 @@ class TiffImageFile(ImageFile.ImageFile):
|
|||
"Return the current frame number"
|
||||
return self.__frame
|
||||
|
||||
def _decoder(self, rawmode, layer, tile=None):
|
||||
def _decoder(self, rawmode, layer, stride):
|
||||
"Setup decoder contexts"
|
||||
|
||||
args = None
|
||||
if rawmode == "RGB" and self._planar_configuration == 2:
|
||||
rawmode = rawmode[layer]
|
||||
stride /= 3
|
||||
compression = self._compression
|
||||
if compression == "raw":
|
||||
args = (rawmode, 0, 1)
|
||||
args = (rawmode, int(stride), 1)
|
||||
if compression == "jpeg":
|
||||
args = ("RGB", "")
|
||||
elif compression == "packbits":
|
||||
|
@ -1261,7 +1262,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
|||
# build tile descriptors
|
||||
x = y = layer = 0
|
||||
self.tile = []
|
||||
self.use_load_libtiff = self._compression != 'raw'
|
||||
self.use_load_libtiff = READ_LIBTIFF or self._compression != 'raw'
|
||||
if self.use_load_libtiff:
|
||||
# Decoder expects entire file as one tile.
|
||||
# There's a buffer size limit in load (64k)
|
||||
|
@ -1318,13 +1319,16 @@ class TiffImageFile(ImageFile.ImageFile):
|
|||
w = self.tag_v2.get(322)
|
||||
h = self.tag_v2.get(323)
|
||||
|
||||
a = None
|
||||
for offset in offsets:
|
||||
if not a:
|
||||
a = self._decoder(rawmode, layer)
|
||||
if x + w > xsize:
|
||||
stride = w * sum(bps_tuple) / 8 # bytes per line
|
||||
else:
|
||||
stride = 0
|
||||
|
||||
a = self._decoder(rawmode, layer, stride)
|
||||
self.tile.append(
|
||||
(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))
|
||||
x = x + w
|
||||
if x >= self.size[0]:
|
||||
|
@ -1332,7 +1336,6 @@ class TiffImageFile(ImageFile.ImageFile):
|
|||
if y >= self.size[1]:
|
||||
x = y = 0
|
||||
layer += 1
|
||||
a = None
|
||||
self.tile_prefix = self.tag_v2.get(JPEGTABLES, b"")
|
||||
else:
|
||||
if DEBUG:
|
||||
|
|
Loading…
Reference in New Issue
Block a user