mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Set undefined palette values to black
This commit is contained in:
parent
b945154097
commit
7bfc6f16dc
|
@ -84,3 +84,9 @@ def test_rgba_palette(mode, palette):
|
|||
im.putpalette(palette, mode)
|
||||
assert im.getpalette() == [1, 2, 3]
|
||||
assert im.palette.colors == {(1, 2, 3, 4): 0}
|
||||
|
||||
|
||||
def test_undefined_palette_index():
|
||||
im = Image.new("P", (1, 1), 3)
|
||||
im.putpalette((1, 2, 3))
|
||||
assert im.convert("RGB").getpixel((0, 0)) == (0, 0, 0)
|
||||
|
|
|
@ -1676,11 +1676,12 @@ _quantize(ImagingObject *self, PyObject *args) {
|
|||
static PyObject *
|
||||
_putpalette(ImagingObject *self, PyObject *args) {
|
||||
ImagingShuffler unpack;
|
||||
int bits;
|
||||
int i, bits;
|
||||
|
||||
char *rawmode, *palette_mode;
|
||||
UINT8 *palette;
|
||||
Py_ssize_t palettesize;
|
||||
ImagingPalette im_palette;
|
||||
if (!PyArg_ParseTuple(args, "sy#", &rawmode, &palette, &palettesize)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1707,10 +1708,16 @@ _putpalette(ImagingObject *self, PyObject *args) {
|
|||
|
||||
strcpy(self->image->mode, strlen(self->image->mode) == 2 ? "PA" : "P");
|
||||
|
||||
self->image->palette = ImagingPaletteNew(palette_mode);
|
||||
im_palette = ImagingPaletteNew(palette_mode);
|
||||
self->image->palette = im_palette;
|
||||
|
||||
self->image->palette->size = palettesize * 8 / bits;
|
||||
unpack(self->image->palette->palette, palette, self->image->palette->size);
|
||||
im_palette->size = palettesize * 8 / bits;
|
||||
unpack(im_palette->palette, palette, im_palette->size);
|
||||
for (i=im_palette->size; i<256; i++) {
|
||||
im_palette->palette[i * 4] = 0;
|
||||
im_palette->palette[i * 4 + 1] = 0;
|
||||
im_palette->palette[i * 4 + 2] = 0;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
|
Loading…
Reference in New Issue
Block a user