add effective_scale to all APIs

This commit is contained in:
homm 2014-10-12 03:29:20 +04:00
parent 091b15f9d5
commit 84b9f16bfd
5 changed files with 20 additions and 13 deletions

View File

@ -149,11 +149,12 @@ class GaussianBlur(Filter):
"""
name = "GaussianBlur"
def __init__(self, radius=2):
def __init__(self, radius=2, effective_scale=None):
self.radius = radius
self.effective_scale = effective_scale
def filter(self, image):
return image.gaussian_blur(self.radius)
return image.gaussian_blur(self.radius, self.effective_scale)
class UnsharpMask(Filter):

View File

@ -413,15 +413,18 @@ def solarize(image, threshold=128):
# --------------------------------------------------------------------
# PIL USM components, from Kevin Cazabon.
def gaussian_blur(im, radius=None):
""" PIL_usm.gblur(im, [radius])"""
def gaussian_blur(im, radius=None, effective_scale=None):
""" PIL_usm.gblur(im, [radius], [effective_scale])"""
if radius is None:
radius = 5.0
if effective_scale is None:
effective_scale = 2.6
im.load()
return im.im.gaussian_blur(radius)
return im.im.gaussian_blur(radius, effective_scale)
gblur = gaussian_blur

View File

@ -863,7 +863,8 @@ _gaussian_blur(ImagingObject* self, PyObject* args)
Imaging imOut;
float radius = 0;
if (!PyArg_ParseTuple(args, "f", &radius))
float effectiveScale = 2.6;
if (!PyArg_ParseTuple(args, "f|f", &radius, &effectiveScale))
return NULL;
imIn = self->image;
@ -871,7 +872,7 @@ _gaussian_blur(ImagingObject* self, PyObject* args)
if (!imOut)
return NULL;
if (!ImagingGaussianBlur(imIn, imOut, radius))
if (!ImagingGaussianBlur(imIn, imOut, radius, effectiveScale))
return NULL;
return PyImagingNew(imOut);

View File

@ -263,7 +263,8 @@ extern Imaging ImagingFilter(
FLOAT32 offset, FLOAT32 divisor);
extern Imaging ImagingFlipLeftRight(Imaging imOut, Imaging imIn);
extern Imaging ImagingFlipTopBottom(Imaging imOut, Imaging imIn);
extern Imaging ImagingGaussianBlur(Imaging im, Imaging imOut, float radius);
extern Imaging ImagingGaussianBlur(Imaging im, Imaging imOut, float radius,
float effectiveScale);
extern Imaging ImagingGetBand(Imaging im, int band);
extern int ImagingGetBBox(Imaging im, int bbox[4]);
typedef struct { int x, y; INT32 count; INT32 pixel; } ImagingColorItem;

View File

@ -20,7 +20,7 @@ static inline UINT8 clip(double in)
}
static Imaging
gblur(Imaging im, Imaging imOut, float radius, int channels)
gblur(Imaging im, Imaging imOut, float radius, float effectiveScale, int channels)
{
ImagingSectionCookie cookie;
@ -55,7 +55,7 @@ gblur(Imaging im, Imaging imOut, float radius, int channels)
/* Only pixels in effective radius from source pixel are accounted.
The Gaussian values outside 3 x radius is near zero. */
effectiveRadius = (int) ceil(radius * 2.57);
effectiveRadius = (int) ceil(radius * effectiveScale);
/* Window is number of pixels forming the result pixel on one axis.
It is source pixel and effective radius in both directions. */
window = effectiveRadius * 2 + 1;
@ -197,7 +197,8 @@ gblur(Imaging im, Imaging imOut, float radius, int channels)
return imOut;
}
Imaging ImagingGaussianBlur(Imaging im, Imaging imOut, float radius)
Imaging ImagingGaussianBlur(Imaging im, Imaging imOut, float radius,
float effectiveScale)
{
int channels = 0;
@ -214,7 +215,7 @@ Imaging ImagingGaussianBlur(Imaging im, Imaging imOut, float radius)
} else
return ImagingError_ModeError();
return gblur(im, imOut, radius, channels);
return gblur(im, imOut, radius, effectiveScale, channels);
}
Imaging
@ -255,7 +256,7 @@ ImagingUnsharpMask(Imaging im, Imaging imOut, float radius, int percent,
/* first, do a gaussian blur on the image, putting results in imOut
temporarily */
result = gblur(im, imOut, radius, channels);
result = gblur(im, imOut, radius, 2.6, channels);
if (!result)
return NULL;