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

View File

@ -268,8 +268,16 @@ TransposeImage(Imaging im, Imaging imOut)
Imaging 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) || if (strcmp(im->mode, imOut->mode) ||
im->type != imOut->type || im->type != imOut->type ||
im->bands != imOut->bands || im->bands != imOut->bands ||
@ -294,14 +302,19 @@ ImagingBoxBlur(Imaging im, Imaging imOut, float radius)
return NULL; return NULL;
/* Apply one-dimensional blur. /* Apply one-dimensional blur.
HorizontalBoxBlur32 transposes image at same time. */ HorizontalBoxBlur transposes image at same time. */
HorizontalBoxBlur(im, imOut, radius); HorizontalBoxBlur(im, imOut, radius);
for (i = 1; i < n; i ++) {
HorizontalBoxBlur(imOut, imOut, radius);
}
TransposeImage(imOut, temp); TransposeImage(imOut, temp);
/* Blur transposed result from previout step in same direction. /* Blur transposed result from previout step in same direction.
Reseult will be transposed again. We'll get original image Reseult will be transposed again. We'll get original image
blurred in both directions. */ blurred in both directions. */
for (i = 0; i < n; i ++) {
HorizontalBoxBlur(temp, temp, radius); HorizontalBoxBlur(temp, temp, radius);
}
TransposeImage(temp, imOut); TransposeImage(temp, imOut);
ImagingDelete(temp); ImagingDelete(temp);

View File

@ -308,7 +308,7 @@ extern Imaging ImagingTransform(
int fill); int fill);
extern Imaging ImagingUnsharpMask( extern Imaging ImagingUnsharpMask(
Imaging im, Imaging imOut, float radius, int percent, int threshold); 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 ImagingCopy2(Imaging imOut, Imaging imIn);
extern Imaging ImagingConvert2(Imaging imOut, Imaging imIn); extern Imaging ImagingConvert2(Imaging imOut, Imaging imIn);