mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
The optimization algorithm is only applicable to the image of mode="P" or "L".
This commit is contained in:
parent
b5315eb59b
commit
9d60085957
|
@ -433,7 +433,7 @@ def getheader(im, palette=None, info=None):
|
|||
|
||||
usedPaletteColors = paletteBytes = None
|
||||
|
||||
if optimize:
|
||||
if im.mode in ("P", "L") and optimize:
|
||||
usedPaletteColors = []
|
||||
|
||||
# check which colors are used
|
||||
|
|
|
@ -28,13 +28,22 @@ class TestFileGif(PillowTestCase):
|
|||
def test_optimize(self):
|
||||
from io import BytesIO
|
||||
|
||||
def test(optimize):
|
||||
def test_grayscale(optimize):
|
||||
im = Image.new("L", (1, 1), 0)
|
||||
file = BytesIO()
|
||||
im.save(file, "GIF", optimize=optimize)
|
||||
return len(file.getvalue())
|
||||
self.assertEqual(test(0), 800)
|
||||
self.assertEqual(test(1), 38)
|
||||
|
||||
def test_bilevel(optimize):
|
||||
im = Image.new("1", (1, 1), 0)
|
||||
file = BytesIO()
|
||||
im.save(file, "GIF", optimize=optimize)
|
||||
return len(file.getvalue())
|
||||
|
||||
self.assertEqual(test_grayscale(0), 800)
|
||||
self.assertEqual(test_grayscale(1), 38)
|
||||
self.assertEqual(test_bilevel(0), 800)
|
||||
self.assertEqual(test_bilevel(1), 800)
|
||||
|
||||
def test_optimize_full_l(self):
|
||||
from io import BytesIO
|
||||
|
|
Loading…
Reference in New Issue
Block a user