added tests to cover save of four different png transparencies

This commit is contained in:
David Schmidt 2013-03-26 11:24:07 +01:00
parent 638889cae0
commit 5303f0ea66
4 changed files with 39 additions and 11 deletions

BIN
Tests/images/l_trns.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -128,6 +128,34 @@ def test_load_transparent_p():
# image has 124 uniqe qlpha values
assert_equal(len(im.split()[3].getcolors()), 124)
def test_save_p_transparent_palette():
in_file = "Tests/images/pil123p.png"
im = Image.open(in_file)
file = tempfile("temp.png")
assert_no_exception(lambda: im.save(file))
def test_save_p_single_transparency():
in_file = "Tests/images/p_trns_single.png"
im = Image.open(in_file)
file = tempfile("temp.png")
assert_no_exception(lambda: im.save(file))
def test_save_l_transparency():
in_file = "Tests/images/l_trns.png"
im = Image.open(in_file)
file = tempfile("temp.png")
assert_no_exception(lambda: im.save(file))
def test_save_rgb_single_transparency():
in_file = "Tests/images/caption_6_33_22.png"
im = Image.open(in_file)
file = tempfile("temp.png")
assert_no_exception(lambda: im.save(file))
def test_load_verify():
# Check open/load/verify exception (@PIL150)

View File

@ -742,16 +742,16 @@ _convert(ImagingObject* self, PyObject* args)
ImagingObject *paletteimage = NULL;
if (!PyArg_ParseTuple(args, "s|iO", &mode, &dither, &paletteimage))
return NULL;
return NULL;
if (paletteimage != NULL) {
if (!PyImaging_Check(paletteimage)) {
PyObject_Print((PyObject *)paletteimage, stderr, 0);
PyErr_SetString(PyExc_ValueError, "palette argument must be image with mode 'P'");
return NULL;
PyObject_Print((PyObject *)paletteimage, stderr, 0);
PyErr_SetString(PyExc_ValueError, "palette argument must be image with mode 'P'");
return NULL;
}
if (paletteimage->image->palette == NULL) {
PyErr_SetString(PyExc_ValueError, "null palette");
return NULL;
PyErr_SetString(PyExc_ValueError, "null palette");
return NULL;
}
}
@ -1431,16 +1431,16 @@ _putpalettealpha(ImagingObject* self, PyObject* args)
int index;
int alpha = 0;
if (!PyArg_ParseTuple(args, "i|i", &index, &alpha))
return NULL;
return NULL;
if (!self->image->palette) {
PyErr_SetString(PyExc_ValueError, no_palette);
return NULL;
PyErr_SetString(PyExc_ValueError, no_palette);
return NULL;
}
if (index < 0 || index >= 256) {
PyErr_SetString(PyExc_ValueError, outside_palette);
return NULL;
PyErr_SetString(PyExc_ValueError, outside_palette);
return NULL;
}
strcpy(self->image->palette->mode, "RGBA");