mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-05 05:33:10 +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 = im.quantize(method=method)
|
||||||
converted_px = converted.load()
|
converted_px = converted.load()
|
||||||
assert converted_px[0, 0] == converted.palette.colors[color]
|
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;
|
dmax = (unsigned int)~0;
|
||||||
|
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < palette->size; i++) {
|
||||||
int r, g, b;
|
int r, g, b;
|
||||||
unsigned int tmin, tmax;
|
unsigned int tmin, tmax;
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ ImagingPaletteCacheUpdate(ImagingPalette palette, int r, int g, int b) {
|
||||||
d[i] = (unsigned int)~0;
|
d[i] = (unsigned int)~0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < palette->size; i++) {
|
||||||
if (dmin[i] <= dmax) {
|
if (dmin[i] <= dmax) {
|
||||||
int rd, gd, bd;
|
int rd, gd, bd;
|
||||||
int ri, gi, bi;
|
int ri, gi, bi;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user