mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-30 01:43:17 +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;
|
int g = 0, b = 0, a = 0;
|
||||||
double f = 0;
|
double f = 0;
|
||||||
/* Windows 64 bit longs are 32 bits, and 0xFFFFFFFF (white) is a
|
/* 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
|
to return it into a 32 bit C long
|
||||||
*/
|
*/
|
||||||
PY_LONG_LONG r = 0;
|
PY_LONG_LONG r = 0;
|
||||||
|
@ -502,8 +502,12 @@ getink(PyObject *color, Imaging im, char *ink) {
|
||||||
be cast to either UINT8 or INT32 */
|
be cast to either UINT8 or INT32 */
|
||||||
|
|
||||||
int rIsInt = 0;
|
int rIsInt = 0;
|
||||||
if (PyTuple_Check(color) && PyTuple_GET_SIZE(color) == 1) {
|
int tupleSize;
|
||||||
color = PyTuple_GetItem(color, 0);
|
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 ||
|
if (im->type == IMAGING_TYPE_UINT8 || im->type == IMAGING_TYPE_INT32 ||
|
||||||
im->type == IMAGING_TYPE_SPECIAL) {
|
im->type == IMAGING_TYPE_SPECIAL) {
|
||||||
|
@ -531,7 +535,7 @@ getink(PyObject *color, Imaging im, char *ink) {
|
||||||
if (im->bands == 1) {
|
if (im->bands == 1) {
|
||||||
/* unsigned integer, single layer */
|
/* unsigned integer, single layer */
|
||||||
if (rIsInt != 1) {
|
if (rIsInt != 1) {
|
||||||
if (PyTuple_GET_SIZE(color) != 1) {
|
if (tupleSize != 1) {
|
||||||
PyErr_SetString(PyExc_TypeError, "color must be int or single-element tuple");
|
PyErr_SetString(PyExc_TypeError, "color must be int or single-element tuple");
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (!PyArg_ParseTuple(color, "L", &r)) {
|
} else if (!PyArg_ParseTuple(color, "L", &r)) {
|
||||||
|
@ -541,7 +545,6 @@ getink(PyObject *color, Imaging im, char *ink) {
|
||||||
ink[0] = (char)CLIP8(r);
|
ink[0] = (char)CLIP8(r);
|
||||||
ink[1] = ink[2] = ink[3] = 0;
|
ink[1] = ink[2] = ink[3] = 0;
|
||||||
} else {
|
} else {
|
||||||
a = 255;
|
|
||||||
if (rIsInt) {
|
if (rIsInt) {
|
||||||
/* compatibility: ABGR */
|
/* compatibility: ABGR */
|
||||||
a = (UINT8)(r >> 24);
|
a = (UINT8)(r >> 24);
|
||||||
|
@ -549,7 +552,7 @@ getink(PyObject *color, Imaging im, char *ink) {
|
||||||
g = (UINT8)(r >> 8);
|
g = (UINT8)(r >> 8);
|
||||||
r = (UINT8)r;
|
r = (UINT8)r;
|
||||||
} else {
|
} else {
|
||||||
int tupleSize = PyTuple_GET_SIZE(color);
|
a = 255;
|
||||||
if (im->bands == 2) {
|
if (im->bands == 2) {
|
||||||
if (tupleSize != 1 && tupleSize != 2) {
|
if (tupleSize != 1 && tupleSize != 2) {
|
||||||
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one or two elements");
|
PyErr_SetString(PyExc_TypeError, "color must be int, or tuple of one or two elements");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user