mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
When converting to P, restrict colors to palette size
This commit is contained in:
parent
948c064b28
commit
54cb09d8b4
|
@ -108,3 +108,18 @@ def test_palette(method, color):
|
|||
converted = im.quantize(method=method)
|
||||
converted_px = converted.load()
|
||||
assert converted_px[0, 0] == converted.palette.colors[color]
|
||||
|
||||
|
||||
def test_small_palette():
|
||||
# Arrange
|
||||
im = hopper()
|
||||
|
||||
colors = (255, 0, 0, 0, 0, 255)
|
||||
p = Image.new("P", (1, 1))
|
||||
p.putpalette(colors)
|
||||
|
||||
# Act
|
||||
im = im.quantize(palette=p)
|
||||
|
||||
# Assert
|
||||
assert len(im.getcolors()) == 2
|
||||
|
|
|
@ -194,7 +194,7 @@ ImagingPaletteCacheUpdate(ImagingPalette palette, int r, int g, int b) {
|
|||
|
||||
dmax = (unsigned int)~0;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
for (i = 0; i < palette->size; i++) {
|
||||
int r, g, b;
|
||||
unsigned int tmin, tmax;
|
||||
|
||||
|
@ -227,7 +227,7 @@ ImagingPaletteCacheUpdate(ImagingPalette palette, int r, int g, int b) {
|
|||
d[i] = (unsigned int)~0;
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
for (i = 0; i < palette->size; i++) {
|
||||
if (dmin[i] <= dmax) {
|
||||
int rd, gd, bd;
|
||||
int ri, gi, bi;
|
||||
|
|
Loading…
Reference in New Issue
Block a user