shuffled around the code a bit to make it C89 compliant
On my machine, the code now compiles with "-std=c89 -pedantic -Wall", with no warnings (except for those emitted by the Python headers, grr...)
This commit is contained in:
41
_composite.c
41
_composite.c
@@ -38,8 +38,11 @@ typedef struct
|
|||||||
|
|
||||||
static Imaging imaging_python_to_c(PyObject* obj)
|
static Imaging imaging_python_to_c(PyObject* obj)
|
||||||
{
|
{
|
||||||
|
PyObject* im;
|
||||||
|
Imaging image;
|
||||||
|
|
||||||
/* first, get the 'im' attribute */
|
/* first, get the 'im' attribute */
|
||||||
PyObject* im = PyObject_GetAttrString(obj, "im");
|
im = PyObject_GetAttrString(obj, "im");
|
||||||
if (!im)
|
if (!im)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -51,21 +54,34 @@ static Imaging imaging_python_to_c(PyObject* obj)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Imaging image = ((ImagingObject*)im)->image;
|
image = ((ImagingObject*)im)->image;
|
||||||
Py_DECREF(im);
|
Py_DECREF(im);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject* _composite_alpha_over(PyObject* self, PyObject* args)
|
static PyObject* _composite_alpha_over(PyObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
|
/* raw input python variables */
|
||||||
PyObject* dest, * src, * pos, * mask;
|
PyObject* dest, * src, * pos, * mask;
|
||||||
|
/* libImaging handles */
|
||||||
|
Imaging imDest, imSrc, imMask;
|
||||||
|
/* cached blend properties */
|
||||||
|
int src_has_alpha, mask_offset, mask_stride;
|
||||||
|
/* destination position and size */
|
||||||
|
int dx, dy, xsize, ysize;
|
||||||
|
/* source position */
|
||||||
|
int sx, sy;
|
||||||
|
/* iteration variables */
|
||||||
|
unsigned int x, y, i;
|
||||||
|
/* temporary calculation variables */
|
||||||
|
int tmp1, tmp2, tmp3;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "OOOO", &dest, &src, &pos, &mask))
|
if (!PyArg_ParseTuple(args, "OOOO", &dest, &src, &pos, &mask))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
Imaging imDest = imaging_python_to_c(dest);
|
imDest = imaging_python_to_c(dest);
|
||||||
Imaging imSrc = imaging_python_to_c(src);
|
imSrc = imaging_python_to_c(src);
|
||||||
Imaging imMask = imaging_python_to_c(mask);
|
imMask = imaging_python_to_c(mask);
|
||||||
|
|
||||||
if (!imDest || !imSrc || !imMask)
|
if (!imDest || !imSrc || !imMask)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -97,14 +113,13 @@ static PyObject* _composite_alpha_over(PyObject* self, PyObject* args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* set up flags for the src/mask type */
|
/* set up flags for the src/mask type */
|
||||||
int src_has_alpha = (imSrc->pixelsize == 4 ? 1 : 0);
|
src_has_alpha = (imSrc->pixelsize == 4 ? 1 : 0);
|
||||||
/* how far into image the first alpha byte resides */
|
/* how far into image the first alpha byte resides */
|
||||||
int mask_offset = (imMask->pixelsize == 4 ? 3 : 0);
|
mask_offset = (imMask->pixelsize == 4 ? 3 : 0);
|
||||||
/* how many bytes to skip to get to the next alpha byte */
|
/* how many bytes to skip to get to the next alpha byte */
|
||||||
int mask_stride = imMask->pixelsize;
|
mask_stride = imMask->pixelsize;
|
||||||
|
|
||||||
/* destination position read */
|
/* destination position read */
|
||||||
int dx, dy, xsize, ysize;
|
|
||||||
if (!PyArg_ParseTuple(pos, "iiii", &dx, &dy, &xsize, &ysize))
|
if (!PyArg_ParseTuple(pos, "iiii", &dx, &dy, &xsize, &ysize))
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_TypeError, "given blend destination rect is not valid");
|
PyErr_SetString(PyExc_TypeError, "given blend destination rect is not valid");
|
||||||
@@ -112,8 +127,6 @@ static PyObject* _composite_alpha_over(PyObject* self, PyObject* args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* set up the source position, size and destination position */
|
/* set up the source position, size and destination position */
|
||||||
int sx, sy;
|
|
||||||
|
|
||||||
/* handle negative dest pos */
|
/* handle negative dest pos */
|
||||||
if (dx < 0)
|
if (dx < 0)
|
||||||
{
|
{
|
||||||
@@ -149,12 +162,6 @@ static PyObject* _composite_alpha_over(PyObject* self, PyObject* args)
|
|||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* iteration variables */
|
|
||||||
unsigned int x, y, i;
|
|
||||||
|
|
||||||
/* temporary calculation variables */
|
|
||||||
int tmp1, tmp2, tmp3;
|
|
||||||
|
|
||||||
for (y = 0; y < ysize; y++)
|
for (y = 0; y < ysize; y++)
|
||||||
{
|
{
|
||||||
UINT8* out = (UINT8*) imDest->image[dy + y] + dx*4;
|
UINT8* out = (UINT8*) imDest->image[dy + y] + dx*4;
|
||||||
|
|||||||
Reference in New Issue
Block a user