mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-07 13:54:45 +03:00
Merge a190d64165
into 86ab020736
This commit is contained in:
commit
7813748f7a
|
@ -4,6 +4,9 @@ Changelog (Pillow)
|
||||||
2.4.0 (unreleased)
|
2.4.0 (unreleased)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
- Conversions enabled from RGBA->P, Fixes #544
|
||||||
|
[wiredfool]
|
||||||
|
|
||||||
- Add more detailed error messages to Image.py
|
- Add more detailed error messages to Image.py
|
||||||
[larsmans]
|
[larsmans]
|
||||||
|
|
||||||
|
|
16
PIL/Image.py
16
PIL/Image.py
|
@ -735,6 +735,9 @@ class Image:
|
||||||
im = self.im.convert_matrix(mode, matrix)
|
im = self.im.convert_matrix(mode, matrix)
|
||||||
return self._new(im)
|
return self._new(im)
|
||||||
|
|
||||||
|
if mode == "P" and self.mode == "RGBA":
|
||||||
|
return self.quantize(colors)
|
||||||
|
|
||||||
if mode == "P" and palette == ADAPTIVE:
|
if mode == "P" and palette == ADAPTIVE:
|
||||||
im = self.im.quantize(colors)
|
im = self.im.quantize(colors)
|
||||||
new = self._new(im)
|
new = self._new(im)
|
||||||
|
@ -762,7 +765,7 @@ class Image:
|
||||||
|
|
||||||
return self._new(im)
|
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:
|
# methods:
|
||||||
# 0 = median cut
|
# 0 = median cut
|
||||||
|
@ -774,6 +777,17 @@ class Image:
|
||||||
|
|
||||||
self.load()
|
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:
|
if palette:
|
||||||
# use palette from reference image
|
# use palette from reference image
|
||||||
palette.load()
|
palette.load()
|
||||||
|
|
|
@ -46,5 +46,13 @@ def test_16bit_workaround():
|
||||||
im = Image.open('Tests/images/16bit.cropped.tif')
|
im = Image.open('Tests/images/16bit.cropped.tif')
|
||||||
_test_float_conversion(im.convert('I'))
|
_test_float_conversion(im.convert('I'))
|
||||||
|
|
||||||
|
def test_rgba_p():
|
||||||
|
im = lena('RGBA')
|
||||||
|
im.putalpha(lena('L'))
|
||||||
|
|
||||||
|
converted = im.convert('P')
|
||||||
|
comparable = converted.convert('RGBA')
|
||||||
|
|
||||||
|
assert_image_similar(im, comparable, 20)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,3 +20,8 @@ def test_octree_quantize():
|
||||||
assert_image(im, "P", im.size)
|
assert_image(im, "P", im.size)
|
||||||
|
|
||||||
assert len(im.getcolors()) == 100
|
assert len(im.getcolors()) == 100
|
||||||
|
|
||||||
|
def test_rgba_quantize():
|
||||||
|
im = lena('RGBA')
|
||||||
|
assert_no_exception(lambda: im.quantize())
|
||||||
|
assert_exception(Exception, lambda: im.quantize(method=0))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user