mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Break existing sharpen API to accept sigma and improve precision
This commit is contained in:
@@ -135,10 +135,10 @@ namespace sharp {
|
||||
}
|
||||
|
||||
/*
|
||||
* Gaussian blur (use sigma <0 for fast blur)
|
||||
* Gaussian blur. Use sigma of -1.0 for fast blur.
|
||||
*/
|
||||
VImage Blur(VImage image, double const sigma) {
|
||||
if (sigma < 0.0) {
|
||||
if (sigma == -1.0) {
|
||||
// Fast, mild blur - averages neighbouring pixels
|
||||
VImage blur = VImage::new_matrixv(3, 3,
|
||||
1.0, 1.0, 1.0,
|
||||
@@ -153,10 +153,10 @@ namespace sharp {
|
||||
}
|
||||
|
||||
/*
|
||||
* Sharpen flat and jagged areas. Use radius of -1 for fast sharpen.
|
||||
* Sharpen flat and jagged areas. Use sigma of -1.0 for fast sharpen.
|
||||
*/
|
||||
VImage Sharpen(VImage image, int const radius, double const flat, double const jagged) {
|
||||
if (radius == -1) {
|
||||
VImage Sharpen(VImage image, double const sigma, double const flat, double const jagged) {
|
||||
if (sigma == -1.0) {
|
||||
// Fast, mild sharpen
|
||||
VImage sharpen = VImage::new_matrixv(3, 3,
|
||||
-1.0, -1.0, -1.0,
|
||||
@@ -167,7 +167,7 @@ namespace sharp {
|
||||
} else {
|
||||
// Slow, accurate sharpen in LAB colour space, with control over flat vs jagged areas
|
||||
return image.sharpen(
|
||||
VImage::option()->set("radius", radius)->set("m1", flat)->set("m2", jagged)
|
||||
VImage::option()->set("sigma", sigma)->set("m1", flat)->set("m2", jagged)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,14 @@ namespace sharp {
|
||||
VImage Gamma(VImage image, double const exponent);
|
||||
|
||||
/*
|
||||
* Gaussian blur. Use sigma of -1 for fast blur.
|
||||
* Gaussian blur. Use sigma of -1.0 for fast blur.
|
||||
*/
|
||||
VImage Blur(VImage image, double const sigma);
|
||||
|
||||
/*
|
||||
* Sharpen flat and jagged areas. Use radius of -1 for fast sharpen.
|
||||
* Sharpen flat and jagged areas. Use sigma of -1.0 for fast sharpen.
|
||||
*/
|
||||
VImage Sharpen(VImage image, int const radius, double const flat, double const jagged);
|
||||
VImage Sharpen(VImage image, double const sigma, double const flat, double const jagged);
|
||||
|
||||
/*
|
||||
Calculate crop area based on image entropy
|
||||
|
||||
@@ -444,7 +444,7 @@ class PipelineWorker : public AsyncWorker {
|
||||
|
||||
bool shouldAffineTransform = xresidual != 1.0 || yresidual != 1.0;
|
||||
bool shouldBlur = baton->blurSigma != 0.0;
|
||||
bool shouldSharpen = baton->sharpenRadius != 0;
|
||||
bool shouldSharpen = baton->sharpenSigma != 0.0;
|
||||
bool shouldThreshold = baton->threshold != 0;
|
||||
bool shouldPremultiplyAlpha = HasAlpha(image) &&
|
||||
(shouldAffineTransform || shouldBlur || shouldSharpen || hasOverlay);
|
||||
@@ -598,7 +598,7 @@ class PipelineWorker : public AsyncWorker {
|
||||
|
||||
// Sharpen
|
||||
if (shouldSharpen) {
|
||||
image = Sharpen(image, baton->sharpenRadius, baton->sharpenFlat, baton->sharpenJagged);
|
||||
image = Sharpen(image, baton->sharpenSigma, baton->sharpenFlat, baton->sharpenJagged);
|
||||
}
|
||||
|
||||
// Composite with overlay, if present
|
||||
@@ -1053,7 +1053,7 @@ NAN_METHOD(pipeline) {
|
||||
baton->flatten = attrAs<bool>(options, "flatten");
|
||||
baton->negate = attrAs<bool>(options, "negate");
|
||||
baton->blurSigma = attrAs<double>(options, "blurSigma");
|
||||
baton->sharpenRadius = attrAs<int32_t>(options, "sharpenRadius");
|
||||
baton->sharpenSigma = attrAs<double>(options, "sharpenSigma");
|
||||
baton->sharpenFlat = attrAs<double>(options, "sharpenFlat");
|
||||
baton->sharpenJagged = attrAs<double>(options, "sharpenJagged");
|
||||
baton->threshold = attrAs<int32_t>(options, "threshold");
|
||||
|
||||
@@ -51,7 +51,7 @@ struct PipelineBaton {
|
||||
bool flatten;
|
||||
bool negate;
|
||||
double blurSigma;
|
||||
int sharpenRadius;
|
||||
double sharpenSigma;
|
||||
double sharpenFlat;
|
||||
double sharpenJagged;
|
||||
int threshold;
|
||||
@@ -104,7 +104,7 @@ struct PipelineBaton {
|
||||
flatten(false),
|
||||
negate(false),
|
||||
blurSigma(0.0),
|
||||
sharpenRadius(0),
|
||||
sharpenSigma(0.0),
|
||||
sharpenFlat(1.0),
|
||||
sharpenJagged(2.0),
|
||||
threshold(0),
|
||||
|
||||
Reference in New Issue
Block a user