mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
Allow getpixel to accept a list
This commit is contained in:
parent
091ab74429
commit
d8c3135b6b
|
@ -213,6 +213,10 @@ class TestImageGetPixel(AccessTest):
|
||||||
def test_basic(self, mode):
|
def test_basic(self, mode):
|
||||||
self.check(mode)
|
self.check(mode)
|
||||||
|
|
||||||
|
def test_list(self):
|
||||||
|
im = hopper()
|
||||||
|
assert im.getpixel([0, 0]) == (20, 20, 70)
|
||||||
|
|
||||||
@pytest.mark.parametrize("mode", ("I;16", "I;16B"))
|
@pytest.mark.parametrize("mode", ("I;16", "I;16B"))
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"expected_color", (2**15 - 1, 2**15, 2**15 + 1, 2**16 - 1)
|
"expected_color", (2**15 - 1, 2**15, 2**15 + 1, 2**16 - 1)
|
||||||
|
|
|
@ -1146,11 +1146,15 @@ static inline int
|
||||||
_getxy(PyObject *xy, int *x, int *y) {
|
_getxy(PyObject *xy, int *x, int *y) {
|
||||||
PyObject *value;
|
PyObject *value;
|
||||||
|
|
||||||
if (!PyTuple_Check(xy) || PyTuple_GET_SIZE(xy) != 2) {
|
int tuple = PyTuple_Check(xy);
|
||||||
|
if (
|
||||||
|
!(tuple && PyTuple_GET_SIZE(xy) == 2) &&
|
||||||
|
!(PyList_Check(xy) && PyList_GET_SIZE(xy) == 2)
|
||||||
|
) {
|
||||||
goto badarg;
|
goto badarg;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = PyTuple_GET_ITEM(xy, 0);
|
value = tuple ? PyTuple_GET_ITEM(xy, 0) : PyList_GET_ITEM(xy, 0);
|
||||||
if (PyLong_Check(value)) {
|
if (PyLong_Check(value)) {
|
||||||
*x = PyLong_AS_LONG(value);
|
*x = PyLong_AS_LONG(value);
|
||||||
} else if (PyFloat_Check(value)) {
|
} else if (PyFloat_Check(value)) {
|
||||||
|
@ -1164,7 +1168,7 @@ _getxy(PyObject *xy, int *x, int *y) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
value = PyTuple_GET_ITEM(xy, 1);
|
value = tuple ? PyTuple_GET_ITEM(xy, 1) : PyList_GET_ITEM(xy, 1);
|
||||||
if (PyLong_Check(value)) {
|
if (PyLong_Check(value)) {
|
||||||
*y = PyLong_AS_LONG(value);
|
*y = PyLong_AS_LONG(value);
|
||||||
} else if (PyFloat_Check(value)) {
|
} else if (PyFloat_Check(value)) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user