Skip to content

Commit

Permalink
Merge pull request #5452 from radarhere/missing_samplesperpixel
Browse files Browse the repository at this point in the history
Updated default value for SAMPLESPERPIXEL TIFF tag
  • Loading branch information
hugovk authored May 14, 2021
2 parents d74cf22 + 6fc039a commit f027397
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Binary file not shown.
9 changes: 7 additions & 2 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,13 @@ def test_strip_planar_16bit_RGBa(self):
assert_image_equal_tofile(im, "Tests/images/tiff_16bit_RGBa_target.png")

def test_old_style_jpeg(self):
infile = "Tests/images/old-style-jpeg-compression.tif"
with Image.open(infile) as im:
with Image.open("Tests/images/old-style-jpeg-compression.tif") as im:
assert_image_equal_tofile(im, "Tests/images/old-style-jpeg-compression.png")

def test_open_missing_samplesperpixel(self):
with Image.open(
"Tests/images/old-style-jpeg-compression-no-samplesperpixel.tif"
) as im:
assert_image_equal_tofile(im, "Tests/images/old-style-jpeg-compression.png")

def test_no_rows_per_strip(self):
Expand Down
5 changes: 4 additions & 1 deletion src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,10 @@ def _setup(self):
if bps_count > len(bps_tuple) and len(bps_tuple) == 1:
bps_tuple = bps_tuple * bps_count

samplesPerPixel = self.tag_v2.get(SAMPLESPERPIXEL, 1)
samplesPerPixel = self.tag_v2.get(
SAMPLESPERPIXEL,
3 if self._compression == "tiff_jpeg" and photo in (2, 6) else 1,
)
if len(bps_tuple) != samplesPerPixel:
raise SyntaxError("unknown data organization")

Expand Down

0 comments on commit f027397

Please sign in to comment.