mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-01 02:13:11 +03:00
versions, feature checking
This commit is contained in:
parent
0472b91d16
commit
014ca1497d
|
@ -8,6 +8,13 @@ except:
|
||||||
skip('webp support not installed')
|
skip('webp support not installed')
|
||||||
|
|
||||||
|
|
||||||
|
def test_version():
|
||||||
|
assert_no_exception(lambda: _webp.WebPDecoderVersion())
|
||||||
|
|
||||||
|
def test_good_alpha():
|
||||||
|
assert_equal(_webp.WebPDecoderBuggyAlpha(), 0)
|
||||||
|
|
||||||
|
|
||||||
def test_read_rgb():
|
def test_read_rgb():
|
||||||
|
|
||||||
file_path = "Images/lena.webp"
|
file_path = "Images/lena.webp"
|
||||||
|
@ -24,23 +31,6 @@ def test_read_rgb():
|
||||||
assert_image_equal(image, target)
|
assert_image_equal(image, target)
|
||||||
|
|
||||||
|
|
||||||
def test_read_rgba():
|
|
||||||
# Generated with `cwebp transparent.png -o transparent.webp`
|
|
||||||
file_path = "Images/transparent.webp"
|
|
||||||
image = Image.open(file_path)
|
|
||||||
|
|
||||||
assert_equal(image.mode, "RGBA")
|
|
||||||
assert_equal(image.size, (200, 150))
|
|
||||||
assert_equal(image.format, "WEBP")
|
|
||||||
assert_no_exception(lambda: image.load())
|
|
||||||
assert_no_exception(lambda: image.getdata())
|
|
||||||
|
|
||||||
orig_bytes = image.tobytes()
|
|
||||||
|
|
||||||
target = Image.open('Images/transparent.png')
|
|
||||||
assert_image_similar(image, target, 20.0)
|
|
||||||
|
|
||||||
|
|
||||||
def test_write_rgb():
|
def test_write_rgb():
|
||||||
"""
|
"""
|
||||||
Can we write a RGB mode file to webp without error. Does it have the bits we
|
Can we write a RGB mode file to webp without error. Does it have the bits we
|
||||||
|
@ -98,3 +88,23 @@ def test_write_rgba():
|
||||||
assert_no_exception(image.getdata)
|
assert_no_exception(image.getdata)
|
||||||
|
|
||||||
assert_image_similar(image, pil_image, 1.0)
|
assert_image_similar(image, pil_image, 1.0)
|
||||||
|
|
||||||
|
if _webp.WebPDecoderBuggyAlpha():
|
||||||
|
skip("Buggy early version of webp installed, not testing transparency")
|
||||||
|
|
||||||
|
def test_read_rgba():
|
||||||
|
# Generated with `cwebp transparent.png -o transparent.webp`
|
||||||
|
file_path = "Images/transparent.webp"
|
||||||
|
image = Image.open(file_path)
|
||||||
|
|
||||||
|
assert_equal(image.mode, "RGBA")
|
||||||
|
assert_equal(image.size, (200, 150))
|
||||||
|
assert_equal(image.format, "WEBP")
|
||||||
|
assert_no_exception(lambda: image.load())
|
||||||
|
assert_no_exception(lambda: image.getdata())
|
||||||
|
|
||||||
|
orig_bytes = image.tobytes()
|
||||||
|
|
||||||
|
target = Image.open('Images/transparent.png')
|
||||||
|
assert_image_similar(image, target, 20.0)
|
||||||
|
|
||||||
|
|
42
_webp.c
42
_webp.c
|
@ -148,34 +148,34 @@ PyObject* WebPDecode_wrapper(PyObject* self, PyObject* args)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.output.colorspace < MODE_YUV) {
|
if (config.output.colorspace < MODE_YUV) {
|
||||||
bytes = PyBytes_FromStringAndSize((char *)config.output.u.RGBA.rgba, config.output.u.RGBA.size);
|
bytes = PyBytes_FromStringAndSize((char *)config.output.u.RGBA.rgba,
|
||||||
|
config.output.u.RGBA.size);
|
||||||
} else {
|
} else {
|
||||||
// Skipping YUV for now.
|
// Skipping YUV for now. Need Test Images.
|
||||||
bytes = PyBytes_FromStringAndSize((char *)config.output.u.YUVA.y, config.output.u.YUVA.y_size);
|
// UNDONE -- unclear if we'll ever get here if we set mode_rgb*
|
||||||
}
|
bytes = PyBytes_FromStringAndSize((char *)config.output.u.YUVA.y,
|
||||||
switch(config.output.colorspace) {
|
config.output.u.YUVA.y_size);
|
||||||
// UNDONE, alternate orderings
|
|
||||||
case MODE_RGB:
|
|
||||||
mode = "RGB";
|
|
||||||
break;
|
|
||||||
case MODE_RGBA:
|
|
||||||
mode = "RGBA";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
mode = "ERR";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
height = config.output.height;
|
ret = Py_BuildValue("SiiS", bytes, config.output.width,
|
||||||
width = config.output.width;
|
config.output.height, PyBytes_FromString(mode));
|
||||||
|
|
||||||
|
|
||||||
ret = Py_BuildValue("SiiS", bytes, width, height, PyBytes_FromString(mode));
|
|
||||||
WebPFreeDecBuffer(&config.output);
|
WebPFreeDecBuffer(&config.output);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the decoder's version number, packed in hexadecimal using 8bits for
|
||||||
|
// each of major/minor/revision. E.g: v2.5.7 is 0x020507.
|
||||||
|
PyObject* WebPDecoderVersion_wrapper(PyObject* self, PyObject* args){
|
||||||
|
return Py_BuildValue("i", WebPGetDecoderVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The version of webp that ships with (0.1.2) Ubuntu 12.04 doesn't handle alpha well.
|
||||||
|
* Files that are valid with 0.3 are reported as being invalid.
|
||||||
|
*/
|
||||||
|
PyObject* WebPDecoderBuggyAlpha_wrapper(PyObject* self, PyObject* args){
|
||||||
|
return Py_BuildValue("i", WebPGetDecoderVersion()==0x0102);
|
||||||
|
}
|
||||||
|
|
||||||
static PyMethodDef webpMethods[] =
|
static PyMethodDef webpMethods[] =
|
||||||
{
|
{
|
||||||
|
@ -183,6 +183,8 @@ static PyMethodDef webpMethods[] =
|
||||||
{"WebPEncodeRGB", WebPEncodeRGB_wrapper, METH_VARARGS, "WebPEncodeRGB"},
|
{"WebPEncodeRGB", WebPEncodeRGB_wrapper, METH_VARARGS, "WebPEncodeRGB"},
|
||||||
{"WebPEncodeRGBA", WebPEncodeRGBA_wrapper, METH_VARARGS, "WebPEncodeRGBA"},
|
{"WebPEncodeRGBA", WebPEncodeRGBA_wrapper, METH_VARARGS, "WebPEncodeRGBA"},
|
||||||
{"WebPDecode", WebPDecode_wrapper, METH_VARARGS, "WebPDecode"},
|
{"WebPDecode", WebPDecode_wrapper, METH_VARARGS, "WebPDecode"},
|
||||||
|
{"WebPDecoderVersion", WebPDecoderVersion_wrapper, METH_VARARGS, "WebPVersion"},
|
||||||
|
{"WebPDecoderBuggyAlpha", WebPDecoderBuggyAlpha_wrapper, METH_VARARGS, "WebPDecoderBuggyAlpha"},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user