From 67944cedc7293a2e1f568f47a1cce25ee7eaf148 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 18 Jan 2022 19:40:57 +1100 Subject: [PATCH] Always save with contiguous planar configuration --- Tests/test_file_tiff.py | 11 +++++++++++ src/PIL/TiffImagePlugin.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 5801e1766..68409ad1e 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -594,6 +594,17 @@ class TestFileTiff: with Image.open(infile) as im: assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png") + def test_planar_configuration_save(self, tmp_path): + infile = "Tests/images/tiff_tiled_planar_raw.tif" + with Image.open(infile) as im: + assert im._planar_configuration == 2 + + outfile = str(tmp_path / "temp.tif") + im.save(outfile) + + with Image.open(outfile) as reloaded: + assert_image_equal_tofile(reloaded, infile) + def test_palette(self, tmp_path): def roundtrip(mode): outfile = str(tmp_path / "temp.tif") diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index e54082fec..39617c77d 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1528,7 +1528,7 @@ def _save(im, fp, filename): libtiff = WRITE_LIBTIFF or compression != "raw" # required for color libtiff images - ifd[PLANAR_CONFIGURATION] = getattr(im, "_planar_configuration", 1) + ifd[PLANAR_CONFIGURATION] = 1 ifd[IMAGEWIDTH] = im.size[0] ifd[IMAGELENGTH] = im.size[1]