Skip to content

Commit

Permalink
Merge 8dcbf9c into 555544c
Browse files Browse the repository at this point in the history
  • Loading branch information
wiredfool committed Mar 10, 2016
2 parents 555544c + 8dcbf9c commit 5c8bdf3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
6 changes: 6 additions & 0 deletions PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,12 @@ def convert(self, mode=None, matrix=None, dither=None,
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'):
Expand Down
59 changes: 31 additions & 28 deletions _imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,53 +471,53 @@ 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) {
case IMAGING_TYPE_UINT8:
/* 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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5c8bdf3

Please sign in to comment.