mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Removed duplicate calls to PyTuple_GET_SIZE
This commit is contained in:
parent
9e6ae98362
commit
01cdfb6b27
|
@ -491,7 +491,7 @@ getink(PyObject *color, Imaging im, char *ink) {
|
|||
int g = 0, b = 0, a = 0;
|
||||
double f = 0;
|
||||
/* Windows 64 bit longs are 32 bits, and 0xFFFFFFFF (white) is a
|
||||
python long (not int) that raises an overflow error when trying
|
||||
Python long (not int) that raises an overflow error when trying
|
||||
to return it into a 32 bit C long
|
||||
*/
|
||||
PY_LONG_LONG r = 0;
|
||||
|
@ -502,8 +502,12 @@ getink(PyObject *color, Imaging im, char *ink) {
|
|||
be cast to either UINT8 or INT32 */
|
||||
|
||||
int rIsInt = 0;
|
||||
if (PyTuple_Check(color) && PyTuple_GET_SIZE(color) == 1) {
|
||||
color = PyTuple_GetItem(color, 0);
|
||||
int tupleSize;
|
||||
if (PyTuple_Check(color)) {
|
||||
tupleSize = PyTuple_GET_SIZE(color);
|
||||
if (tupleSize == 1) {
|
||||
color = PyTuple_GetItem(color, 0);
|
||||
}
|
||||
}
|
||||
if (im->type == IMAGING_TYPE_UINT8 || im->type == IMAGING_TYPE_INT32 ||
|
||||
im->type == IMAGING_TYPE_SPECIAL) {
|
||||
|
@ -531,7 +535,7 @@ getink(PyObject *color, Imaging im, char *ink) {
|
|||
if (im->bands == 1) {
|
||||
/* unsigned integer, single layer */
|
||||
if (rIsInt != 1) {
|
||||
if (PyTuple_GET_SIZE(color) != 1) {
|
||||
if (tupleSize != 1) {
|
||||
PyErr_SetString(PyExc_TypeError, "color must be int or single-element tuple");
|
||||
return NULL;
|
||||
} else if (!PyArg_ParseTuple(color, "L", &r)) {
|
||||
|
@ -541,7 +545,6 @@ getink(PyObject *color, Imaging im, char *ink) {
|
|||
ink[0] = (char)CLIP8(r);
|
||||
ink[1] = ink[2] = ink[3] = 0;
|
||||
} else {
|
||||
a = 255;
|
||||
if (rIsInt) {
|
||||
/* compatibility: ABGR */
|
||||
a = (UINT8)(r >> 24);
|
||||
|
@ -549,7 +552,7 @@ getink(PyObject *color, Imaging im, char *ink) {
|
|||
g = (UINT8)(r >> 8);
|
||||
r = (UINT8)r;
|
||||
} else {
|
||||
int tupleSize = PyTuple_GET_SIZE(color);
|
||||
a = 255;
|
||||
if (im->bands == 2) {
|
||||
if (tupleSize != 1 && tupleSize != 2) {
|
||||
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one or two elements");
|
||||
|
|
Loading…
Reference in New Issue
Block a user