diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 3b2e6cb20..dba16d346 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -303,6 +303,15 @@ class TestFileJpeg(PillowTestCase): filename = "Tests/images/junk_jpeg_header.jpg" Image.open(filename) + def _n_qtables_helper(self, n, test_file): + im = Image.open(test_file) + f = self.tempfile('temp.jpg') + im.save(f, qtables=[[n]*64]*n) + im = Image.open(f) + self.assertEqual(len(im.quantization), n) + reloaded = self.roundtrip(im, qtables="keep") + self.assertEqual(im.quantization, reloaded.quantization) + def test_qtables(self): im = Image.open("Tests/images/hopper.jpg") qtables = im.quantization @@ -359,6 +368,15 @@ class TestFileJpeg(PillowTestCase): 1: standard_chrominance_qtable }), 30) + self._n_qtables_helper(1, "Tests/images/hopper_gray.jpg") + self._n_qtables_helper(1, "Tests/images/pil_sample_rgb.jpg") + self._n_qtables_helper(2, "Tests/images/pil_sample_rgb.jpg") + self._n_qtables_helper(3, "Tests/images/pil_sample_rgb.jpg") + self._n_qtables_helper(1, "Tests/images/pil_sample_cmyk.jpg") + self._n_qtables_helper(2, "Tests/images/pil_sample_cmyk.jpg") + self._n_qtables_helper(3, "Tests/images/pil_sample_cmyk.jpg") + self._n_qtables_helper(4, "Tests/images/pil_sample_cmyk.jpg") + # not a sequence self.assertRaises(Exception, lambda: self.roundtrip(im, qtables='a')) # sequence wrong length