This commit is contained in:
Marcus Brinkmann 2016-03-09 07:03:00 +00:00
commit 1ef813367b

View File

@ -471,29 +471,29 @@ getpixel(Imaging im, ImagingAccess access, int x, int y)
static char* static char*
getink(PyObject* color, Imaging im, char* ink) getink(PyObject* color, Imaging im, char* ink)
{ {
int r, g, b, a; int r = -1;
int g, b, a;
double f; double f;
/* fill ink buffer (four bytes) with something that can /* fill ink buffer (four bytes) with something that can
be cast to either UINT8 or INT32 */ be cast to either UINT8 or INT32 */
int rIsInt = 1; int rIsInt = 0;
if (im->type == IMAGING_TYPE_UINT8 || if (im->type == IMAGING_TYPE_UINT8 ||
im->type == IMAGING_TYPE_INT32 || im->type == IMAGING_TYPE_INT32 ||
im->type == IMAGING_TYPE_SPECIAL) { im->type == IMAGING_TYPE_SPECIAL) {
#if PY_VERSION_HEX >= 0x03000000
if (PyLong_Check(color)) { if (PyLong_Check(color)) {
r = (int) PyLong_AsLong(color); r = (int) PyLong_AsLong(color);
#else if (!(r == -1 && PyErr_Occurred()))
if (PyInt_Check(color) || PyLong_Check(color)) { rIsInt = 1;
if (PyInt_Check(color))
r = PyInt_AS_LONG(color);
else
r = (int) PyLong_AsLong(color);
#endif
} }
if (r == -1 && PyErr_Occurred()) #if PY_VERSION_HEX < 0x03000000
rIsInt = 0; else if (PyInt_Check(color)) {
r = PyInt_AS_LONG(color);
if (!(r == -1 && PyErr_Occurred()))
rIsInt = 1;
}
#endif
} }
switch (im->type) { switch (im->type) {
@ -507,17 +507,7 @@ getink(PyObject* color, Imaging im, char* ink)
ink[1] = ink[2] = ink[3] = 0; ink[1] = ink[2] = ink[3] = 0;
} else { } else {
a = 255; a = 255;
#if PY_VERSION_HEX >= 0x03000000 if (rIsInt) {
if (PyLong_Check(color)) {
r = (int) PyLong_AsLong(color);
#else
if (PyInt_Check(color) || PyLong_Check(color)) {
if (PyInt_Check(color))
r = PyInt_AS_LONG(color);
else
r = (int) PyLong_AsLong(color);
#endif
/* compatibility: ABGR */ /* compatibility: ABGR */
a = (UINT8) (r >> 24); a = (UINT8) (r >> 24);
b = (UINT8) (r >> 16); b = (UINT8) (r >> 16);
@ -3596,4 +3586,3 @@ init_imaging(void)
setup_module(m); setup_module(m);
} }
#endif #endif