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* static char*
getink(PyObject* color, Imaging im, char* ink) getink(PyObject* color, Imaging im, char* ink)
{ {
int r, g, b, a; int r=0, g=0, b=0, a=0;
double f; double f=0;
/* 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) {
@ -491,33 +491,28 @@ getink(PyObject* color, Imaging im, char* ink)
else else
r = (int) PyLong_AsLong(color); r = (int) PyLong_AsLong(color);
#endif #endif
rIsInt = 1;
} }
if (r == -1 && PyErr_Occurred()) if (r == -1 && PyErr_Occurred()) {
rIsInt = 0; rIsInt = 0;
} }
}
switch (im->type) { switch (im->type) {
case IMAGING_TYPE_UINT8: case IMAGING_TYPE_UINT8:
/* unsigned integer */ /* unsigned integer */
if (im->bands == 1) { if (im->bands == 1) {
/* unsigned integer, single layer */ /* unsigned integer, single layer */
if (rIsInt != 1) if (rIsInt != 1) {
if (!PyArg_ParseTuple(color, "i", &r)) {
return NULL; return NULL;
}
}
ink[0] = CLIP(r); ink[0] = CLIP(r);
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);