mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Merge pull request #1663 from wiredfool/uninitialized-variable
Fixes uninitialized variable warning in _imaging.c:getink
This commit is contained in:
commit
b1f6cecd70
|
@ -879,6 +879,12 @@ class Image(object):
|
|||
trns_im = Image()._new(core.new(self.mode, (1, 1)))
|
||||
if self.mode == 'P':
|
||||
trns_im.putpalette(self.palette)
|
||||
if type(t) == tuple:
|
||||
try:
|
||||
t = trns_im.palette.getcolor(t)
|
||||
except:
|
||||
raise ValueError("Couldn't allocate a palette "+
|
||||
"color for transparency")
|
||||
trns_im.putpixel((0, 0), t)
|
||||
|
||||
if mode in ('L', 'RGB'):
|
||||
|
|
59
_imaging.c
59
_imaging.c
|
@ -471,29 +471,36 @@ 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 g=0, b=0, a=0;
|
||||
double f=0;
|
||||
/* Windows 64 bit longs are 32 bits, and 0xFFFFFFFF (white) is a
|
||||
python long (not int) that raises an overflow error when trying
|
||||
to return it into a 32 bit C long
|
||||
*/
|
||||
PY_LONG_LONG r = 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) {
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
if (PyLong_Check(color)) {
|
||||
r = (int) PyLong_AsLong(color);
|
||||
if (PyLong_Check(color)) {
|
||||
r = PyLong_AsLongLong(color);
|
||||
#else
|
||||
if (PyInt_Check(color) || PyLong_Check(color)) {
|
||||
if (PyInt_Check(color))
|
||||
r = PyInt_AS_LONG(color);
|
||||
else
|
||||
r = (int) PyLong_AsLong(color);
|
||||
if (PyInt_Check(color) || PyLong_Check(color)) {
|
||||
if (PyInt_Check(color))
|
||||
r = PyInt_AS_LONG(color);
|
||||
else
|
||||
r = PyLong_AsLongLong(color);
|
||||
#endif
|
||||
}
|
||||
if (r == -1 && PyErr_Occurred())
|
||||
rIsInt = 0;
|
||||
rIsInt = 1;
|
||||
}
|
||||
if (r == -1 && PyErr_Occurred()) {
|
||||
rIsInt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
switch (im->type) {
|
||||
|
@ -501,23 +508,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);
|
||||
|
@ -590,13 +590,14 @@ _fill(PyObject* self, PyObject* args)
|
|||
if (!im)
|
||||
return NULL;
|
||||
|
||||
buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0;
|
||||
if (color) {
|
||||
if (!getink(color, im, buffer)) {
|
||||
ImagingDelete(im);
|
||||
return NULL;
|
||||
}
|
||||
} else
|
||||
buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0;
|
||||
}
|
||||
|
||||
|
||||
(void) ImagingFill(im, buffer);
|
||||
|
||||
|
@ -1342,6 +1343,8 @@ _putdata(ImagingObject* self, PyObject* args)
|
|||
INT32 inkint;
|
||||
} u;
|
||||
|
||||
u.inkint = 0;
|
||||
|
||||
op = PySequence_Fast_GET_ITEM(seq, i);
|
||||
if (!op || !getink(op, image, u.ink)) {
|
||||
Py_DECREF(seq);
|
||||
|
|
Loading…
Reference in New Issue
Block a user