mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-24 08:14:10 +03:00
Check quality_layers type
This commit is contained in:
parent
e3d5494a51
commit
61397de88b
|
@ -105,6 +105,22 @@ class TestFileJpeg2k(PillowTestCase):
|
||||||
im.load()
|
im.load()
|
||||||
self.assertEqual(im.size, (160, 120))
|
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):
|
def test_layers(self):
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
test_card.save(out, 'JPEG2000', quality_layers=[100, 50, 10],
|
test_card.save(out, 'JPEG2000', quality_layers=[100, 50, 10],
|
||||||
|
|
|
@ -232,6 +232,13 @@ def _save(im, fp, filename):
|
||||||
tile_size = info.get('tile_size', None)
|
tile_size = info.get('tile_size', None)
|
||||||
quality_mode = info.get('quality_mode', 'rates')
|
quality_mode = info.get('quality_mode', 'rates')
|
||||||
quality_layers = info.get('quality_layers', None)
|
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)
|
num_resolutions = info.get('num_resolutions', 0)
|
||||||
cblk_size = info.get('codeblock_size', None)
|
cblk_size = info.get('codeblock_size', None)
|
||||||
precinct_size = info.get('precinct_size', None)
|
precinct_size = info.get('precinct_size', None)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user