mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +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):
|
||||
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(
|
||||
"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) {
|
||||
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;
|
||||
}
|
||||
|
||||
value = PyTuple_GET_ITEM(xy, 0);
|
||||
value = tuple ? PyTuple_GET_ITEM(xy, 0) : PyList_GET_ITEM(xy, 0);
|
||||
if (PyLong_Check(value)) {
|
||||
*x = PyLong_AS_LONG(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)) {
|
||||
*y = PyLong_AS_LONG(value);
|
||||
} else if (PyFloat_Check(value)) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user