diff --git a/Tests/images/tiff_gray_2_4_bpp/hopper2.tif b/Tests/images/tiff_gray_2_4_bpp/hopper2.tif new file mode 100644 index 000000000..70057219a Binary files /dev/null and b/Tests/images/tiff_gray_2_4_bpp/hopper2.tif differ diff --git a/Tests/images/tiff_gray_2_4_bpp/hopper2I.tif b/Tests/images/tiff_gray_2_4_bpp/hopper2I.tif new file mode 100644 index 000000000..9feaa08f0 Binary files /dev/null and b/Tests/images/tiff_gray_2_4_bpp/hopper2I.tif differ diff --git a/Tests/images/tiff_gray_2_4_bpp/hopper2IR.tif b/Tests/images/tiff_gray_2_4_bpp/hopper2IR.tif new file mode 100644 index 000000000..462416955 Binary files /dev/null and b/Tests/images/tiff_gray_2_4_bpp/hopper2IR.tif differ diff --git a/Tests/images/tiff_gray_2_4_bpp/hopper2R.tif b/Tests/images/tiff_gray_2_4_bpp/hopper2R.tif new file mode 100644 index 000000000..65e0f623e Binary files /dev/null and b/Tests/images/tiff_gray_2_4_bpp/hopper2R.tif differ diff --git a/Tests/images/tiff_gray_2_4_bpp/hopper4.tif b/Tests/images/tiff_gray_2_4_bpp/hopper4.tif new file mode 100644 index 000000000..7a38271ea Binary files /dev/null and b/Tests/images/tiff_gray_2_4_bpp/hopper4.tif differ diff --git a/Tests/images/tiff_gray_2_4_bpp/hopper4I.tif b/Tests/images/tiff_gray_2_4_bpp/hopper4I.tif new file mode 100644 index 000000000..5c3a17f52 Binary files /dev/null and b/Tests/images/tiff_gray_2_4_bpp/hopper4I.tif differ diff --git a/Tests/images/tiff_gray_2_4_bpp/hopper4IR.tif b/Tests/images/tiff_gray_2_4_bpp/hopper4IR.tif new file mode 100644 index 000000000..7652f5e6d Binary files /dev/null and b/Tests/images/tiff_gray_2_4_bpp/hopper4IR.tif differ diff --git a/Tests/images/tiff_gray_2_4_bpp/hopper4R.tif b/Tests/images/tiff_gray_2_4_bpp/hopper4R.tif new file mode 100644 index 000000000..0cdf4d26e Binary files /dev/null and b/Tests/images/tiff_gray_2_4_bpp/hopper4R.tif differ diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 313fb545f..36fa2496a 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -421,6 +421,39 @@ class TestFileLibTiff(LibTiffTestCase): self.assertEqual(im.mode, "L") self.assert_image_similar(im, original, 7.3) + def test_gray_semibyte_per_pixel(self): + test_files = ( + ( + 24.8,#epsilon + (#group + "Tests/images/tiff_gray_2_4_bpp/hopper2.tif", + "Tests/images/tiff_gray_2_4_bpp/hopper2I.tif", + "Tests/images/tiff_gray_2_4_bpp/hopper2R.tif", + "Tests/images/tiff_gray_2_4_bpp/hopper2IR.tif", + ) + ), + ( + 7.3,#epsilon + (#group + "Tests/images/tiff_gray_2_4_bpp/hopper4.tif", + "Tests/images/tiff_gray_2_4_bpp/hopper4I.tif", + "Tests/images/tiff_gray_2_4_bpp/hopper4R.tif", + "Tests/images/tiff_gray_2_4_bpp/hopper4IR.tif", + ) + ), + ) + original = hopper("L") + for epsilon, group in test_files: + im = Image.open(group[0]) + self.assertEqual(im.size, (128, 128)) + self.assertEqual(im.mode, "L") + self.assert_image_similar(im, original, epsilon) + for file in group[1:]: + im2 = Image.open(file) + self.assertEqual(im2.size, (128, 128)) + self.assertEqual(im2.mode, "L") + self.assert_image_equal(im, im2) + def test_save_bytesio(self): # PR 1011 # Test TIFF saving to io.BytesIO() object. diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 26b6bd4c3..f943d8c92 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -323,6 +323,39 @@ class TestFileTiff(PillowTestCase): self.assertEqual(im.mode, "L") self.assert_image_similar(im, original, 7.3) + def test_gray_semibyte_per_pixel(self): + test_files = ( + ( + 24.8,#epsilon + (#group + "Tests/images/tiff_gray_2_4_bpp/hopper2.tif", + "Tests/images/tiff_gray_2_4_bpp/hopper2I.tif", + "Tests/images/tiff_gray_2_4_bpp/hopper2R.tif", + "Tests/images/tiff_gray_2_4_bpp/hopper2IR.tif", + ) + ), + ( + 7.3,#epsilon + (#group + "Tests/images/tiff_gray_2_4_bpp/hopper4.tif", + "Tests/images/tiff_gray_2_4_bpp/hopper4I.tif", + "Tests/images/tiff_gray_2_4_bpp/hopper4R.tif", + "Tests/images/tiff_gray_2_4_bpp/hopper4IR.tif", + ) + ), + ) + original = hopper("L") + for epsilon, group in test_files: + im = Image.open(group[0]) + self.assertEqual(im.size, (128, 128)) + self.assertEqual(im.mode, "L") + self.assert_image_similar(im, original, epsilon) + for file in group[1:]: + im2 = Image.open(file) + self.assertEqual(im2.size, (128, 128)) + self.assertEqual(im2.mode, "L") + self.assert_image_equal(im, im2) + def test_page_number_x_0(self): # Issue 973 # Test TIFF with tag 297 (Page Number) having value of 0 0.