Expose optional precision parameter of blur operation (#4168)

This commit is contained in:
Marcos Casagrande
2024-07-20 14:53:23 +02:00
committed by GitHub
parent 10c6f474d9
commit 67a4592756
10 changed files with 103 additions and 15 deletions

View File

@@ -144,7 +144,7 @@ namespace sharp {
/*
* Gaussian blur. Use sigma of -1.0 for fast blur.
*/
VImage Blur(VImage image, double const sigma) {
VImage Blur(VImage image, double const sigma, VipsPrecision precision) {
if (sigma == -1.0) {
// Fast, mild blur - averages neighbouring pixels
VImage blur = VImage::new_matrixv(3, 3,
@@ -155,7 +155,8 @@ namespace sharp {
return image.conv(blur);
} else {
// Slower, accurate Gaussian blur
return StaySequential(image).gaussblur(sigma);
return StaySequential(image).gaussblur(sigma, VImage::option()
->set("precision", precision));
}
}

View File

@@ -47,7 +47,7 @@ namespace sharp {
/*
* Gaussian blur. Use sigma of -1.0 for fast blur.
*/
VImage Blur(VImage image, double const sigma);
VImage Blur(VImage image, double const sigma, VipsPrecision precision);
/*
* Convolution with a kernel.

View File

@@ -592,7 +592,7 @@ class PipelineWorker : public Napi::AsyncWorker {
// Blur
if (shouldBlur) {
image = sharp::Blur(image, baton->blurSigma);
image = sharp::Blur(image, baton->blurSigma, baton->precision);
}
// Unflatten the image
@@ -1541,6 +1541,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
baton->negate = sharp::AttrAsBool(options, "negate");
baton->negateAlpha = sharp::AttrAsBool(options, "negateAlpha");
baton->blurSigma = sharp::AttrAsDouble(options, "blurSigma");
baton->precision = sharp::AttrAsEnum<VipsPrecision>(options, "precision", VIPS_TYPE_PRECISION);
baton->brightness = sharp::AttrAsDouble(options, "brightness");
baton->saturation = sharp::AttrAsDouble(options, "saturation");
baton->hue = sharp::AttrAsInt32(options, "hue");

View File

@@ -78,6 +78,7 @@ struct PipelineBaton {
bool negate;
bool negateAlpha;
double blurSigma;
VipsPrecision precision;
double brightness;
double saturation;
int hue;