mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-13 05:06:49 +03:00
support for multiple passes with only two transposes
This commit is contained in:
parent
d91d7b9826
commit
516bd90cf7
|
@ -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);
|
||||||
|
|
|
@ -195,7 +195,7 @@ HorizontalBoxBlur(Imaging im, Imaging imOut, float floatRadius)
|
||||||
for (y = 0; y < im->ysize; y++) {
|
for (y = 0; y < im->ysize; y++) {
|
||||||
LineBoxBlur8(
|
LineBoxBlur8(
|
||||||
im->image8[y],
|
im->image8[y],
|
||||||
(UINT8 *)lineOut,
|
(UINT8 *) lineOut,
|
||||||
im->xsize - 1,
|
im->xsize - 1,
|
||||||
radius, edgeA, edgeB,
|
radius, edgeA, edgeB,
|
||||||
ww, fw
|
ww, fw
|
||||||
|
@ -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. */
|
||||||
HorizontalBoxBlur(temp, temp, radius);
|
for (i = 0; i < n; i ++) {
|
||||||
|
HorizontalBoxBlur(temp, temp, radius);
|
||||||
|
}
|
||||||
TransposeImage(temp, imOut);
|
TransposeImage(temp, imOut);
|
||||||
|
|
||||||
ImagingDelete(temp);
|
ImagingDelete(temp);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user