support for multiple passes with only two transposes

This commit is contained in:
homm 2014-10-19 00:14:26 +04:00
parent d91d7b9826
commit 516bd90cf7
3 changed files with 21 additions and 7 deletions

View File

@ -1810,7 +1810,8 @@ _box_blur(ImagingObject* self, PyObject* args)
Imaging imOut;
float radius;
if (!PyArg_ParseTuple(args, "f", &radius))
int n = 1;
if (!PyArg_ParseTuple(args, "f|i", &radius, &n))
return NULL;
imIn = self->image;
@ -1818,7 +1819,7 @@ _box_blur(ImagingObject* self, PyObject* args)
if (!imOut)
return NULL;
if (!ImagingBoxBlur(imIn, imOut, radius))
if (!ImagingBoxBlur(imIn, imOut, radius, n))
return NULL;
return PyImagingNew(imOut);

View File

@ -195,7 +195,7 @@ HorizontalBoxBlur(Imaging im, Imaging imOut, float floatRadius)
for (y = 0; y < im->ysize; y++) {
LineBoxBlur8(
im->image8[y],
(UINT8 *)lineOut,
(UINT8 *) lineOut,
im->xsize - 1,
radius, edgeA, edgeB,
ww, fw
@ -268,8 +268,16 @@ TransposeImage(Imaging im, Imaging imOut)
Imaging
ImagingBoxBlur(Imaging im, Imaging imOut, float radius)
ImagingBoxBlur(Imaging im, Imaging imOut, float radius, int n)
{
int i;
if (n < 1) {
return ImagingError_ValueError(
"number of passes must be greater than zero"
);
}
if (strcmp(im->mode, imOut->mode) ||
im->type != imOut->type ||
im->bands != imOut->bands ||
@ -294,14 +302,19 @@ ImagingBoxBlur(Imaging im, Imaging imOut, float radius)
return NULL;
/* Apply one-dimensional blur.
HorizontalBoxBlur32 transposes image at same time. */
HorizontalBoxBlur transposes image at same time. */
HorizontalBoxBlur(im, imOut, radius);
for (i = 1; i < n; i ++) {
HorizontalBoxBlur(imOut, imOut, radius);
}
TransposeImage(imOut, temp);
/* Blur transposed result from previout step in same direction.
Reseult will be transposed again. We'll get original image
blurred in both directions. */
for (i = 0; i < n; i ++) {
HorizontalBoxBlur(temp, temp, radius);
}
TransposeImage(temp, imOut);
ImagingDelete(temp);

View File

@ -308,7 +308,7 @@ extern Imaging ImagingTransform(
int fill);
extern Imaging ImagingUnsharpMask(
Imaging im, Imaging imOut, float radius, int percent, int threshold);
extern Imaging ImagingBoxBlur(Imaging im, Imaging imOut, float radius);
extern Imaging ImagingBoxBlur(Imaging im, Imaging imOut, float radius, int n);
extern Imaging ImagingCopy2(Imaging imOut, Imaging imIn);
extern Imaging ImagingConvert2(Imaging imOut, Imaging imIn);