fix uninitalized variable warning, fix logic

This commit is contained in:
wiredfool 2016-01-14 08:57:36 -08:00
parent 66c99b9d20
commit 5ff9f24fcc

View File

@ -471,13 +471,13 @@ getpixel(Imaging im, ImagingAccess access, int x, int y)
static char*
getink(PyObject* color, Imaging im, char* ink)
{
int r, g, b, a;
double f;
int r=0, g=0, b=0, a=0;
double f=0;
/* fill ink buffer (four bytes) with something that can
be cast to either UINT8 or INT32 */
int rIsInt = 1;
int rIsInt = 0;
if (im->type == IMAGING_TYPE_UINT8 ||
im->type == IMAGING_TYPE_INT32 ||
im->type == IMAGING_TYPE_SPECIAL) {
@ -491,9 +491,11 @@ getink(PyObject* color, Imaging im, char* ink)
else
r = (int) PyLong_AsLong(color);
#endif
rIsInt = 1;
}
if (r == -1 && PyErr_Occurred())
if (r == -1 && PyErr_Occurred()) {
rIsInt = 0;
}
}
switch (im->type) {
@ -501,23 +503,16 @@ getink(PyObject* color, Imaging im, char* ink)
/* unsigned integer */
if (im->bands == 1) {
/* unsigned integer, single layer */
if (rIsInt != 1)
return NULL;
if (rIsInt != 1) {
if (!PyArg_ParseTuple(color, "i", &r)) {
return NULL;
}
}
ink[0] = CLIP(r);
ink[1] = ink[2] = ink[3] = 0;
} else {
a = 255;
#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
if (rIsInt) {
/* compatibility: ABGR */
a = (UINT8) (r >> 24);
b = (UINT8) (r >> 16);