mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Sane quantize defaults for RGBA->P, fixes #544
This commit is contained in:
parent
9518214980
commit
abebac25cc
16
PIL/Image.py
16
PIL/Image.py
|
@ -735,6 +735,9 @@ class Image:
|
|||
im = self.im.convert_matrix(mode, matrix)
|
||||
return self._new(im)
|
||||
|
||||
if mode == "P" and self.mode == "RGBA":
|
||||
return self.quantize(colors)
|
||||
|
||||
if mode == "P" and palette == ADAPTIVE:
|
||||
im = self.im.quantize(colors)
|
||||
new = self._new(im)
|
||||
|
@ -762,7 +765,7 @@ class Image:
|
|||
|
||||
return self._new(im)
|
||||
|
||||
def quantize(self, colors=256, method=0, kmeans=0, palette=None):
|
||||
def quantize(self, colors=256, method=None, kmeans=0, palette=None):
|
||||
|
||||
# methods:
|
||||
# 0 = median cut
|
||||
|
@ -774,6 +777,17 @@ class Image:
|
|||
|
||||
self.load()
|
||||
|
||||
if method is None:
|
||||
# defaults:
|
||||
method = 0
|
||||
if self.mode == 'RGBA':
|
||||
method = 2
|
||||
|
||||
if self.mode == 'RGBA' and method != 2:
|
||||
# Caller specified an invalid mode.
|
||||
raise ValueError('Fast Octree (method == 2) is the ' +
|
||||
' only valid method for quantizing RGBA images')
|
||||
|
||||
if palette:
|
||||
# use palette from reference image
|
||||
palette.load()
|
||||
|
|
Loading…
Reference in New Issue
Block a user