mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
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:
parent
197885164b
commit
c8ce29c239
16
_imaging.c
16
_imaging.c
|
@ -510,8 +510,17 @@ getink(PyObject* color, Imaging im, char* ink)
|
|||
ink[1] = ink[2] = ink[3] = 0;
|
||||
} else {
|
||||
a = 255;
|
||||
if (PyInt_Check(color)) {
|
||||
r = PyInt_AS_LONG(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);
|
||||
else
|
||||
r = (int) PyLong_AsLong(color);
|
||||
#endif
|
||||
|
||||
/* compatibility: ABGR */
|
||||
a = (UINT8) (r >> 24);
|
||||
b = (UINT8) (r >> 16);
|
||||
|
@ -1205,8 +1214,9 @@ _putdata(ImagingObject* self, PyObject* args)
|
|||
PyObject* data;
|
||||
double scale = 1.0;
|
||||
double offset = 0.0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O|dd", &data, &scale, &offset))
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
if (!PySequence_Check(data)) {
|
||||
PyErr_SetString(PyExc_TypeError, must_be_sequence);
|
||||
|
|
Loading…
Reference in New Issue
Block a user