Merge pull request #3464 from radarhere/quality_layers

Check quality_layers type
This commit is contained in:
Hugo 2018-11-16 17:55:06 +02:00 committed by GitHub
commit 0b881555ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -105,6 +105,22 @@ class TestFileJpeg2k(PillowTestCase):
im.load()
self.assertEqual(im.size, (160, 120))
def test_layers_type(self):
outfile = self.tempfile('temp_layers.jp2')
for quality_layers in [
[100, 50, 10],
(100, 50, 10),
None
]:
test_card.save(outfile, quality_layers=quality_layers)
for quality_layers in [
'quality_layers',
('100', '50', '10')
]:
self.assertRaises(ValueError, test_card.save, outfile,
quality_layers=quality_layers)
def test_layers(self):
out = BytesIO()
test_card.save(out, 'JPEG2000', quality_layers=[100, 50, 10],

View File

@ -232,6 +232,13 @@ def _save(im, fp, filename):
tile_size = info.get('tile_size', None)
quality_mode = info.get('quality_mode', 'rates')
quality_layers = info.get('quality_layers', None)
if quality_layers is not None and not (
isinstance(quality_layers, (list, tuple)) and
all([isinstance(quality_layer, (int, float))
for quality_layer in quality_layers])
):
raise ValueError('quality_layers must be a sequence of numbers')
num_resolutions = info.get('num_resolutions', 0)
cblk_size = info.get('codeblock_size', None)
precinct_size = info.get('precinct_size', None)