From 759a9663af679eb84be2dda2000f02315288c114 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Thu, 28 Oct 2010 16:56:10 -0400 Subject: [PATCH] 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...) --- _composite.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/_composite.c b/_composite.c index 93c2c69..7ed9f71 100644 --- a/_composite.c +++ b/_composite.c @@ -38,8 +38,11 @@ typedef struct static Imaging imaging_python_to_c(PyObject* obj) { + PyObject* im; + Imaging image; + /* first, get the 'im' attribute */ - PyObject* im = PyObject_GetAttrString(obj, "im"); + im = PyObject_GetAttrString(obj, "im"); if (!im) return NULL; @@ -51,21 +54,34 @@ static Imaging imaging_python_to_c(PyObject* obj) return NULL; } - Imaging image = ((ImagingObject*)im)->image; + image = ((ImagingObject*)im)->image; Py_DECREF(im); return image; } static PyObject* _composite_alpha_over(PyObject* self, PyObject* args) { + /* raw input python variables */ 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)) return NULL; - Imaging imDest = imaging_python_to_c(dest); - Imaging imSrc = imaging_python_to_c(src); - Imaging imMask = imaging_python_to_c(mask); + imDest = imaging_python_to_c(dest); + imSrc = imaging_python_to_c(src); + imMask = imaging_python_to_c(mask); if (!imDest || !imSrc || !imMask) return NULL; @@ -97,14 +113,13 @@ static PyObject* _composite_alpha_over(PyObject* self, PyObject* args) } /* 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 */ - 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 */ - int mask_stride = imMask->pixelsize; + mask_stride = imMask->pixelsize; /* destination position read */ - int dx, dy, xsize, ysize; if (!PyArg_ParseTuple(pos, "iiii", &dx, &dy, &xsize, &ysize)) { 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 */ - int sx, sy; - /* handle negative dest pos */ if (dx < 0) { @@ -149,12 +162,6 @@ static PyObject* _composite_alpha_over(PyObject* self, PyObject* args) return dest; } - /* iteration variables */ - unsigned int x, y, i; - - /* temporary calculation variables */ - int tmp1, tmp2, tmp3; - for (y = 0; y < ysize; y++) { UINT8* out = (UINT8*) imDest->image[dy + y] + dx*4;