FIX: Handle long values in _imaging getink

This gets the putdata test case to run correctly under 2.6/2.7. It fixes an
issue where the value 0xFFFFFFFF (which is long in old Python) isn't
recognized and putdata tries to parse it as a tuple.

The original fix comes from Christoph Gohlke. It was adapted to work in
both 2.* and 3.*.
This commit is contained in:
Brian Crowell 2012-10-15 15:03:09 -05:00 committed by Brian Crowell
parent 197885164b
commit c8ce29c239

View File

@ -510,8 +510,17 @@ 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 (PyInt_Check(color)) { #if PY_VERSION_HEX >= 0x03000000
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); 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);
@ -1205,6 +1214,7 @@ _putdata(ImagingObject* self, PyObject* args)
PyObject* data; PyObject* data;
double scale = 1.0; double scale = 1.0;
double offset = 0.0; double offset = 0.0;
if (!PyArg_ParseTuple(args, "O|dd", &data, &scale, &offset)) if (!PyArg_ParseTuple(args, "O|dd", &data, &scale, &offset))
return NULL; return NULL;